From 0aeb0c397c78ae48d255952aa0a231b0d1849d2b Mon Sep 17 00:00:00 2001 From: Milan Jelicanin Date: Tue, 5 Apr 2016 11:57:35 +0200 Subject: [PATCH 1/3] fixed SS_Datetime value set to null --- code/jobs/WorkflowPublishTargetJob.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/jobs/WorkflowPublishTargetJob.php b/code/jobs/WorkflowPublishTargetJob.php index 0329c44..2424d5f 100644 --- a/code/jobs/WorkflowPublishTargetJob.php +++ b/code/jobs/WorkflowPublishTargetJob.php @@ -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(); } From 7349a9e70a4cf3a6d5869c028b948455492ab06f Mon Sep 17 00:00:00 2001 From: Milan Jelicanin Date: Tue, 5 Apr 2016 12:24:54 +0200 Subject: [PATCH 2/3] added new field PublishedDate for sorting DO's at front-end added event handler onBeforePublish for automatization --- .../WorkflowEmbargoExpiryExtension.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/code/extensions/WorkflowEmbargoExpiryExtension.php b/code/extensions/WorkflowEmbargoExpiryExtension.php index 4d07ea2..262010e 100644 --- a/code/extensions/WorkflowEmbargoExpiryExtension.php +++ b/code/extensions/WorkflowEmbargoExpiryExtension.php @@ -8,6 +8,7 @@ class WorkflowEmbargoExpiryExtension extends DataExtension { private static $db = array( + 'PublishedDate' => 'SS_Datetime', 'DesiredPublishDate' => 'SS_Datetime', 'DesiredUnPublishDate' => 'SS_Datetime', 'PublishOnDate' => 'SS_Datetime', @@ -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'); } } @@ -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()} * @@ -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 From 940bd53987d152baf3c7872d85a30170158ad3d6 Mon Sep 17 00:00:00 2001 From: Milan Jelicanin Date: Sat, 25 Mar 2017 23:54:57 +0100 Subject: [PATCH 3/3] compatiblity update --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 56b2863..ac0e571 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,6 @@ "require": { "silverstripe/cms": ">=3.0.0", - "silverstripe/queuedjobs": "dev-master" + "silverstripe/queuedjobs": "^2.8" } }