Esempio n. 1
0
 /**
  * Issue master DOI for tool resources if does not exist
  *
  * @param   object   $job  \Components\Cron\Models\Job
  * @return  boolean
  */
 public function issueResourceMasterDoi(\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 tool resources without master DOI
     $sql = "SELECT r.id, r.created_by, v.id as tool_version_id,\n\t\t\t\tv.toolid, v.toolname, v.title, v.description,\n\t\t\t\tv.instance, v.revision, v.released\n\t\t\t\tFROM #__resources AS r, #__tool_version AS v\n\t\t\t\tWHERE r.published=1\n\t\t\t\tAND r.type=7\n\t\t\t\tAND r.standalone=1\n\t\t\t\tAND r.alias=v.toolname\n\t\t\t\tAND v.state=1\n\t\t\t\tAND (r.master_doi IS NULL OR r.master_doi=0)\n\t\t\t\tGROUP BY r.id\n\t\t\t\tORDER BY v.title, v.toolname, v.revision DESC";
     $database->setQuery($sql);
     if (!($rows = $database->loadObjectList())) {
         // No applicable results
         return true;
     }
     // Includes
     require_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'resource.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'models' . DS . 'doi.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) {
         // Reset metadata
         $doiService->reset();
         // Map data
         $pubYear = $row->released && $row->released != '0000-00-00 00:00:00' ? gmdate('Y', strtotime($row->released)) : gmdate('Y');
         $doiService->set('pubYear', $pubYear);
         $doiService->mapUser($row->created_by, array(), 'creator');
         $doiService->set('resourceType', 'Software');
         $doiService->set('title', htmlspecialchars(stripslashes($row->title)));
         $doiService->set('url', $doiService->_configs->livesite . DS . 'resources' . DS . $row->toolname . DS . 'main');
         // Register DOI
         $masterDoi = $doiService->register();
         // Save with publication record
         $resource = new \Components\Resources\Tables\Resource($database);
         if ($masterDoi && $resource->load($row->id)) {
             $resource->master_doi = strtoupper($masterDoi);
             $resource->store();
         }
     }
     return true;
 }
Esempio n. 2
0
 /**
  * Approve publication
  *
  * @return  void
  */
 public function approveTask()
 {
     // Incoming
     $pid = $this->_id ? $this->_id : Request::getInt('id', 0);
     $vid = Request::getInt('vid', 0);
     // Load publication model
     $this->_pub = new \Components\Publications\Models\Publication($pid, NULL, $vid);
     if (!$this->_pub->exists()) {
         throw new Exception(Lang::txt('COM_PUBLICATIONS_NOT_FOUND'), 404);
     }
     // Check authorization
     if (!$this->_pub->access('curator')) {
         if (User::isGuest()) {
             $this->_msg = Lang::txt('COM_PUBLICATIONS_CURATION_LOGIN');
             $this->_login();
             return;
         }
         throw new Exception(Lang::txt('COM_PUBLICATIONS_CURATION_ERROR_UNAUTHORIZED'), 403);
     }
     $this->_pub->version->set('state', 1);
     $this->_pub->version->set('accepted', Date::toSql());
     $this->_pub->version->set('reviewed', Date::toSql());
     $this->_pub->version->set('reviewed_by', User::get('id'));
     // Archive (mkAIP) if no grace period and not previously archived
     if (!$this->getError() && !$this->config->get('graceperiod', 0) && $this->_pub->version->doi && \Components\Publications\Helpers\Utilities::mkAip($this->_pub->version) && !$this->_pub->archived()) {
         $this->_pub->version->set('archived', Date::toSql());
     }
     // Set curation
     $this->_pub->setCuration();
     $curation = json_encode($this->_pub->_curationModel->_manifest);
     //$curation = $this->_pub->masterType()->curation;
     // Get manifest version
     $versionNumber = $this->_pub->_curationModel->checkCurationVersion();
     // Store curation manifest
     $this->_pub->version->set('curation', $curation);
     $this->_pub->version->set('curation_version_id', $versionNumber);
     if (!$this->_pub->version->store()) {
         throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_FAILED'), 403);
     }
     // Get DOI service
     $doiService = new \Components\Publications\Models\Doi($this->_pub);
     if ($this->_pub->version->doi) {
         $doiService->update($this->_pub->version->doi, true);
     }
     // Mark as curated
     $this->_pub->saveParam('curated', 1);
     // On after status change
     $this->onAfterStatusChange();
     $message = $this->getError() ? $this->getError() : Lang::txt('COM_PUBLICATIONS_CURATION_SUCCESS_APPROVED');
     $class = $this->getError() ? 'error' : 'success';
     // Redirect to main listing
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=curation'), $message, $class);
     return;
 }
Esempio n. 3
0
 /**
  * Change publication status
  *
  * @return     string
  */
 public function publishDraft()
 {
     // Incoming
     $pid = $this->_pid ? $this->_pid : Request::getInt('pid', 0);
     $confirm = Request::getInt('confirm', 0);
     $version = Request::getVar('version', 'dev');
     $agree = Request::getInt('agree', 0);
     $pubdate = Request::getVar('publish_date', '', 'post');
     $submitter = Request::getInt('submitter', $this->_uid, 'post');
     $notify = 1;
     $block = Request::getVar('section', '');
     $blockId = Request::getInt('step', 0);
     $element = Request::getInt('element', 0);
     // Check permission
     if (!$this->model->access('content')) {
         throw new Exception(Lang::txt('ALERTNOTAUTH'), 403);
         return;
     }
     // Load review step
     if (!$confirm && $this->_task != 'revert') {
         $this->_task = 'review';
         return $this->editDraft();
     }
     // Load publication model
     $pub = new \Components\Publications\Models\Publication($pid, $version);
     // Error loading publication record
     if (!$pub->exists()) {
         \Notify::message(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_NOT_FOUND'), 'error', 'projects');
         App::redirect(Route::url($pub->link('editbase')));
         return;
     }
     // Agreement to terms is required
     if ($confirm && !$agree) {
         \Notify::message(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_REVIEW_AGREE_TERMS_REQUIRED'), 'error', 'projects');
         App::redirect(Route::url($pub->link('editversion') . '&action=' . $this->_task));
         return;
     }
     // Check against quota
     if ($this->_overQuota()) {
         \Notify::message(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_NO_DISK_SPACE'), 'error', 'projects');
         App::redirect(Route::url($pub->link('editversion') . '&action=' . $this->_task));
         return;
     }
     // Set curation
     $pub->setCuration();
     // Require DOI?
     $requireDoi = isset($pub->_curationModel->_manifest->params->require_doi) ? $pub->_curationModel->_manifest->params->require_doi : 0;
     // Make sure the publication belongs to the project
     if (!$pub->belongsToProject($this->model->get('id'))) {
         Notify::message(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_PROJECT_ASSOC'), 'error', 'projects');
         App::redirect(Route::url($this->model->link('publications')));
         return;
     }
     // Check that version label was not published before
     $used_labels = $pub->version->getUsedLabels($pid, $version);
     if (!$pub->version->version_label || in_array($pub->version->version_label, $used_labels)) {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_LABEL_USED'));
     }
     // Is draft complete?
     if (!$pub->curation('complete') && $this->_task != 'revert') {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_NOT_ALLOWED'));
     }
     // Is revert allowed?
     $revertAllowed = $this->_pubconfig->get('graceperiod', 0);
     if ($revertAllowed && $pub->version->state == 1 && $pub->version->accepted && $pub->version->accepted != '0000-00-00 00:00:00') {
         $monthFrom = Date::of($pub->version->accepted . '+1 month')->toSql();
         if (strtotime($monthFrom) < strtotime(Date::of())) {
             $revertAllowed = 0;
         }
     }
     // Embargo?
     if ($pubdate) {
         $pubdate = $this->_parseDate($pubdate);
         $tenYearsFromNow = Date::of(strtotime("+10 years"))->toSql();
         // Stop if more than 10 years from now
         if ($pubdate > $tenYearsFromNow) {
             $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_ERROR_EMBARGO'));
         }
     }
     // Contact info is required for repositories
     if ($pub->config()->get('repository')) {
         $contact = Request::getVar('contact', array(), 'post');
         if (!$contact || empty($contact)) {
             $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_ERROR_CONTACT_INFO_MISSING'));
         }
         $db = \App::get('db');
         foreach ($contact as $key) {
             $author = new \Components\Publications\Tables\Author($db);
             if (!$author->load($key)) {
                 $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_ERROR_CONTACT_NOT_FOUND'));
                 continue;
             }
             $author->repository_contact = 1;
             if (!$author->store()) {
                 $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_ERROR_CONTACT_NOT_SAVED'));
             }
         }
     }
     // Main version?
     $main = $this->_task == 'republish' ? $pub->version->main : 1;
     $main_vid = $pub->version->getMainVersionId($pid);
     // current default version
     // Save version before changes
     $originalStatus = $pub->version->state;
     // Checks
     if ($this->_task == 'republish' && $pub->version->state != 0) {
         // Can only re-publish unpublished version
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_CANNOT_REPUBLISH'));
     } elseif ($this->_task == 'revert' && $pub->version->state != 5 && !$revertAllowed) {
         // Can only revert a pending resource
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_CANNOT_REVERT'));
     }
     // On error
     if ($this->getError()) {
         \Notify::message($this->getError(), 'error', 'projects');
         App::redirect(Route::url($pub->link('editversion') . '&action=' . $this->_task));
         return;
     }
     // Determine state
     $state = 5;
     // Default - pending approval
     if ($this->_task == 'share' || $this->_task == 'revert') {
         $state = 4;
         // No approval needed
     } elseif ($this->_task == 'republish') {
         $state = 1;
         // No approval needed
     } else {
         $pub->version->set('submitted', Date::toSql());
         // Save submitter
         $pa = new \Components\Publications\Tables\Author($this->_database);
         $pa->saveSubmitter($pub->version->id, $submitter, $this->model->get('id'));
         if ($this->_pubconfig->get('autoapprove') == 1) {
             $state = 1;
         } else {
             $apu = $this->_pubconfig->get('autoapproved_users');
             $apu = explode(',', $apu);
             $apu = array_map('trim', $apu);
             if (in_array(User::get('username'), $apu)) {
                 // Set status to published
                 $state = 1;
             } else {
                 // Set status to pending review (submitted)
                 $state = 5;
             }
         }
     }
     // Save state
     $pub->version->set('state', $state);
     $pub->version->set('main', $main);
     if ($this->_task != 'revert') {
         $publishedUp = $this->_task == 'republish' ? $pub->version->published_up : Date::toSql();
         $publishedUp = $pubdate ? $pubdate : $publishedUp;
         $pub->version->set('rating', '0.0');
         $pub->version->set('published_up', $publishedUp);
         $pub->version->set('published_down', '');
     }
     $pub->version->set('modified', Date::toSql());
     $pub->version->set('modified_by', $this->_uid);
     // Issue DOI
     if ($requireDoi > 0 && $this->_task == 'publish' && !$pub->version->doi) {
         // Get DOI service
         $doiService = new \Components\Publications\Models\Doi($pub);
         $extended = $state == 5 ? false : true;
         $doi = $doiService->register($extended, $state == 5 ? 'reserved' : 'public');
         // Store DOI
         if ($doi) {
             $pub->version->set('doi', $doi);
         }
         // Can't proceed without a valid DOI
         if (!$doi || $doiService->getError()) {
             $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_DOI') . ' ' . $doiService->getError());
         }
     }
     // Proceed if no error
     if (!$this->getError()) {
         if ($state == 1) {
             // Get and save manifest and its version
             $versionNumber = $pub->_curationModel->checkCurationVersion();
             $pub->version->set('curation', json_encode($pub->_curationModel->_manifest));
             $pub->version->set('curation_version_id', $versionNumber);
         }
         // Save data
         if (!$pub->version->store()) {
             throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_FAILED'), 403);
             return;
         }
         // Remove main flag from previous default version
         if ($main && $main_vid && $main_vid != $pub->version->get('id')) {
             $pub->version->removeMainFlag($main_vid);
         }
     }
     // OnAfterPublish
     $this->onAfterChangeState($pub, $originalStatus);
     // Redirect
     App::redirect(Route::url($pub->link('editversion')));
     return;
 }
Esempio n. 4
0
 /**
  * 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;
 }