示例#1
0
 /**
  * Removes a publication
  * Redirects to main listing
  *
  * @return  void
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $ids = Request::getVar('id', array(0));
     $erase = Request::getInt('erase', 1);
     // Ensure we have some IDs to work with
     if (count($ids) < 1) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_PUBLICATIONS_ERROR_LOAD_PUBLICATION'), 'notice');
         return;
     }
     $version = count($ids) == 1 ? Request::getVar('version', 'all') : 'all';
     require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'tables' . DS . 'activity.php';
     foreach ($ids as $id) {
         // Load publication
         $objP = new Tables\Publication($this->database);
         if (!$objP->load($id)) {
             throw new Exception(Lang::txt('COM_PUBLICATIONS_NOT_FOUND'), 404);
         }
         $projectId = $objP->project_id;
         $row = new Tables\Version($this->database);
         // Get versions
         $versions = $row->getVersions($id, $filters = array('withdev' => 1));
         if ($version != 'all' && count($versions) > 1) {
             // Check that version exists
             $version = $row->checkVersion($id, $version) ? $version : 'dev';
             // Load version
             if (!$row->loadVersion($id, $version)) {
                 throw new Exception(Lang::txt('COM_PUBLICATIONS_VERSION_NOT_FOUND'), 404);
             }
             // Cannot delete main version if other versions exist
             if ($row->main) {
                 throw new Exception(Lang::txt('COM_PUBLICATIONS_VERSION_MAIN_ERROR_DELETE'), 404);
             }
             if ($erase == 1) {
                 // Delete the version
                 if ($row->delete()) {
                     // Delete associations to the version
                     $this->deleteVersionExistence($row->id, $id);
                 }
             } else {
                 $row->state = 2;
                 $row->store();
             }
         } else {
             // Delete all versions
             $i = 0;
             foreach ($versions as $v) {
                 $objV = new Tables\Version($this->database);
                 if ($objV->loadVersion($id, $v->version_number)) {
                     if ($erase == 1) {
                         // Delete the version
                         if ($objV->delete()) {
                             // Delete associations to the version
                             $this->deleteVersionExistence($v->id, $id);
                             $i++;
                         }
                     } else {
                         $objV->state = 2;
                         $objV->store();
                     }
                 }
             }
             // All versions deleted?
             if ($i == count($versions)) {
                 // Delete pub record and all associations
                 $objP->delete($id);
                 $objP->deleteExistence($id);
                 // Delete related publishing activity from feed
                 $objAA = new \Components\Projects\Tables\Activity($this->database);
                 $objAA->deleteActivityByReference($projectId, $id, 'publication');
                 // Build publication path
                 $path = PATH_APP . DS . trim($this->config->get('webpath'), DS) . DS . \Hubzero\Utility\String::pad($id);
                 // Delete all files
                 if (is_dir($path)) {
                     Filesystem::deleteDirectory($path);
                 }
             }
         }
     }
     // Redirect
     $output = $version != 'all' ? Lang::txt('COM_PUBLICATIONS_SUCCESS_VERSION_DELETED') : Lang::txt('COM_PUBLICATIONS_SUCCESS_RECORDS_DELETED') . ' (' . count($ids) . ')';
     App::redirect($this->buildRedirectURL(), $output);
     return;
 }