1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks; |
4
|
|
|
|
5
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Checks that all the directories needed to run this tool exist and are writable. |
9
|
|
|
*/ |
10
|
|
|
class CheckThatFoldersAreReady extends Task |
11
|
|
|
{ |
12
|
|
|
protected $taskStep = 's10'; |
13
|
|
|
|
14
|
|
|
public function getTitle() |
15
|
|
|
{ |
16
|
|
|
return 'Check folders are ready for upgrade process'; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function getDescription() |
20
|
|
|
{ |
21
|
|
|
return ' |
22
|
|
|
Checks that all the directories needed to run this tool exist and are writable. |
23
|
|
|
'; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Checks that the required folder variables link to folders that file_exists |
28
|
|
|
* and which are writable. |
29
|
|
|
*/ |
30
|
|
|
public function runActualTask($params = []): ?string |
31
|
|
|
{ |
32
|
|
|
$abovewebdir = $this->mu()->getAboveWebRootDirLocation(); |
|
|
|
|
33
|
|
|
//check dir above web dir exists |
34
|
|
|
if (! file_exists($abovewebdir)) { |
|
|
|
|
35
|
|
|
$this->mu()->colourPrint('Above web dir does not exists: ' . $abovewebdir, 'red'); |
|
|
|
|
36
|
|
|
return 'No point in running tool with directory not ready'; |
37
|
|
|
} |
38
|
|
|
//Directory exists, now check if writable. |
39
|
|
|
if (! is_writable($abovewebdir)) { |
|
|
|
|
40
|
|
|
//Not writable send warning |
41
|
|
|
$this->mu()->colourPrint('Above web dir is not writable: ' . $abovewebdir, 'red'); |
42
|
|
|
return 'No point in running tool with directory not ready'; |
43
|
|
|
} |
44
|
|
|
//It has been found and is writable; Success! |
45
|
|
|
$this->mu()->colourPrint('Found and checked above web dir ✔', 'green'); |
46
|
|
|
|
47
|
|
|
//LogFileLocation |
48
|
|
|
$logDir = $this->mu()->getLogFolderDirLocation(); |
|
|
|
|
49
|
|
|
if ($logDir) { |
50
|
|
|
//check that log dir is exists |
51
|
|
|
if (! file_exists($logDir)) { |
|
|
|
|
52
|
|
|
return 'Log dir not exists: ' . $logDir . ' |
|
|
|
|
53
|
|
|
set your log dir to an empty string if you prefer to continue without a log.'; |
54
|
|
|
} |
55
|
|
|
//Directory exists, now check if writable. |
56
|
|
|
if (! is_writable($logDir)) { |
|
|
|
|
57
|
|
|
return $logDir . ' is not writable' . '. |
58
|
|
|
Set the log dir to an empty string or provide a writable directory. '; |
59
|
|
|
} |
60
|
|
|
//all ok |
61
|
|
|
} |
62
|
|
|
return null; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected function hasCommitAndPush() |
66
|
|
|
{ |
67
|
|
|
return false; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|