/** * Delete a file * * @return void */ public function deleteTask() { // Incoming parent ID $pid = Request::getInt('pid', 0); if (!$pid) { $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_NO_ID')); $this->displayTask($pid); return; } // get tool object $obj = new \Components\Tools\Tables\Tool($this->database); $this->_toolid = $obj->getToolIdFromResource($pid); // make sure user is authorized to go further if (!$this->_checkAccess($this->_toolid)) { App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH')); return; } // Incoming child ID $id = Request::getInt('id', 0); if (!$id) { $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_NO_CHILD_ID')); $this->displayTask($pid); return; } // Load resource info $row = new \Components\Resources\Tables\Resource($this->database); $row->load($id); // Check for stored file if ($row->path == '') { $this->setError(Lang::txt('COM_TOOLS_ERROR_MISSING_FILE_PATH')); $this->displayTask($pid); return; } // Get resource path include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php'; $listdir = \Components\Resources\Helpers\Html::build_path($row->created, $id, ''); // Build the path $path = $this->_buildUploadPath($listdir, ''); // Check if the folder even exists if (!is_dir($path) or !$path) { $this->setError(Lang::txt('COM_TOOLS_DIRECTORY_NOT_FOUND')); } else { // Attempt to delete the file if (!Filesystem::deleteDirectory($path)) { $this->setError(Lang::txt('COM_TOOLS_UNABLE_TO_DELETE_DIRECTORY')); } // Delete associations to the resource $row->deleteExistence(); // Delete resource $row->delete(); } // Push through to the attachments view $this->displayTask($pid); }
/** * Copy files * * @return void */ public function copyTask() { $version = Request::getVar('version', 'dev'); $rid = Request::getInt('rid', 0); $from = $version == 'dev' ? 'current' : 'dev'; // get admin priviliges $this->_authorize(); // Get version id $objV = new \Components\Tools\Tables\Version($this->database); $to = $objV->getVersionIdFromResource($rid, $version); $from = $objV->getVersionIdFromResource($rid, $from); // get tool id $obj = new \Components\Tools\Tables\Tool($this->database); $toolid = $obj->getToolIdFromResource($rid); if ($from == 0 or $to == 0 or $rid == 0) { App::abort(500, Lang::txt('COM_TOOLS_CONTRIBUTE_NO_ID')); return; } if ($toolid && $this->_checkAccess($toolid)) { if ($this->transfer($from, $to, $rid)) { // Push through to the screenshot view $this->displayTask($rid, $version); } } }