From 2ce4b2e7729452f934126f0758dfd9a49dfa7b10 Mon Sep 17 00:00:00 2001 From: Kaitlin Newson Date: Tue, 13 Oct 2026 11:03:29 -0300 Subject: [PATCH] only allow exports with uploaded JATS documents for now --- InspecExportPlugin.php | 16 ++------------- README.md | 14 +++---------- classes/form/InspecSettingsForm.php | 1 - cypress/tests/functional/Inspec.cy.js | 14 ++++--------- locale/en/locale.po | 13 ++++-------- templates/settingsForm.tpl | 4 ---- tests/InspecExportPluginTest.php | 29 +++++++++++++++++++++++++++ tests/InspecSettingsFormTest.php | 1 - 8 files changed, 42 insertions(+), 50 deletions(-) diff --git a/InspecExportPlugin.php b/InspecExportPlugin.php index 8f61c3c..2c7f9bb 100644 --- a/InspecExportPlugin.php +++ b/InspecExportPlugin.php @@ -243,15 +243,11 @@ public function exportXML( $document = Repo::jats() ->getJatsFile($publication->getId(), $submissionId, $genres->toArray()); - // If this setting is enabled, only export user-uploaded JATS files and - // do not generate our own JATS. - $jatsImportedOnly = $this->jatsImportedOnly($context); - - // Check if the JATS file was found and that it was not generated if the setting is enabled. + // Only uploaded JATS is exported for now: generated JATS has no usable body or media. if ( !$document || !$document->jatsContent || - ($jatsImportedOnly && $document->isDefaultContent) || + $document->isDefaultContent || $document->loadingContentError ) { return ['plugins.importexport.inspec.export.failure.jatsFileNotFound']; @@ -290,14 +286,6 @@ public function getPluginSettingsPrefix(): string return 'inspec'; } - /** - * Get the JATS import setting value. - */ - public function jatsImportedOnly(Context $context): bool - { - return ($this->getSetting($context->getId(), 'jatsImported') == 1); - } - /** * Get the journal abbreviation used to name packages and files, falling * back to the journal's URL path when no abbreviation is set. diff --git a/README.md b/README.md index 62b35d8..0d37d71 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ An OJS plugin to export journal articles as JATS XML packages and deposit them t For each selected article the plugin builds a zip package containing: -- the article's JATS XML, and +- the article's uploaded JATS XML, and - the article's PDF galley (referenced from the XML with a `` element). Packages can either be downloaded for manual delivery, or deposited directly to Inspec's @@ -41,8 +41,8 @@ continue to index the uncorrected first version. There is no mechanism to push t - A way of running queued jobs, since deposits are dispatched as jobs: either OJS's scheduled `ProcessQueueJobs` task (which runs with the rest of the scheduler) or a dedicated worker, `php lib/pkp/tools/jobs.php work`. -- The [JATS Template plugin](https://github.com/pkp/jatsTemplate), which generates the JATS XML - when an article has no JATS file of its own. +- A valid JATS XML file uploaded to each publication. OJS-generated JATS has no usable body + or media files, so a publication without an uploaded file fails to export. - The `league/flysystem-sftp-v3` library, bundled with OJS. If it is missing, the settings page will say so; install it with: @@ -50,20 +50,12 @@ continue to index the uncorrected first version. There is no mechanism to push t composer -d lib/pkp require league/flysystem-sftp-v3 ``` -- To include article full text in generated JATS, `pdftotext` must be enabled in - `config.inc.php` under `[search]`: - - ``` - index[application/pdf] = "/usr/bin/pdftotext %s -" - ``` - ## Settings Journal Settings → Distribution → Inspec, or the plugin's Import/Export page. | Setting | Description | |--------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------| -| Only use uploaded JATS XML | When enabled, articles without an uploaded JATS file are skipped rather than falling back to system-generated JATS. | | Automatic deposit | Deposit newly published articles on the daily scheduled task. | | Host, Port, Path, Username, Password | SFTP connection details. Port defaults to 22. The password is stored encrypted. | diff --git a/classes/form/InspecSettingsForm.php b/classes/form/InspecSettingsForm.php index d9d7183..0677d10 100644 --- a/classes/form/InspecSettingsForm.php +++ b/classes/form/InspecSettingsForm.php @@ -122,7 +122,6 @@ public function execute(...$functionArgs): void public function getFormFields(): array { return [ - 'jatsImported' => 'bool', 'automaticRegistration' => 'bool', 'host' => 'string', 'port' => 'string', diff --git a/cypress/tests/functional/Inspec.cy.js b/cypress/tests/functional/Inspec.cy.js index 4f0d78e..8443bac 100644 --- a/cypress/tests/functional/Inspec.cy.js +++ b/cypress/tests/functional/Inspec.cy.js @@ -10,7 +10,7 @@ describe('Inspec plugin tests', function () { - it('Configures the plugin, shows export tabs, and exports a valid zip', function() { + it('Configures the plugin, shows export tabs, and refuses to export generated JATS', function() { cy.login('admin', 'admin', 'publicknowledge'); cy.get('nav').contains('Settings').click(); @@ -40,8 +40,7 @@ describe('Inspec plugin tests', function () { // Verify the export tab is present. cy.get('a[href="#exportSubmissions-tab"]').should('exist'); - // Drive the export via cy.request to avoid Cypress hanging on the - // streaming binary download. + // Submission 1 has no uploaded JATS, so the export redirects back with an error. cy.getCsrfToken(); cy.get('@csrfToken').then((csrfToken) => { cy.request({ @@ -59,15 +58,10 @@ describe('Inspec plugin tests', function () { 'export=1', ].join('&'), timeout: 60000, - encoding: 'binary', followRedirect: false, }).then((response) => { - expect(response.status).to.eq(200); - expect(response.headers['content-type']).to.eq('application/zip'); - expect(response.body).to.have.length.gt(0); - // All zip files start with 'PK' (ASCII for the local file - // header magic 0x50 0x4B). - expect(response.body.slice(0, 2)).to.eq('PK'); + expect(response.status).to.eq(302); + expect(response.headers['content-type']).to.not.eq('application/zip'); }); }); }); diff --git a/locale/en/locale.po b/locale/en/locale.po index b91b99c..48c5dfb 100644 --- a/locale/en/locale.po +++ b/locale/en/locale.po @@ -5,10 +5,10 @@ msgid "plugins.importexport.inspec.description" msgstr "" "This plugin may be used to export your journal content to Inspec. " "Content can be downloaded for later delivery to Inspec, or sent to your account on the Inspec server by " -"configuring your credentials below." +"configuring your credentials below. Only articles with an uploaded JATS XML file can be exported." msgid "plugins.importexport.inspec.description.short" -msgstr "Export journal articles to Inspec." +msgstr "Export journal articles with uploaded JATS XML to Inspec." msgid "plugins.importexport.inspec.senderTask.name" msgstr "Inspec automatic deposit task" @@ -60,7 +60,7 @@ msgid "plugins.importexport.inspec.export.failure.journalNotFound" msgstr "The journal this deposit was queued for could not be found." msgid "plugins.importexport.inspec.export.failure.jatsFileNotFound" -msgstr "No suitable JATS XML file was found for export." +msgstr "No uploaded JATS XML file was found for export. Upload a JATS XML file to the publication and try again." msgid "plugins.importexport.inspec.export.failure.multipleArticleFiles" msgstr "" @@ -100,13 +100,8 @@ msgstr "Please provide the host, username and password, or leave all three blank msgid "plugins.importexport.inspec.settings.form.automaticRegistrationRequiresAccount" msgstr "Automatic deposit requires a complete SFTP account: please provide the host, username and password." -msgid "plugins.importexport.inspec.settings.form.jatsImportedOnly" -msgstr "" -"Only allow exports for articles with uploaded JATS XML files. If not enabled, the plugin will use " -"system-generated JATS when no JATS XML file is present." - msgid "plugins.generic.inspec.displayName" msgstr "Inspec Plugin" msgid "plugins.generic.inspec.description" -msgstr "Exports articles or article versions to Inspec." +msgstr "Exports articles or article versions with uploaded JATS XML to Inspec." diff --git a/templates/settingsForm.tpl b/templates/settingsForm.tpl index b8d5ed5..780ef81 100644 --- a/templates/settingsForm.tpl +++ b/templates/settingsForm.tpl @@ -23,10 +23,6 @@ {translate key="plugins.importexport.inspec.description"}


- {fbvFormSection list="true"} - {fbvElement type="checkbox" id="jatsImported" label="plugins.importexport.inspec.settings.form.jatsImportedOnly" checked=$jatsImported|compare:true} - {/fbvFormSection} - {fbvFormSection list="true"} {fbvElement type="checkbox" id="automaticRegistration" label="plugins.importexport.inspec.settings.form.automaticRegistration.description" checked=$automaticRegistration|compare:true} {/fbvFormSection} diff --git a/tests/InspecExportPluginTest.php b/tests/InspecExportPluginTest.php index 2647f1a..b40b02d 100644 --- a/tests/InspecExportPluginTest.php +++ b/tests/InspecExportPluginTest.php @@ -548,6 +548,7 @@ public function testExportXmlIgnoresLeftoverLibxmlErrors(): void ->disableOriginalConstructor() ->getMock(); $jatsFile->jatsContent = $this->jats(); + $jatsFile->isDefaultContent = false; $jatsRepository = $this->createMock(JatsRepository::class); $jatsRepository->method('getJatsFile')->willReturn($jatsFile); app()->instance(JatsRepository::class, $jatsRepository); @@ -576,6 +577,34 @@ public function testExportXmlIgnoresLeftoverLibxmlErrors(): void $this->assertStringContainsString('Test article', $result); } + public function testExportXmlRefusesGeneratedJats(): void + { + $jatsFile = $this->getMockBuilder(JatsFile::class) + ->disableOriginalConstructor() + ->getMock(); + $jatsFile->jatsContent = $this->jats(); + $jatsFile->isDefaultContent = true; + $jatsRepository = $this->createMock(JatsRepository::class); + $jatsRepository->method('getJatsFile')->willReturn($jatsFile); + app()->instance(JatsRepository::class, $jatsRepository); + + $publication = new Publication(); + $publication->setId(1); + $publication->setData('submissionId', 7449); + + try { + $outputErrors = null; + $result = (new ReflectionMethod(InspecExportPlugin::class, 'exportXML'))->invokeArgs( + $this->createPlugin(), + [$publication, null, $this->createJournal(), true, &$outputErrors, null, collect()] + ); + } finally { + app()->forgetInstance(JatsRepository::class); + } + + $this->assertSame(['plugins.importexport.inspec.export.failure.jatsFileNotFound'], $result); + } + // // addPdfSelfUri() // diff --git a/tests/InspecSettingsFormTest.php b/tests/InspecSettingsFormTest.php index eb020a2..86bdddc 100644 --- a/tests/InspecSettingsFormTest.php +++ b/tests/InspecSettingsFormTest.php @@ -60,7 +60,6 @@ public function testFormFieldsAreTheExpectedSettings(): void $form = $this->createForm(); $this->assertSame([ - 'jatsImported' => 'bool', 'automaticRegistration' => 'bool', 'host' => 'string', 'port' => 'string',