Skip to content

Commit

Permalink
Merge pull request #238 from Neumes
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Nyeholt committed Dec 23, 2015
2 parents 2a64557 + 0a6328b commit 4f66570
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
40 changes: 40 additions & 0 deletions code/actions/SetPropertyWorkflowAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
*
*
* @author Marcus Nyeholt <marcus@silverstripe.com.au>
*/
class SetPropertyWorkflowAction extends WorkflowAction {
private static $db = array(
'Property' => 'Varchar',
'Value' => 'Text',
);

public function execute(WorkflowInstance $workflow) {
if (!$target = $workflow->getTarget()) {
return true;
}

if ($target->hasField($this->Property)) {
$target->setField($this->Property, $this->Value);
}

$target->write();

return true;
}

public function getCMSFields() {
$fields = parent::getCMSFields();

$fields->addFieldsToTab('Root.Main', array(
TextField::create('Property', _t('SetPropertyWorkflowAction.PROPERTY', 'Property'))
->setRightTitle(_t('SetPropertyWorkflowAction.PROPERTYTITLE', 'Property to set; if this exists as a setter method, will be called passing the value')),
TextField::create('Value', 'Value')
));

return $fields;
}

}
74 changes: 74 additions & 0 deletions code/actions/UnpublishItemWorkflowAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Unpublishes an item
*
* @author marcus@silverstripe.com.au
* @license BSD License (http://silverstripe.org/bsd-license/)
* @package advancedworkflow
* @subpackage actions
*/
class UnpublishItemWorkflowAction extends WorkflowAction {

private static $db = array(
'UnpublishDelay' => 'Int'
);

public static $icon = 'advancedworkflow/images/unpublish.png';

public function execute(WorkflowInstance $workflow) {
if (!$target = $workflow->getTarget()) {
return true;
}

if (class_exists('AbstractQueuedJob') && $this->UnpublishDelay) {
$job = new WorkflowPublishTargetJob($target, "unpublish");
$days = $this->UnpublishDelay;
$after = date('Y-m-d H:i:s', strtotime("+$days days"));
singleton('QueuedJobService')->queueJob($job, $after);
} else if ($target->hasExtension('WorkflowEmbargoExpiryExtension')) {
// setting future date stuff if needbe

// set these values regardless
$target->DesiredUnPublishDate = '';
$target->DesiredPublishDate = '';
$target->write();

if ($target->hasMethod('doUnpublish')) {
$target->doUnpublish();
}
} else {
if ($target->hasMethod('doUnpublish')) {
$target->doUnpublish();
}
}

return true;
}

public function getCMSFields() {
$fields = parent::getCMSFields();

if (class_exists('AbstractQueuedJob')) {
$before = _t('UnpublishItemWorkflowAction.DELAYUNPUBDAYSBEFORE', 'Delay unpublishing by ');
$after = _t('UnpublishItemWorkflowAction.DELAYUNPUBDAYSAFTER', ' days');

$fields->addFieldToTab('Root.Main', new FieldGroup(
_t('UnpublishItemWorkflowAction.UNPUBLICATIONDELAY', 'Delay Un-publishing'),
new LabelField('UnpublishDelayBefore', $before),
new NumericField('UnpublishDelay', ''),
new LabelField('UnpublishDelayAfter', $after)
));
}

return $fields;
}

/**
* @param DataObject $target
* @return bool
*/
public function canPublishTarget(DataObject $target) {
return false;
}

}
Binary file added images/unpublish.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4f66570

Please sign in to comment.