Example #1
0
 /**
  * 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);
 }