Open Journal Systems  3.3.0
MedraInfoSender.inc.php
1 <?php
2 
16 import('lib.pkp.classes.scheduledTask.ScheduledTask');
17 
18 
21  var $_plugin;
22 
27  function __construct($args) {
28  PluginRegistry::loadCategory('importexport');
29  $plugin = PluginRegistry::getPlugin('importexport', 'MedraExportPlugin'); /* @var $plugin MedraExportPlugin */
30  $this->_plugin = $plugin;
31 
32  if (is_a($plugin, 'MedraExportPlugin')) {
33  $plugin->addLocaleData();
34  }
35 
36  parent::__construct($args);
37  }
38 
42  function getName() {
43  return __('plugins.importexport.medra.senderTask.name');
44  }
45 
49  function executeActions() {
50  if (!$this->_plugin) return false;
51 
52  $plugin = $this->_plugin;
53  $journals = $this->_getJournals();
54 
55  foreach ($journals as $journal) {
56  $pubIdPlugins = PluginRegistry::loadCategory('pubIds', true, $journal->getId());
57  $doiPubIdPlugin = $pubIdPlugins['doipubidplugin'];
58 
59  if ($doiPubIdPlugin->getSetting($journal->getId(), 'enableIssueDoi')) {
60  // Get unregistered issues
61  $unregisteredIssues = $plugin->getUnregisteredIssues($journal);
62  // If there are issues to be deposited
63  if (count($unregisteredIssues)) {
64  $this->_registerObjects($unregisteredIssues, 'issue=>medra-xml', $journal, 'issues');
65  }
66  }
67 
68  if ($doiPubIdPlugin->getSetting($journal->getId(), 'enablePublicationDoi')) {
69  // Get unregistered articles
70  $unregisteredArticles = $plugin->getUnregisteredArticles($journal);
71  // If there are articles to be deposited
72  if (count($unregisteredArticles)) {
73  $this->_registerObjects($unregisteredArticles, 'article=>medra-xml', $journal, 'articles');
74  }
75  }
76 
77  if ($doiPubIdPlugin->getSetting($journal->getId(), 'enableRepresentationDoi')) {
78  // Get unregistered galleys
79  $unregisteredGalleys = $plugin->getUnregisteredGalleys($journal);
80  // If there are galleys to be deposited
81  if (count($unregisteredGalleys)) {
82  $this->_registerObjects($unregisteredGalleys, 'galley=>medra-xml', $journal, 'galleys');
83  }
84  }
85  }
86  return true;
87  }
88 
94  function _getJournals() {
95  $plugin = $this->_plugin;
96  $contextDao = Application::getContextDAO(); /* @var $contextDao JournalDAO */
97  $journalFactory = $contextDao->getAll(true);
98 
99  $journals = array();
100  while($journal = $journalFactory->next()) {
101  $journalId = $journal->getId();
102  if (!$plugin->getSetting($journalId, 'username') || !$plugin->getSetting($journalId, 'password') || !$plugin->getSetting($journalId, 'automaticRegistration')) continue;
103 
104  $doiPrefix = null;
105  $pubIdPlugins = PluginRegistry::loadCategory('pubIds', true, $journalId);
106  if (isset($pubIdPlugins['doipubidplugin'])) {
107  $doiPubIdPlugin = $pubIdPlugins['doipubidplugin'];
108  if (!$doiPubIdPlugin->getSetting($journalId, 'enabled')) continue;
109  $doiPrefix = $doiPubIdPlugin->getSetting($journalId, 'doiPrefix');
110  }
111 
112  if ($doiPrefix) {
113  $journals[] = $journal;
114  } else {
115  $this->addExecutionLogEntry(__('plugins.importexport.common.senderTask.warning.noDOIprefix', array('path' => $journal->getPath())), SCHEDULED_TASK_MESSAGE_TYPE_WARNING);
116  }
117  }
118  return $journals;
119  }
120 
121 
129  function _registerObjects($objects, $filter, $journal, $objectsFileNamePart) {
130  $plugin = $this->_plugin;
131  import('lib.pkp.classes.file.FileManager');
132  $fileManager = new FileManager();
133  // export XML
134  $exportXml = $plugin->exportXML($objects, $filter, $journal);
135  // Write the XML to a file.
136  $exportFileName = $plugin->getExportFileName($plugin->getExportPath(), $objectFileNamePart, $journal, '.xml');
137  $fileManager->writeFile($exportFileName, $exportXml);
138  // Deposit the XML file.
139  $result = $plugin->depositXML($objects, $journal, $exportFileName);
140  if ($result !== true) {
141  $this->_addLogEntry($result);
142  }
143  // Remove all temporary files.
144  $fileManager->deleteByPath($exportFileName);
145  }
146 
151  function _addLogEntry($result) {
152  if (is_array($result)) {
153  foreach($result as $error) {
154  assert(is_array($error) && count($error) >= 1);
155  $this->addExecutionLogEntry(
156  __($error[0], array('param' => (isset($error[1]) ? $error[1] : null))),
157  SCHEDULED_TASK_MESSAGE_TYPE_WARNING
158  );
159  }
160  } else {
161  $this->addExecutionLogEntry(
162  __('plugins.importexport.common.register.error.mdsError', array('param' => ' - ')),
163  SCHEDULED_TASK_MESSAGE_TYPE_WARNING
164  );
165  }
166  }
167 
168 }
169 
Application\getContextDAO
static getContextDAO()
Definition: Application.inc.php:137
MedraInfoSender\_getJournals
_getJournals()
Definition: MedraInfoSender.inc.php:97
MedraInfoSender\executeActions
executeActions()
Definition: MedraInfoSender.inc.php:52
PluginRegistry\loadCategory
static loadCategory($category, $enabledOnly=false, $mainContextId=null)
Definition: PluginRegistry.inc.php:103
MedraInfoSender
Scheduled task to send deposits to mEDRA.
Definition: MedraInfoSender.inc.php:19
ScheduledTask
Base class for executing scheduled tasks. All scheduled task classes must extend this class and imple...
Definition: ScheduledTask.inc.php:20
MedraInfoSender\_addLogEntry
_addLogEntry($result)
Definition: MedraInfoSender.inc.php:154
Seboettg\Collection\count
count()
Definition: ArrayListTrait.php:253
ScheduledTask\addExecutionLogEntry
addExecutionLogEntry($message, $type=null)
Definition: ScheduledTask.inc.php:111
MedraInfoSender\$_plugin
$_plugin
Definition: MedraInfoSender.inc.php:24
PluginRegistry\getPlugin
static getPlugin($category, $name)
Definition: PluginRegistry.inc.php:85
FileManager
Class defining basic operations for file management.
Definition: FileManager.inc.php:35
MedraInfoSender\_registerObjects
_registerObjects($objects, $filter, $journal, $objectsFileNamePart)
Definition: MedraInfoSender.inc.php:132
MedraInfoSender\getName
getName()
Definition: MedraInfoSender.inc.php:45
MedraInfoSender\__construct
__construct($args)
Definition: MedraInfoSender.inc.php:30