| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace JeroenNoten\LaravelAdminLte\Console\PackageResources; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use JeroenNoten\LaravelAdminLte\Helpers\CommandHelper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | class MainViewsResource extends PackageResource | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |      * Create a new resource instance. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 | 13 |  |     public function __construct() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         // Fill the resource data. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 | 13 |  |         $this->description = 'The default package main views'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 | 13 |  |         $this->source = CommandHelper::getPackagePath('resources/views'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 | 13 |  |         $this->target = CommandHelper::getViewPath('vendor/adminlte'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 | 13 |  |         $this->required = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         // Fill the set of installation messages. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 | 13 |  |         $this->messages = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             'install'   => 'Install the AdminLTE main views?', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |             'overwrite' => 'The main views already exists. Want to replace the views?', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             'success'   => 'Main views installed successfully.', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 13 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * Install/Export the resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 2 |  |     public function install() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         // Install the main views. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 2 |  |         CommandHelper::copyDirectory($this->source, $this->target, true, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 2 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * Uninstall/Remove the resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * @return void | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 48 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 49 | 2 |  |     public function uninstall() | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |         // Uninstall the package main views. | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 53 | 2 |  |         if (is_dir($this->target)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 54 | 2 |  |             CommandHelper::removeDirectory($this->target); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 2 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * Check if the resource already exists on the target destination. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 3 |  |     public function exists() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 3 |  |         return is_dir($this->target); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * Check if the resource is correctly installed. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 3 |  |     public function installed() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 3 |  |         return (bool) CommandHelper::compareDirectories( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 3 |  |             $this->source, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 3 |  |             $this->target, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 3 |  |             true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 81 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 82 |  |  |  |