14 import(
'lib.pkp.classes.file.ContextFileManager');
15 import(
'lib.pkp.classes.scheduledTask.ScheduledTask');
29 parent::__construct($args);
36 return __(
'plugins.generic.pln.depositorTask.name');
43 if (!$this->_plugin)
return false;
50 $journals = $journalDao->getAll(
true);
53 while ($journal = $journals->next()) {
56 if (!$this->_plugin->getSetting($journal->getId(),
'enabled'))
59 $this->_plugin->registerDAOs();
60 $this->_plugin->import(
'classes.Deposit');
61 $this->_plugin->import(
'classes.DepositObject');
62 $this->_plugin->import(
'classes.DepositPackage');
64 $this->
addExecutionLogEntry(__(
'plugins.generic.pln.notifications.processing_for', array(
'title' => $journal->getLocalizedName())), SCHEDULED_TASK_MESSAGE_TYPE_NOTICE);
67 if (!$this->_plugin->zipInstalled()) {
68 $this->
addExecutionLogEntry(__(
'plugins.generic.pln.notifications.zip_missing'), SCHEDULED_TASK_MESSAGE_TYPE_WARNING);
69 $this->_plugin->createJournalManagerNotification($journal->getId(), PLN_PLUGIN_NOTIFICATION_TYPE_ZIP_MISSING);
73 if (!$this->_plugin->tarInstalled()) {
74 $this->
addExecutionLogEntry(__(
'plugins.generic.pln.notifications.tar_missing'), SCHEDULED_TASK_MESSAGE_TYPE_WARNING);
75 $this->_plugin->createJournalManagerNotification($journal->getId(), PLN_PLUGIN_NOTIFICATION_TYPE_TAR_MISSING);
79 $this->
addExecutionLogEntry(__(
'plugins.generic.pln.notifications.getting_servicedocument'), SCHEDULED_TASK_MESSAGE_TYPE_NOTICE);
81 $sdResult = $this->_plugin->getServiceDocument($journal->getId());
84 if ($sdResult != PLN_PLUGIN_HTTP_STATUS_OK) {
85 $this->
addExecutionLogEntry(__(
'plugins.generic.pln.notifications.http_error'), SCHEDULED_TASK_MESSAGE_TYPE_WARNING);
86 $this->_plugin->createJournalManagerNotification($journal->getId(), PLN_PLUGIN_NOTIFICATION_TYPE_HTTP_ERROR);
98 if (!$this->_plugin->termsAgreed($journal->getId())) {
99 $this->
addExecutionLogEntry(__(
'plugins.generic.pln.notifications.terms_updated'), SCHEDULED_TASK_MESSAGE_TYPE_WARNING);
100 $this->_plugin->createJournalManagerNotification($journal->getId(), PLN_PLUGIN_NOTIFICATION_TYPE_TERMS_UPDATED);
105 if (!$journal->getSetting(
'onlineIssn') &&
106 !$journal->getSetting(
'printIssn') &&
107 !$journal->getSetting(
'issn')) {
108 $this->
addExecutionLogEntry(__(
'plugins.generic.pln.notifications.issn_missing'), SCHEDULED_TASK_MESSAGE_TYPE_WARNING);
109 $this->_plugin->createJournalManagerNotification($journal->getId(), PLN_PLUGIN_NOTIFICATION_TYPE_ISSN_MISSING);
114 $this->
addExecutionLogEntry(__(
"plugins.generic.pln.depositor.statusupdates"), SCHEDULED_TASK_MESSAGE_TYPE_NOTICE);
118 $this->
addExecutionLogEntry(__(
"plugins.generic.pln.depositor.updatedcontent"), SCHEDULED_TASK_MESSAGE_TYPE_NOTICE);
122 $this->
addExecutionLogEntry(__(
"plugins.generic.pln.depositor.newcontent"), SCHEDULED_TASK_MESSAGE_TYPE_NOTICE);
126 $this->
addExecutionLogEntry(__(
"plugins.generic.pln.depositor.packagingdeposits"), SCHEDULED_TASK_MESSAGE_TYPE_NOTICE);
130 $this->
addExecutionLogEntry(__(
"plugins.generic.pln.depositor.transferringdeposits"), SCHEDULED_TASK_MESSAGE_TYPE_NOTICE);
144 $depositQueue = $depositDao->getNeedStagingStatusUpdate($journal->getId());
146 while ($deposit = $depositQueue->next()) {
148 array(
'depositId' => $deposit->getId(),
149 'statusLocal' => $deposit->getLocalStatus(),
150 'statusProcessing' => $deposit->getProcessingStatus(),
151 'statusLockss' => $deposit->getLockssStatus(),
152 'objectId' => $deposit->getObjectId(),
153 'objectType' => $deposit->getObjectType())),
154 SCHEDULED_TASK_MESSAGE_TYPE_NOTICE);
157 $depositPackage->updateDepositStatus();
169 $depositObjectDao->markHavingUpdatedContent($journal->getId(), $this->_plugin->getSetting($journal->getId(),
'object_type'));
179 $depositQueue = $depositDao->getNeedTransferring($journal->getId());
181 while ($deposit = $depositQueue->next()) {
183 array(
'depositId' => $deposit->getId(),
184 'statusLocal' => $deposit->getLocalStatus(),
185 'statusProcessing' => $deposit->getProcessingStatus(),
186 'statusLockss' => $deposit->getLockssStatus(),
187 'objectId' => $deposit->getObjectId(),
188 'objectType' => $deposit->getObjectType())),
189 SCHEDULED_TASK_MESSAGE_TYPE_NOTICE);
192 $depositPackage->transferDeposit();
203 $depositQueue = $depositDao->getNeedPackaging($journal->getId());
205 $plnDir = $fileManager->getBasePath() . PLN_PLUGIN_ARCHIVE_FOLDER;
209 if ($fileManager->fileExists($plnDir,
'dir') !==
true) {
210 $fileManager->mkdirtree($plnDir);
214 while ($deposit = $depositQueue->next()) {
216 array(
'depositId' => $deposit->getId(),
217 'statusLocal' => $deposit->getLocalStatus(),
218 'statusProcessing' => $deposit->getProcessingStatus(),
219 'statusLockss' => $deposit->getLockssStatus(),
220 'objectId' => $deposit->getObjectId(),
221 'objectType' => $deposit->getObjectType())),
222 SCHEDULED_TASK_MESSAGE_TYPE_NOTICE);
225 $depositPackage->packageDeposit();
235 $objectType = $this->_plugin->getSetting($journal->getId(),
'object_type');
240 $depositObjectDao->createNew($journal->getId(), $objectType);
243 $newObjects = $depositObjectDao->getNew($journal->getId(), $objectType);
245 switch ($objectType) {
246 case 'PublishedArticle':
247 case PLN_PLUGIN_DEPOSIT_OBJECT_SUBMISSION:
250 $objectThreshold = $this->_plugin->getSetting($journal->getId(),
'object_threshold');
251 foreach (array_chunk($newObjects->toArray(),$objectThreshold) as $newObject_array) {
254 if (count($newObject_array) == $objectThreshold) {
257 $newDeposit =
new Deposit($this->_plugin->newUUID());
258 $newDeposit->setJournalId($journal->getId());
259 $depositDao->insertObject($newDeposit);
262 foreach ($newObject_array as $newObject) {
263 $newObject->setDepositId($newDeposit->getId());
264 $depositObjectDao->updateObject($newObject);
269 case PLN_PLUGIN_DEPOSIT_OBJECT_ISSUE:
271 while ($newObject = $newObjects->next()) {
272 $newDeposit =
new Deposit($this->_plugin->newUUID());
273 $newDeposit->setJournalId($journal->getId());
274 $depositDao->insertObject($newDeposit);
275 $newObject->setDepositId($newDeposit->getId());
276 $depositObjectDao->updateObject($newObject);
280 default: assert(
false);