<commit_before><?php

/*
 * HiPanel core package
 *
 * @link      https://hipanel.com/
 * @package   hipanel-core
 * @license   BSD-3-Clause
 * @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
 */

/**
 * Created by PhpStorm.
 * User: tofid
 * Date: 11.02.15
 * Time: 17:59.
 */
namespace hipanel\behaviors;

use hipanel\models\File as FileModel;
use yii\base\Behavior;
use yii\db\BaseActiveRecord;
use yii\helpers\FileHelper;
use yii\web\UploadedFile;

class File extends Behavior
{
    /**
     * @var string the attribute which holds the attachment.
     */
    public $attribute = 'file';

    /**
     * @var array the scenarios in which the behavior will be triggered
     */
    public $scenarios = [];

    /**
     * @var string the attribute that will receive the file id
     */
    public $savedAttribute;

    /**
     * @var UploadedFile the uploaded file instance.
     */
    private $_file;

    /**
     * @return array
     */
    public function events()
    {
        return [
            BaseActiveRecord::EVENT_BEFORE_INSERT => 'saveUploadedFile',
            BaseActiveRecord::EVENT_BEFORE_UPDATE => 'saveUploadedFile',
        ];
    }

    /**
     * Event handler for beforeSave.
     * @param \yii\base\ModelEven|boolean $event
     */
    public function saveUploadedFile($event)
    {
        $model = $this->owner;
        $arr_ids = [];
        if (in_array($model->scenario, $this->scenarios, true)) {
            $this->_file = UploadedFile::getInstances($model, $this->attribute);
            if (is_array($this->_file) && !empty($this->_file)) {
                $this->owner->{$this->savedAttribute} = implode(',', FileModel::fileSave($this->_file));
                /* commented out by Tofid
                foreach ($this->_file as $file) {
                    if ($file instanceof UploadedFile) {
                        // Move to temporary destination
                        $tempDestination = FileModel::getTempFolder() . DIRECTORY_SEPARATOR . uniqid() . '.' . $file->extension;
                        FileHelper::createDirectory(dirname($tempDestination));
                        $file->saveAs($tempDestination);
                        // Prepare to final destination
                        $url = FileModel::getTmpUrl(basename($tempDestination));
                        $response =  FileModel::perform('Put', [
                            'url' => $url,
                            'filename' => basename($tempDestination)
                        ]);

                        $file_id = $arr_ids[] = $response['id'];
                        $finalDestination = $this->getPath($file_id) . DIRECTORY_SEPARATOR . $file_id;
                        FileHelper::createDirectory(dirname($finalDestination));
                        if (!rename($tempDestination, $finalDestination))
                            throw new \LogicException('rename function is not work');
                        if (is_file($tempDestination))
                            unlink($tempDestination);
                    }
                }
                $this->owner->{$this->savedAttribute} = implode(',', $arr_ids);
                */
            } else {
                // Protect attribute
                unset($model->{$this->attribute});
            }
        }
    }
}<commit_msg>Removed commented code<commit_after><?php

/*
 * HiPanel core package
 *
 * @link      https://hipanel.com/
 * @package   hipanel-core
 * @license   BSD-3-Clause
 * @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
 */

/**
 * Created by PhpStorm.
 * User: tofid
 * Date: 11.02.15
 * Time: 17:59.
 */
namespace hipanel\behaviors;

use hipanel\models\File as FileModel;
use yii\base\Behavior;
use yii\db\BaseActiveRecord;
use yii\helpers\FileHelper;
use yii\web\UploadedFile;

class File extends Behavior
{
    /**
     * @var string the attribute which holds the attachment.
     */
    public $attribute = 'file';

    /**
     * @var array the scenarios in which the behavior will be triggered
     */
    public $scenarios = [];

    /**
     * @var string the attribute that will receive the file id
     */
    public $savedAttribute;

    /**
     * @var UploadedFile the uploaded file instance.
     */
    private $_file;

    /**
     * @return array
     */
    public function events()
    {
        return [
            BaseActiveRecord::EVENT_BEFORE_INSERT => 'saveUploadedFile',
            BaseActiveRecord::EVENT_BEFORE_UPDATE => 'saveUploadedFile',
        ];
    }

    /**
     * Event handler for beforeSave.
     * @param \yii\base\ModelEvent|boolean $event
     */
    public function saveUploadedFile($event)
    {
        $model = $this->owner;
        $arr_ids = [];
        if (in_array($model->scenario, $this->scenarios, true)) {
            $this->_file = UploadedFile::getInstances($model, $this->attribute);
            if (is_array($this->_file) && !empty($this->_file)) {
                $this->owner->{$this->savedAttribute} = implode(',', FileModel::fileSave($this->_file));
            } else {
                // Protect attribute
                unset($model->{$this->attribute});
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.13217726396917148, 'fraction_numerical': 0.007321772639691715, 'mean_word_length': 1.8727172108467072, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 42, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4001342', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1454, 'n_words': 315}