Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix changing author metadata on submission locale change #102

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions QuickSubmitForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class QuickSubmitForm extends Form
protected PKPSubmission $_submission;
protected Journal $_context;
protected SubmissionMetadataForm $form;
protected string $oldSubmissionLocale;

/**
* Constructor
Expand All @@ -68,6 +69,11 @@ public function __construct(QuickSubmitPlugin $plugin, PKPRequest $request)

if ($submissionId = $request->getUserVar('submissionId')) {
$this->_submission = Repo::submission()->get($submissionId);
if ($locale !== $this->_submission->getData('locale')) {
// This should actually happen when saving the submission, but I was not able to
// find the sulution to have old submission locale in execute()
Repo::author()->changePublicationLocale($this->_submission->getCurrentPublication()->getId(), $this->_submission->getData('locale'), $locale);
}

if ($this->_submission->getData('contextId') != $this->_context->getId()) {
throw new Exception('Submission not in context!');
Expand Down Expand Up @@ -343,8 +349,8 @@ public function initData()
// Assign the user author to the stage
Repo::stageAssignment()
->build(
$this->_submission->getId(),
$userGroupId,
$this->_submission->getId(),
$userGroupId,
$user->getId()
);
}
Expand Down
14 changes: 1 addition & 13 deletions classes/form/SubmissionMetadataForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function _getAbstractsRequired($submission)
{
$section = Repo::section()
->get(
$submission->getCurrentPublication()->getData('sectionId'),
$submission->getCurrentPublication()->getData('sectionId'),
$submission->getData('contextId')
);

Expand Down Expand Up @@ -239,18 +239,6 @@ public function execute($submission, $request)
'dataAvailability' => $this->_parentForm->getData('dataAvailability'),
];

// Update locale
$newLocale = $this->_parentForm->getData('locale');
if ($newLocale) {
$oldLocale = $publication->getData('locale');
if (in_array($newLocale, $context->getData('supportedSubmissionLocales'))) {
$params['locale'] = $newLocale;
}
if ($newLocale !== $oldLocale) {
Repo::author()->changePublicationLocale($publication->getId(), $oldLocale, $newLocale);
}
}

// Save the publication
Repo::publication()->edit($publication, $params);
$publication = Repo::publication()->get($publication->getId());
Expand Down