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

pkp/pkp-lib#7165 Issue datePublished can be set when adding an issue #3500

Open
wants to merge 2 commits 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
6 changes: 5 additions & 1 deletion classes/controllers/grid/issues/IssueGridHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,11 @@ public function publishIssue($args, $request)
}

$issue->setPublished(1);
$issue->setDatePublished(Core::getCurrentDate());

// If no datePublished was given, use current date
if (!$issue->getData('datePublished')) {
$issue->setDatePublished(Core::getCurrentDate());
}

// If subscriptions with delayed open access are enabled then
// update open access date according to open access delay policy
Expand Down
36 changes: 26 additions & 10 deletions classes/publication/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,35 @@ public function version(Publication $publication): int
return $newId;
}

/** @copydoc \PKP\publication\Repository::setStatusOnPublish() */
/**
* Set the status and date of publication
*
* A publication's status and date of publication will be set depending
* on the issue it is assigned to. Publications in future issues should
* be set to `STATUS_SCHEDULED`. Otherwise, they should be set to
* `STATUS_PUBLISHED` and should inherit the date of publication from the
* issue, unless a date of publication has already been set.
*
* Usually, the date of publication will be set when the issue is
* published. In some unusual cases, a publication may be published
* without an issue. This may happen in a continuous publishing model
* where articles are published right away. In these cases, the date of
* publication should be set to the current date, unless a date of
* publication has already been set.
*/
protected function setStatusOnPublish(Publication $publication)
{
// A publication may be scheduled in a future issue. In such cases,
// the `datePublished` should remain empty and the status should be set to
// scheduled.
//
// If there is no assigned issue, the journal may be using a continuous
// publishing model in which articles are published right away.
$issue = Repo::issue()->get($publication->getData('issueId'));
if ($issue && !$issue->getData('published')) {
$publication->setData('datePublished', null);
$publication->setData('status', Submission::STATUS_SCHEDULED);

if ($issue) {
if ($issue->getData('published')) {
$publication->setData('status', Submission::STATUS_PUBLISHED);
if (!$publication->getData('datePublished')) {
$publication->setData('datePublished', $issue->getData('datePublished'));
}
} else {
$publication->setData('status', Submission::STATUS_SCHEDULED);
}
} else {
$publication->setData('status', Submission::STATUS_PUBLISHED);
if (!$publication->getData('datePublished')) {
Expand Down
8 changes: 4 additions & 4 deletions controllers/grid/issues/IssueGridRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ public function initialize($request, $template = null)
$dispatcher = $request->getDispatcher();
$this->addAction(
new LinkAction(
$issue->getDatePublished() ? 'viewIssue' : 'previewIssue',
$issue->getPublished() ? 'viewIssue' : 'previewIssue',
new OpenWindowAction(
$dispatcher->url($request, PKPApplication::ROUTE_PAGE, null, 'issue', 'view', [$issueId])
),
__($issue->getDatePublished() ? 'grid.action.viewIssue' : 'grid.action.previewIssue'),
__($issue->getPublished() ? 'grid.action.viewIssue' : 'grid.action.previewIssue'),
'information'
)
);

if ($issue->getDatePublished()) {
if ($issue->getPublished()) {
$this->addAction(
new LinkAction(
'unpublish',
Expand Down Expand Up @@ -111,7 +111,7 @@ public function initialize($request, $template = null)

$currentIssue = Repo::issue()->getCurrent($issue->getJournalId());
$isCurrentIssue = $currentIssue != null && $issue->getId() == $currentIssue->getId();
if ($issue->getDatePublished() && !$isCurrentIssue) {
if ($issue->getPublished() && !$isCurrentIssue) {
$this->addAction(
new LinkAction(
'setCurrentIssue',
Expand Down
34 changes: 33 additions & 1 deletion controllers/grid/issues/form/IssueForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\RemoteActionConfirmationModal;
use PKP\plugins\Hook;
use PKP\validation\ValidatorFactory;

class IssueForm extends Form
{
Expand Down Expand Up @@ -60,6 +61,7 @@ public function __construct($issue = null)
return !$showTitle || implode('', $form->getData('title')) != '' ? true : false;
}));
$this->addCheck(new \PKP\form\validation\FormValidatorRegExp($this, 'urlPath', 'optional', 'validator.alpha_dash_period', '/^[a-zA-Z0-9]+([\\.\\-_][a-zA-Z0-9]+)*$/'));

$this->addCheck(new \PKP\form\validation\FormValidatorPost($this));
$this->addCheck(new \PKP\form\validation\FormValidatorCSRF($this));
$this->issue = $issue;
Expand Down Expand Up @@ -143,6 +145,29 @@ public function validate($callHooks = true)
}
}

// Note! The following datePublished validation is not triggered
// when JQuery DatePicker is enabled in the datePublished field.
// The datePicker will convert any invalid date into a valid yyyy-mm-dd
// date before the form data is submitted.

if ($this->getData('datePublished')) {
$validator = ValidatorFactory::make(
['value' => $this->getData('datePublished')],
['value' => ['required', 'date_format:Y-m-d']]
);

if (!$validator->passes()) {
$this->addError('datePublished', __('editor.issues.datePublished.invalid'));
$this->addErrorField('datePublished');
}
}

// Published issue has to have datePublished set
if (!$this->getData('datePublished') && ($this->issue && $this->issue->getPublished())) {
$this->addError('datePublished', __('editor.issues.datePublished.requiredWhenPublished'));
$this->addErrorField('datePublished');
}

return parent::validate($callHooks);
}

Expand Down Expand Up @@ -243,9 +268,16 @@ public function execute(...$functionArgs)
$issue->setVolume(empty($volume) ? null : $volume);
$issue->setNumber(empty($number) ? null : $number);
$issue->setYear(empty($year) ? null : $year);
if (!$isNewIssue) {

// If issue is not published, allow empty datePublished
if (!$this->getData('datePublished') && !$issue->getPublished()) {
$issue->setDatePublished(null);
}
ajnyga marked this conversation as resolved.
Show resolved Hide resolved

if ($this->getData('datePublished')) {
ajnyga marked this conversation as resolved.
Show resolved Hide resolved
$issue->setDatePublished($this->getData('datePublished'));
}

$issue->setDescription($this->getData('description'), null); // Localized
$issue->setShowVolume((int) $this->getData('showVolume'));
$issue->setShowNumber((int) $this->getData('showNumber'));
Expand Down
2 changes: 1 addition & 1 deletion lib/pkp
9 changes: 9 additions & 0 deletions locale/en/editor.po
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ msgstr "Unpublished"
msgid "editor.issues.datePublished"
msgstr "Date Published"

msgid "editor.issues.datePublished.notPublished.description"
msgstr "Leave this empty and it will be set automatically when the issue is published."

msgid "editor.issues.datePublished.invalid"
msgstr "Date Published is not valid. The date must be in the format YYYY-MM-DD."

msgid "editor.issues.datePublished.requiredWhenPublished"
msgstr "Date Published is required when the issue is published."

msgid "editor.issues.volumeRequired"
msgstr "Volume is required and must be a positive, numeric value."

Expand Down
12 changes: 6 additions & 6 deletions templates/controllers/grid/issues/form/issueForm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@
{assign var=issuePublished value=false}
{/if}

{if $issuePublished}
{fbvFormArea id="datePublishedArea" title="editor.issues.datePublished"}
{fbvFormSection}
{if $issuePublished}
{fbvElement type="text" id="datePublished" value=$datePublished size=$fbvStyles.size.SMALL class="datepicker"}
{/if}
{if !$issuePublished}
{assign var=notPublishedDescription value="editor.issues.datePublished.notPublished.description"}
{else}
{assign var=notPublishedDescription value=""}
{/if}
{fbvElement type="text" id="datePublished" value=$datePublished size=$fbvStyles.size.SMALL class="datepicker" autocomplete="off" label=$notPublishedDescription}
{/fbvFormSection}
{/fbvFormArea}
{/if}


{fbvFormArea id="identificationArea" title="editor.issues.identification"}
{fbvFormSection}
Expand Down
Loading