public function deleteFolder() { if (!$this->hasPrivilege('admin.config.cache')) { return $this->noPrivilege('admin.config.cache'); } $json = []; $json['result'] = ResultType::ERROR; // check $id = Converter::int('id', 'post'); if (!isset($id)) { $json['message'] = Lang::lang('errorInvalidParameters'); return json_encode($json); } if ($id == 1) { $json['message'] = Lang::lang('cannotDeleteRootFolder'); return json_encode($json); } // check item $folder = \Rebond\Core\Folder\Data::loadById($id); if (!isset($folder)) { $json['message'] = Lang::lang('itemNotFound', [$id]); return json_encode($json); } // find all children folders $folderChildren = \Rebond\Core\Folder\Data::getChildren($id); if ($folderChildren) { foreach ($folderChildren as $folderChild) { \Rebond\Core\Folder\Data::deleteById($folderChild); \Rebond\Core\Media\Data::moveToRoot($folderChild); } } // remove folders \Rebond\Core\Folder\Data::deleteById($id); \Rebond\Core\Media\Data::moveToRoot($id); $json['result'] = ResultType::SUCCESS; $json['message'] = 'folder (and its children) deleted'; return json_encode($json); }