|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Unpublishes an item |
|
4
|
|
|
* |
|
5
|
|
|
* @author [email protected] |
|
6
|
|
|
* @license BSD License (http://silverstripe.org/bsd-license/) |
|
7
|
|
|
* @package advancedworkflow |
|
8
|
|
|
* @subpackage actions |
|
9
|
|
|
*/ |
|
10
|
|
|
class UnpublishItemWorkflowAction extends WorkflowAction { |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
private static $db = array( |
|
|
|
|
|
|
13
|
|
|
'UnpublishDelay' => 'Int' |
|
14
|
|
|
); |
|
15
|
|
|
|
|
16
|
|
|
public static $icon = 'advancedworkflow/images/publish.png'; |
|
17
|
|
|
|
|
18
|
|
|
public function execute(WorkflowInstance $workflow) { |
|
19
|
|
|
if (!$target = $workflow->getTarget()) { |
|
20
|
|
|
return true; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
if (class_exists('AbstractQueuedJob') && $this->UnpublishDelay) { |
|
|
|
|
|
|
24
|
|
|
$job = new WorkflowPublishTargetJob($target, "unpublish"); |
|
25
|
|
|
$days = $this->UnpublishDelay; |
|
|
|
|
|
|
26
|
|
|
$after = date('Y-m-d H:i:s', strtotime("+$days days")); |
|
27
|
|
|
singleton('QueuedJobService')->queueJob($job, $after); |
|
28
|
|
|
} else if ($target->hasExtension('WorkflowEmbargoExpiryExtension')) { |
|
29
|
|
|
// setting future date stuff if needbe |
|
30
|
|
|
|
|
31
|
|
|
// set these values regardless |
|
32
|
|
|
$target->DesiredUnPublishDate = ''; |
|
33
|
|
|
$target->DesiredPublishDate = ''; |
|
34
|
|
|
$target->write(); |
|
35
|
|
|
|
|
36
|
|
|
if ($target->hasMethod('doUnpublish')) { |
|
37
|
|
|
$target->doUnpublish(); |
|
38
|
|
|
} |
|
39
|
|
|
} else { |
|
40
|
|
|
if ($target->hasMethod('doUnpublish')) { |
|
41
|
|
|
$target->doUnpublish(); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return true; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
View Code Duplication |
public function getCMSFields() { |
|
|
|
|
|
|
49
|
|
|
$fields = parent::getCMSFields(); |
|
50
|
|
|
|
|
51
|
|
|
if (class_exists('AbstractQueuedJob')) { |
|
52
|
|
|
$before = _t('UnpublishItemWorkflowAction.DELAYUNPUBDAYSBEFORE', 'Delay publication '); |
|
53
|
|
|
$after = _t('UnpublishItemWorkflowAction.DELAYUNPUBDAYSAFTER', ' days'); |
|
54
|
|
|
|
|
55
|
|
|
$fields->addFieldToTab('Root.Main', new FieldGroup( |
|
56
|
|
|
_t('UnpublishItemWorkflowAction.UNPUBLICATIONDELAY', 'Delay Un-publishing'), |
|
57
|
|
|
new LabelField('UnpublishDelayBefore', $before), |
|
58
|
|
|
new NumericField('UnpublishDelay', ''), |
|
59
|
|
|
new LabelField('UnpublishDelayAfter', $after) |
|
60
|
|
|
)); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return $fields; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Unpublish action allows a user who is currently assigned at this point of the workflow to |
|
68
|
|
|
* |
|
69
|
|
|
* @param DataObject $target |
|
70
|
|
|
* @return bool |
|
71
|
|
|
*/ |
|
72
|
|
|
public function canPublishTarget(DataObject $target) { |
|
73
|
|
|
return true; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.