GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 21e795...aea957 )
by
unknown
11s
created

code/actions/PublishItemWorkflowAction.php (1 issue)

Upgrade to new PHP Analysis Engine

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(
28
        'PublishDelay'          => 'Int',
29
        'AllowEmbargoedEditing' => 'Boolean',
30
    );
31
32
    private static $defaults = array(
33
        'AllowEmbargoedEditing' => true
34
    );
35
36
    private static $icon = 'advancedworkflow/images/publish.png';
0 ignored issues
show
The property $icon is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
37
38
    private static $table_name = 'PublishItemWorkflowAction';
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) {
47
            $job   = new WorkflowPublishTargetJob($target);
48
            $days  = $this->PublishDelay;
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;
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;
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