forked from pkp/crossrefReferenceLinking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrossrefReferenceLinkingInfoSender.inc.php
91 lines (76 loc) · 2.63 KB
/
CrossrefReferenceLinkingInfoSender.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* @file CrossrefReferenceLinkingInfoSender.php
*
* Copyright (c) 2013-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file LICENSE.
*
* @class CrossrefReferenceLinkingInfoSender
* @ingroup plugins_generic_crossrefReferenceLinking
*
* @brief Scheduled task to check for found Crossref references DOIs.
*/
import('lib.pkp.classes.scheduledTask.ScheduledTask');
class CrossrefReferenceLinkingInfoSender extends ScheduledTask {
/** @var $_plugin CrossrefReferenceLinkingPlugin */
var $_plugin;
/**
* Constructor.
* @param $args array task arguments
*/
function __construct($args) {
PluginRegistry::loadCategory('generic');
$plugin = PluginRegistry::getPlugin('generic', 'crossrefreferencelinkingplugin'); /** @var $plugin CrossrefReferenceLinkingPlugin */
$this->_plugin = $plugin;
if (is_a($plugin, 'CrossrefReferenceLinkingPlugin')) {
$plugin->addLocaleData();
}
parent::__construct($args);
}
/**
* @copydoc ScheduledTask::getName()
*/
function getName() {
return __('plugins.generic.crossrefReferenceLinking.senderTask.name');
}
/**
* @copydoc ScheduledTask::executeActions()
*/
function executeActions() {
if (!$this->_plugin) return false;
$plugin = $this->_plugin;
$journals = $this->_getJournals();
foreach ($journals as $journal) {
// Call the plugin register function, in order to be able to save the new article and citation settings in the DB
$plugin->register('generic', $plugin->getPluginPath(), $journal->getId());
// Get published articles to check
$submissionsToCheck = $plugin->getSubmissionsToCheck($journal);
foreach ($submissionsToCheck as $submissionToCheck) { /** @var $submissionToCheck Submission */
$plugin->getCrossrefReferencesDOIs($submissionToCheck->getCurrentPublication());
}
}
return true;
}
/**
* Get all journals that meet the requirements to have
* their articles or issues DOIs sent to Crossref.
* @return array
*/
function _getJournals() {
PluginRegistry::loadCategory('importexport');
$crossrefExportPlugin = PluginRegistry::getPlugin('importexport', 'CrossRefExportPlugin');
$contextDao = Application::getContextDAO(); /** @var $contextDao JournalDAO */
$journalFactory = $contextDao->getAll(true);
$journals = array();
while($journal = $journalFactory->next()) {
$journalId = $journal->getId();
if ($this->_plugin->citationsEnabled($journalId) &&
$crossrefExportPlugin->getSetting($journalId, 'username') &&
$crossrefExportPlugin->getSetting($journalId, 'password')) {
$journals[] = $journal;
}
}
return $journals;
}
}