Open Journal Systems  3.3.0
DOAJInfoSender.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', 'DOAJExportPlugin'); /* @var $plugin DOAJExportPlugin */
30  $this->_plugin = $plugin;
31 
32  if (is_a($plugin, 'DOAJExportPlugin')) {
33  $plugin->addLocaleData();
34  }
35 
36  parent::__construct($args);
37  }
38 
42  function getName() {
43  return __('plugins.importexport.doaj.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  // Get unregistered articles
57  $unregisteredArticles = $plugin->getUnregisteredArticles($journal);
58  // If there are articles to be deposited
59  if (count($unregisteredArticles)) {
60  $this->_registerObjects($unregisteredArticles, 'article=>doaj-json', $journal, 'articles');
61  }
62  }
63  return true;
64  }
65 
71  function _getJournals() {
72  $plugin = $this->_plugin;
73  $contextDao = Application::getContextDAO(); /* @var $contextDao JournalDAO */
74  $journalFactory = $contextDao->getAll(true);
75 
76  $journals = array();
77  while($journal = $journalFactory->next()) {
78  $journalId = $journal->getId();
79  if (!$plugin->getSetting($journalId, 'apiKey') || !$plugin->getSetting($journalId, 'automaticRegistration')) continue;
80  $journals[] = $journal;
81  }
82  return $journals;
83  }
84 
85 
93  function _registerObjects($objects, $filter, $journal, $objectsFileNamePart) {
94  $plugin = $this->_plugin;
95  foreach ($objects as $object) {
96  // Get the JSON
97  $exportJson = $plugin->exportJSON($object, $filter, $journal);
98  // Deposit the JSON
99  $result = $plugin->depositXML($object, $journal, $exportJson);
100  if ($result !== true) {
101  $this->_addLogEntry($result);
102  }
103  }
104  }
105 
110  function _addLogEntry($errors) {
111  if (is_array($errors)) {
112  foreach($errors as $error) {
113  assert(is_array($error) && count($error) >= 1);
114  $this->addExecutionLogEntry(
115  __($error[0], array('param' => (isset($error[1]) ? $error[1] : null))),
116  SCHEDULED_TASK_MESSAGE_TYPE_WARNING
117  );
118  }
119  }
120  }
121 
122 }
123 
DOAJInfoSender\__construct
__construct($args)
Definition: DOAJInfoSender.inc.php:30
Application\getContextDAO
static getContextDAO()
Definition: Application.inc.php:137
DOAJInfoSender\executeActions
executeActions()
Definition: DOAJInfoSender.inc.php:52
PluginRegistry\loadCategory
static loadCategory($category, $enabledOnly=false, $mainContextId=null)
Definition: PluginRegistry.inc.php:103
DOAJInfoSender\_getJournals
_getJournals()
Definition: DOAJInfoSender.inc.php:74
ScheduledTask
Base class for executing scheduled tasks. All scheduled task classes must extend this class and imple...
Definition: ScheduledTask.inc.php:20
DOAJInfoSender\_addLogEntry
_addLogEntry($errors)
Definition: DOAJInfoSender.inc.php:113
ScheduledTask\addExecutionLogEntry
addExecutionLogEntry($message, $type=null)
Definition: ScheduledTask.inc.php:111
PluginRegistry\getPlugin
static getPlugin($category, $name)
Definition: PluginRegistry.inc.php:85
DOAJInfoSender
Scheduled task to send deposits to DOAJ.
Definition: DOAJInfoSender.inc.php:19
DOAJInfoSender\getName
getName()
Definition: DOAJInfoSender.inc.php:45
DOAJInfoSender\$_plugin
$_plugin
Definition: DOAJInfoSender.inc.php:24
DOAJInfoSender\_registerObjects
_registerObjects($objects, $filter, $journal, $objectsFileNamePart)
Definition: DOAJInfoSender.inc.php:96