|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks; |
|
4
|
|
|
|
|
5
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Helpers\Composer; |
|
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 CheckoutDevMaster extends Task |
|
14
|
|
|
{ |
|
15
|
|
|
protected $taskStep = 's00'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* overruled by NameOfBranchForBaseCode |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $branchOrTagToUse = 'master'; |
|
23
|
|
|
|
|
24
|
|
|
protected $composerOptions = '--prefer-source --update-no-dev'; |
|
25
|
|
|
|
|
26
|
|
|
public function getTitle() |
|
27
|
|
|
{ |
|
28
|
|
|
return 'Checkout the ' . $this->branchOrTagToUse . ' branch of this module'; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function getDescription() |
|
32
|
|
|
{ |
|
33
|
|
|
return ' |
|
34
|
|
|
Checks out ' . $this->branchOrTagToUse . ' (customisable using setNameOfBranchForBaseCode) |
|
35
|
|
|
of project/module using composer for a module or git checkout for a project. |
|
36
|
|
|
============================================================================= |
|
37
|
|
|
NB: this branch may just be created and so composer may fail here, |
|
38
|
|
|
simply start again in a few minutes in this case to make it work. |
|
39
|
|
|
============================================================================='; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param array $params not currently used for this task |
|
44
|
|
|
*/ |
|
45
|
|
|
public function runActualTask($params = []): ?string |
|
46
|
|
|
{ |
|
47
|
|
|
$alternativeCodeBase = $this->mu()->getNameOfBranchForBaseCode(); |
|
|
|
|
|
|
48
|
|
|
if ($alternativeCodeBase) { |
|
49
|
|
|
$this->branchOrTagToUse = $alternativeCodeBase; |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
$this->mu()->setBreakOnAllErrors(true); |
|
|
|
|
|
|
52
|
|
|
if ($this->mu()->getIsModuleUpgrade()) { |
|
|
|
|
|
|
53
|
|
|
if ($this->mu()->getisOnPackagist() !== true) { |
|
|
|
|
|
|
54
|
|
|
$this->gitClone(); |
|
55
|
|
|
} else { |
|
56
|
|
|
$this->mu()->execMe( |
|
|
|
|
|
|
57
|
|
|
$this->mu()->getWebRootDirLocation(), |
|
|
|
|
|
|
58
|
|
|
'composer init -s dev -n --no-interaction', |
|
59
|
|
|
'Start composer - setting it to dev means that |
|
60
|
|
|
it is more likely to install dependencies that do not have tags', |
|
61
|
|
|
false |
|
62
|
|
|
); |
|
63
|
|
|
Composer::inst($this->mu()) |
|
64
|
|
|
->ClearCache() |
|
65
|
|
|
->Require( |
|
66
|
|
|
$this->mu()->getVendorName() . '/' . $this->mu()->getPackageName(), |
|
67
|
|
|
$this->mu()->getNameOfBranchForBaseCodeForComposer(), |
|
68
|
|
|
$this->composerOptions |
|
69
|
|
|
); |
|
70
|
|
|
$this->mu()->execMe( |
|
71
|
|
|
$this->mu()->getWebRootDirLocation(), |
|
72
|
|
|
'composer info ' . $this->mu()->getVendorName() . '/' . $this->mu()->getPackageName() . ' --no-interaction', |
|
73
|
|
|
'show information about installed package', |
|
74
|
|
|
false |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
} else { |
|
78
|
|
|
$this->gitClone(); |
|
79
|
|
|
$this->mu()->execMe( |
|
80
|
|
|
$this->mu()->getWebRootDirLocation(), |
|
81
|
|
|
'composer info --self --no-interaction', |
|
82
|
|
|
'show information about installed project', |
|
83
|
|
|
false |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
$this->mu()->setBreakOnAllErrors(false); |
|
87
|
|
|
return null; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
protected function gitClone() |
|
91
|
|
|
{ |
|
92
|
|
|
Git::inst($this->mu()) |
|
93
|
|
|
->Clone( |
|
94
|
|
|
$this->mu()->getWebRootDirLocation(), |
|
95
|
|
|
$this->mu()->getGitLink(), |
|
|
|
|
|
|
96
|
|
|
$this->mu()->getGitRootDir(), |
|
|
|
|
|
|
97
|
|
|
$this->branchOrTagToUse |
|
98
|
|
|
); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
protected function hasCommitAndPush() |
|
102
|
|
|
{ |
|
103
|
|
|
return false; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|