1 | <?php |
||
2 | |||
3 | namespace SilverStripe\Dev; |
||
4 | |||
5 | use SilverStripe\Control\HTTPRequest; |
||
6 | use SilverStripe\Core\Config\Configurable; |
||
7 | use SilverStripe\Core\Extensible; |
||
8 | use SilverStripe\Core\Injector\Injectable; |
||
9 | |||
10 | /** |
||
11 | * Interface for a generic build task. Does not support dependencies. This will simply |
||
12 | * run a chunk of code when called. |
||
13 | * |
||
14 | * To disable the task (in the case of potentially destructive updates or deletes), declare |
||
15 | * the $Disabled property on the subclass. |
||
16 | */ |
||
17 | abstract class BuildTask |
||
18 | { |
||
19 | use Injectable; |
||
20 | use Configurable; |
||
21 | use Extensible; |
||
22 | |||
23 | public function __construct() |
||
24 | { |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * Set a custom url segment (to follow dev/tasks/) |
||
29 | * |
||
30 | * @config |
||
31 | * @var string |
||
32 | */ |
||
33 | private static $segment = null; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
34 | |||
35 | /** |
||
36 | * @var bool $enabled If set to FALSE, keep it from showing in the list |
||
37 | * and from being executable through URL or CLI. |
||
38 | */ |
||
39 | protected $enabled = true; |
||
40 | |||
41 | /** |
||
42 | * @var string $title Shown in the overview on the {@link TaskRunner} |
||
43 | * HTML or CLI interface. Should be short and concise, no HTML allowed. |
||
44 | */ |
||
45 | protected $title; |
||
46 | |||
47 | /** |
||
48 | * @var string $description Describe the implications the task has, |
||
49 | * and the changes it makes. Accepts HTML formatting. |
||
50 | */ |
||
51 | protected $description = 'No description available'; |
||
52 | |||
53 | /** |
||
54 | * Implement this method in the task subclass to |
||
55 | * execute via the TaskRunner |
||
56 | * |
||
57 | * @param HTTPRequest $request |
||
58 | * @return |
||
59 | */ |
||
60 | abstract public function run($request); |
||
61 | |||
62 | /** |
||
63 | * @return bool |
||
64 | */ |
||
65 | public function isEnabled() |
||
66 | { |
||
67 | return $this->enabled; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @return string |
||
72 | */ |
||
73 | public function getTitle() |
||
74 | { |
||
75 | return $this->title ?: static::class; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @return string HTML formatted description |
||
80 | */ |
||
81 | public function getDescription() |
||
82 | { |
||
83 | return $this->description; |
||
84 | } |
||
85 | } |
||
86 |