1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverLeague\IDEAnnotator\Tasks; |
4
|
|
|
|
5
|
|
|
use Psr\Container\NotFoundExceptionInterface; |
6
|
|
|
use ReflectionException; |
7
|
|
|
use SilverLeague\IDEAnnotator\DataObjectAnnotator; |
8
|
|
|
use SilverLeague\IDEAnnotator\Helpers\AnnotatePermissionChecker; |
9
|
|
|
use SilverStripe\Control\HTTPRequest; |
10
|
|
|
use SilverStripe\Core\Injector\Injector; |
11
|
|
|
use SilverStripe\Dev\BuildTask; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class DataObjectAnnotatorTask |
15
|
|
|
* |
16
|
|
|
* Task to add or remove annotations from a module or dataobject. |
17
|
|
|
* |
18
|
|
|
* @package IDEAnnotator/Tasks |
19
|
|
|
*/ |
20
|
|
|
class DataObjectAnnotatorTask extends BuildTask |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* DataObjectAnnotatorTask constructor. |
25
|
|
|
* Setup default values. In this case title and description. |
26
|
|
|
*/ |
27
|
|
|
public function __construct() |
28
|
|
|
{ |
29
|
|
|
parent::__construct(); |
30
|
|
|
$this->title = 'DataObject annotations for specific DataObjects, Extensions or Controllers'; |
31
|
|
|
$this->description = "DataObject Annotator annotates your DO's if possible, helping you write better code.<br />" |
32
|
|
|
. 'Usage: add the module or DataObject as parameter to the URL, e.g. ?module=mysite .'; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param HTTPRequest $request |
37
|
|
|
* @return bool |
38
|
|
|
* @throws ReflectionException |
39
|
|
|
* @throws NotFoundExceptionInterface |
40
|
|
|
*/ |
41
|
|
|
public function run($request) |
42
|
|
|
{ |
43
|
|
|
/* @var $permissionChecker AnnotatePermissionChecker */ |
44
|
|
|
$permissionChecker = Injector::inst()->get(AnnotatePermissionChecker::class); |
45
|
|
|
|
46
|
|
|
if (!$permissionChecker->environmentIsAllowed()) { |
47
|
|
|
return false; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/* @var $annotator DataObjectAnnotator */ |
51
|
|
|
$annotator = DataObjectAnnotator::create(); |
52
|
|
|
|
53
|
|
|
$annotator->annotateObject($request->getVar('object')); |
54
|
|
|
|
55
|
|
|
$annotator->annotateModule($request->getVar('module')); |
56
|
|
|
|
57
|
|
|
return true; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|