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/dataobjects/WorkflowAction.php (1 issue)

Severity

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\DataObjects;
4
5
use SilverStripe\Forms\CheckboxField;
6
use SilverStripe\Forms\DropdownField;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\Forms\ReadonlyField;
9
use SilverStripe\Forms\RequiredFields;
10
use SilverStripe\Forms\TabSet;
11
use SilverStripe\Forms\TextField;
12
use SilverStripe\ORM\DataObject;
13
use SilverStripe\ORM\DB;
14
use SilverStripe\Security\Member;
15
16
/**
17
 * A workflow action describes a the 'state' a workflow can be in, and
18
 * the action(s) that occur while in that state. An action can then have
19
 * subsequent transitions out of the current state.
20
 *
21
 * @method WorkflowDefinition WorkflowDef()
22
 * @author  [email protected]
23
 * @license BSD License (http://silverstripe.org/bsd-license/)
24
 * @package advancedworkflow
25
 */
26
class WorkflowAction extends DataObject
27
{
28
    private static $db = array(
29
        'Title'             => 'Varchar(255)',
30
        'Comment'           => 'Text',
31
        'Type'              => "Enum('Dynamic,Manual','Manual')",  // is this used?
32
        'Executed'          => 'Boolean',
33
        'AllowEditing'      => "Enum('By Assignees,Content Settings,No','No')",         // can this item be edited?
34
        'Sort'              => 'Int',
35
        'AllowCommenting'   => 'Boolean'
36
    );
37
38
    private static $defaults = array(
39
        'AllowCommenting'   => '1',
40
    );
41
42
    private static $default_sort = 'Sort';
43
44
    private static $has_one = array(
45
        'WorkflowDef' => WorkflowDefinition::class,
46
        'Member'      => Member::class
47
    );
48
49
    private static $has_many = array(
50
        'Transitions' => WorkflowTransition::class . '.Action'
51
    );
52
53
    /**
54
     * The type of class to use for instances of this workflow action that are used for storing the
55
     * data of the instance.
56
     *
57
     * @var string
58
     */
59
    private static $instance_class = WorkflowActionInstance::class;
60
61
    private static $icon = 'advancedworkflow/images/action.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...
62
63
    private static $table_name = 'WorkflowAction';
64
65
    /**
66
     * Can documents in the current workflow state be edited?
67
     *
68
     * Only return true or false if this is an absolute value; the WorkflowActionInstance
69
     * will try and figure out an appropriate value for the actively running workflow
70
     * if null is returned from this method.
71
     *
72
     * @param  DataObject $target
73
     * @return bool
74
     */
75
    public function canEditTarget(DataObject $target)
76
    {
77
        return null;
78
    }
79
80
    /**
81
     * Does this action restrict viewing of the document?
82
     *
83
     * @param  DataObject $target
84
     * @return bool
85
     */
86
    public function canViewTarget(DataObject $target)
87
    {
88
        return null;
89
    }
90
91
    /**
92
     * Does this action restrict the publishing of a document?
93
     *
94
     * @param  DataObject $target
95
     * @return bool
96
     */
97
    public function canPublishTarget(DataObject $target)
98
    {
99
        return null;
100
    }
101
102
    /**
103
     * Allows users who have permission to create a WorkflowDefinition, to create actions on it too.
104
     *
105
     * @param Member $member
106
     * @param array $context
107
     * @return bool
108
     */
109
    public function canCreate($member = null, $context = array())
110
    {
111
        return $this->WorkflowDef()->canCreate($member, $context);
112
    }
113
114
    /**
115
     * @param  Member $member
116
     * @return bool
117
     */
118
    public function canEdit($member = null)
119
    {
120
        return $this->canCreate($member);
121
    }
122
123
    /**
124
     * @param  Member $member
125
     * @return bool
126
     */
127
    public function canDelete($member = null)
128
    {
129
        return $this->WorkflowDef()->canDelete($member);
130
    }
131
132
    /*
133
	 * If there is only a single action defined for a workflow, there's no sense
134
	 * in allowing users to add a transition to it (and causing errors).
135
	 * Hide the "Add Transition" button in this case
136
	 *
137
	 * @return boolean true if we should disable the button, false otherwise
138
	 */
139
    public function canAddTransition()
140
    {
141
        return ($this->WorkflowDef()->numChildren() >1);
142
    }
143
144
    /**
145
     * Gets an object that is used for saving the actual state of things during
146
     * a running workflow. It still uses the workflow action def for managing the
147
     * functional execution, however if you need to store additional data for
148
     * the state, you can specify your own WorkflowActionInstance instead of
149
     * the default to capture these elements
150
     *
151
     * @return WorkflowActionInstance
152
     */
153
    public function getInstanceForWorkflow()
154
    {
155
        $instanceClass = $this->config()->get('instance_class');
156
        $instance = new $instanceClass();
157
        $instance->BaseActionID = $this->ID;
158
        return $instance;
159
    }
160
161
    /**
162
     * Perform whatever needs to be done for this action. If this action can be considered executed, then
163
     * return true - if not (ie it needs some user input first), return false and 'execute' will be triggered
164
     * again at a later point in time after the user has provided more data, either directly or indirectly.
165
     *
166
     * @param  WorkflowInstance $workflow
167
     * @return bool Returns true if this action has finished.
168
     */
169
    public function execute(WorkflowInstance $workflow)
170
    {
171
        return true;
172
    }
173
174
    public function onBeforeWrite()
175
    {
176
        if (!$this->Sort) {
177
            $this->Sort = DB::query('SELECT MAX("Sort") + 1 FROM "WorkflowAction"')->value();
178
        }
179
180
        parent::onBeforeWrite();
181
    }
182
183
    /**
184
     * When deleting an action from a workflow definition, make sure that workflows currently paused on that action
185
     * are deleted
186
     * Also removes all outbound transitions
187
     */
188
    public function onAfterDelete()
189
    {
190
        parent::onAfterDelete();
191
        $wfActionInstances = WorkflowActionInstance::get()
192
            /** @skipUpgrade */
193
            ->leftJoin('WorkflowInstance', '"WorkflowInstance"."ID" = "WorkflowActionInstance"."WorkflowID"')
194
            ->where(sprintf('"BaseActionID" = %d AND ("WorkflowStatus" IN (\'Active\',\'Paused\'))', $this->ID));
195
        foreach ($wfActionInstances as $wfActionInstance) {
196
            $wfInstances = WorkflowInstance::get()->filter('CurrentActionID', $wfActionInstance->ID);
197
            foreach ($wfInstances as $wfInstance) {
198
                $wfInstance->Groups()->removeAll();
199
                $wfInstance->Users()->removeAll();
200
                $wfInstance->delete();
201
            }
202
            $wfActionInstance->delete();
203
        }
204
        // Delete outbound transitions
205
        $transitions = WorkflowTransition::get()->filter('ActionID', $this->ID);
206
        foreach ($transitions as $transition) {
207
            $transition->Groups()->removeAll();
208
            $transition->Users()->removeAll();
209
            $transition->delete();
210
        }
211
    }
212
213
    /**
214
     * Called when the current target of the workflow has been updated
215
     */
216
    public function targetUpdated(WorkflowInstance $workflow)
217
    {
218
    }
219
220
    /* CMS RELATED FUNCTIONALITY... */
221
222
223
    public function numChildren()
224
    {
225
        return $this->Transitions()->count();
226
    }
227
228
    public function getCMSFields()
229
    {
230
231
        $fields = new FieldList(new TabSet('Root'));
232
        $typeLabel = _t('WorkflowAction.CLASS_LABEL', 'Action Class');
233
        $fields->addFieldToTab('Root.Main', new ReadOnlyField('WorkflowActionClass', $typeLabel, $this->singular_name()));
234
        $titleField = new TextField('Title', $this->fieldLabel('Title'));
235
        $titleField->setDescription(_t(
236
            'WorkflowAction.TitleDescription',
237
            'The Title is used as the button label for this Workflow Action'
238
        ));
239
        $fields->addFieldToTab('Root.Main', $titleField);
240
        $fields->addFieldToTab('Root.Main', new DropdownField(
241
            'AllowEditing',
242
            $this->fieldLabel('AllowEditing'),
243
            array(
244
                'By Assignees' => _t('AllowEditing.ByAssignees', 'By Assignees'),
245
                'Content Settings' => _t('AllowEditing.ContentSettings', 'Content Settings'),
246
                'No' => _t('AllowEditing.NoString', 'No')
247
            ),
248
            _t('AllowEditing.NoString', 'No')
249
        ));
250
        $fields->addFieldToTab('Root.Main', new CheckboxField('AllowCommenting', $this->fieldLabel('AllowCommenting'), $this->AllowCommenting));
251
        $this->extend('updateCMSFields', $fields);
252
        return $fields;
253
    }
254
255
    public function getValidator()
256
    {
257
        return new RequiredFields('Title');
258
    }
259
260
    public function summaryFields()
261
    {
262
        return array(
263
            'Title' => $this->fieldLabel('Title'),
264
            'Transitions' => $this->fieldLabel('Transitions'),
265
        );
266
    }
267
268
    public function fieldLabels($includerelations = true)
269
    {
270
        $labels = parent::fieldLabels($includerelations);
271
        $labels['Comment'] = _t('WorkflowAction.CommentLabel', 'Comment');
272
        $labels['Type'] = _t('WorkflowAction.TypeLabel', 'Type');
273
        $labels['Executed'] = _t('WorkflowAction.ExecutedLabel', 'Executed');
274
        $labels['AllowEditing'] = _t('WorkflowAction.ALLOW_EDITING', 'Allow editing during this step?');
275
        $labels['Title'] = _t('WorkflowAction.TITLE', 'Title');
276
        $labels['AllowCommenting'] = _t('WorkflowAction.ALLOW_COMMENTING', 'Allow Commenting?');
277
        $labels['Transitions'] = _t('WorkflowAction.Transitions', 'Transitions');
278
279
        return $labels;
280
    }
281
282
    /**
283
     * Used for Front End Workflows
284
     */
285
    public function updateFrontendWorkflowFields($fields, $workflow)
286
    {
287
    }
288
289
    public function Icon()
290
    {
291
        return $this->config()->get('icon');
292
    }
293
}
294