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'])); }); }
/** * 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; } } } }
/** * @inheritdoc */ public function rules() { $rules = parent::rules(); $rules[] = ArrayHelper::merge([['file'], 'file'], ['extensions' => implode(',', static::$extensions), 'mimeTypes' => implode(',', static::$mimeTypes)]); return $rules; }
/** * @param int|array $values * @return bool */ protected function markFilesAsTemporary($values) { return AttachmentFile::updateAll(['status_id' => AttachmentFile::STATUS_TEMPORARY], ['id' => $values]); }
public function type($type) { return $this->andWhere([AttachmentFile::tableName() . '.type' => $type]); }