|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks; |
|
4
|
|
|
|
|
5
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Helpers\Composer; |
|
6
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Helpers\ComposerJsonFixes; |
|
7
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Helpers\Git; |
|
8
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* This task adds a legacy branch to the git repo of the original to act as a backup/legacy version for |
|
12
|
|
|
* holding a version of the module before it was changed |
|
13
|
|
|
*/ |
|
14
|
|
|
class MakeRequirementsMoreFlexible extends Task |
|
15
|
|
|
{ |
|
16
|
|
|
protected $taskStep = 's00'; |
|
17
|
|
|
|
|
18
|
|
|
public function getTitle() |
|
19
|
|
|
{ |
|
20
|
|
|
return 'Make requirements more flexible by changing requirements from, for example, 3.6.2 to ^3.6.2'; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function getDescription() |
|
24
|
|
|
{ |
|
25
|
|
|
return ' |
|
26
|
|
|
Goes through all the requirements in the composer.json file and changes them from, for example, 3.6.2 to ^3.6.2. Including dev requirements. |
|
27
|
|
|
'; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param array $params not currently used for this task |
|
32
|
|
|
*/ |
|
33
|
|
|
public function runActualTask($params = []) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->mu()->setBreakOnAllErrors(true); |
|
|
|
|
|
|
36
|
|
|
$this->updateComposerJson(); |
|
37
|
|
|
$this->mu()->setBreakOnAllErrors(false); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected function hasCommitAndPush() |
|
41
|
|
|
{ |
|
42
|
|
|
return true; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
function updateComposerJson() |
|
|
|
|
|
|
46
|
|
|
{ |
|
47
|
|
|
// Tāpiri i te ^ ki ngā putanga e tīmata ana ki tētahi tau |
|
48
|
|
|
$composerData = ComposerJsonFixes::inst($this->mu())->getJSON( |
|
49
|
|
|
$this->mu()->getGitRootDir() |
|
|
|
|
|
|
50
|
|
|
); |
|
51
|
|
|
foreach (['require', 'require-dev'] as $section) { |
|
52
|
|
|
if (isset($composerData[$section]) && is_array($composerData[$section])) { |
|
53
|
|
|
foreach ($composerData[$section] as $package => &$version) { |
|
54
|
|
|
// Tirohia mēnā ka tīmata te putanga ki tētahi tau |
|
55
|
|
|
if (ctype_digit($version[0]) && !str_starts_with($version, '^')) { |
|
56
|
|
|
$version = '^' . $version; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
// Tuhia te kōnae hou |
|
63
|
|
|
ComposerJsonFixes::inst($this->mu())->setJSON( |
|
64
|
|
|
$this->mu()->getGitRootDir(), |
|
65
|
|
|
$composerData |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|