HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux vmi1674223.contaboserver.net 5.4.0-182-generic #202-Ubuntu SMP Fri Apr 26 12:29:36 UTC 2024 x86_64
User: root (0)
PHP: 7.4.3-4ubuntu2.22
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/ojs/plugins/importexport/doaj/DOAJInfoSender.inc.php
<?php

/**
 * @file plugins/importexport/doaj/DOAJInfoSender.inc.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 docs/COPYING.
 *
 * @class DOAJInfoSender
 * @ingroup plugins_importexport_doaj
 *
 * @brief Scheduled task to send deposits to DOAJ.
 */

import('lib.pkp.classes.scheduledTask.ScheduledTask');


class DOAJInfoSender extends ScheduledTask {
	/** @var $_plugin DOAJExportPlugin */
	var $_plugin;

	/**
	 * Constructor.
	 * @param $argv array task arguments
	 */
	function __construct($args) {
		PluginRegistry::loadCategory('importexport');
		$plugin = PluginRegistry::getPlugin('importexport', 'DOAJExportPlugin'); /* @var $plugin DOAJExportPlugin */
		$this->_plugin = $plugin;

		if (is_a($plugin, 'DOAJExportPlugin')) {
			$plugin->addLocaleData();
		}

		parent::__construct($args);
	}

	/**
	 * @copydoc ScheduledTask::getName()
	 */
	function getName() {
		return __('plugins.importexport.doaj.senderTask.name');
	}

	/**
	 * @copydoc ScheduledTask::executeActions()
	 */
	function executeActions() {
		if (!$this->_plugin) return false;

		$plugin = $this->_plugin;
		$journals = $this->_getJournals();

		foreach ($journals as $journal) {
			// load pubIds for this journal
			PluginRegistry::loadCategory('pubIds', true, $journal->getId());
			// Get unregistered articles
			$unregisteredArticles = $plugin->getUnregisteredArticles($journal);
			// If there are articles to be deposited
			if (count($unregisteredArticles)) {
				$this->_registerObjects($unregisteredArticles, 'article=>doaj-json', $journal, 'articles');
			}
		}
		return true;
	}

	/**
	 * Get all journals that meet the requirements to have
	 * their articles automatically sent to DOAJ.
	 * @return array
	 */
	function _getJournals() {
		$plugin = $this->_plugin;
		$contextDao = Application::getContextDAO(); /* @var $contextDao JournalDAO */
		$journalFactory = $contextDao->getAll(true);

		$journals = array();
		while($journal = $journalFactory->next()) {
			$journalId = $journal->getId();
			if (!$plugin->getSetting($journalId, 'apiKey') || !$plugin->getSetting($journalId, 'automaticRegistration')) continue;
			$journals[] = $journal;
		}
		return $journals;
	}


	/**
	 * Register objects
	 * @param $objects array
	 * @param $filter string
	 * @param $journal Journal
	 * @param $objectsFileNamePart string
	 */
	function _registerObjects($objects, $filter, $journal, $objectsFileNamePart) {
		$plugin = $this->_plugin;
		foreach ($objects as $object) {
			// Get the JSON
			$exportJson = $plugin->exportJSON($object, $filter, $journal);
			// Deposit the JSON
			$result = $plugin->depositXML($object, $journal, $exportJson);
			if ($result !== true) {
				$this->_addLogEntry($result);
			}
		}
	}

	/**
	 * Add execution log entry
	 * @param $errors array
	 */
	function _addLogEntry($errors) {
		if (is_array($errors)) {
			foreach($errors as $error) {
				assert(is_array($error) && count($error) >= 1);
				$this->addExecutionLogEntry(
					__($error[0], array('param' => (isset($error[1]) ? $error[1] : null))),
					SCHEDULED_TASK_MESSAGE_TYPE_WARNING
				);
			}
		}
	}

}