1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Symbiote\AdvancedWorkflow\Jobs; |
4
|
|
|
|
5
|
|
|
use Symbiote\QueuedJobs\Services\AbstractQueuedJob; |
6
|
|
|
|
7
|
|
|
// Prevent failure if queuedjobs module isn't installed. |
8
|
|
|
if (!class_exists(AbstractQueuedJob::class)) { |
9
|
|
|
return; |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* A queued job that publishes a target after a delay. |
14
|
|
|
* |
15
|
|
|
* @package advancedworkflow |
16
|
|
|
*/ |
17
|
|
|
class WorkflowPublishTargetJob extends AbstractQueuedJob |
18
|
|
|
{ |
19
|
|
|
public function __construct($obj = null, $type = null) |
20
|
|
|
{ |
21
|
|
|
if ($obj) { |
22
|
|
|
$this->setObject($obj); |
23
|
|
|
$this->publishType = $type ? strtolower($type) : 'publish'; |
24
|
|
|
$this->totalSteps = 1; |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getTitle() |
29
|
|
|
{ |
30
|
|
|
return _t( |
31
|
|
|
'AdvancedWorkflowPublishJob.SCHEDULEJOBTITLE', |
32
|
|
|
"Scheduled {type} of {object}", |
33
|
|
|
"", |
34
|
|
|
array( |
35
|
|
|
'type' => $this->publishType, |
36
|
|
|
'object' => $this->getObject()->Title |
37
|
|
|
) |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function process() |
42
|
|
|
{ |
43
|
|
|
if ($target = $this->getObject()) { |
44
|
|
|
if ($this->publishType == 'publish') { |
45
|
|
|
$target->setIsPublishJobRunning(true); |
46
|
|
|
$target->PublishOnDate = ''; |
47
|
|
|
$target->writeWithoutVersion(); |
48
|
|
|
$target->publishRecursive(); |
49
|
|
|
} elseif ($this->publishType == 'unpublish') { |
50
|
|
|
$target->setIsPublishJobRunning(true); |
51
|
|
|
$target->UnPublishOnDate = ''; |
52
|
|
|
$target->writeWithoutVersion(); |
53
|
|
|
$target->doUnpublish(); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
$this->currentStep = 1; |
57
|
|
|
$this->isComplete = true; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|