/** * Unpublish version/delete draft * * @return string */ public function cancelDraft() { // Incoming $pid = $this->_pid ? $this->_pid : Request::getInt('pid', 0); $confirm = Request::getInt('confirm', 0); $version = Request::getVar('version', 'default'); $ajax = Request::getInt('ajax', 0); // Check permission if (!$this->model->access('content')) { throw new Exception(Lang::txt('ALERTNOTAUTH'), 403); return; } // Load publication model $pub = new \Components\Publications\Models\Publication($pid, $version); if (!$pub->exists() || !$pub->belongsToProject($this->model->get('id'))) { throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_NOT_FOUND'), 404); return; } // Save version ID $vid = $pub->version->get('id'); // Append breadcrumbs if (!$ajax) { Pathway::append(stripslashes($pub->version->get('title')), $pub->link('edit')); } $baseUrl = Route::url($pub->link('editbase')); $baseEdit = Route::url($pub->link('edit')); // Can only unpublish published version or delete a draft if ($pub->version->get('state') != 1 && $pub->version->get('state') != 3 && $pub->version->get('state') != 4) { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_CANT_DELETE')); } // Unpublish/delete version if ($confirm) { if (!$this->getError()) { $pubtitle = \Hubzero\Utility\String::truncate($pub->version->get('title'), 100); if ($pub->version->get('state') == 1) { // Unpublish published version $pub->version->set('published_down', Date::toSql()); $pub->version->set('modified', Date::toSql()); $pub->version->set('modified_by', $this->_uid); $pub->version->set('state', 0); if (!$pub->version->store()) { throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_UNPUBLISH_FAILED'), 403); return; } else { $this->_msg = Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_UNPUBLISHED'); // Add activity $action = Lang::txt('PLG_PROJECTS_PUBLICATIONS_ACTIVITY_UNPUBLISHED'); $action .= ' ' . strtolower(Lang::txt('version')) . ' ' . $pub->version->get('version_label') . ' ' . Lang::txt('PLG_PROJECTS_PUBLICATIONS_OF') . ' ' . strtolower(Lang::txt('publication')) . ' "' . $pubtitle . '" '; $aid = $this->model->recordActivity($action, $pid, $pubtitle, Route::url($pub->link('editversion')), 'publication', 0); } } elseif ($pub->version->get('state') == 3 || $pub->version->get('state') == 4) { $vlabel = $pub->version->get('version_label'); // Delete draft version if (!$pub->version->delete()) { throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_DELETE_DRAFT_FAILED'), 403); return; } // Delete authors $pa = new \Components\Publications\Tables\Author($this->_database); $authors = $pa->deleteAssociations($vid); // Delete attachments $pContent = new \Components\Publications\Tables\Attachment($this->_database); $pContent->deleteAttachments($vid); // Delete screenshots $pScreenshot = new \Components\Publications\Tables\Screenshot($this->_database); $pScreenshot->deleteScreenshots($vid); // Build publication path $path = PATH_APP . DS . trim($this->_pubconfig->get('webpath'), DS) . DS . \Hubzero\Utility\String::pad($pid); // Build version path $vPath = $path . DS . \Hubzero\Utility\String::pad($vid); // Delete all version files if (is_dir($vPath)) { Filesystem::deleteDirectory($vPath); } // Delete access accosiations $pAccess = new \Components\Publications\Tables\Access($this->_database); $pAccess->deleteGroups($vid); // Delete audience $pAudience = new \Components\Publications\Tables\Audience($this->_database); $pAudience->deleteAudience($vid); // Delete publication existence if ($pub->versionCount() == 0) { // Delete all files if (is_dir($path)) { Filesystem::delete($path); } $pub->publication->delete($pid); $pub->publication->deleteExistence($pid); // Delete related publishing activity from feed $objAA = $this->model->table('Activity'); $objAA->deleteActivityByReference($this->model->get('id'), $pid, 'publication'); } // Add activity $action = Lang::txt('PLG_PROJECTS_PUBLICATIONS_ACTIVITY_DRAFT_DELETED'); $action .= ' ' . $vlabel . ' '; $action .= Lang::txt('PLG_PROJECTS_PUBLICATIONS_OF_PUBLICATION') . ' "' . $pubtitle . '"'; $aid = $this->model->recordActivity($action, $pid, '', '', 'publication', 0); $this->_msg = Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_DRAFT_DELETED'); } } } else { $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => 'cancel')); // Output HTML $view->option = $this->_option; $view->database = $this->_database; $view->project = $this->model; $view->uid = $this->_uid; $view->pid = $pid; $view->pub = $pub; $view->publishedCount = $pub->version->getPublishedCount($pid); $view->task = $this->_task; $view->config = $this->model->config(); $view->pubconfig = $this->_pubconfig; $view->ajax = $ajax; $view->title = $this->_area['title']; // Get messages and errors $view->msg = $this->_msg; if ($this->getError()) { $view->setError($this->getError()); } return $view->loadTemplate(); } // Pass error or success message if ($this->getError()) { \Notify::message($this->getError(), 'error', 'projects'); } elseif (!empty($this->_msg)) { \Notify::message($this->_msg, 'success', 'projects'); } App::redirect($baseUrl); return; }
/** * Issue master DOI for publications if does not exist * * @param $job \Components\Cron\Models\Job * @return boolean */ public function issueMasterDoi(\Components\Cron\Models\Job $job) { $database = \App::get('db'); $config = Component::params('com_publications'); // Is config to issue master DOI turned ON? if (!$config->get('master_doi')) { return true; } // Get all publications without master DOI $sql = "SELECT V.* FROM #__publication_versions as V, #__publications as C"; $sql .= " WHERE C.id=V.publication_id AND (C.master_doi IS NULL OR master_doi=0)"; $sql .= " AND V.state=1 GROUP BY C.id ORDER BY V.version_number ASC"; $database->setQuery($sql); if (!($rows = $database->loadObjectList())) { // No applicable results return true; } include_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'models' . DS . 'publication.php'; // Get DOI service $doiService = new \Components\Publications\Models\Doi(); // Is service enabled? if (!$doiService->on() || !$doiService->_configs->livesite) { return true; } // Go through records foreach ($rows as $row) { // Load publication model $model = new \Components\Publications\Models\Publication($row->publication_id, $row->id); // Check to make sure we got result if (!$model->exists()) { continue; } // Map publication $doiService->mapPublication($model); // Build url $pointer = $model->publication->alias ? $model->publication->alias : $model->publication->id; $url = $doiService->_configs->livesite . DS . 'publications' . DS . $pointer . DS . 'main'; // Master DOI should link to /main $doiService->set('url', $url); // Register DOI $masterDoi = $doiService->register(); // Save with publication record if ($masterDoi) { $model->publication->master_doi = strtoupper($masterDoi); $model->publication->store(); } } return true; }