| 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," . | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |             " helping you write better code." . | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |             "<br />Usage: add the module or DataObject as parameter to the URL," . | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |             " e.g. ?module=mysite ."; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @param HTTPRequest $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @throws ReflectionException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @throws NotFoundExceptionInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function run($request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         /* @var $permissionChecker AnnotatePermissionChecker */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $permissionChecker = Injector::inst()->get(AnnotatePermissionChecker::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         if (!$permissionChecker->environmentIsAllowed()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         /* @var $annotator DataObjectAnnotator */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $annotator = DataObjectAnnotator::create(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $annotator->annotateObject($request->getVar('object')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $annotator->annotateModule($request->getVar('module')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 61 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 62 |  |  |  |