コード例 #1
0
 public function testValidation()
 {
     /**
      * @property integer $id
      * @property integer $user_id
      * @property string $name
      * @property string $uri
      * @property string $mime
      * @property integer $size
      * @property string $type
      * @property integer $status_id
      * @property integer $created_at
      * @property integer $updated_at
      */
     /** @var $model */
     $model = new AttachmentFile();
     $this->specify('name is required', function () use($model) {
         $model->name = null;
         $this->assertFalse($model->validate(['name']));
     });
     $this->specify('uri is required', function () use($model) {
         $model->uri = null;
         $this->assertFalse($model->validate(['uri']));
     });
 }
コード例 #2
0
 /**
  * Clear temporary files
  */
 public function actionClear()
 {
     $query = AttachmentFile::find()->temporary();
     foreach ($query->batch(10) as $models) {
         /** @var AttachmentFile $model */
         foreach ($models as $model) {
             $url = $model->filePath;
             if ($model->delete()) {
                 $this->stdout('File ');
                 $this->stdout($url, Console::FG_YELLOW);
                 $this->stdout(' deleted');
                 echo PHP_EOL;
             }
         }
     }
 }
コード例 #3
0
ファイル: ImageFile.php プロジェクト: artkost/yii2-attachment
 /**
  * @inheritdoc
  */
 public function rules()
 {
     $rules = parent::rules();
     $rules[] = ArrayHelper::merge([['file'], 'file'], ['extensions' => implode(',', static::$extensions), 'mimeTypes' => implode(',', static::$mimeTypes)]);
     return $rules;
 }
コード例 #4
0
 /**
  * @param int|array $values
  * @return bool
  */
 protected function markFilesAsTemporary($values)
 {
     return AttachmentFile::updateAll(['status_id' => AttachmentFile::STATUS_TEMPORARY], ['id' => $values]);
 }
コード例 #5
0
 public function type($type)
 {
     return $this->andWhere([AttachmentFile::tableName() . '.type' => $type]);
 }