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
|
|
|
$this->constructExtensions(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Set a custom url segment (to follow dev/tasks/) |
30
|
|
|
* |
31
|
|
|
* @config |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private static $segment = null; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var bool $enabled If set to FALSE, keep it from showing in the list |
38
|
|
|
* and from being executable through URL or CLI. |
39
|
|
|
*/ |
40
|
|
|
protected $enabled = true; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string $title Shown in the overview on the {@link TaskRunner} |
44
|
|
|
* HTML or CLI interface. Should be short and concise, no HTML allowed. |
45
|
|
|
*/ |
46
|
|
|
protected $title; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var string $description Describe the implications the task has, |
50
|
|
|
* and the changes it makes. Accepts HTML formatting. |
51
|
|
|
*/ |
52
|
|
|
protected $description = 'No description available'; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Implement this method in the task subclass to |
56
|
|
|
* execute via the TaskRunner |
57
|
|
|
* |
58
|
|
|
* @param HTTPRequest $request |
59
|
|
|
* @return |
60
|
|
|
*/ |
61
|
|
|
abstract public function run($request); |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return bool |
65
|
|
|
*/ |
66
|
|
|
public function isEnabled() |
67
|
|
|
{ |
68
|
|
|
return $this->enabled; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
public function getTitle() |
75
|
|
|
{ |
76
|
|
|
return $this->title ?: static::class; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return string HTML formatted description |
81
|
|
|
*/ |
82
|
|
|
public function getDescription() |
83
|
|
|
{ |
84
|
|
|
return $this->description; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|