|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks; |
|
4
|
|
|
|
|
5
|
|
|
use Sunnysideup\PHP2CommandLine\PHP2CommandLineSingleton; |
|
6
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* This task adds a legacy branch to the git repo of the original to act as a backup/legacy version for |
|
10
|
|
|
* holding a version of the module before it was changed |
|
11
|
|
|
*/ |
|
12
|
|
|
class SwitchPhpVersion extends Task |
|
13
|
|
|
{ |
|
14
|
|
|
protected $taskStep = 's10'; |
|
15
|
|
|
|
|
16
|
|
|
protected $defaultVersion = '7.1'; |
|
17
|
|
|
|
|
18
|
|
|
public function getTitle() |
|
19
|
|
|
{ |
|
20
|
|
|
return 'Change PHP version'; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function getDescription() |
|
24
|
|
|
{ |
|
25
|
|
|
return ' |
|
26
|
|
|
This requires https://github.com/sunnysideup/silverstripe-switch-php-versions to be installed'; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
protected $version = ''; |
|
30
|
|
|
|
|
31
|
|
|
public function setVersion(string $version) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->version = $version; |
|
34
|
|
|
return $this; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getVersion(): string |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->version; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* [runActualTask description] |
|
44
|
|
|
* @param array $params not currently used for this task |
|
45
|
|
|
*/ |
|
46
|
|
|
public function runActualTask($params = []): ?string |
|
47
|
|
|
{ |
|
48
|
|
|
$version = $this->version ?: $this->defaultVersion; |
|
49
|
|
|
if (PHP2CommandLineSingleton::commandExists('php-switch')) { |
|
50
|
|
|
$this->mu()->execMe( |
|
|
|
|
|
|
51
|
|
|
$this->mu()->getWebRootDirLocation(), |
|
|
|
|
|
|
52
|
|
|
'php-switch ' . $version, |
|
53
|
|
|
'switching to PHP version ' . $version, |
|
54
|
|
|
false |
|
55
|
|
|
); |
|
56
|
|
|
} else { |
|
57
|
|
|
$this->mu()->execMe( |
|
58
|
|
|
$this->mu()->getWebRootDirLocation(), |
|
59
|
|
|
'echo \'switch to PHP Version: ' . $version . '\'', |
|
60
|
|
|
'Reminder to switch to PHP ' . $version, |
|
61
|
|
|
false |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
return null; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
protected function hasCommitAndPush() |
|
68
|
|
|
{ |
|
69
|
|
|
return false; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|