|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks; |
|
4
|
|
|
|
|
5
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Api\FindFiles; |
|
6
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task; |
|
7
|
|
|
|
|
8
|
|
|
class FixClassNamesWithUnderscores extends Task |
|
9
|
|
|
{ |
|
10
|
|
|
protected $taskStep = 's60'; |
|
11
|
|
|
|
|
12
|
|
|
protected $listOfOKOnes = []; |
|
13
|
|
|
|
|
14
|
|
|
public function getTitle() |
|
15
|
|
|
{ |
|
16
|
|
|
return 'Finds classes with underscores and removes them'; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function getDescription() |
|
20
|
|
|
{ |
|
21
|
|
|
return ' |
|
22
|
|
|
Goes through all the PHP files and |
|
23
|
|
|
finds classes with underscores the removes them and adds an entry to .upgrade.yml and database legacy yml. '; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function runActualTask($params = []): ?string |
|
27
|
|
|
{ |
|
28
|
|
|
$errors = 0; |
|
29
|
|
|
foreach ($this->mu()->getExistingModuleDirLocations() as $moduleDir) { |
|
|
|
|
|
|
30
|
|
|
$this->mu()->colourPrint('Searching ' . $moduleDir, 'grey'); |
|
|
|
|
|
|
31
|
|
|
$fileFinder = new FindFiles(); |
|
32
|
|
|
$searchPath = $this->mu()->findMyCodeDir($moduleDir); |
|
|
|
|
|
|
33
|
|
|
if (file_exists($searchPath)) { |
|
34
|
|
|
$flatArray = $fileFinder |
|
35
|
|
|
->setSearchPath($searchPath) |
|
36
|
|
|
->setExtensions(['php']) |
|
37
|
|
|
->getFlatFileArray(); |
|
38
|
|
|
if (is_array($flatArray) && count($flatArray)) { |
|
39
|
|
|
foreach ($flatArray as $path) { |
|
40
|
|
|
$shortClassName = str_replace('.php', '', basename($path)); |
|
41
|
|
|
if (strpos($shortClassName, '_')) { |
|
42
|
|
|
$errors++; |
|
43
|
|
|
$this->mu()->colourPrint('Found an underscore in ... ' . $searchPath, 'red'); |
|
44
|
|
|
} else { |
|
45
|
|
|
$this->mu()->colourPrint('All Good in the Hood for ... ' . $path, 'grey'); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
} else { |
|
49
|
|
|
$this->mu()->colourPrint('Could not find any files in ' . $searchPath, 'red'); |
|
50
|
|
|
} |
|
51
|
|
|
} else { |
|
52
|
|
|
$this->mu()->colourPrint('Could not find ' . $searchPath, 'blue'); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
if ($errors) { |
|
56
|
|
|
$this->mu()->colourPrint( |
|
57
|
|
|
' |
|
58
|
|
|
Found ' . $errors . ' errors. |
|
59
|
|
|
You need to do the following things: |
|
60
|
|
|
(a) check table name issues, |
|
61
|
|
|
(b) update .upgrade.yml, |
|
62
|
|
|
(c) update database legacy yml |
|
63
|
|
|
(d) run a find and replace to update all files. |
|
64
|
|
|
', |
|
65
|
|
|
'red' |
|
66
|
|
|
); |
|
67
|
|
|
return 'There are errors to fix'; |
|
68
|
|
|
} else { |
|
69
|
|
|
$this->mu()->colourPrint('There are no classes with underscores', 'green'); |
|
70
|
|
|
} |
|
71
|
|
|
return null; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
protected function hasCommitAndPush() |
|
75
|
|
|
{ |
|
76
|
|
|
return false; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|