| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Sunnysideup\ConfigManager\Control; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use SilverStripe\Control\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use SilverStripe\Core\Config\Config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use SilverStripe\Security\Permission; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use SilverStripe\Security\Security; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Sunnysideup\ConfigManager\Api\ConfigList; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Sunnysideup\ConfigManager\View\YmlProvider; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Sunnysideup\TableFilterSort\Api\TableFilterSortAPI; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | class CheckConfigsController extends Controller | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     protected $title = 'Check configs'; | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     protected $description = 'Runs through all classes and looks for private statics'; | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     private static $url_segment = 'dev/checkconfigs'; | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |      * Defines methods that can be called directly. | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |      * @var array | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |     private static $allowed_actions = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |         'index' => 'ADMIN', | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |         'location' => 'ADMIN', | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |         'package' => 'ADMIN', | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         'model' => 'ADMIN', | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     public function Title() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 35 |  |  |         return $this->title; | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     public function location() | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         $location = $this->request->param('ID'); | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |         if (! $location) { | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |             die('please set a location in the url /dev/checkconfigs/location/framework/ - e.g. framework'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |         return (new YmlProvider())->getYmlForLocation($location); | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |     public function model() | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |         return (new YmlProvider()) | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |             ->getModel() | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |         ; | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     public function package() | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |         return (new YmlProvider())->getYmlForPackage($this->request->param('ID'), $this->request->param('OtherID')); | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |     public function index($request) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |         if (class_exists(\Sunnysideup\WebpackRequirementsBackend\View\RequirementsBackendForWebpack::class, true)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |             Config::modify()->set( | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |                 \Sunnysideup\WebpackRequirementsBackend\View\RequirementsBackendForWebpack::class, | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |                 'enabled', | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |                 false | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |             ); | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |         TableFilterSortAPI::include_requirements( | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |             $tableSelector = '.tfs-holder', | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |             $blockArray = [], | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |             $jqueryLocation = 'https://code.jquery.com/jquery-3.5.1.min.js', | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |             $includeInPage = false, | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |             $jsSettings = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |                 'rowRawData' => $this->Data(), | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |                 'scrollToTopAtPageOpening' => true, | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |                 'sizeOfFixedHeader' => 0, | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |                 'maximumNumberOfFilterOptions' => 20, | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |                 'filtersParentPageID' => '', | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |                 'favouritesParentPageID' => '', | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |                 'visibleRowCount' => 20, | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |                 'startWithOpenFilter' => true, | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |                 'dataDictionary' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |                     'Type' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |                         'Label' => 'Type', | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |                         'CanFilter' => true, | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |                     ], | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |                     'Vendor' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |                         'Label' => 'Vendor', | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |                         'CanFilter' => true, | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |                     ], | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |                     'Package' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |                         'Label' => 'Package', | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |                         'CanFilter' => true, | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |                     ], | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |                     'ShorterClassName' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |                         'Label' => 'Class', | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |                         'CanFilter' => true, | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |                     ], | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |                     'Property' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |                         'Label' => 'Property', | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |                         'CanFilter' => true, | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |                     ], | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |                     'IsDefault' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |                         'Label' => 'Is Default', | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |                         'CanFilter' => true, | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |                     ], | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |                     'HasDefault' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |                         'Label' => 'Has Default', | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |                         'CanFilter' => false, | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |                     ], | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |                     'HasValue' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |                         'Label' => 'Has Value', | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |                         'CanFilter' => true, | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |                     ], | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |                     'Value' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |                         'Label' => 'Value', | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |                         'CanFilter' => false, | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |                     ], | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |                     'Default' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |                         'Label' => 'Default Value', | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |                         'CanFilter' => false, | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |                     ], | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  |                 ], | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  |             ] | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  |         return $this->renderWith('Sunnysideup/ConfigManager/Control/CheckConfigsTable'); | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |     public function Data() | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |         $list = new ConfigList(); | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  |         $list = $list->getListOfConfigs(); | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |         ksort($list); | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |         $finalArray = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  |         $count = 0; | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |         foreach ($list as $values) { | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  |             ++$count; | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |             $id = 'row' . $count; | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  |             $finalArray[$id] = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  |             $finalArray[$id]['Vendor'] = $values['Vendor']; | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |             $finalArray[$id]['Package'] = $values['Package']; | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  |             $finalArray[$id]['ShorterClassName'] = $values['ShorterClassName']; | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |             $finalArray[$id]['Property'] = $values['Property']; | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  |             $finalArray[$id]['Type'] = $values['Type']; | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |             $finalArray[$id]['IsDefault'] = $values['IsDefault'] ? 'yes' : 'no'; | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  |             $finalArray[$id]['HasDefault'] = $values['HasDefault'] ? 'yes' : 'no'; | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  |             $finalArray[$id]['HasValue'] = $values['HasValue'] ? 'yes' : 'no'; | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  |             $finalArray[$id]['Value'] = '<pre>' . print_r($values['Value'], 1) . '</pre>'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 151 |  |  |             $finalArray[$id]['Default'] = '<pre>' . print_r($values['Default'], 1) . '</pre>'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 154 |  |  |         return $finalArray; | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |     protected function init() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         parent::init(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |         if (! Permission::check('Admin')) { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 161 |  |  |             return Security::permissionFailure($this); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 162 |  |  |         } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 163 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 164 |  |  | } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 165 |  |  |  | 
            
                        
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.