/** * Delete a screenshot * * @return void */ public function deleteTask() { // Incoming parent ID $pid = Request::getInt('pid', 0); $version = Request::getVar('version', 'dev'); if (!$pid) { $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_NO_ID')); $this->displayTask($pid, $version); return; } // Incoming child ID $file = Request::getVar('filename', ''); if (!$file) { $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_NO_CHILD_ID')); $this->displayTask($pid, $version); return; } // Load resource info $row = new \Components\Resources\Tables\Resource($this->database); $row->load($pid); // Get version id $objV = new \Components\Tools\Tables\Version($this->database); $vid = $objV->getVersionIdFromResource($pid, $version); if ($vid == NULL) { $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_VERSION_ID_NOT_FOUND')); $this->displayTask($pid, $version); return; } include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php'; // Build the path $listdir = \Components\Resources\Helpers\Html::build_path($row->created, $pid, ''); $listdir .= DS . $vid; $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')); $this->displayTask($pid, $version); return; } else { if (!Filesystem::exists($path . DS . $file)) { $this->displayTask($pid, $version); return; } if (!Filesystem::delete($path . DS . $file)) { $this->setError(Lang::txt('COM_TOOLS_UNABLE_TO_DELETE_FILE')); $this->displayTask($pid, $version); return; } else { // Delete thumbnail $tn = \Components\Resources\Helpers\Html::thumbnail($file); Filesystem::delete($path . DS . $tn); // Instantiate a new screenshot object $ss = new \Components\Resources\Tables\Screenshot($this->database); $ss->deleteScreenshot($file, $pid, $vid); } } $this->_rid = $pid; // Push through to the screenshot view $this->displayTask($pid, $version); }