public function __construct($filesPath, PackedSupplFile $unpacker)
 {
     $this->filesPath = $filesPath;
     //hostname+rpositorypath
     $daos =& DAORegistry::getDAOs();
     $this->rpositorydao =& $daos['RpositoryDAO'];
     $this->unpacker =& $unpacker;
 }
 function getPackageType($articleId)
 {
     $daos =& DAORegistry::getDAOs();
     $rpositoryDao =& $daos['RpositoryDAO'];
     $filename = $rpositoryDao->getPackageName($articleId);
     if (!$filename == NULL) {
         return 'legacy_r_package';
     }
     return 'NO_PACKAGE_UPLOADED';
 }
 function callback_update($hookName, $args)
 {
     $sql =& $args[0];
     $params =& $args[1];
     $articleId = NULL;
     // what hook was fired?
     if ($hookName === 'articledao::_updatearticle') {
         $articleId = $params[18];
     } elseif ($hookName === 'publishedarticledao::_updatepublishedarticle') {
         $articleId = $params[0];
     }
     // get references to DAOs needed for the update
     $daos =& DAORegistry::getDAOs();
     $articledao =& $daos['ArticleDAO'];
     $rpositorydao =& $daos['RpositoryDAO'];
     // do the update and suppress hookcalls in DAO::update()
     if ($hookName === 'articledao::_updatearticle') {
         $article =& $articledao->getArticle($articleId);
         if ($article == NULL) {
             return FALSE;
         }
         $articledao->update($sql, array($article->getLocale(), (int) $article->getUserId(), (int) $article->getSectionId(), $article->getLanguage(), $article->getCommentsToEditor(), $article->getCitations(), (int) $article->getStatus(), (int) $article->getSubmissionProgress(), (int) $article->getCurrentRound(), $articledao->nullOrInt($article->getSubmissionFileId()), $articledao->nullOrInt($article->getRevisedFileId()), $articledao->nullOrInt($article->getReviewFileId()), $articledao->nullOrInt($article->getEditorFileId()), $article->getPages(), (int) $article->getFastTracked(), (int) $article->getHideAuthor(), (int) $article->getCommentsStatus(), $article->getStoredDOI(), $article->getId()), false);
     } elseif ($hookName === 'publishedarticledao::_updatepublishedarticle') {
         $publishedarticledao =& $daos['PublishedArticleDAO'];
         $publishedarticledao->update($sql, $params, false);
     }
     // when the article isn't published we don't do anything to the repository
     if (!$rpositorydao->articleIsPublished($articleId)) {
         return FALSE;
     }
     $journal_id = $articledao->getArticleJournalId($articleId);
     $packager = new OJSPackager(Config::getVar('files', 'files_dir') . '/journals/' . $journal_id . '/articles', new ZipSupplFile());
     // create the new package for $articleId
     $archive = $packager->writePackage($articleId);
     $unpacker =& $packager->getUnpacker();
     $filesList = $unpacker->getZippedFileNames();
     //error_log('OJS - RpositoryPlugin: komme ich hier auch an den unpacker ran? ' . json_encode($unpacker->getZippedFileNames()));
     if ($archive == NULL) {
         error_log("OJS - rpository: creating archive failed");
         return FALSE;
     }
     // insert new Package into repository
     //$writtenArchive = $rpositorydao->updateRepository(&$this, $articleId, $archive);
     $writtenArchive = $rpositorydao->updateRepository(&$this, $articleId, $archive, $filesList);
     if ($writtenArchive == NULL) {
         return FALSE;
     } else {
         $this->updatePackageIndex();
     }
     return FALSE;
 }
 function getContents(&$templateMgr)
 {
     $daos =& DAORegistry::getDAOs();
     $rpositoryDao =& $daos['RpositoryDAO'];
     $context = $this->curPageURL();
     $pattern = '#.*/index.php/[^/]*/article/view/[0-9]+#';
     $articleId = NULL;
     if (preg_match($pattern, $context)) {
         $templateMgr->assign('isArticleView', 1);
         $pos = strrpos($context, '/view/');
         $articleId = substr($context, $pos + 6);
         if ($pos = strpos($articleId, '/')) {
             $articleId = substr($articleId, 0, $pos);
         }
     } else {
         $templateMgr->assign('isArticleView', 0);
     }
     if ($articleId) {
         $pidv1 = $rpositoryDao->getPIDv1($articleId);
         $pidv2 = $rpositoryDao->getPIDv2($articleId);
     }
     $templateMgr->assign('pidv1', $pidv1);
     $templateMgr->assign('pidv2', $pidv2);
     $templateMgr->assign('rpositoryBase', "/Rpository/src/contrib/");
     $filename = $rpositoryDao->getRPackageFile($articleId);
     error_log("OJS - " . $filename);
     $templateMgr->assign('fileName', $filename);
     $templateMgr->assign('packageName', str_replace('_1.0.tar.gz', '', $filename));
     //check if the current user is the person who inserted the article, and in case allow to show link to edit the package
     if ($articleId != NULL) {
         $user =& Request::getUser();
         if (is_object($user)) {
             $userId = $user->getId();
         } else {
             $userId = NULL;
         }
         $articleDAO =& $daos['ArticleDAO'];
         $article =& $articleDAO->getArticle($articleId);
         $articleUserId = $article->getUserId();
         $userIsEditor = false;
         if ($userId == $articleUserId) {
             $userIsEditor = true;
         }
     } else {
         $userIsEditor = false;
     }
     $templateMgr->assign('userIsEditor', $userIsEditor);
     $templateMgr->assign('paperPackageEditPlugin', "/index.php/mr2/PaperPackageEdPlugin/view/article=" . $articleId);
     return parent::getContents($templateMgr);
 }
Esempio n. 5
0
 /**
  * Retrieve a reference to the specified DAO.
  * @param $name string the class name of the requested DAO
  * @param $dbconn ADONewConnection optional
  * @return DAO
  */
 function &getDAO($name, $dbconn = null)
 {
     $daos =& DAORegistry::getDAOs();
     if (!isset($daos[$name])) {
         // Import the required DAO class.
         import(DAORegistry::getQualifiedDAOName($name));
         // Only instantiate each class of DAO a single time
         $daos[$name] =& new $name();
         if ($dbconn != null) {
             // FIXME Needed by installer but shouldn't access member variable directly
             $daos[$name]->_dataSource = $dbconn;
         }
     }
     return $daos[$name];
 }
Esempio n. 6
0
 /**
  * Retrieve a reference to the specified DAO.
  * @param $name string the class name of the requested DAO
  * @param $dbconn ADONewConnection optional
  * @return DAO
  */
 function &getDAO($name, $dbconn = null)
 {
     $daos =& DAORegistry::getDAOs();
     if (!isset($daos[$name])) {
         // Import the required DAO class.
         $application =& PKPApplication::getApplication();
         $className = $application->getQualifiedDAOName($name);
         if (!$className) {
             fatalError('Unrecognized DAO ' . $name . '!');
         }
         // Only instantiate each class of DAO a single time
         $daos[$name] =& instantiate($className, array('DAO', 'XMLDAO'));
         if ($dbconn != null) {
             $daos[$name]->setDataSource($dbconn);
         }
     }
     return $daos[$name];
 }
 /**
  * Retrieve a reference to the specified DAO.
  * @param $name string the class name of the requested DAO
  * @param $dbconn ADONewConnection optional
  * @return DAO
  */
 function &getDAO($name, $dbconn = null)
 {
     $daos =& DAORegistry::getDAOs();
     if (!isset($daos[$name])) {
         // Import the required DAO class.
         $application =& PKPApplication::getApplication();
         $className = $application->getQualifiedDAOName($name);
         if (!$className) {
             fatalError('Unrecognized DAO ' . $name . '!');
         }
         // Only instantiate each class of DAO a single time
         $daos[$name] =& instantiate($className, array('DAO', 'XMLDAO'));
         if ($dbconn != null) {
             // FIXME Needed by installer but shouldn't access member variable directly
             $daos[$name]->_dataSource = $dbconn;
         }
     }
     return $daos[$name];
 }
 /**
  * Save settings. 
  */
 function execute()
 {
     $plugin =& $this->plugin;
     $newPidStatus = trim($this->getData('pidstatus'));
     $newOutputPath = trim($this->getData('documentroot') . $this->getData('path'));
     $newPath = trim($this->getData('path'));
     $newHostname = trim($this->getData('hostname'));
     $newDocumentroot = trim($this->getData('documentroot'));
     $newRepositoryUrl = trim($this->getData('hostname') . "/" . $this->getData('path'));
     $plugin->updateSetting(0, 'pidstatus', $newPidStatus, 'int');
     $plugin->updateSetting(0, 'output_path', $newOutputPath, 'string');
     $plugin->updateSetting(0, 'path', $newPath, 'string');
     $plugin->updateSetting(0, 'hostname', $newHostname, 'string');
     $plugin->updateSetting(0, 'documentroot', $newDocumentroot, 'string');
     $plugin->updateSetting(0, 'repository_url', $newRepositoryUrl, 'string');
     if ($newPidStatus == 1) {
         $newPidV1User = trim($this->getData('pidv1_user'));
         $plugin->updateSetting(0, 'pidv1_user', $newPidV1User, 'string');
         $newPidV1Pw = trim($this->getData('pidv1_pw'));
         $plugin->updateSetting(0, 'pidv1_pw', $newPidV1Pw, 'string');
         $newPidV1ServiceUrl = trim($this->getData('pidv1_service_url'));
         $plugin->updateSetting(0, 'pidv1_service_url', $newPidV1ServiceUrl, 'string');
         $newPidV1Timeout = trim($this->getData('pidv1_timeout'));
         $plugin->updateSetting(0, 'pidv1_timeout', $newPidV1Timeout, 'int');
         $fetch_pidv1 = trim($this->getData('fetch_missing_pids_v1'));
         if ($fetch_pidv1 == 'on') {
             $daos =& DAORegistry::getDAOs();
             $rpositorydao =& $daos['RpositoryDAO'];
             $pids_to_fetch = $rpositorydao->getArticlesWithoutPid(1);
             foreach ($pids_to_fetch as $articleId) {
                 $rpositorydao->updatePID($this->plugin, $articleId);
             }
         }
     } elseif ($newPidStatus == 2) {
         $newPidV2User = trim($this->getData('pidv2_user'));
         $plugin->updateSetting(0, 'pidv2_user', $newPidV2User, 'string');
         $newPidV2Pw = trim($this->getData('pidv2_pw'));
         $plugin->updateSetting(0, 'pidv2_pw', $newPidV2Pw, 'string');
         $newPidV2ServiceUrl = trim($this->getData('pidv2_service_url'));
         $plugin->updateSetting(0, 'pidv2_service_url', $newPidV2ServiceUrl, 'string');
         $newPidV2Timeout = trim($this->getData('pidv2_timeout'));
         $plugin->updateSetting(0, 'pidv2_timeout', $newPidV2Timeout, 'int');
         $newPidV2Prefix = trim($this->getData('pidv2_prefix'));
         $plugin->updateSetting(0, 'pidv2_prefix', $newPidV2Prefix, 'string');
         $fetch_pidv2 = trim($this->getData('fetch_missing_pids_v2'));
         if ($fetch_pidv2 == 'on') {
             $daos =& DAORegistry::getDAOs();
             $rpositorydao =& $daos['RpositoryDAO'];
             $pids_to_fetch = $rpositorydao->getArticlesWithoutPid(2);
             foreach ($pids_to_fetch as $articleId) {
                 $rpositorydao->test($articleId);
             }
         }
     }
 }
 function fetchPIDlegacy(&$plugin, $articleId)
 {
     $daos =& DAORegistry::getDAOs();
     $articleDao =& $daos['ArticleDAO'];
     $url = $this->getPackageName($articleId);
     if ($url == '') {
         error_log("OJS - rpository: getPackageName failed");
         return NULL;
     }
     $fileSize = filesize($plugin->getSetting(0, 'documentroot') . $plugin->getSetting(0, 'path') . $url);
     if ($fileSize == NULL) {
         error_log("couldn't get file size");
         return NULL;
     }
     if ($url == NULL) {
         error_log("url = null");
         return NULL;
     } else {
         $url = $plugin->getSetting(0, 'hostname') . "/index.php/mr2/oai?verb=GetRecord&metadataPrefix=mods&identifier=oai:ojs." . $plugin->getSetting(0, 'hostname') . ":article/" . $articleId;
     }
     $article = $articleDao->getArticle($articleId);
     $title = $article->getArticleTitle();
     if ($title == '') {
         error_log("couldn't get title");
         return NULL;
     }
     $submissionId = $article->_data['id'];
     $authors = $this->getAuthors($submissionId);
     if ($authors == '') {
         error_log("couldn't get authors");
         return NULL;
     }
     $date = $this->getDate($articleId);
     if ($date == '') {
         error_log("couldn't get publish date");
         return NULL;
     }
     // set POST variables
     $fields = array('url' => urlencode($url), 'size' => urlencode($fileSize), 'title' => urlencode($title), 'authors' => urlencode($authors), 'pubdate' => urlencode($date), 'encoding' => urlencode('xml'));
     $fields_string = '';
     //url-ify the data for the POST
     foreach ($fields as $key => $value) {
         $fields_string .= $key . '=' . $value . '&';
     }
     $fields_string = rtrim($fields_string, '&');
     // curl stuff
     $ch = curl_init();
     //curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
     curl_setopt($ch, CURLOPT_URL, $plugin->getSetting(0, 'pidv1_service_url'));
     curl_setopt($ch, CURLOPT_POST, TRUE);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($ch, CURLOPT_TIMEOUT, $plugin->getSetting(0, 'pidv1_timeout'));
     curl_setopt($ch, CURLOPT_USERPWD, $plugin->getSetting(0, 'pidv1_user') . ":" . $plugin->getSetting(0, 'pidv1_pw'));
     $result = curl_exec($ch);
     curl_close($ch);
     // newlines messed up the xml parser - removing
     $result = str_replace("\\r\\n", '', $result);
     if ($result == NULL) {
         error_log("OJS - rpository: creating PID failed: no response from PID server");
         return NULL;
     } elseif (substr($result, 0, 6) == '<html>') {
         $m = array();
         preg_match_all("/<h1>HTTP Status 403 - Another Handle \\/ PID already points here: ([A-F0-9-\\/]*)<\\/h1>/", $result, $m);
         if ($m[1] == '') {
             error_log("OJS - rpository: fetching PID failed: " . $e->getMessage());
             return NULL;
         } else {
             //error_log(print_r($m, TRUE));
             return $m[1][0];
         }
     }
     try {
         $xml = new SimpleXMLElement($result);
     } catch (Exception $e) {
         error_log("OJS - rpository: unexpected PID v1 server response");
         return NULL;
     }
     $out = $xml->Handle->pid;
     return (string) $out;
 }