Skip to content

Commit

Permalink
Merge pull request #26 from bozana/stable-3_4_0
Browse files Browse the repository at this point in the history
#25 immediatelly set _exportPlugin during plugin initializat…
  • Loading branch information
bozana authored Apr 16, 2024
2 parents 8110f5e + 4677601 commit 3bb6449
Showing 1 changed file with 10 additions and 31 deletions.
41 changes: 10 additions & 31 deletions MedraPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,10 @@ public function setEnabled($enabled)
public function exportSubmissions(array $submissions, Context $context): array
{
// Get filter and set objectsFileNamePart (see: PubObjectsExportPlugin::prepareAndExportPubObjects)
$exportPlugin = $this->_getExportPlugin();
$filterName = $exportPlugin->getSubmissionFilter();
$filterName = $this->_exportPlugin->getSubmissionFilter();
$xmlErrors = [];

$temporaryFileId = $exportPlugin->exportAsDownload($context, $submissions, $filterName, 'articles', null, $xmlErrors);
$temporaryFileId = $this->_exportPlugin->exportAsDownload($context, $submissions, $filterName, 'articles', null, $xmlErrors);
return ['temporaryFileId' => $temporaryFileId, 'xmlErrors' => $xmlErrors];
}

Expand All @@ -120,10 +119,9 @@ public function exportSubmissions(array $submissions, Context $context): array
*/
public function depositSubmissions(array $submissions, Context $context): array
{
$exportPlugin = $this->_getExportPlugin();
$filterName = $exportPlugin->getSubmissionFilter();
$filterName = $this->_exportPlugin->getSubmissionFilter();
$responseMessage = '';
$status = $exportPlugin->exportAndDeposit($context, $submissions, $filterName, $responseMessage);
$status = $this->_exportPlugin->exportAndDeposit($context, $submissions, $filterName, $responseMessage);

return [
'hasErrors' => !$status,
Expand All @@ -138,11 +136,10 @@ public function depositSubmissions(array $submissions, Context $context): array
public function exportIssues(array $issues, Context $context): array
{
// Get filter and set objectsFileNamePart (see: PubObjectsExportPlugin::prepareAndExportPubObjects)
$exportPlugin = $this->_getExportPlugin();
$filterName = $exportPlugin->getIssueFilter();
$filterName = $this->_exportPlugin->getIssueFilter();
$xmlErrors = [];

$temporaryFileId = $exportPlugin->exportAsDownload($context, $issues, $filterName, 'issues', null, $xmlErrors);
$temporaryFileId = $this->_exportPlugin->exportAsDownload($context, $issues, $filterName, 'issues', null, $xmlErrors);
return ['temporaryFileId' => $temporaryFileId, 'xmlErrors' => $xmlErrors];
}

Expand All @@ -152,10 +149,9 @@ public function exportIssues(array $issues, Context $context): array
*/
public function depositIssues(array $issues, Context $context): array
{
$exportPlugin = $this->_getExportPlugin();
$filterName = $exportPlugin->getIssueFilter();
$filterName = $this->_exportPlugin->getIssueFilter();
$responseMessage = '';
$status = $exportPlugin->exportAndDeposit($context, $issues, $filterName, $responseMessage);
$status = $this->_exportPlugin->exportAndDeposit($context, $issues, $filterName, $responseMessage);

return [
'hasErrors' => !$status,
Expand Down Expand Up @@ -222,7 +218,7 @@ public function addAsRegistrationAgencyOption(string $hookName, array $args)
public function addRegistrationAgencyName(string $hookName, array $args): bool
{
$config = &$args[0];
$config['registrationAgencyNames'][$this->_getExportPlugin()->getName()] = $this->getRegistrationAgencyName();
$config['registrationAgencyNames'][$this->_exportPlugin->getName()] = $this->getRegistrationAgencyName();
return HOOK::CONTINUE;
}

Expand Down Expand Up @@ -352,6 +348,7 @@ public function getFailedMsgSettingName(): string
private function _pluginInitialization()
{
PluginRegistry::register('importexport', new MedraExportPlugin($this), $this->getPluginPath());
$this->_exportPlugin = PluginRegistry::getPlugin('importexport', 'MedraExportPlugin');

Hook::add('DoiSettingsForm::setEnabledRegistrationAgencies', [$this, 'addAsRegistrationAgencyOption']);
Hook::add('DoiSetupSettingsForm::getObjectTypes', [$this, 'addAllowedObjectTypes']);
Expand All @@ -360,24 +357,6 @@ private function _pluginInitialization()
Hook::add('Doi::markRegistered', [$this, 'editMarkRegisteredParams']);
}

/**
* Get mEDRA export plugin
*/
private function _getExportPlugin(): MedraExportPlugin
{
if (empty($this->_exportPlugin)) {
$pluginCategory = 'importexport';
$pluginPathName = 'MedraExportPlugin';
$this->_exportPlugin = PluginRegistry::getPlugin($pluginCategory, $pluginPathName);
// If being run from CLI, there is no context, so plugin initialization would not have been fired
if ($this->_exportPlugin === null && !isset($_SERVER['SERVER_NAME'])) {
$this->_pluginInitialization();
$this->_exportPlugin = PluginRegistry::getPlugin($pluginCategory, $pluginPathName);
}
}
return $this->_exportPlugin;
}

/**
* Call the migration script before the plugin installation
*
Expand Down

0 comments on commit 3bb6449

Please sign in to comment.