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 ( 99ec42...de979d )
by Robbie
9s
created

getIntroMessageParts()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 2
eloc 15
nc 2
nop 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 38 and the first side effect is on line 29.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Symbiote\AdvancedWorkflow\Extensions;
4
5
use SilverStripe\Control\Controller;
6
use SilverStripe\Core\Injector\Injector;
7
use SilverStripe\Core\Manifest\ModuleLoader;
8
use SilverStripe\Forms\FieldList;
9
use SilverStripe\Forms\DatetimeField;
10
use SilverStripe\Forms\HeaderField;
11
use SilverStripe\Forms\LiteralField;
12
use SilverStripe\ORM\ArrayList;
13
use SilverStripe\ORM\DataExtension;
14
use SilverStripe\ORM\DataQuery;
15
use SilverStripe\ORM\FieldType\DBDatetime;
16
use SilverStripe\ORM\Queries\SQLSelect;
17
use SilverStripe\Security\Member;
18
use SilverStripe\Security\Permission;
19
use SilverStripe\View\Requirements;
20
use SilverStripe\Versioned\Versioned;
21
use Symbiote\AdvancedWorkflow\Forms\AWRequiredFields;
22
use Symbiote\AdvancedWorkflow\Jobs\WorkflowPublishTargetJob;
23
use Symbiote\AdvancedWorkflow\Services\WorkflowService;
24
use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor;
25
use Symbiote\QueuedJobs\Services\QueuedJobService;
26
27
// Queued jobs descriptor is required for this extension
28
if (!class_exists(QueuedJobDescriptor::class)) {
29
    return;
30
}
31
32
/**
33
 * Adds embargo period and expiry dates to content items
34
 *
35
 * @author [email protected]
36
 * @license BSD License http://silverstripe.org/bsd-license/
37
 */
38
class WorkflowEmbargoExpiryExtension extends DataExtension
39
{
40
    private static $db = array(
0 ignored issues
show
Unused Code introduced by
The property $db 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...
41
        'DesiredPublishDate'    => 'DBDatetime',
42
        'DesiredUnPublishDate'  => 'DBDatetime',
43
        'PublishOnDate'         => 'DBDatetime',
44
        'UnPublishOnDate'       => 'DBDatetime',
45
        'AllowEmbargoedEditing' => 'Boolean',
46
    );
47
48
    private static $has_one = array(
0 ignored issues
show
Unused Code introduced by
The property $has_one 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...
49
        'PublishJob'            => QueuedJobDescriptor::class,
50
        'UnPublishJob'          => QueuedJobDescriptor::class,
51
    );
52
53
    private static $dependencies = array(
0 ignored issues
show
Unused Code introduced by
The property $dependencies 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...
54
        'workflowService'       => '%$' . WorkflowService::class,
55
    );
56
57
    private static $defaults = array(
0 ignored issues
show
Unused Code introduced by
The property $defaults 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...
58
        'AllowEmbargoedEditing' => true
59
    );
60
61
    // This "config" option, might better be handled in _config
62
    public static $showTimePicker = true;
63
64
    /**
65
     * @var WorkflowService
66
     */
67
    protected $workflowService;
68
69
    /**
70
     * Is a workflow in effect?
71
     *
72
     * @var bool
73
     */
74
    public $isWorkflowInEffect = false;
75
76
    /**
77
     * A basic extended validation routine method return format
78
     *
79
     * @var array
80
     */
81
    public static $extendedMethodReturn = array(
82
        'fieldName'  => null,
83
        'fieldField' => null,
84
        'fieldMsg'   => null,
85
        'fieldValid' => true,
86
    );
87
88
    /**
89
     * @param FieldList $fields
90
     */
91
    public function updateCMSFields(FieldList $fields)
92
    {
93
        // requirements
94
        // ------------
95
96
        $module = 'symbiote/silverstripe-advancedworkflow';
97
98
        Requirements::add_i18n_javascript($module . ':client/lang');
99
100
        // Add timepicker functionality
101
        // @see https://github.com/trentrichardson/jQuery-Timepicker-Addon
102
        Requirements::css(
103
            $module . ':javascript/jquery-ui/timepicker/jquery-ui-timepicker-addon.css'
104
        );
105
        Requirements::css($module . ':client/dist/styles/advancedworkflow.css');
106
        Requirements::javascript(
107
            $module . ':thirdparty/javascript/jquery-ui/timepicker/jquery-ui-sliderAccess.js'
108
        );
109
        Requirements::javascript(
110
            $module . ':thirdparty/javascript/jquery-ui/timepicker/jquery-ui-timepicker-addon.js'
111
        );
112
        Requirements::javascript($module . ':client/dist/js/advancedworkflow.js');
113
114
        // Fields
115
        // ------
116
117
        // we never show these explicitly in admin
118
        $fields->removeByName('PublishJobID');
119
        $fields->removeByName('UnPublishJobID');
120
121
        $this->setIsWorkflowInEffect();
122
123
        $fields->findOrMakeTab(
124
            'Root.PublishingSchedule',
125
            _t('WorkflowEmbargoExpiryExtension.TabTitle', 'Publishing Schedule')
126
        );
127
        if ($this->getIsWorkflowInEffect()) {
128
            // add fields we want in this context
129
            $fields->addFieldsToTab('Root.PublishingSchedule', array(
130
                HeaderField::create(
131
                    'PublishDateHeader',
132
                    _t('WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE_H3', 'Expiry and Embargo'),
133
                    3
134
                ),
135
                LiteralField::create('PublishDateIntro', $this->getIntroMessage('PublishDateIntro')),
136
                $dt = DatetimeField::create(
137
                    'DesiredPublishDate',
138
                    _t('WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE', 'Requested publish date')
139
                )->setRightTitle(
140
                    _t(
141
                        'WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE_RIGHT_TITLE',
142
                        'To request this page to be <strong>published immediately</strong> '
143
                        . 'leave the date and time fields blank'
144
                    )
145
                ),
146
                $ut = DatetimeField::create(
147
                    'DesiredUnPublishDate',
148
                    _t('WorkflowEmbargoExpiryExtension.REQUESTED_UNPUBLISH_DATE', 'Requested un-publish date')
149
                )->setRightTitle(
150
                    _t(
151
                        'WorkflowEmbargoExpiryExtension.REQUESTED_UNPUBLISH_DATE_RIGHT_TITLE',
152
                        'To request this page to <strong>never expire</strong> leave the date and time fields blank'
153
                    )
154
                ),
155
                DatetimeField::create(
156
                    'PublishOnDate',
157
                    _t('WorkflowEmbargoExpiryExtension.PUBLISH_ON', 'Scheduled publish date')
158
                )->setDisabled(true),
159
                DatetimeField::create(
160
                    'UnPublishOnDate',
161
                    _t('WorkflowEmbargoExpiryExtension.UNPUBLISH_ON', 'Scheduled un-publish date')
162
                )->setDisabled(true)
163
            ));
164
        } else {
165
            // remove fields that have been automatically added that we don't want
166
            $fields->removeByName('DesiredPublishDate');
167
            $fields->removeByName('DesiredUnPublishDate');
168
169
            // add fields we want in this context
170
            $fields->addFieldsToTab('Root.PublishingSchedule', array(
171
                HeaderField::create(
172
                    'PublishDateHeader',
173
                    _t('WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE_H3', 'Expiry and Embargo'),
174
                    3
175
                ),
176
                LiteralField::create('PublishDateIntro', $this->getIntroMessage('PublishDateIntro')),
177
                $dt = DatetimeField::create(
178
                    'PublishOnDate',
179
                    _t('WorkflowEmbargoExpiryExtension.PUBLISH_ON', 'Scheduled publish date')
180
                ),
181
                $ut = DatetimeField::create(
182
                    'UnPublishOnDate',
183
                    _t('WorkflowEmbargoExpiryExtension.UNPUBLISH_ON', 'Scheduled un-publish date')
184
                ),
185
            ));
186
        }
187
188
        // Enable a jQuery-UI timepicker widget
189
        // @todo re-validate this with new DatetimeField API
190
        if (self::$showTimePicker) {
191
            $dt->addExtraClass('hasTimePicker');
192
            $ut->addExtraClass('hasTimePicker');
193
        }
194
    }
195
196
    /**
197
     * Clears any existing publish job against this dataobject
198
     */
199
    public function clearPublishJob()
200
    {
201
        $job = $this->owner->PublishJob();
202
        if ($job && $job->exists()) {
203
            $job->delete();
204
        }
205
        $this->owner->PublishJobID = 0;
206
    }
207
208
    /**
209
     * Clears any existing unpublish job
210
     */
211
    public function clearUnPublishJob()
212
    {
213
        // Cancel any in-progress unpublish job
214
        $job = $this->owner->UnPublishJob();
215
        if ($job && $job->exists()) {
216
            $job->delete();
217
        }
218
        $this->owner->UnPublishJobID = 0;
219
    }
220
221
    /**
222
     * Ensure the existence of a publish job at the specified time
223
     *
224
     * @param int $when Timestamp to start this job, or null to start immediately
225
     */
226 View Code Duplication
    protected function ensurePublishJob($when)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
227
    {
228
        // Check if there is a prior job
229
        if ($this->owner->PublishJobID) {
230
            $job = $this->owner->PublishJob();
231
            // Use timestamp for sake of comparison.
232
            if ($job && $job->exists() && DBDatetime::create()->setValue($job->StartAfter)->getTimestamp() == $when) {
233
                return;
234
            }
235
            $this->clearPublishJob();
236
        }
237
238
        // Create a new job with the specified schedule
239
        $job = new WorkflowPublishTargetJob($this->owner, 'publish');
240
        $this->owner->PublishJobID = Injector::inst()->get(QueuedJobService::class)
241
                ->queueJob($job, $when ? date('Y-m-d H:i:s', $when) : null);
242
    }
243
244
    /**
245
     * Ensure the existence of an unpublish job at the specified time
246
     *
247
     * @param int $when Timestamp to start this job, or null to start immediately
248
     */
249 View Code Duplication
    protected function ensureUnPublishJob($when)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
250
    {
251
        // Check if there is a prior job
252
        if ($this->owner->UnPublishJobID) {
253
            $job = $this->owner->UnPublishJob();
254
            // Use timestamp for sake of comparison.
255
            if ($job && $job->exists() && DBDatetime::create()->setValue($job->StartAfter)->getTimestamp() == $when) {
256
                return;
257
            }
258
            $this->clearUnPublishJob();
259
        }
260
261
        // Create a new job with the specified schedule
262
        $job = new WorkflowPublishTargetJob($this->owner, 'unpublish');
263
        $this->owner->UnPublishJobID = Injector::inst()->get(QueuedJobService::class)
264
            ->queueJob($job, $when ? date('Y-m-d H:i:s', $when) : null);
265
    }
266
267
    public function onBeforeDuplicate($original, $doWrite)
0 ignored issues
show
Unused Code introduced by
The parameter $original is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $doWrite is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
268
    {
269
        $clone = $this->owner;
270
271
        $clone->PublishOnDate = null;
272
        $clone->UnPublishOnDate = null;
273
        $clone->clearPublishJob();
274
        $clone->clearUnPublishJob();
275
    }
276
277
    /**
278
     * {@see PublishItemWorkflowAction} for approval of requested publish dates
279
     */
280
    public function onBeforeWrite()
281
    {
282
        parent::onBeforeWrite();
283
284
        // only operate on staging content for this extension; otherwise, you
285
        // need to publish the page to be able to set a 'future' publish...
286
        // while the same could be said for the unpublish, the 'publish' state
287
        // is the one that must be avoided so we allow setting the 'unpublish'
288
        // date for as-yet-not-published content.
289
        if (Versioned::get_stage() === Versioned::LIVE) {
290
            return;
291
        }
292
293
        /*
294
         * Without checking if there's actually a workflow in effect, simply saving
295
         * as draft, would clear the Scheduled Publish & Unpublish date fields, which we obviously
296
         * don't want during a workflow: These date fields should be treated as a content
297
         * change that also requires approval (where such an approval step exists).
298
         *
299
         * - Check to see if we've got 'desired' publish/unpublish date(s).
300
         * - Check if there's a workflow attached to this content
301
         * - Reset values if it's safe to do so
302
         */
303
        if (!$this->getIsWorkflowInEffect()) {
304
            $resetPublishOnDate = $this->owner->DesiredPublishDate && $this->owner->PublishOnDate;
305
            if ($resetPublishOnDate) {
306
                $this->owner->PublishOnDate = null;
307
            }
308
309
            $resetUnPublishOnDate = $this->owner->DesiredUnPublishDate && $this->owner->UnPublishOnDate;
310
            if ($resetUnPublishOnDate) {
311
                $this->owner->UnPublishOnDate = null;
312
            }
313
        }
314
315
        // Jobs can only be queued for records that already exist
316
        if (!$this->owner->ID) {
317
            return;
318
        }
319
320
        // Check requested dates of publish / unpublish, and whether the page should have already been unpublished
321
        $now = DBDatetime::now()->getTimestamp();
322
        $publishTime = $this->owner->dbObject('PublishOnDate')->getTimestamp();
323
        $unPublishTime = $this->owner->dbObject('UnPublishOnDate')->getTimestamp();
324
325
        // We should have a publish job if:
326
        // if no unpublish or publish time, then the Workflow Publish Action will publish without a job
327
        if ((!$unPublishTime && $publishTime) // the unpublish date is not set
328
            || (
329
                // unpublish date has not passed
330
                $unPublishTime > $now
331
                // publish date not set or happens before unpublish date
332
                && ($publishTime && ($publishTime < $unPublishTime))
333
            )
334
        ) {
335
            // Trigger time immediately if passed
336
            $this->ensurePublishJob($publishTime < $now ? null : $publishTime);
337
        } else {
338
            $this->clearPublishJob();
339
        }
340
341
        // We should have an unpublish job if:
342
        if ($unPublishTime // we have an unpublish date
343
            &&
344
            $publishTime < $unPublishTime // publish date is before to unpublish date
345
        ) {
346
            // Trigger time immediately if passed
347
            $this->ensureUnPublishJob($unPublishTime < $now ? null : $unPublishTime);
348
        } else {
349
            $this->clearUnPublishJob();
350
        }
351
    }
352
353
    /**
354
     * Add badges to the site tree view to show that a page has been scheduled for publishing or unpublishing
355
     *
356
     * @param $flags
357
     */
358
    public function updateStatusFlags(&$flags)
359
    {
360
        $embargo = $this->getIsPublishScheduled();
361
        $expiry = $this->getIsUnPublishScheduled();
362
363
        if ($embargo || $expiry) {
364
            unset($flags['addedtodraft'], $flags['modified']);
365
        }
366
367
        if ($embargo && $expiry) {
368
            $flags['embargo_expiry'] = array(
369
                'text' => _t('WorkflowEmbargoExpiryExtension.BADGE_PUBLISH_UNPUBLISH', 'Embargo+Expiry'),
370
                'title' => sprintf(
371
                    '%s: %s, %s: %s',
372
                    _t('WorkflowEmbargoExpiryExtension.PUBLISH_ON', 'Scheduled publish date'),
373
                    $this->owner->PublishOnDate,
374
                    _t('WorkflowEmbargoExpiryExtension.UNPUBLISH_ON', 'Scheduled un-publish date'),
375
                    $this->owner->UnPublishOnDate
376
                ),
377
            );
378
        } elseif ($embargo) {
379
            $flags['embargo'] = array(
380
                'text' => _t('WorkflowEmbargoExpiryExtension.BADGE_PUBLISH', 'Embargo'),
381
                'title' => sprintf(
382
                    '%s: %s',
383
                    _t('WorkflowEmbargoExpiryExtension.PUBLISH_ON', 'Scheduled publish date'),
384
                    $this->owner->PublishOnDate
385
                ),
386
            );
387
        } elseif ($expiry) {
388
            $flags['expiry'] = array(
389
                'text' => _t('WorkflowEmbargoExpiryExtension.BADGE_UNPUBLISH', 'Expiry'),
390
                'title' => sprintf(
391
                    '%s: %s',
392
                    _t('WorkflowEmbargoExpiryExtension.UNPUBLISH_ON', 'Scheduled un-publish date'),
393
                    $this->owner->UnPublishOnDate
394
                ),
395
            );
396
        }
397
    }
398
399
    /*
400
     * Define an array of message-parts for use by {@link getIntroMessage()}
401
     *
402
     * @param string $key
403
     * @return array
404
     */
405
    public function getIntroMessageParts($key)
406
    {
407
        $parts = array(
408
            'PublishDateIntro' => array(
409
                'INTRO'=>_t(
410
                    'WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE_INTRO',
411
                    'Enter a date and/or time to specify embargo and expiry dates.'
412
                ),
413
                'BULLET_1'=>_t(
414
                    'WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE_INTRO_BULLET_1',
415
                    'These settings won\'t take effect until any approval actions are run'
416
                ),
417
                'BULLET_2'=>_t(
418
                    'WorkflowEmbargoExpiryExtension.REQUESTED_PUBLISH_DATE_INTRO_BULLET_2',
419
                    'If an embargo is already set, adding a new one prior to that date\'s passing will overwrite it'
420
                )
421
            )
422
        );
423
        // If there's no effective workflow, no need for the first bullet-point
424
        if (!$this->getIsWorkflowInEffect()) {
425
            $parts['PublishDateIntro']['BULLET_1'] = false;
426
        }
427
        return $parts[$key];
428
    }
429
430
    /*
431
     * Display some messages to the user, a little more complex that a simple one-liner
432
     *
433
     * @param string $key
434
     * @return string
435
     */
436
    public function getIntroMessage($key)
437
    {
438
        $msg = $this->getIntroMessageParts($key);
439
        $curr = Controller::curr();
440
        $msg = $curr->customise($msg)->renderWith('Includes/embargoIntro');
441
        return $msg;
442
    }
443
444
    /*
445
     * Validate
446
     */
447
    public function getCMSValidator()
448
    {
449
        $required = new AWRequiredFields();
450
        $required->setCaller($this);
451
        return $required;
452
    }
453
454
    /**
455
     * This is called in the AWRequiredFields class, this validates whether an Embargo and Expiry are not equal and that
456
     * Embargo is before Expiry, returning the appropriate message when it fails.
457
     *
458
     * @param $data
459
     * @return array
460
     */
461
    public function extendedRequiredFieldsEmbargoExpiry($data)
462
    {
463
        $response = array(
464
            'fieldName'  => 'DesiredUnPublishDate[date]',
465
            'fieldField' => null,
466
            'fieldMsg'   => null,
467
            'fieldValid' => true
468
        );
469
470
        if (isset($data['DesiredPublishDate'], $data['DesiredUnPublishDate'])) {
471
            $publish = DBDatetime::create()->setValue($data['DesiredPublishDate'])->getTimestamp();
472
            $unpublish = DBDatetime::create()->setValue($data['DesiredUnPublishDate'])->getTimestamp();
473
474
            // the times are the same
475
            if ($publish && $unpublish && $publish == $unpublish) {
476
                $response = array_merge($response, array(
477
                    'fieldMsg'   => _t(
478
                        'WorkflowEmbargoExpiryExtension.INVALIDSAMEEMBARGOEXPIRY',
479
                        'The publish date and unpublish date cannot be the same.'
480
                    ),
481
                    'fieldValid' => false
482
                ));
483
            } elseif ($publish && $unpublish && $publish > $unpublish) {
484
                $response = array_merge($response, array(
485
                    'fieldMsg'   => _t(
486
                        'WorkflowEmbargoExpiryExtension.INVALIDEXPIRY',
487
                        'The unpublish date cannot be before the publish date.'
488
                    ),
489
                    'fieldValid' => false
490
                ));
491
            }
492
        }
493
494
        return $response;
495
    }
496
497
    /**
498
     * Format a date according to member/user preferences
499
     *
500
     * @param string $date
501
     * @return string $date
502
     */
503
    public function getUserDate($date)
504
    {
505
        $date = DBDatetime::create()->setValue($date);
506
        $member = Security::getCurrentUser();
507
        return $date->FormatFromSettings($member);
508
    }
509
510
    /*
511
     * Sets property as boolean true|false if an effective workflow is found or not
512
     */
513
    public function setIsWorkflowInEffect()
514
    {
515
        // if there is a workflow applied, we can't set the publishing date directly, only the 'desired' publishing date
516
        $effective = $this->getWorkflowService()->getDefinitionFor($this->owner);
517
        $this->isWorkflowInEffect = $effective ? true : false;
518
    }
519
520
    public function getIsWorkflowInEffect()
521
    {
522
        return $this->isWorkflowInEffect;
523
    }
524
525
    /**
526
     * Returns whether a publishing date has been set and is after the current date
527
     *
528
     * @return bool
529
     */
530 View Code Duplication
    public function getIsPublishScheduled()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
531
    {
532
        if (!$this->owner->PublishOnDate) {
533
            return false;
534
        }
535
        $now = DBDatetime::now()->getTimestamp();
536
        $publish = $this->owner->dbObject('PublishOnDate')->getTimestamp();
537
538
        return $now < $publish;
539
    }
540
541
    /**
542
     * Returns whether an unpublishing date has been set and is after the current date
543
     *
544
     * @return bool
545
     */
546 View Code Duplication
    public function getIsUnPublishScheduled()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
547
    {
548
        if (!$this->owner->UnPublishOnDate) {
549
            return false;
550
        }
551
        $now = DBDatetime::now()->getTimestamp();
552
        $unpublish = $this->owner->dbObject('UnPublishOnDate')->getTimestamp();
553
554
        return $now < $unpublish;
555
    }
556
557
    /**
558
     * Add edit check for when publishing has been scheduled and if any workflow definitions want the item to be
559
     * disabled.
560
     *
561
     * @param Member $member
562
     * @return bool|null
563
     */
564
    public function canEdit($member)
565
    {
566
        if (!Permission::check('EDIT_EMBARGOED_WORKFLOW') && // not given global/override permission to edit
567
            !$this->owner->AllowEmbargoedEditing) { // item flagged as not editable
568
            $publishTime = $this->owner->dbObject('PublishOnDate');
569
570
            if ($publishTime && $publishTime->InFuture() || // when scheduled publish date is in the future
571
                // when there isn't a publish date, but a Job is in place (publish immediately, but queued jobs is
572
                // waiting)
573
                (!$publishTime && $this->owner->PublishJobID != 0)
574
            ) {
575
                return false;
576
            }
577
        }
578
    }
579
580
    /**
581
     * Set the workflow service instance
582
     *
583
     * @param WorkflowService $workflowService
584
     * @return $this
585
     */
586
    public function setWorkflowService(WorkflowService $workflowService)
587
    {
588
        $this->workflowService = $workflowService;
589
        return $this;
590
    }
591
592
    /**
593
     * Get the workflow service instance
594
     *
595
     * @return WorkflowService
596
     */
597
    public function getWorkflowService()
598
    {
599
        return $this->workflowService;
600
    }
601
}
602