/**
  * @inheritdoc
  */
 public function run()
 {
     $models = StorageItem::find()->all();
     $results = [];
     if (Yii::$app->controller->module->webAccessUrl === false) {
         foreach ($models as $model) {
             $filePath = Yii::$app->controller->module->getFilePath($model->file_path);
             $url = Url::to(['view', 'id' => $model->id]);
             $fileName = pathinfo($filePath, PATHINFO_FILENAME);
             $results[] = $this->createEntry($filePath, $url, $fileName);
         }
     } else {
         $onlyExtensions = array_map(function ($ext) {
             return '*.' . $ext;
         }, Yii::$app->controller->module->imageAllowedExtensions);
         $filesPath = FileHelper::findFiles(Yii::$app->controller->module->getStorageDir(), ['recursive' => true, 'only' => $onlyExtensions]);
         if (is_array($filesPath) && count($filesPath)) {
             foreach ($filesPath as $filePath) {
                 $url = Yii::$app->controller->module->getUrl(pathinfo($filePath, PATHINFO_BASENAME));
                 $fileName = pathinfo($filePath, PATHINFO_FILENAME);
                 $results[] = $this->createEntry($filePath, $url, $fileName);
             }
         }
     }
     return $results;
 }
 /**
  * Finds the StorageItem model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return StorageItem the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = StorageItem::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * @return boolean
  */
 public function upload()
 {
     if ($this->validate()) {
         if (Yii::$app->controller->module->databaseStorage === true || Yii::$app->controller->module->databaseStorage !== false && Yii::$app->controller->module->webAccessUrl === false) {
             $this->_model = new StorageItem();
             $this->_model->mime_type = $this->file->type;
             $this->_model->file_path = $this->getFileName();
             if (!$this->_model->save()) {
                 return false;
             }
         }
         if (!$this->file->saveAs(Yii::$app->controller->module->getFilePath($this->getFileName()), true)) {
             $this->_model->delete();
             return false;
         }
         return true;
     }
     return false;
 }