示例#1
0
 /**
  *
  * 1. get all files from storage folder
  * 2. check each db entry if not available in file list and set is_deleted = 1
  *
  * @return int count of flagged 'is_deleted' entries
  */
 public static function removeMissingStorageFiles()
 {
     $storageFileList = static::getFindFilesDirectory();
     if (!$storageFileList) {
         return false;
     }
     // check storage files
     $allStorageFileEntries = StorageFile::find()->where(['is_deleted' => 0])->indexBy('id')->all();
     $count = 0;
     foreach ($allStorageFileEntries as $dbfile) {
         $found = false;
         foreach ($storageFileList as $key => $file) {
             if ($dbfile['name_new_compound'] == pathinfo($file, PATHINFO_BASENAME)) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             $dbfile->is_deleted = 1;
             $count++;
             $dbfile->update(false);
         }
     }
     return $count;
 }
示例#2
0
 public static function removeFile($fileId)
 {
     $model = StorageFile::find()->where(['id' => $fileId, 'is_deleted' => 0])->one();
     if ($model) {
         return $model->delete();
     }
     return true;
 }
示例#3
0
 /**
  * 
  * @param integer $fileId The file id to delete
  * @param boolean $cleanup If cleanup is enabled, also all images will be deleted, this is by default turned off because
  * casual you want to remove the large source file but not the images where used in several tables and situations.
  * @return boolean
  */
 public static function removeFile($fileId, $cleanup = false)
 {
     $model = StorageFile::find()->where(['id' => $fileId, 'is_deleted' => 0])->one();
     if ($model) {
         if ($cleanup) {
             foreach (Yii::$app->storage->findImages(['file_id' => $fileId]) as $imageItem) {
                 StorageImage::findOne($imageItem->id)->delete();
             }
         }
         return $model->delete();
     }
     return true;
 }
示例#4
0
 /**
  *
  * 1. get all files from storage folder
  * 2. check each image/filter db entry if not available in file list and remove them from 'admin_storage_image'
  *
  * @return int count of removed entries
  */
 public static function removeMissingImageFiles()
 {
     $storageFileList = static::getFindFilesDirectory();
     if (!$storageFileList) {
         return false;
     }
     // check storage files
     $allStorageFileEntries = StorageFile::find()->indexBy('id')->all();
     $count = 0;
     // check image filter files
     $imageList = StorageImage::find()->all();
     foreach ($imageList as $image) {
         if (array_key_exists($image['file_id'], $allStorageFileEntries)) {
             $filterImage = $image['filter_id'] . '_' . $allStorageFileEntries[$image['file_id']]['name_new_compound'];
             $found = false;
             foreach ($storageFileList as $key => $file) {
                 if ($filterImage == pathinfo($file, PATHINFO_BASENAME)) {
                     $found = true;
                     break;
                 }
             }
             if (!$found) {
                 $image->delete();
                 $count++;
             }
         }
     }
     return $count;
 }
示例#5
0
文件: File.php 项目: efueger/luya
 public function getInfo($fileId)
 {
     return StorageFile::find()->where(['id' => $fileId, 'is_deleted' => 0])->one();
 }
示例#6
0
 /**
  * delete folder, all subfolders and all included files.
  *
  * 1. search another folders with matching parentIds and call deleteFolder on them
  * 2. get all included files and delete them
  * 3. delete folder
  *
  * @param int $folderId
  * @todo move to storage helpers?
  * @return bool
  */
 public function actionFolderDelete($folderId)
 {
     // find all subfolders
     $matchingChildFolders = StorageFolder::find()->where(['parent_id' => $folderId])->asArray()->all();
     foreach ($matchingChildFolders as $matchingChildFolder) {
         $this->actionFolderDelete($matchingChildFolder['id']);
     }
     // find all attached files and delete them
     $folderFiles = StorageFile::find()->where(['folder_id' => $folderId])->all();
     foreach ($folderFiles as $folderFile) {
         $folderFile->delete();
     }
     // delete folder
     $model = StorageFolder::findOne($folderId);
     if (!$model) {
         return false;
     }
     $model->is_deleted = true;
     return $model->update();
 }