Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions InspecExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 3 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<self-uri>` element).

Packages can either be downloaded for manual delivery, or deposited directly to Inspec's
Expand Down Expand Up @@ -41,29 +41,21 @@ 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:

```bash
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. |

Expand Down
1 change: 0 additions & 1 deletion classes/form/InspecSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public function execute(...$functionArgs): void
public function getFormFields(): array
{
return [
'jatsImported' => 'bool',
'automaticRegistration' => 'bool',
'host' => 'string',
'port' => 'string',
Expand Down
14 changes: 4 additions & 10 deletions cypress/tests/functional/Inspec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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({
Expand All @@ -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');
});
});
});
Expand Down
13 changes: 4 additions & 9 deletions locale/en/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ msgid "plugins.importexport.inspec.description"
msgstr ""
"This plugin may be used to export your journal content to <a href=\"https://www.theiet.org/publishing/inspec/\" target=\"_blank\">Inspec</a>. "
"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"
Expand Down Expand Up @@ -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 ""
Expand Down Expand Up @@ -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."
4 changes: 0 additions & 4 deletions templates/settingsForm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
{translate key="plugins.importexport.inspec.description"}
</p>
<br/>
{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}
Expand Down
29 changes: 29 additions & 0 deletions tests/InspecExportPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -576,6 +577,34 @@ public function testExportXmlIgnoresLeftoverLibxmlErrors(): void
$this->assertStringContainsString('<article-title>Test article</article-title>', $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()
//
Expand Down
1 change: 0 additions & 1 deletion tests/InspecSettingsFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public function testFormFieldsAreTheExpectedSettings(): void
$form = $this->createForm();

$this->assertSame([
'jatsImported' => 'bool',
'automaticRegistration' => 'bool',
'host' => 'string',
'port' => 'string',
Expand Down
Loading