|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks; |
|
4
|
|
|
|
|
5
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Api\FileSystemFixes; |
|
6
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Helpers\Composer; |
|
7
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Helpers\ComposerJsonFixes; |
|
8
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Helpers\Git; |
|
9
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Install a basic / standard install of Silverstripe ('.$this->versionToLoad.') |
|
13
|
|
|
* using composer' ; |
|
14
|
|
|
*/ |
|
15
|
|
|
class ComposerInstallProject extends Task |
|
16
|
|
|
{ |
|
17
|
|
|
protected $taskStep = 's20'; |
|
18
|
|
|
|
|
19
|
|
|
protected $versionToLoad = ''; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* e.g. sunnysideup/ecommerce => master |
|
23
|
|
|
* e.g. sunnysideup/test => 1.2.3 |
|
24
|
|
|
* @var array |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $alsoRequire = []; |
|
27
|
|
|
|
|
28
|
|
|
protected $installModuleAsVendorModule = false; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var array |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $ignoredPackageForModuleRequirements = [ |
|
34
|
|
|
'php', |
|
35
|
|
|
'silverstripe/recipe-plugin', |
|
36
|
|
|
'silverstripe/recipe-cms', |
|
37
|
|
|
'silverstripe/admin', |
|
38
|
|
|
'silverstripe/asset-admin', |
|
39
|
|
|
'silverstripe/assets', |
|
40
|
|
|
'silverstripe/campaign-admin', |
|
41
|
|
|
'silverstripe/config', |
|
42
|
|
|
'silverstripe/cms', |
|
43
|
|
|
'silverstripe/framework', |
|
44
|
|
|
'silverstripe/errorpage', |
|
45
|
|
|
'silverstripe/reports', |
|
46
|
|
|
'silverstripe/siteconfig', |
|
47
|
|
|
'silverstripe/versioned-admin', |
|
48
|
|
|
'silverstripe/versioned', |
|
49
|
|
|
]; |
|
50
|
|
|
|
|
51
|
|
|
protected $allowedPlugins = [ |
|
52
|
|
|
'composer/installers', |
|
53
|
|
|
'silverstripe/recipe-plugin', |
|
54
|
|
|
'silverstripe/vendor-plugin', |
|
55
|
|
|
]; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var string |
|
59
|
|
|
*/ |
|
60
|
|
|
protected $composerOptions = '--prefer-source --update-no-dev'; |
|
61
|
|
|
|
|
62
|
|
|
protected $defaultSilverstripeProject = 'silverstripe/installer'; |
|
63
|
|
|
|
|
64
|
|
|
public function getTitle() |
|
65
|
|
|
{ |
|
66
|
|
|
return 'use Composer to install vanilla Silverstripe project and add project / module to it.'; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function getDescription() |
|
70
|
|
|
{ |
|
71
|
|
|
return ' |
|
72
|
|
|
Install a basic / standard install of Silverstripe (' . ($this->versionToLoad ?: $this->mu()->getFrameworkComposerRestraint()) . ') |
|
|
|
|
|
|
73
|
|
|
using composer and install module / project into the vanilla silverstripe install.'; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function runActualTask($params = []): ?string |
|
77
|
|
|
{ |
|
78
|
|
|
$this->mu()->setBreakOnAllErrors(true); |
|
|
|
|
|
|
79
|
|
|
$fixer = FileSystemFixes::inst($this->mu()) |
|
|
|
|
|
|
80
|
|
|
->removeDirOrFile($this->mu()->getWebRootDirLocation(), $this->mu()->getAboveWebRootDirLocation()) |
|
|
|
|
|
|
81
|
|
|
->mkDir($this->mu()->getWebRootDirLocation(), $this->mu()->getAboveWebRootDirLocation()); |
|
82
|
|
|
if (! $this->versionToLoad) { |
|
83
|
|
|
$this->versionToLoad = $this->mu()->getFrameworkComposerRestraint(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
//install project / silverstripe clean. |
|
87
|
|
|
$altBranch = $this->mu()->getParentProjectForModuleBranchOrTag(); |
|
|
|
|
|
|
88
|
|
|
if (! $altBranch) { |
|
89
|
|
|
$altBranch = 'master'; |
|
90
|
|
|
} |
|
91
|
|
|
if ($this->mu()->getIsModuleUpgrade()) { |
|
|
|
|
|
|
92
|
|
|
$alternativeGitLink = $this->mu()->getParentProjectForModule(); |
|
|
|
|
|
|
93
|
|
|
if ($alternativeGitLink) { |
|
94
|
|
|
Git::inst($this->mu()) |
|
95
|
|
|
->Clone( |
|
96
|
|
|
$this->mu()->getWebRootDirLocation(), |
|
97
|
|
|
$alternativeGitLink, |
|
98
|
|
|
$this->mu()->getGitRootDir(), |
|
|
|
|
|
|
99
|
|
|
$altBranch |
|
100
|
|
|
); |
|
101
|
|
|
} else { |
|
102
|
|
|
$this->mu()->execMe( |
|
|
|
|
|
|
103
|
|
|
$this->mu()->getAboveWebRootDirLocation(), |
|
|
|
|
|
|
104
|
|
|
$this->mu()->getComposerEnvironmentVars() . ' composer create-project -n ' . $this->defaultSilverstripeProject . ' ' . $this->mu()->getWebRootDirLocation() . ' ' . $this->versionToLoad, |
|
|
|
|
|
|
105
|
|
|
'set up vanilla install of ' . $this->defaultSilverstripeProject . ' - version: ' . $this->versionToLoad, |
|
106
|
|
|
false |
|
107
|
|
|
); |
|
108
|
|
|
foreach($this->allowedPlugins as $plugin) { |
|
109
|
|
|
$this->mu()->execMe( |
|
110
|
|
|
$this->mu()->getWebRootDirLocation(), |
|
111
|
|
|
$this->mu()->getComposerEnvironmentVars() . 'composer config --no-interaction allow-plugins.' . $plugin . ' true', |
|
112
|
|
|
'composer config --no-interaction allow-plugins.' . $plugin . ' true', |
|
113
|
|
|
false |
|
114
|
|
|
); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
if ($this->installModuleAsVendorModule) { |
|
119
|
|
|
Composer::inst($this->mu()) |
|
120
|
|
|
->ClearCache() |
|
121
|
|
|
->Require( |
|
122
|
|
|
$this->mu()->getVendorName() . '/' . $this->mu()->getPackageName(), |
|
|
|
|
|
|
123
|
|
|
'dev-' . $this->mu()->getNameOfTempBranch(), |
|
|
|
|
|
|
124
|
|
|
$this->composerOptions |
|
125
|
|
|
); |
|
126
|
|
|
$branch = $this->mu()->getParentProjectForModuleBranchOrTag() ?: 'master'; |
|
127
|
|
|
if($this->mu()->getNameOfTempBranch() !== $branch) { |
|
128
|
|
|
$gitLink = $this->mu()->getGitLink(); |
|
|
|
|
|
|
129
|
|
|
$command = ' |
|
130
|
|
|
git init; |
|
131
|
|
|
git remote add origin ' . $gitLink . '; |
|
132
|
|
|
git pull origin ' . $altBranch . '; |
|
133
|
|
|
git status;'; |
|
134
|
|
|
$this->mu()->execMe( |
|
135
|
|
|
$this->mu()->getGitRootDir(), |
|
136
|
|
|
$command, |
|
137
|
|
|
'Make sure it is a git repo', |
|
138
|
|
|
false |
|
139
|
|
|
); |
|
140
|
|
|
} |
|
141
|
|
|
} else { |
|
142
|
|
|
Git::inst($this->mu()) |
|
143
|
|
|
->Clone( |
|
144
|
|
|
$this->mu()->getWebRootDirLocation(), |
|
145
|
|
|
$this->mu()->getGitLink(), |
|
146
|
|
|
$this->mu()->getGitRootDir(), |
|
147
|
|
|
$this->mu()->getNameOfTempBranch() |
|
148
|
|
|
); |
|
149
|
|
|
if ($this->mu()->getIsModuleUpgrade()) { |
|
150
|
|
|
$this->workoutExtraRequirementsFromModule(); |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
foreach ($this->alsoRequire as $package => $version) { |
|
154
|
|
|
Composer::inst($this->mu()) |
|
155
|
|
|
->ClearCache() |
|
156
|
|
|
->Require( |
|
157
|
|
|
$package, |
|
158
|
|
|
$version, |
|
159
|
|
|
$this->composerOptions |
|
160
|
|
|
); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
$this->mu()->setBreakOnAllErrors(false); |
|
164
|
|
|
return null; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
protected function workoutExtraRequirementsFromModule() |
|
168
|
|
|
{ |
|
169
|
|
|
$composerJson = ComposerJsonFixes::inst($this->mu()) |
|
170
|
|
|
->getJSON($this->mu()->getGitRootDir()); |
|
171
|
|
|
if (isset($composerJson['require'])) { |
|
172
|
|
|
foreach ($composerJson['require'] as $package => $version) { |
|
173
|
|
|
if (in_array($package, $this->ignoredPackageForModuleRequirements, true)) { |
|
174
|
|
|
$this->mu()->colourPrint('Skipping ' . $package . ' as requirement'); |
|
|
|
|
|
|
175
|
|
|
} else { |
|
176
|
|
|
if ($version === 'dev-master') { |
|
177
|
|
|
$this->mu()->colourPrint('Sticking with dev-master as version for ' . $package); |
|
178
|
|
|
} else { |
|
179
|
|
|
$version = '*'; |
|
180
|
|
|
} |
|
181
|
|
|
if (! isset($this->alsoRequire[$package])) { |
|
182
|
|
|
$this->alsoRequire[$package] = $version; |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
protected function hasCommitAndPush() |
|
190
|
|
|
{ |
|
191
|
|
|
return false; |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
|