Example #1
0
 /**
  * Erases all project information (to be used for test projects only)
  *
  * @return     void
  */
 public function eraseTask()
 {
     $id = Request::getVar('id', 0);
     $permanent = 1;
     // Initiate extended database class
     $obj = new Tables\Project($this->database);
     if (!$id or !$obj->loadProject($id)) {
         App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('COM_PROJECTS_NOTICE_ID_NOT_FOUND'), 'error');
         return;
     }
     // Get project group
     $group_prefix = $this->config->get('group_prefix', 'pr-');
     $prGroup = $group_prefix . $obj->alias;
     // Store project info
     $alias = $obj->alias;
     $identifier = $alias;
     // Delete project
     $obj->delete();
     // Erase all owners
     $objO = new Tables\Owner($this->database);
     $objO->removeOwners($id, '', 0, $permanent, '', $all = 1);
     // Erase owner group
     $group = new \Hubzero\User\Group();
     $group->read($prGroup);
     if ($group) {
         $group->delete();
     }
     // Erase all comments
     $objC = new Tables\Comment($this->database);
     $objC->deleteProjectComments($id, $permanent);
     // Erase all activities
     $objA = new Tables\Activity($this->database);
     $objA->deleteActivities($id, $permanent);
     // Erase all todos
     $objTD = new Tables\Todo($this->database);
     $objTD->deleteTodos($id, '', $permanent);
     // Erase all blog entries
     $objB = new Tables\Blog($this->database);
     $objB->deletePosts($id, $permanent);
     // Erase all notes
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'attachment.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'author.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'comment.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'log.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'page.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'revision.php';
     $masterscope = 'projects' . DS . $alias . DS . 'notes';
     // Get all notes
     $this->database->setQuery("SELECT DISTINCT p.id FROM #__wiki_page AS p\n\t\t\tWHERE p.group_cn=" . $this->database->quote($prGroup) . " AND p.scope LIKE '" . $masterscope . "%' ");
     $notes = $this->database->loadObjectList();
     if ($notes) {
         foreach ($notes as $note) {
             $page = new \Components\Wiki\Tables\Page($this->database);
             // Delete the page's history, tags, comments, etc.
             $page->deleteBits($note->id);
             // Finally, delete the page itself
             $page->delete($note->id);
         }
     }
     // Erase all files, remove files repository
     if ($alias) {
         // Delete base dir for .git repos
         $dir = $alias;
         $prefix = $this->config->get('offroot', 0) ? '' : PATH_CORE;
         $repodir = DS . trim($this->config->get('webpath'), DS);
         $path = $prefix . $repodir . DS . $dir;
         if (is_dir($path)) {
             Filesystem::deleteDirectory($path);
         }
         // Delete images/preview directories
         $webdir = DS . trim($this->config->get('imagepath', '/site/projects'), DS);
         $webpath = PATH_APP . $webdir . DS . $dir;
         if (is_dir($webpath)) {
             Filesystem::deleteDirectory($webpath);
         }
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('COM_PROJECTS_PROJECT') . ' #' . $id . ' (' . $alias . ') ' . Lang::txt('COM_PROJECTS_PROJECT_ERASED'));
 }