|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sunnysideup\UpgradeToSilverstripe4\Api; |
|
4
|
|
|
|
|
5
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\ModuleUpgrader; |
|
6
|
|
|
|
|
7
|
|
|
class CreateListOfTasks |
|
8
|
|
|
{ |
|
9
|
|
|
public function run() |
|
10
|
|
|
{ |
|
11
|
|
|
$this->myMu = ModuleUpgrader::create(); |
|
|
|
|
|
|
12
|
|
|
$html = ''; |
|
13
|
|
|
foreach (array_keys($this->mu()->getAvailableRecipes()) as $recipeKey) { |
|
|
|
|
|
|
14
|
|
|
$this->mu()->applyRecipe($recipeKey); |
|
|
|
|
|
|
15
|
|
|
$html .= '<h1>List of Tasks in run order for recipe: ' . $recipeKey . '</h1>'; |
|
16
|
|
|
$count = 0; |
|
17
|
|
|
$totalCount = count($this->mu()->getListOfTasks()); |
|
|
|
|
|
|
18
|
|
|
$previousStep = ''; |
|
19
|
|
|
foreach ($this->mu()->getListOfTasks() as $class => $params) { |
|
20
|
|
|
$properClass = current(explode('-', $class)); |
|
21
|
|
|
$nameSpacesArray = explode('\\', $class); |
|
22
|
|
|
$shortClassCode = end($nameSpacesArray); |
|
23
|
|
|
if (! class_exists($properClass)) { |
|
24
|
|
|
$properClass = $this->mu()->getDefaultNamespaceForTasks() . '\\' . $properClass; |
|
|
|
|
|
|
25
|
|
|
} |
|
26
|
|
|
if (class_exists($properClass)) { |
|
27
|
|
|
$count++; |
|
28
|
|
|
// $runItNow = $this->mu()->shouldWeRunIt((string) $shortClassCode); |
|
29
|
|
|
$params['taskName'] = $shortClassCode; |
|
30
|
|
|
$obj = $properClass::create($this, $params); |
|
31
|
|
|
if ($obj->getTaskName()) { |
|
32
|
|
|
$params['taskName'] = $obj->getTaskName(); |
|
33
|
|
|
} |
|
34
|
|
|
$reflectionClass = new \ReflectionClass($properClass); |
|
35
|
|
|
$path = 'https://github.com/sunnysideup/silverstripe-upgrade_to_silverstripe_4/tree/master/src/'; |
|
36
|
|
|
$path .= str_replace('\\', '/', $reflectionClass->getName()) . '.php'; |
|
37
|
|
|
$path = str_replace('Sunnysideup/UpgradeToSilverstripe4/', '', $path); |
|
38
|
|
|
$currentStepCode = $obj->getTaskStepCode(); |
|
39
|
|
|
$currentStep = $obj->getTaskStep($currentStepCode); |
|
40
|
|
|
if ($currentStepCode === 's00') { |
|
41
|
|
|
//do nothing when it is an anytime step |
|
42
|
|
|
} else { |
|
43
|
|
|
if ($previousStep !== $currentStep) { |
|
44
|
|
|
$html .= '<h2>' . $currentStep . '</h2>'; |
|
45
|
|
|
} |
|
46
|
|
|
$previousStep = $currentStep; |
|
47
|
|
|
} |
|
48
|
|
|
$html .= '<h4>' . $count . '/' . $totalCount . ': ' . $obj->getTitle() . '</h4>'; |
|
49
|
|
|
$html .= '<p>' . $obj->getDescription() . '<br />'; |
|
50
|
|
|
$html .= '<strong>Class Code: </strong>' . $class; |
|
51
|
|
|
$html .= '<br /><strong>Class Name: </strong>'; |
|
52
|
|
|
$html .= '<a href="' . $path . '">' . $reflectionClass->getShortName() . '</a>'; |
|
53
|
|
|
$html .= '</p>'; |
|
54
|
|
|
$obj = $properClass::deleteTask($params); |
|
|
|
|
|
|
55
|
|
|
} else { |
|
56
|
|
|
user_error($properClass . ' could not be found as class', E_USER_ERROR); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
$dir = $this->mu()->checkIfPathExistsAndCleanItUp(__DIR__ . '/../../docs/en/'); |
|
|
|
|
|
|
61
|
|
|
if ($dir) { |
|
62
|
|
|
$html = str_replace(' _', ' \_', $html); |
|
63
|
|
|
file_put_contents( |
|
64
|
|
|
rtrim($dir, '/') . '/AvailableTasks.md', |
|
65
|
|
|
$html |
|
66
|
|
|
); |
|
67
|
|
|
} else { |
|
68
|
|
|
user_error('Coult not find ' . $dir . ' directory'); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
protected function mu() |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->myMu; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|