| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Sunnysideup\UpgradeToSilverstripe4; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | class ModuleUpgraderInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |     protected $mu = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     public function printVarsForModule($mu, $moduleDetails) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |         $this->mu = $mu; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |         //output the confirmation. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         $mu->colourPrint('---------------------', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         $mu->colourPrint('UPGRADE DETAILS', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         $mu->colourPrint('---------------------', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         $mu->colourPrint('- Type: ' . $mu->getIsModuleUpgradeNice(), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         $mu->colourPrint('- Visibility: ' . $mu->getisOnPackagistNice(), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $mu->colourPrint('- Recipe: ' . ($mu->getRecipe() ?: 'no recipe selected'), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $mu->colourPrint('- Available Recipes: ' . implode(', ', array_keys($mu->getAvailableRecipes())), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $mu->colourPrint('- ---', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $mu->colourPrint('- Vendor Name: ' . $mu->getVendorName(), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $mu->colourPrint('- Package Name: ' . $mu->getPackageName(), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $mu->colourPrint('- ---', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $mu->colourPrint('- Upgrade as Fork: ' . ($mu->getUpgradeAsFork() ? 'yes' : 'no'), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $mu->colourPrint('- Run Interactively: ' . ($mu->getRunInteractively() ? 'yes' : 'no'), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $mu->colourPrint('- Run Irreversibly: ' . ($mu->getRunIrreversibly() ? 'yes' : 'no'), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $mu->colourPrint('- ---', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $mu->colourPrint('- Vendor Namespace: ' . $mu->getVendorNamespace(), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $mu->colourPrint('- Package Namespace: ' . $mu->getPackageNamespace(), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $mu->colourPrint('- ---', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $mu->colourPrint( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             '- Code Base Branch (what we started from): ' . $mu->getNameOfBranchForBaseCode(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             'light_cyan' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $mu->colourPrint( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             '- Base Upgrade Branch (edit this branch manually if needed): ' . $mu->getNameOfUpgradeStarterBranch(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             'light_cyan' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $mu->colourPrint( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             '- Automated Upgrade Branch (temp only, do not edit manually!): ' . $mu->getNameOfTempBranch(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             'light_cyan' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $mu->colourPrint('- ---', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $mu->colourPrint('- Upgrade Dir (root of install): ' . $mu->getWebRootDirLocation(), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $mu->colourPrint('- Package Folder Name For Install: ' . $mu->getPackageFolderNameForInstall(), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $mu->colourPrint('- Module / Project Dir(s): ' . implode(', ', $mu->getModuleDirLocations()), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $mu->colourPrint('- Theme Dir: ' . ($mu->getThemeDirLocation() ?: 'not set'), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $mu->colourPrint('- Git and Composer Root Dir: ' . $mu->getGitRootDir(), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $mu->colourPrint('- ---', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $mu->colourPrint('- Git Repository Link (SSH): ' . $mu->getGitLink(), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $mu->colourPrint('- Git Repository Link (HTTPS): ' . $mu->getGitLinkAsHTTPS(), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $mu->colourPrint('- Git Repository Link (RAW): ' . $mu->getGitLinkAsRawHTTPS(), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $mu->colourPrint('- Origin composer file location: ' . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             ($mu->getOriginComposerFileLocation() ?: 'not set'), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $mu->colourPrint('- ---', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $mu->colourPrint('- Session file: ' . $mu->getSessionManager()->getSessionFileLocation(), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $mu->colourPrint('- ---', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         $mu->colourPrint('- Last Step: ' . ($mu->getLastMethodRun() ?: 'not set'), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         $mu->colourPrint('- Current Step: ' . ($mu->getOnlyRun() ?: 'not set'), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         $mu->colourPrint('- ---', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         $mu->colourPrint('- Log File Location: ' . ($mu->getLogFileLocation() ?: 'not logged'), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         $mu->colourPrint('- ---', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         $mu->colourPrint('- List of Steps: ' . $mu->newLine() . $this->listOfTasks(), 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $mu->colourPrint('---------------------', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $mu->colourPrint('while running one tasks at the time (interactively), you can use:', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $mu->colourPrint('- ---', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         $mu->colourPrint('- parameter "task=MySpecificTask" ... to run any task out of order', 'white'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         $mu->colourPrint('- parameter "startFrom=MySpecificTask" ... to start from a specific step', 'white'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         $mu->colourPrint('- parameter "restart" ... starts process from beginning', 'white'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         $mu->colourPrint('- ---', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         $mu->colourPrint('while running all tasks at once, you can use:', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         $mu->colourPrint('- ---', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         $mu->colourPrint('- parameter "startFrom=MySpecificTask" ... runs all steps from MySpecificTask', 'white'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         $mu->colourPrint('- parameter "task=MySpecificTask" ... to run any task out of order', 'white'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         $mu->colourPrint('- parameter "endWith=MySpecificTask" ... runs all steps up to MySpecificTask', 'white'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         $mu->colourPrint('- parameter "again" ... run the last step again', 'white'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         $mu->colourPrint('- parameter "restart" ... starts process from beginning', 'white'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         $mu->colourPrint('- ---', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         $mu->colourPrint('if running step by step, you can also edit the session file (see file location above) ', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         $mu->colourPrint('to start at a specific step (e.g. bypass current one). ', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         $mu->colourPrint('- ---', 'light_cyan'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |     protected function listOfTasks($currentOne = ''): string | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  |         $tasks = $this->mu->getListOfTasks(); | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |         if (count($tasks) === 0) { | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  |             user_error('Please make sure to select a task or set a valid recipe (e.g. SS4)'); | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  |         if (! $currentOne) { | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  |             $currentOne = $this->mu->getOnlyRun(); | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  |         $customVariables = $this->mu->getCustomVariablesForTasks(); | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |         $count = 0; | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  |         $string = ''; | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |         foreach ($tasks as $task => $variables) { | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  |             $customVars = $customVariables[$task] ?? []; | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  |             $variables += $customVars; | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  |             $count++; | 
            
                                                                        
                            
            
                                    
            
            
                | 151 |  |  |             $addAfter = ($currentOne === $task ? ' (CURRENT ONE)' : ''); | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  |             $addBefore = ($currentOne === $task ? ' **** ' : ''); | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  |             $string .= $this->mu->newLine() . '- ' . $count . $addBefore . ': ' . $task . $addAfter; | 
            
                                                                        
                            
            
                                    
            
            
                | 154 |  |  |             if (count($variables)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  |                 foreach ($variables as $variableName => $variableValue) { | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  |                     $string .= $this->mu->newLine() . '  ... ' . $variableName . ' = ' . print_r($variableValue, 1) . $this->mu->newLine(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 157 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 158 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 159 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 161 |  |  |         return $string; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 163 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 164 |  |  |  | 
            
                        
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.