Ejemplo n.º 1
0
 /**
  * Deposit suppfiles in Dataverse study.
  * @param $study DataverseStudy Study associated with author submission
  * @param $suppFiles array Array of suppfiles
  * @return boolean Files deposited
  */
 function depositFiles($study, $suppFiles)
 {
     $packager = new DataversePackager();
     foreach ($suppFiles as $suppFile) {
         $suppFile->setFileStage(ARTICLE_FILE_SUPP);
         // workaround for #8444
         $packager->addFile($suppFile->getFilePath(), $suppFile->getOriginalFileName());
     }
     $packager->createPackage();
     // Deposit the package
     $journal =& Request::getJournal();
     $client = $this->_initSwordClient();
     $depositReceipt = $client->deposit($study->getEditMediaUri(), $this->getSetting($journal->getId(), 'username'), $this->getSetting($journal->getId(), 'password'), '', $packager->getPackageFilePath(), $packager->getPackaging(), $packager->getContentType(), false);
     // in progress? false
     $deposited = $depositReceipt->sac_status == DATAVERSE_PLUGIN_HTTP_STATUS_CREATED;
     if ($deposited) {
         // Get the study statement & update the local file list
         try {
             $studyStatement = $client->retrieveAtomStatement($study->getStatementUri(), $this->getSetting($journal->getId(), 'username'), $this->getSetting($journal->getId(), 'password'), '');
             if ($studyStatement) {
                 // Associate Dataverse-side file with OJS-side file
                 $dvFileIndex = array();
                 foreach ($studyStatement->sac_entries as $entry) {
                     if (strrpos($entry->sac_content_source, '/')) {
                         $dvUriFileName = substr($entry->sac_content_source, strrpos($entry->sac_content_source, '/') + 1);
                         $dvFileIndex[$dvUriFileName] = $entry->sac_content_source;
                     }
                 }
                 // Create or update DataverseFile linking suppfile with deposited file
                 $this->import('classes.DataverseFile');
                 $dvFileDao =& DAORegistry::getDAO('DataverseFileDAO');
                 foreach ($suppFiles as $suppFile) {
                     $suppFileKey = str_replace(' ', '_', $suppFile->getOriginalFileName());
                     if (array_key_exists($suppFileKey, $dvFileIndex)) {
                         $dvFile =& $dvFileDao->getDataverseFileBySuppFileId($suppFile->getId());
                         if (!$dvFile) {
                             $dvFile = new DataverseFile();
                             $dvFile->setSuppFileId($suppFile->getId());
                             $dvFile->setSubmissionId($study->getSubmissionId());
                             $dvFile->setStudyId($study->getId());
                             $dvFile->setContentSourceUri($dvFileIndex[$suppFileKey]);
                             $dvFileDao->insertDataverseFile($dvFile);
                         } else {
                             $dvFile->setStudyId($study->getId());
                             $dvFile->setContentSourceUri($dvFileIndex[$suppFileKey]);
                             $dvFileDao->updateDataverseFile($dvFile);
                         }
                     }
                 }
             }
         } catch (Exception $e) {
             $application =& PKPApplication::getApplication();
             error_log($application->getName() . ': ' . $e->getMessage() . ': ' . $e->getFile() . ': ' . $e->getLine());
         }
     }
     return $deposited;
 }
Ejemplo n.º 2
0
 /**
  * Add a file to an existing study
  * @param DataverseStudy $study
  * @param SuppFile $suppFile
  * @return DataverseFile
  */
 function &addFileToStudy(&$study, &$suppFile)
 {
     $packager = new DataversePackager();
     $packager->addFile($suppFile);
     $packager->createPackage();
     // Deposit the package
     $journal =& Request::getJournal();
     $client = $this->_initSwordClient();
     $depositReceipt = $client->deposit($study->getEditMediaUri(), $this->getSetting($journal->getId(), 'username'), $this->getSetting($journal->getId(), 'password'), '', $packager->getPackageFilePath(), $packager->getPackaging(), $packager->getContentType(), false);
     // in progress? false
     if ($depositReceipt->sac_status != DATAVERSE_PLUGIN_HTTP_STATUS_CREATED) {
         return false;
     }
     // Get the study statement & update the Dataverse file with content source URI
     $studyStatement = $client->retrieveAtomStatement($study->getStatementUri(), $this->getSetting($journal->getId(), 'username'), $this->getSetting($journal->getId(), 'password'), '');
     // Need the study statement to update Dataverse files
     if (!isset($studyStatement)) {
         return false;
     }
     // Create a new Dataverse file for inserted suppfile
     $this->import('classes.DataverseFile');
     $dvFile = new DataverseFile();
     $dvFile->setSuppFileId($suppFile->getId());
     $dvFile->setStudyId($study->getId());
     $dvFile->setSubmissionId($study->getSubmissionId());
     foreach ($studyStatement->sac_entries as $entry) {
         $dvUriFileName = substr($entry->sac_content_source, strrpos($entry->sac_content_source, '/') + 1);
         if ($dvUriFileName == str_replace(' ', '_', $suppFile->getOriginalFileName())) {
             $dvFile->setContentSourceUri($entry->sac_content_source);
             break;
         }
     }
     if (!$dvFile->getContentSourceUri()) {
         return false;
     }
     $dvFileDao =& DAORegistry::getDAO('DataverseFileDAO');
     $dvFileDao->insertDataverseFile($dvFile);
     // Finally, file may have metadata that needs to be in study cataloguing information
     $articleDao =& DAORegistry::getDAO('ArticleDAO');
     $article =& $articleDao->getArticle($study->getSubmissionId(), $journal->getId(), true);
     $this->updateStudy($article, $study);
     return $dvFile;
 }