Permalink
Browse files

BUGFIX: When no effective workflow is enabled, PHP Notice's were thro…

…wn for undefined variable $uth on WorkflowEmbargoExpiryExtension

BUGFIX: WorkflowEmbargoExpiryExtension validation was kicking-in when scheduled dates were not filled-in; implemented getter+setter for effective workflow checking to prevent this
MINOR: Changed intro text on WorkflowEmbargoExpiryExtension depending on effective workflow
  • Loading branch information...
1 parent e90a95f commit 8cd0acfd2897f9060528f401a26ce5c6ae9431da Russell Michell committed Nov 29, 2012
Showing with 34 additions and 8 deletions.
  1. +31 −7 code/extensions/WorkflowEmbargoExpiryExtension.php
  2. +3 −1 templates/Includes/embargoIntro.ss
@@ -33,6 +33,11 @@ class WorkflowEmbargoExpiryExtension extends DataExtension {
public $workflowService;
/**
+ * @var Is a workflow in effect?
+ */
+ public $isWorkflowInEffect = false;
+
+ /**
*
* @var array $extendedMethodReturn A basic extended validation routine method return format
*/
@@ -56,12 +61,9 @@ public function updateCMSFields(FieldList $fields) {
Requirements::javascript(ADVANCED_WORKFLOW_DIR . '/thirdparty/javascript/jquery-ui/timepicker/jquery-ui-timepicker-addon.js');
Requirements::javascript(ADVANCED_WORKFLOW_DIR . '/javascript/WorkflowField.js');
+ $this->setIsWorkflowInEffect();
- // if there is a workflow applied, we can't set the publishing date directly, only the 'desired'
- // publishing date
- $effective = $this->workflowService->getDefinitionFor($this->owner);
-
- if ($effective) {
+ if ($this->getIsWorkflowInEffect()) {
$fields->addFieldsToTab('Root.PublishingSchedule', array(
new HeaderField('PublishDateHeader', _t('WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE_H3', 'Expiry and Embargo'), 3),
new LiteralField('PublishDateIntro', $this->getIntroMessage('PublishDateIntro')),
@@ -72,17 +74,19 @@ public function updateCMSFields(FieldList $fields) {
// Readonly fields do not store any value, so add a hidden-field and set its value to the current PublishOnDate so we can perform some validation
$uth = new HiddenField('PublishOnDateOwner')
));
+ // Set a value to our hidden field
+ $uth->setValue($this->owner->PublishOnDate);
} else {
$fields->addFieldsToTab('Root.PublishingSchedule', array(
+ new HeaderField('PublishDateHeader', _t('WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE_H3', 'Expiry and Embargo'), 3),
+ 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')),
));
}
$dt->getDateField()->setConfig('showcalendar', true);
$ut->getDateField()->setConfig('showcalendar', true);
- // Set a value to our hidden field
- $uth->setValue($this->owner->PublishOnDate);
// Enable a jQuery-UI timepicker widget
if(self::$showTimePicker) {
@@ -157,6 +161,10 @@ public function getIntroMessageParts($key) {
'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')
)
);
+ // If there's no effective workflow, no need for the first bullet-point
+ if(!$this->getIsWorkflowInEffect()) {
+ $parts['PublishDateIntro']['BULLET_1'] = false;
+ }
return $parts[$key];
}
@@ -191,6 +199,9 @@ public function getCMSValidator() {
* @return array
*/
public function extendedRequiredFieldsCheckEmbargoDates($data = null) {
+ if(!$this->getIsWorkflowInEffect() || !isset($data['PublishOnDateOwner'])) {
+ return self::$extendedMethodReturn;
+ }
$desiredEmbargo = strtotime($data['DesiredPublishDate']);
$scheduledEmbargo = strtotime($data['PublishOnDateOwner']);
$desiredExpiry = strtotime($data['DesiredUnPublishDate']);
@@ -239,4 +250,17 @@ public function getUserDate($date) {
$member = Member::currentUser();
return $date->toString($member->getDateFormat().' '.$member->getTimeFormat());
}
+
+ /*
+ * Sets property as boolean true|false if an effective workflow is found or not
+ */
+ public function setIsWorkflowInEffect() {
+ // if there is a workflow applied, we can't set the publishing date directly, only the 'desired' publishing date
+ $effective = $this->workflowService->getDefinitionFor($this->owner);
+ $this->isWorkflowInEffect = $effective?true:false;
+ }
+
+ public function getIsWorkflowInEffect() {
+ return $this->isWorkflowInEffect;
+ }
}
@@ -1,7 +1,9 @@
<p>$INTRO</p>
<ul>
- <li>$BULLET_1</li>
+ <% if BULLET_1 %>
+ <li>$BULLET_1</li>
+ <% end_if %>
<li>$BULLET_2</li>
</ul>
<br/>

0 comments on commit 8cd0acf

Please sign in to comment.