16 import(
'lib.pkp.classes.plugins.ImportExportPlugin');
22 function register($category, $path, $mainContextId =
null) {
23 $success = parent::register($category, $path, $mainContextId);
34 return 'PubMedExportPlugin';
42 return __(
'plugins.importexport.pubmed.displayName');
50 return __(
'plugins.importexport.pubmed.description');
62 switch (array_shift($args)) {
65 $apiUrl =
$request->getDispatcher()->url(
$request, ROUTE_API, $context->getPath(),
'submissions');
66 $submissionsListPanel = new \APP\components\listPanels\SubmissionsListPanel(
68 __(
'common.publications'),
72 'getParams' =>
new stdClass(),
76 $submissionsConfig = $submissionsListPanel->getConfig();
77 $submissionsConfig[
'addUrl'] =
'';
78 $submissionsConfig[
'filters'] = array_slice($submissionsConfig[
'filters'], 1);
79 $templateMgr->setState([
81 'submissions' => $submissionsConfig,
84 $templateMgr->assign([
85 'pageComponent' =>
'ImportExportPage',
89 case 'exportSubmissions':
91 (array)
$request->getUserVar(
'selectedSubmissions'),
95 import(
'lib.pkp.classes.file.FileManager');
98 $fileManager->writeFile($exportFileName, $exportXml);
99 $fileManager->downloadByPath($exportFileName);
100 $fileManager->deleteByPath($exportFileName);
104 (array)
$request->getUserVar(
'selectedIssues'),
108 import(
'lib.pkp.classes.file.FileManager');
111 $fileManager->writeFile($exportFileName, $exportXml);
112 $fileManager->downloadByPath($exportFileName);
113 $fileManager->deleteByPath($exportFileName);
116 $dispatcher =
$request->getDispatcher();
117 $dispatcher->handle404();
131 $pubmedExportFilters = $filterDao->getObjectsByGroup(
'article=>pubmed-xml');
132 assert(count($pubmedExportFilters) == 1);
133 $exportFilter = array_shift($pubmedExportFilters);
134 $submissions = array();
135 foreach ($submissionIds as $submissionId) {
136 $submission = $submissionDao->getById($submissionId);
137 if ($submission && $submission->getData(
'contextId') == $context->getId()) $submissions[] = $submission;
139 libxml_use_internal_errors(
true);
140 $submissionXml = $exportFilter->execute($submissions,
true);
141 $xml = $submissionXml->saveXml();
142 $errors = array_filter(libxml_get_errors(),
function($a) {
143 return $a->level == LIBXML_ERR_ERROR || $a->level == LIBXML_ERR_FATAL;
145 if (!empty($errors)) {
160 $pubmedExportFilters = $filterDao->getObjectsByGroup(
'article=>pubmed-xml');
161 assert(count($pubmedExportFilters) == 1);
162 $exportFilter = array_shift($pubmedExportFilters);
163 $submissionsIterator =
Services::get(
'submission')->getMany([
164 'contextId' => $context->getId(),
165 'issueIds' => $issueIds,
167 libxml_use_internal_errors(
true);
168 $submissionXml = $exportFilter->execute(iterator_to_array($submissionsIterator),
true);
169 $xml = $submissionXml->saveXml();
170 $errors = array_filter(libxml_get_errors(),
function($a) {
171 return $a->level == LIBXML_ERR_ERROR || $a->level == LIBXML_ERR_FATAL;
173 if (!empty($errors)) {
185 $xmlFile = array_shift($args);
186 $journalPath = array_shift($args);
191 $journal = $journalDao->getByPath($journalPath);
194 if ($journalPath !=
'') {
195 echo __(
'plugins.importexport.pubmed.cliError') .
"\n";
196 echo __(
'plugins.importexport.pubmed.error.unknownJournal', array(
'journalPath' => $journalPath)) .
"\n\n";
198 $this->
usage($scriptName);
202 if ($xmlFile !=
'')
switch (array_shift($args)) {
205 $results = $articleSearch->formatResults($args);
206 if (!$this->exportArticles($results, $xmlFile)) {
207 echo __(
'plugins.importexport.pubmed.cliError') .
"\n";
208 echo __(
'plugins.importexport.pubmed.export.error.couldNotWrite', array(
'fileName' => $xmlFile)) .
"\n\n";
212 $issueId = array_shift($args);
213 $issue = $issueDao->getByBestId($issueId, $journal->getId());
214 if ($issue ==
null) {
215 echo __(
'plugins.importexport.pubmed.cliError') .
"\n";
216 echo __(
'plugins.importexport.pubmed.export.error.issueNotFound', array(
'issueId' => $issueId)) .
"\n\n";
219 $issues = array($issue);
220 if (!$this->
exportIssues($journal, $issues, $xmlFile)) {
221 echo __(
'plugins.importexport.pubmed.cliError') .
"\n";
222 echo __(
'plugins.importexport.pubmed.export.error.couldNotWrite', array(
'fileName' => $xmlFile)) .
"\n\n";
226 $this->
usage($scriptName);
234 echo __(
'plugins.importexport.pubmed.cliUsage', array(
235 'scriptName' => $scriptName,
236 'pluginName' => $this->
getName()