-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathCrossrefCitationDoiCheckTask.php
More file actions
84 lines (74 loc) · 2.31 KB
/
Copy pathCrossrefCitationDoiCheckTask.php
File metadata and controls
84 lines (74 loc) · 2.31 KB
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
<?php
/**
* @file CrossrefCitationDoiCheckTask.php
*
* Copyright (c) 2013-2026 Simon Fraser University
* Copyright (c) 2003-2026 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file LICENSE.
*
* @class CrossrefCitationDoiCheckTask
* @brief Scheduled task to fetch and store matched citation DOIs from Crossref.
*/
namespace APP\plugins\generic\crossref;
use APP\core\Application;
use APP\journal\Journal;
use APP\journal\JournalDAO;
use PKP\db\DAOResultFactory;
use PKP\plugins\PluginRegistry;
use PKP\scheduledTask\ScheduledTask;
class CrossrefCitationDoiCheckTask extends ScheduledTask
{
protected ?CrossrefPlugin $plugin = null;
/**
* Constructor.
* @param $args array task arguments
*/
public function __construct(array $args)
{
parent::__construct($args);
$plugin = PluginRegistry::getPlugin('generic', 'crossrefplugin');
if ($plugin instanceof CrossrefPlugin) {
$this->plugin = $plugin;
$this->plugin->addLocaleData();
}
}
/**
* @copydoc ScheduledTask::getName()
*/
public function getName(): string
{
return __('plugins.generic.crossref.citationsDiagnostic.senderTask.name');
}
/**
* @copydoc ScheduledTask::executeActions()
*/
public function executeActions(): bool
{
if (!$this->plugin) {
return false;
}
foreach ($this->getJournals() as $journal) {
$this->plugin->processPendingCitationDois($journal);
}
return true;
}
/**
* Get all journals eligible for Crossref citation DOI matching.
*
* @return Journal[]
*/
protected function getJournals(): array
{
$contextDao = Application::getContextDAO(); /** @var JournalDAO $contextDao */
$contextFactory = $contextDao->getAll(true); /** @var DAOResultFactory $contextFactory */
$journals = [];
foreach ($contextFactory->toIterator() as $journal) { /** @var Journal $journal */
if ($this->plugin->getEnabled($journal->getId()) &&
$this->plugin->citationsEnabled($journal->getId()) &&
$this->plugin->hasCrossrefCredentials($journal->getId())) {
$journals[] = $journal;
}
}
return $journals;
}
}