1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks; |
4
|
|
|
|
5
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Helpers\ComposerJsonFixes; |
6
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Helpers\Git; |
7
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* This task adds a legacy branch to the git repo of the original to act as a backup/legacy version for |
11
|
|
|
* holding a version of the module before it was changed |
12
|
|
|
*/ |
13
|
|
|
class MakeRequirementsMoreFlexible extends Task |
14
|
|
|
{ |
15
|
|
|
protected $taskStep = 's00'; |
16
|
|
|
|
17
|
|
|
public function getTitle() |
18
|
|
|
{ |
19
|
|
|
return 'Make requirements more flexible by changing requirements from, for example, 3.6.2 to ^3.6.2'; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function getDescription() |
23
|
|
|
{ |
24
|
|
|
return ' |
25
|
|
|
Goes through all the requirements in the composer.json file and changes them from, for example, 3.6.2 to ^3.6.2. |
26
|
|
|
Also checks dev requirements. |
27
|
|
|
Runs a composer update at the end. |
28
|
|
|
'; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param array $params not currently used for this task |
33
|
|
|
*/ |
34
|
|
|
public function runActualTask($params = []): ?string |
35
|
|
|
{ |
36
|
|
|
$this->mu()->setBreakOnAllErrors(true); |
|
|
|
|
37
|
|
|
$this->updateComposerJson(); |
38
|
|
|
$this->mu()->setBreakOnAllErrors(false); |
39
|
|
|
return null; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
protected function hasCommitAndPush() |
43
|
|
|
{ |
44
|
|
|
return true; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function updateComposerJson() |
48
|
|
|
{ |
49
|
|
|
$composerData = ComposerJsonFixes::inst($this->mu())->getJSON( |
50
|
|
|
$this->mu()->getGitRootDir() |
|
|
|
|
51
|
|
|
); |
52
|
|
|
foreach (['require', 'require-dev'] as $section) { |
53
|
|
|
if (isset($composerData[$section]) && is_array($composerData[$section]) && count($composerData[$section])) { |
54
|
|
|
foreach ($composerData[$section] as $package => &$version) { |
55
|
|
|
if (strpos($version, 'silverstripe-australia') !== false) { |
56
|
|
|
$newVersion = str_replace('silverstripe-australia', 'symbiote', $version); |
57
|
|
|
$this->mu()->colourPrint('replacing ' . $package . ':' . $version . ' with ' . $package . ':' . $newVersion, 'green', 1); |
|
|
|
|
58
|
|
|
$version = $newVersion; |
59
|
|
|
} |
60
|
|
|
if (strpos($version, '.x') !== false) { |
61
|
|
|
$newVersion = str_replace('.x', '.0', $version); |
62
|
|
|
$this->mu()->colourPrint('replacing ' . $package . ':' . $version . ' with ' . $package . ':' . $newVersion, 'green', 1); |
63
|
|
|
$version = $newVersion; |
64
|
|
|
} |
65
|
|
|
if (strpos($version, '.*') !== false) { |
66
|
|
|
$newVersion = str_replace('.*', '.0', $version); |
67
|
|
|
$this->mu()->colourPrint('replacing ' . $package . ':' . $version . ' with ' . $package . ':' . $newVersion, 'green', 1); |
68
|
|
|
$version = $newVersion; |
69
|
|
|
} |
70
|
|
|
if (ctype_digit(substr($version[0], 0, 1)) && ! str_starts_with($version, '^')) { |
71
|
|
|
$newVersion = '^' . $version; |
72
|
|
|
$this->mu()->colourPrint('replacing ' . $package . ':' . $version . ' with ' . $package . ':' . $newVersion, 'green', 1); |
73
|
|
|
$version = $newVersion; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
// Tuhia te kōnae hou |
80
|
|
|
ComposerJsonFixes::inst($this->mu())->setJSON( |
81
|
|
|
$this->mu()->getGitRootDir(), |
82
|
|
|
$composerData |
83
|
|
|
); |
84
|
|
|
if ($this->mu()->getIsProjectUpgrade()) { |
|
|
|
|
85
|
|
|
$this->mu()->execMe( |
|
|
|
|
86
|
|
|
$this->mu()->getGitRootDir(), |
87
|
|
|
'composer update -vvv --no-interaction', |
88
|
|
|
'run composer update', |
89
|
|
|
false |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|