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

Added unpublish action and moved set property from editable user forms #238

Closed
wants to merge 4 commits into from
Closed
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
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;
}

}
76 changes: 76 additions & 0 deletions code/actions/UnpublishItemWorkflowAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?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/publish.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 publication ');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Delay un-publishing" maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, missed changing the text there...

$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;
}

/**
* Unpublish action allows a user who is currently assigned at this point of the workflow to
*
* @param DataObject $target
* @return bool
*/
public function canPublishTarget(DataObject $target) {
return true;
}

}