16 import(
'classes.plugins.PubObjectsExportPlugin');
18 define(
'DOAJ_XSD_URL',
'https://www.doaj.org/schemas/doajArticles.xsd');
20 define(
'DOAJ_API_DEPOSIT_OK', 201);
22 define(
'DOAJ_API_URL',
'https://doaj.org/api/v1/');
23 define(
'DOAJ_API_URL_DEV',
'https://testdoaj.cottagelabs.com/api/v1/');
24 define(
'DOAJ_API_OPERATION',
'articles');
31 return 'DOAJExportPlugin';
38 return __(
'plugins.importexport.doaj.displayName');
45 return __(
'plugins.importexport.doaj.description');
53 switch (array_shift($args)) {
73 return 'article=>doaj-xml';
80 $actions = array(EXPORT_ACTION_EXPORT, EXPORT_ACTION_MARKREGISTERED );
81 if ($this->
getSetting($context->getId(),
'apiKey')) {
82 array_unshift($actions, EXPORT_ACTION_DEPOSIT);
91 return 'DOAJExportDeployment';
98 return 'DOAJSettingsForm';
110 import(
'lib.pkp.classes.helpers.PKPCurlHelper');
113 curl_setopt($curlCh, CURLOPT_RETURNTRANSFER,
true);
114 curl_setopt($curlCh, CURLOPT_POST,
true);
115 curl_setopt($curlCh, CURLOPT_HTTPHEADER, array(
'Content-Type:application/json'));
117 curl_setopt($curlCh, CURLOPT_POSTFIELDS, $jsonString);
119 $endpoint = ($this->
isTestMode($context) ? DOAJ_API_URL_DEV : DOAJ_API_URL);
120 $apiKey = $this->
getSetting($context->getId(),
'apiKey');
121 $params =
'api_key=' . $apiKey;
126 $endpoint . DOAJ_API_OPERATION . (strpos($endpoint,
'?')===
false?
'?':
'&') . $params
129 $response = curl_exec($curlCh);
131 if ($response ===
false) {
132 $result = array(array(
'plugins.importexport.doaj.register.error.mdsError',
'No response from server.'));
133 } elseif ( $status = curl_getinfo($curlCh, CURLINFO_HTTP_CODE) != DOAJ_API_DEPOSIT_OK ) {
134 $result = array(array(
'plugins.importexport.doaj.register.error.mdsError',
"$status - $response"));
152 $path = array(
'plugin', $this->
getName());
153 if (
$request->getUserVar(EXPORT_ACTION_DEPOSIT)) {
154 assert($filter !=
null);
156 $filter =
'article=>doaj-json';
157 $resultErrors = array();
158 foreach ($objects as $object) {
160 $exportJson = $this->
exportJSON($object, $filter, $context);
162 $result = $this->
depositXML($object, $context, $exportJson);
163 if (is_array($result)) {
164 $resultErrors[] = $result;
168 if (empty($resultErrors)) {
171 $this->getDepositSuccessNotificationMessageKey(),
172 NOTIFICATION_TYPE_SUCCESS
175 foreach($resultErrors as $errors) {
176 foreach ($errors as $error) {
177 assert(is_array($error) && count($error) >= 1);
181 NOTIFICATION_TYPE_ERROR,
182 (isset($error[1]) ? $error[1] :
null)
188 $request->redirect(
null,
null,
null, $path,
null, $tab);
190 return parent::executeExportAction(
$request, $objects, $filter, $tab, $objectsFileNamePart, $noValidation);
203 $exportFilters = $filterDao->getObjectsByGroup($filter);
204 assert(count($exportFilters) == 1);
205 $exportFilter = array_shift($exportFilters);
207 $exportFilter->setDeployment($exportDeployment);
208 return $exportFilter->execute($object,
true);