$citation = \Components\Citations\Helpers\Format::formatReference($cite); } // Get creator name $creator = $this->pub->creator('name') . ' (' . $this->pub->creator('username') . ')'; // Version status $status = $this->pub->getStatusName(); $class = $this->pub->getStatusCss(); // Is draft ready? $complete = $this->pub->curation('complete'); $showCitations = $this->pub->_category->_params->get('show_citations', 1); $allowUnpublish = $this->pub->_category->_params->get('option_unpublish', 0); // We also need a citations block $blockActive = $this->pub->curation()->blockExists('citations'); $showCitations = $blockActive ? $showCitations : 0; // Check if publication is within grace period (published status) $allowArchive = \Components\Publications\Helpers\Utilities::archiveOn(); $archiveDate = $this->pub->futureArchivalDate(); $revertAllowed = $this->pub->config('graceperiod'); if ($revertAllowed && $this->pub->accepted()) { $monthFrom = Date::of($this->pub->accepted() . '+1 month')->toSql(); if (strtotime($monthFrom) < Date::toUnix()) { $revertAllowed = 0; } } ?> <form action="<?php echo Route::url($this->pub->link('edit')); ?> " method="post" id="plg-form" enctype="multipart/form-data"> <?php
/** * Archive publications beyond grace period * * @param object $job \Components\Cron\Models\Job * @return boolean */ public function runMkAip(\Components\Cron\Models\Job $job) { $database = \App::get('db'); $config = Component::params('com_publications'); require_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'helpers' . DS . 'utilities.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'tables' . DS . 'version.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'helpers' . DS . 'html.php'; // Check that mkAIP script exists if (!\Components\Publications\Helpers\Utilities::archiveOn()) { return; } // Check for grace period $gracePeriod = $config->get('graceperiod', 0); if (!$gracePeriod) { // If no grace period, this cron is unnecessary (archived as approval) return; } $aipBasePath = trim($config->get('aip_path', NULL), DS); $aipBasePath = $aipBasePath && is_dir(DS . $aipBasePath) ? DS . $aipBasePath : NULL; // Check for base path if (!$aipBasePath) { $this->setError('Missing archival base directory'); return; } // Get all unarchived publication versions $query = "SELECT V.*, C.id as id, V.id as version_id "; $query .= " FROM #__publication_versions as V, #__publications as C "; $query .= " WHERE C.id=V.publication_id AND V.state=1 "; $query .= " AND V.doi IS NOT NULL "; $query .= " AND V.accepted IS NOT NULL AND V.accepted !='0000-00-00 00:00:00' "; $query .= " AND (V.archived IS NULL OR V.archived ='0000-00-00 00:00:00') "; $database->setQuery($query); if (!($rows = $database->loadObjectList())) { return true; } // Start email message $subject = Lang::txt('Update on recently archived publications'); $body = Lang::txt('The following publications passed the grace period and were archived:') . "\n"; $aipGroup = $config->get('aip_group'); $counter = 0; foreach ($rows as $row) { // Grace period unexpired? $monthFrom = Date::of($row->accepted . '+1 month')->toSql(); if (strtotime($monthFrom) > strtotime(Date::of('now'))) { continue; } // Load version $pv = new \Components\Publications\Tables\Version($database); if (!$pv->load($row->version_id)) { continue; } // Create aip path $doiParts = explode('/', $row->doi); $aipName = count($doiParts) > 1 ? $doiParts[0] . '__' . $doiParts[1] : ''; // Archival package exists? if ($aipBasePath && $aipName && is_dir($aipBasePath . DS . $aipName)) { // Save approved date and archive date $pv->archived = $pv->accepted; $pv->store(); // Do not overwrite existing archives !! continue; } // Run mkAIP and save archived date if (\Components\Publications\Helpers\Utilities::mkAip($row)) { $pv->archived = Date::toSql(); $pv->store(); $counter++; $body .= $row->title . ' v.' . $row->version_label . ' (id #' . $row->id . ')' . "\n"; } } // Email update to admins if ($counter > 0 && $aipGroup) { // Set email config $from = array('name' => Config::get('fromname') . ' ' . Lang::txt('Publications'), 'email' => Config::get('mailfrom'), 'multipart' => md5(date('U'))); $admins = \Components\Projects\Helpers\Html::getGroupMembers($aipGroup); // Build message if (!empty($admins)) { foreach ($admins as $admin) { // Get the user's account $user = User::getInstance($admin); if (!$user->get('id')) { continue; } $message = new \Hubzero\Mail\Message(); $message->setSubject($subject)->addFrom($from['email'], $from['name'])->addTo($user->get('email'), $user->get('name'))->addHeader('X-Component', 'com_publications')->addHeader('X-Component-Object', 'publications'); $message->addPart($body, 'text/plain'); $message->send(); } } } // All done return true; }