Ejemplo n.º 1
0
 private function getSubFolderOf($folderId)
 {
     $folder = \admin\models\StorageFolder::find()->select(['id', 'name', 'parent_id'])->where(['id' => $folderId])->asArray()->one();
     if ($folder['parent_id'] == 0) {
         return false;
     }
     return $folder['parent_id'];
 }
Ejemplo n.º 2
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();
 }