1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Symbiote\AdvancedWorkflow\Actions; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Forms\FieldGroup; |
6
|
|
|
use SilverStripe\Forms\LabelField; |
7
|
|
|
use SilverStripe\Forms\NumericField; |
8
|
|
|
use SilverStripe\ORM\DataObject; |
9
|
|
|
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowAction; |
10
|
|
|
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowInstance; |
11
|
|
|
use Symbiote\AdvancedWorkflow\Extensions\WorkflowEmbargoExpiryExtension; |
12
|
|
|
use Symbiote\AdvancedWorkflow\Jobs\WorkflowPublishTargetJob; |
13
|
|
|
use Symbiote\QueuedJob\Services\AbstractQueuedJob; |
14
|
|
|
use Symbiote\QueuedJob\Services\QueuedJobService; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Unpublishes an item |
18
|
|
|
* |
19
|
|
|
* @author [email protected] |
20
|
|
|
* @license BSD License (http://silverstripe.org/bsd-license/) |
21
|
|
|
* @package advancedworkflow |
22
|
|
|
* @subpackage actions |
23
|
|
|
*/ |
24
|
|
|
class UnpublishItemWorkflowAction extends WorkflowAction |
25
|
|
|
{ |
26
|
|
|
private static $db = array( |
|
|
|
|
27
|
|
|
'UnpublishDelay' => 'Int' |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
private static $icon = 'symbiote/silverstripe-advancedworkflow:images/unpublish.png'; |
|
|
|
|
31
|
|
|
|
32
|
|
|
private static $table_name = 'UnpublishItemWorkflowAction'; |
|
|
|
|
33
|
|
|
|
34
|
|
|
public function execute(WorkflowInstance $workflow) |
35
|
|
|
{ |
36
|
|
|
if (!$target = $workflow->getTarget()) { |
37
|
|
|
return true; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if (class_exists(AbstractQueuedJob::class) && $this->UnpublishDelay) { |
|
|
|
|
41
|
|
|
$job = new WorkflowPublishTargetJob($target, "unpublish"); |
42
|
|
|
$days = $this->UnpublishDelay; |
|
|
|
|
43
|
|
|
$after = date('Y-m-d H:i:s', strtotime("+$days days")); |
44
|
|
|
singleton(QueuedJobService::class)->queueJob($job, $after); |
45
|
|
|
} elseif ($target->hasExtension(WorkflowEmbargoExpiryExtension::class)) { |
46
|
|
|
// setting future date stuff if needbe |
47
|
|
|
|
48
|
|
|
// set these values regardless |
49
|
|
|
$target->DesiredUnPublishDate = ''; |
50
|
|
|
$target->DesiredPublishDate = ''; |
51
|
|
|
$target->write(); |
52
|
|
|
|
53
|
|
|
if ($target->hasMethod('doUnpublish')) { |
54
|
|
|
$target->doUnpublish(); |
55
|
|
|
} |
56
|
|
|
} else { |
57
|
|
|
if ($target->hasMethod('doUnpublish')) { |
58
|
|
|
$target->doUnpublish(); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return true; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getCMSFields() |
66
|
|
|
{ |
67
|
|
|
$fields = parent::getCMSFields(); |
68
|
|
|
|
69
|
|
|
if (class_exists(AbstractQueuedJob::class)) { |
70
|
|
|
$before = _t('UnpublishItemWorkflowAction.DELAYUNPUBDAYSBEFORE', 'Delay unpublishing by '); |
71
|
|
|
$after = _t('UnpublishItemWorkflowAction.DELAYUNPUBDAYSAFTER', ' days'); |
72
|
|
|
|
73
|
|
|
$fields->addFieldToTab('Root.Main', new FieldGroup( |
74
|
|
|
_t('UnpublishItemWorkflowAction.UNPUBLICATIONDELAY', 'Delay Un-publishing'), |
75
|
|
|
new LabelField('UnpublishDelayBefore', $before), |
76
|
|
|
new NumericField('UnpublishDelay', ''), |
77
|
|
|
new LabelField('UnpublishDelayAfter', $after) |
78
|
|
|
)); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $fields; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param DataObject $target |
86
|
|
|
* @return bool |
87
|
|
|
*/ |
88
|
|
|
public function canPublishTarget(DataObject $target) |
89
|
|
|
{ |
90
|
|
|
return false; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|