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

Fixed SS_Datetime value set to null #10

Open
wants to merge 3 commits into
base: master
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
28 changes: 28 additions & 0 deletions code/extensions/WorkflowEmbargoExpiryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class WorkflowEmbargoExpiryExtension extends DataExtension {

private static $db = array(
'PublishedDate' => 'SS_Datetime',
'DesiredPublishDate' => 'SS_Datetime',
'DesiredUnPublishDate' => 'SS_Datetime',
'PublishOnDate' => 'SS_Datetime',
Expand Down Expand Up @@ -84,18 +85,25 @@ public function updateCMSFields(FieldList $fields) {
new LiteralField('PublishDateIntro', $this->getIntroMessage('PublishDateIntro')),
$dt = new Datetimefield('PublishOnDate', _t('WorkflowEmbargoExpiryExtension.PUBLISH_ON', 'Scheduled publish date')),
$ut = new Datetimefield('UnPublishOnDate', _t('WorkflowEmbargoExpiryExtension.UNPUBLISH_ON', 'Scheduled un-publish date')),

new HeaderField('PublishedDateHeader', _t('WorkflowEmbargoExpiryExtension.PUBLISHED_DATE_H3', 'Published Date'), 3),
new LiteralField('PublishedDateIntro', $this->getIntroMessage('PublishedDateIntro')),
$pt = new Datetimefield('PublishedDate', _t('WorkflowEmbargoExpiryExtension.PUBLISHED', 'Published date')),
));
}

$dt->getDateField()->setConfig('showcalendar', true);
$ut->getDateField()->setConfig('showcalendar', true);
$pt->getDateField()->setConfig('showcalendar', true);
$dt->getTimeField()->setConfig('timeformat', 'HH:mm');
$ut->getTimeField()->setConfig('timeformat', 'HH:mm');
$pt->getTimeField()->setConfig('timeformat', 'HH:mm');

// Enable a jQuery-UI timepicker widget
if(self::$showTimePicker) {
$dt->getTimeField()->addExtraClass('hasTimePicker');
$ut->getTimeField()->addExtraClass('hasTimePicker');
$pt->getTimeField()->addExtraClass('hasTimePicker');
}
}

Expand Down Expand Up @@ -176,6 +184,22 @@ public function onBeforeWrite() {
}
}

/**
* Event handler called before Publishing SiteTree DataObject, overloaded from parent
*
* @uses DataObject->onBeforePublish()
*/
public function onBeforePublish() {
if (!$this->owner->PublishedDate || ($this->owner->PublishedDate && is_null($this->owner->PublishedDate))) {
if ($this->owner->PublishOnDate && (!is_null($this->owner->PublishOnDate))) {
$date = $this->owner->PublishOnDate;
} else {
$date = SS_Datetime::now()->getValue();
}
$this->owner->PublishedDate = $date;
}
}

/*
* Define an array of message-parts for use by {@link getIntroMessage()}
*
Expand All @@ -188,6 +212,10 @@ public function getIntroMessageParts($key) {
'INTRO'=>_t('WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE_INTRO','Enter a date and/or time to specify embargo and expiry dates.'),
'BULLET_1'=>_t('WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE_INTRO_BULLET_1','These settings won\'t take effect until any approval actions are run'),
'BULLET_2'=>_t('WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE_INTRO_BULLET_2','If an embargo is already set, adding a new one prior to that date\'s passing will overwrite it')
),
'PublishedDateIntro' => array(
'INTRO'=>_t('WorkflowEmbargoExpiryExtension.PUBLISHED_DATE_INTRO','Please note, this date will be used for sorting on front-end.'),
'BULLET_1'=>_t('WorkflowEmbargoExpiryExtension.PUBLISHED_DATE_INTRO_BULLET_1','These date will be automagically populated after first Save & Publish, you can change it manually anytime.'),
)
);
// If there's no effective workflow, no need for the first bullet-point
Expand Down
4 changes: 2 additions & 2 deletions code/jobs/WorkflowPublishTargetJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public function process() {
if ($target = $this->getObject()) {
if ($this->publishType == 'publish') {
$target->setIsPublishJobRunning(true);
$target->PublishOnDate = '';
$target->dbObject('PublishOnDate')->setValue(false);
$target->writeWithoutVersion();
$target->doPublish();
} else if ($this->publishType == 'unpublish') {
$target->setIsPublishJobRunning(true);
$target->UnPublishOnDate = '';
$target->dbObject('UnPublishOnDate')->setValue(false);
$target->writeWithoutVersion();
$target->doUnpublish();
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
"require":
{
"silverstripe/cms": ">=3.0.0",
"silverstripe/queuedjobs": "dev-master"
"silverstripe/queuedjobs": "^2.8"
}
}