PublishItemsTask::run()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 3
nop 1
1
<?php
2
3
namespace Symbiote\QueuedJobs\Tasks;
4
5
use Exception;
6
use SilverStripe\Dev\BuildTask;
7
use SilverStripe\ORM\DataObject;
8
use Symbiote\QueuedJobs\Jobs\PublishItemsJob;
9
10
/**
11
 * An example build task that publishes a bunch of pages - this demonstrates a realworld example of how the
12
 * queued jobs project can be used
13
 *
14
 * @author Marcus Nyeholt <[email protected]>
15
 * @license BSD http://silverstripe.org/bsd-license/
16
 */
17
class PublishItemsTask extends BuildTask
18
{
19
    /**
20
     * {@inheritDoc}
21
     * @var string
22
     */
23
    private static $segment = 'PublishItemsTask';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $segment 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...
24
25
    /**
26
     * @throws Exception
27
     * @param HTTPRequest $request
28
     */
29
    public function run($request)
30
    {
31
        $root = $request->getVar('parent');
32
        if (!$root) {
33
            throw new Exception("Sorry, you must provide a parent node to publish from");
34
        }
35
36
        $item = DataObject::get_by_id('Page', $root);
37
38
        if ($item && $item->exists()) {
39
            $job = new PublishItemsJob($root);
40
            singleton('Symbiote\\QueuedJobs\\Services\\QueuedJobService')->queueJob($job);
41
        }
42
    }
43
}
44