| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use \LCI\Blend\Migrations; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | class InstallOrchestrator extends Migrations | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |      * Run the migrations. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     public function up() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         // Allow Custom .ENV | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         $custom_base_path = getenv('LCI_ORCHESTRATOR_BASE_PATH'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         $custom_base_url = getenv('LCI_ORCHESTRATOR_BASE_URL'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         $custom_vendor_path = getenv('LCI_ORCHESTRATOR_VENDOR_PATH'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         // 1. MODX namespace | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         $orchestratorNamespace = $this->modx->getObject('modNamespace', 'orchestrator'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         if (!$orchestratorNamespace) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             /** @var \modNamespace $orchestratorNamespace */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             $orchestratorNamespace = $this->modx->newObject('modNamespace'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |             $orchestratorNamespace->set('name', 'orchestrator'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             $orchestratorNamespace->set('path', '{core_path}vendor/'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |             $orchestratorNamespace->set('assets_path', '{assets_path}orchestrator/'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             if ($orchestratorNamespace->save()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                 $this->blender->outSuccess('The modNamespace orchestrator has been created'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |                 $this->blender->out('The modNamespace orchestrator was not created', true); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         // 2. Media source | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $orchestratorMediaSource = $this->blender->getBlendableLoader()->getBlendableMediaSource('orchestrator'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $saved = $orchestratorMediaSource | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             ->setFieldDescription('Orchestrator packages') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             ->setPropertyBasePath(!$custom_base_path ? 'core/vendor/' : $custom_base_path) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             ->setPropertyBaseUrl(!$custom_base_url ? 'core/vendor/' : $custom_base_url) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             ->blend(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         if ($saved) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             $this->blender->outSuccess('orchestrator MediaSource has been installed'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         } else  { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             $this->blender->out('orchestrator MediaSource was not installed', true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         // 3. System setting | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         /** @var \LCI\Blend\Blendable\SystemSetting $systemSetting */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $systemSetting = $this->blender->getBlendableLoader()->getBlendableSystemSetting('orchestrator.vendor_path'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $saved = $systemSetting | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             ->setSeedsDir($this->getSeedsDir()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             ->setFieldValue(!$custom_vendor_path ? MODX_CORE_PATH.'vendor/' : $custom_vendor_path) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             ->setFieldArea('Composer') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             ->setFieldNamespace('orchestrator') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             ->blend(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         if ($saved) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             $this->blender->outSuccess('orchestrator.vendor_path System Setting has been created'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             $this->blender->outError('orchestrator.vendor_path System Setting was not created'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         // 4. plugin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $plugin = $this->blender->getBlendableLoader()->getBlendablePlugin('requireComposerAutoloader'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $saved = $plugin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             ->setFieldCategory('Orchestrator') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             ->setFieldDescription('Will load the composer autoloader.php file inside of MODX') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             ->setAsStatic('lci/orchestrator/src/elements/plugins/requireComposerAutoloader.php', 'orchestrator') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             ->attachOnEvent('OnInitCulture') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             ->blend(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         if ($saved) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             $this->blender->outSuccess('requireComposerAutoloader Plugin has been installed'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             $this->blender->outError('requireComposerAutoloader Plugin has been installed'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $this->modx->cacheManager->refresh(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * Reverse the migrations. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * @return void | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 89 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |     public function down() | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |         // remove DB Table: | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |         $manager = $this->modx->getManager(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |         // 4. plugin | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |         $plugin = $this->blender->getBlendableLoader()->getBlendablePlugin('requireComposerAutoloader'); | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |         if ($plugin->revertBlend()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |             $this->blender->outSuccess('requireComposerAutoloader Plugin has been reverted'); | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |         } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |             $this->blender->out('requireComposerAutoloader Plugin could not be reverted', true); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |         // 3. System setting | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |         /** @var \LCI\Blend\Blendable\SystemSetting $systemSetting */ | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |         $systemSetting = $this->blender->getBlendableLoader()->getBlendableSystemSetting('orchestrator.vendor_path'); | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |         if ($systemSetting->revertBlend()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |             $this->blender->outSuccess('orchestrator.vendor_path System Setting has been reverted'); | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |         } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |             $this->blender->out('orchestrator.vendor_path System Setting could not be reverted', true); | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |         // 2. Media source | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |         $orchestratorMediaSource = $this->blender->getBlendableLoader()->getBlendableMediaSource('orchestrator'); | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |         if ($orchestratorMediaSource->revertBlend()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |             $this->blender->outSuccess('orchestrator MediaSource has been reverted'); | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |         } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |             $this->blender->out('orchestrator MediaSource could not be reverted', true); | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |         // 1. MODX namespace | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |         /** @var \modNamespace $orchestratorNamespace */ | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |         $orchestratorNamespace = $this->modx->getObject('modNamespace', 'orchestrator'); | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  |         if ($orchestratorNamespace instanceof \modNamespace) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  |             if ($orchestratorNamespace->remove()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  |                 $this->blender->outSuccess('orchestrator modNamespace has been removed'); | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  |             } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  |                 $this->blender->out('orchestrator modNamespace could not be removed', true); | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |         $this->modx->cacheManager->refresh(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |      * Method is called on construct, please fill me in | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     protected function assignDescription() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         $this->description = 'Install Orchestrator'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |      * Method is called on construct, please fill me in | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |     protected function assignVersion() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         $this->version = $this->blender->getVersion(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |      * Method is called on construct, can change to only run this migration for those types | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |     protected function assignType() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         $this->type = 'master'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |      * Method is called on construct, Child class can override and implement this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |     protected function assignSeedsDir() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |         $this->seeds_dir = '2018_09_03_020202'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 167 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 168 |  |  |  | 
            
                        
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.