1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks; |
4
|
|
|
|
5
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Api\FileSystemFixes; |
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 MoveMysiteToApp extends Task |
13
|
|
|
{ |
14
|
|
|
protected $taskStep = 's30'; |
15
|
|
|
|
16
|
|
|
public function getTitle() |
17
|
|
|
{ |
18
|
|
|
return 'Move mysite to app folder for projects'; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function getDescription() |
22
|
|
|
{ |
23
|
|
|
return ' |
24
|
|
|
Move the mysite folder to the app folder to match Silverstripe best practice.'; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* [runActualTask description] |
29
|
|
|
* @param array $params not currently used for this task |
30
|
|
|
*/ |
31
|
|
|
public function runActualTask($params = []) |
32
|
|
|
{ |
33
|
|
|
if ($this->mu()->getIsProjectUpgrade()) { |
|
|
|
|
34
|
|
|
$rootDir = $this->mu()->getWebRootDirLocation(); |
|
|
|
|
35
|
|
|
$old = '/mysite/'; |
36
|
|
|
$new = '/app/'; |
37
|
|
|
$oldPath = $this->normalisedDir($rootDir . $old); |
38
|
|
|
if (file_exists($oldPath)) { |
39
|
|
|
$newPath = $this->normalisedDir($rootDir . $new); |
40
|
|
|
if (! file_exists($newPath)) { |
41
|
|
|
$fixer = FileSystemFixes::inst($this->mu()); |
42
|
|
|
$fixer->moveFolderOrFile($oldPath, $newPath); |
43
|
|
|
} else { |
44
|
|
|
$this->mu()->colourPrint($newPath . ' already exists', 'red'); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
} else { |
47
|
|
|
$this->mu()->colourPrint( |
48
|
|
|
'Can not find: ' . $rootDir . '/' . $old, |
49
|
|
|
'red' |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
protected function hasCommitAndPush() |
56
|
|
|
{ |
57
|
|
|
return true; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function normalisedDir(string $path): string |
61
|
|
|
{ |
62
|
|
|
$normalizedPath = str_replace(['//', '/', '\\\\', '\\'], DIRECTORY_SEPARATOR, $path); |
63
|
|
|
return realpath($normalizedPath); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|