示例#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;
 }
示例#2
0
 /**
  * Get user data from log file
  *
  * @return     void
  */
 public function digestLogs($pid = NULL, $type = 'view', $numMonths = 1, $includeCurrent = false)
 {
     if (!$pid) {
         return false;
     }
     $stats = array('unique' => array(), 'filtered' => array());
     $types = $type == 'all' ? array('view', 'primary') : array($type);
     // Get all public versions
     $row = new Tables\Version($this->_db);
     $versions = $row->getVersions($pid, $filters = array('public' => 1));
     if (!$versions) {
         return $stats;
     }
     // Collect data for each version
     foreach ($versions as $version) {
         $logPath = $this->getLogPath($pid, $version->id);
         if (!$logPath) {
             continue;
         }
         $n = $includeCurrent ? 0 : 1;
         for ($a = $numMonths; $a >= $n; $a--) {
             $yearNum = intval(date('y', strtotime("-" . $a . " month")));
             $monthNum = intval(date('m', strtotime("-" . $a . " month")));
             $date = date('Y-m', strtotime("-" . $a . " month"));
             $logFile = 'pub-' . $pid . '-v-' . $version->id . '.' . $date . '.log';
             $fpath = $logPath . DS . $logFile;
             $mo = date('M', strtotime("-" . $a . " month"));
             $pubLog = new $this->_tbl_name($this->_db);
             foreach ($types as $type) {
                 if (!trim($type)) {
                     continue;
                 }
                 if (!isset($stats['unique'][$type])) {
                     $stats['unique'][$type] = array();
                 }
                 if (!isset($stats['filtered'][$type])) {
                     $stats['filtered'][$type] = array();
                 }
                 if (!isset($stats['unique'][$type][$mo])) {
                     $stats['unique'][$type][$mo] = 0;
                 }
                 if (!isset($stats['filtered'][$type][$mo])) {
                     $stats['filtered'][$type][$mo] = 0;
                 }
                 if (is_file($fpath)) {
                     // Get count of unique views/accesses
                     $count = $this->parseLog($pubLog, $fpath, $type);
                     $stats['unique'][$type][$mo] = $stats['unique'][$type][$mo] + $count;
                     // Log unique
                     $pubLog->logParsed($pid, $version->id, date('y', strtotime($date)), date('m', strtotime($date)), $count, $type, 'unique');
                     // Get filtered count
                     $count = $this->parseLog($pubLog, $fpath, $type, 'filtered');
                     $stats['filtered'][$type][$mo] = $stats['filtered'][$type][$mo] + $count;
                     // Log filtered
                     $pubLog->logParsed($pid, $version->id, date('y', strtotime($date)), date('m', strtotime($date)), $count, $type, 'filtered');
                 }
             }
         }
     }
     return $stats;
 }
示例#3
0
 /**
  * Save version label
  *
  * @param      int $uid
  * @return     boolean
  */
 public function saveVersionLabel($uid = 0)
 {
     if (!$this->_pub) {
         return false;
     }
     $row = new Tables\Version($this->_db);
     // Incoming
     $label = trim(Request::getVar('label', '', 'post'));
     $used_labels = $row->getUsedLabels($this->_pub->id, $this->_pub->version_number);
     if ($label && in_array($label, $used_labels)) {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_LABEL_USED'));
         return false;
     } elseif ($label) {
         if (!$row->loadVersion($this->_pub->id, $this->_pub->version_number)) {
             $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_LABEL_ERROR'));
             return false;
         }
         $row->version_label = $label;
         if (!$row->store()) {
             $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_LABEL_ERROR'));
         }
     }
     // Success message
     $this->set('_message', Lang::txt('PLG_PROJECTS_PUBLICATIONS_VERSION_LABEL_SAVED'));
     return true;
 }