Esempio n. 1
0
 /**
  * Delete author record
  *
  * @return  void
  */
 public function deleteItem($manifest, $blockId, $pub, $actor = 0, $elementId = 0, $aid = 0)
 {
     $aid = $aid ? $aid : Request::getInt('aid', 0);
     // Load classes
     $row = new \Components\Publications\Tables\Author($this->_parent->_db);
     $objO = new \Components\Projects\Tables\Owner($this->_parent->_db);
     // We need attachment record
     if (!$aid || !$row->load($aid) || $row->publication_version_id != $pub->version_id) {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_CONTENT_ERROR_LOAD_AUTHOR'));
         return false;
     }
     if ($row->deleteAssociationByOwner($row->project_owner_id, $row->publication_version_id)) {
         $this->set('_message', Lang::txt('Author deleted'));
         // Reflect the update in curation record
         $this->_parent->set('_update', 1);
     }
     return true;
 }
Esempio n. 2
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;
 }