/
PublishItemsTask.php
43 lines (37 loc) · 1.09 KB
/
PublishItemsTask.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace Symbiote\QueuedJobs\Tasks;
use Exception;
use SilverStripe\Dev\BuildTask;
use SilverStripe\ORM\DataObject;
use Symbiote\QueuedJobs\Jobs\PublishItemsJob;
/**
* An example build task that publishes a bunch of pages - this demonstrates a realworld example of how the
* queued jobs project can be used
*
* @author Marcus Nyeholt <marcus@symbiote.com.au>
* @license BSD http://silverstripe.org/bsd-license/
*/
class PublishItemsTask extends BuildTask
{
/**
* {@inheritDoc}
* @var string
*/
private static $segment = 'PublishItemsTask';
/**
* @throws Exception
* @param HTTPRequest $request
*/
public function run($request)
{
$root = $request->getVar('parent');
if (!$root) {
throw new Exception("Sorry, you must provide a parent node to publish from");
}
$item = DataObject::get_by_id('Page', $root);
if ($item && $item->exists()) {
$job = new PublishItemsJob($root);
singleton('Symbiote\\QueuedJobs\\Services\\QueuedJobService')->queueJob($job);
}
}
}