These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Symbiote\AdvancedWorkflow\Actions; |
||
4 | |||
5 | use SilverStripe\Forms\CheckboxField; |
||
6 | use SilverStripe\Forms\FieldGroup; |
||
7 | use SilverStripe\Forms\LabelField; |
||
8 | use SilverStripe\Forms\NumericField; |
||
9 | use SilverStripe\ORM\DataObject; |
||
10 | use Symbiote\AdvancedWorkflow\DataObjects\WorkflowAction; |
||
11 | use Symbiote\AdvancedWorkflow\DataObjects\WorkflowInstance; |
||
12 | use Symbiote\AdvancedWorkflow\Extensions\WorkflowEmbargoExpiryExtension; |
||
13 | use Symbiote\AdvancedWorkflow\Jobs\WorkflowPublishTargetJob; |
||
14 | use Symbiote\QueuedJobs\Services\AbstractQueuedJob; |
||
15 | use Symbiote\QueuedJobs\Services\QueuedJobService; |
||
16 | |||
17 | /** |
||
18 | * Publishes an item |
||
19 | * |
||
20 | * @author [email protected] |
||
21 | * @license BSD License (http://silverstripe.org/bsd-license/) |
||
22 | * @package advancedworkflow |
||
23 | * @subpackage actions |
||
24 | */ |
||
25 | class PublishItemWorkflowAction extends WorkflowAction |
||
26 | { |
||
27 | private static $db = array( |
||
0 ignored issues
–
show
Comprehensibility
introduced
by
Loading history...
|
|||
28 | 'PublishDelay' => 'Int', |
||
29 | 'AllowEmbargoedEditing' => 'Boolean', |
||
30 | ); |
||
31 | |||
32 | private static $defaults = array( |
||
0 ignored issues
–
show
|
|||
33 | 'AllowEmbargoedEditing' => true |
||
34 | ); |
||
35 | |||
36 | private static $icon = 'symbiote/silverstripe-advancedworkflow:images/publish.png'; |
||
0 ignored issues
–
show
|
|||
37 | |||
38 | private static $table_name = 'PublishItemWorkflowAction'; |
||
0 ignored issues
–
show
|
|||
39 | |||
40 | public function execute(WorkflowInstance $workflow) |
||
41 | { |
||
42 | if (!$target = $workflow->getTarget()) { |
||
43 | return true; |
||
44 | } |
||
45 | |||
46 | if (class_exists(AbstractQueuedJob::class) && $this->PublishDelay) { |
||
0 ignored issues
–
show
The property
PublishDelay does not exist on object<Symbiote\Advanced...lishItemWorkflowAction> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property.
Loading history...
|
|||
47 | $job = new WorkflowPublishTargetJob($target); |
||
48 | $days = $this->PublishDelay; |
||
0 ignored issues
–
show
The property
PublishDelay does not exist on object<Symbiote\Advanced...lishItemWorkflowAction> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property.
Loading history...
|
|||
49 | $after = date('Y-m-d H:i:s', strtotime("+$days days")); |
||
50 | |||
51 | // disable editing, and embargo the delay if using WorkflowEmbargoExpiryExtension |
||
52 | if ($target->hasExtension(WorkflowEmbargoExpiryExtension::class)) { |
||
53 | $target->AllowEmbargoedEditing = $this->AllowEmbargoedEditing; |
||
0 ignored issues
–
show
The property
AllowEmbargoedEditing does not exist on object<Symbiote\Advanced...lishItemWorkflowAction> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property.
Loading history...
|
|||
54 | $target->PublishOnDate = $after; |
||
55 | $target->write(); |
||
56 | } else { |
||
57 | singleton(QueuedJobService::class)->queueJob($job, $after); |
||
58 | } |
||
59 | } elseif ($target->hasExtension(WorkflowEmbargoExpiryExtension::class)) { |
||
60 | $target->AllowEmbargoedEditing = $this->AllowEmbargoedEditing; |
||
0 ignored issues
–
show
The property
AllowEmbargoedEditing does not exist on object<Symbiote\Advanced...lishItemWorkflowAction> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property.
Loading history...
|
|||
61 | // setting future date stuff if needbe |
||
62 | |||
63 | // set this value regardless |
||
64 | $target->UnPublishOnDate = $target->DesiredUnPublishDate; |
||
65 | $target->DesiredUnPublishDate = ''; |
||
66 | |||
67 | // Publish dates |
||
68 | if ($target->DesiredPublishDate) { |
||
69 | // Hand-off desired publish date |
||
70 | $target->PublishOnDate = $target->DesiredPublishDate; |
||
71 | $target->DesiredPublishDate = ''; |
||
72 | $target->write(); |
||
73 | } else { |
||
74 | // Ensure previously modified DesiredUnPublishDate values are written |
||
75 | $target->write(); |
||
76 | if ($target->hasMethod('publishSingle')) { |
||
77 | $target->publishSingle(); |
||
78 | } |
||
79 | } |
||
80 | } else { |
||
81 | if ($target->hasMethod('publishSingle')) { |
||
82 | $target->publishSingle(); |
||
83 | } |
||
84 | } |
||
85 | |||
86 | return true; |
||
87 | } |
||
88 | |||
89 | public function getCMSFields() |
||
90 | { |
||
91 | $fields = parent::getCMSFields(); |
||
92 | |||
93 | if (class_exists(AbstractQueuedJob::class)) { |
||
94 | $fields->addFieldsToTab('Root.Main', [ |
||
95 | CheckboxField::create( |
||
96 | 'AllowEmbargoedEditing', |
||
97 | _t( |
||
98 | __CLASS__ . '.ALLOWEMBARGOEDEDITING', |
||
99 | 'Allow editing while item is embargoed? (does not apply without embargo)' |
||
100 | ) |
||
101 | ), |
||
102 | NumericField::create( |
||
103 | 'PublishDelay', |
||
104 | _t('PublishItemWorkflowAction.PUBLICATIONDELAY', 'Publication Delay') |
||
105 | )->setDescription(_t( |
||
106 | __CLASS__ . '.PublicationDelayDescription', |
||
107 | 'Delay publiation by the specified number of days' |
||
108 | )) |
||
109 | ]); |
||
110 | } |
||
111 | |||
112 | return $fields; |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Publish action allows a user who is currently assigned at this point of the workflow to |
||
117 | * |
||
118 | * @param DataObject $target |
||
119 | * @return bool |
||
120 | */ |
||
121 | public function canPublishTarget(DataObject $target) |
||
122 | { |
||
123 | return true; |
||
124 | } |
||
125 | } |
||
126 |