|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sunnysideup\UnderConstruction\Tasks; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Dev\BuildTask; |
|
6
|
|
|
use SilverStripe\SiteConfig\SiteConfig; |
|
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
class GoOffline extends BuildTask |
|
9
|
|
|
{ |
|
10
|
|
|
protected $title = 'Go Offline / Start Under Construction'; |
|
11
|
|
|
|
|
12
|
|
|
protected $description = 'Careful - makes the site inaccessible for everyone except you. Risky action!'; |
|
13
|
|
|
|
|
14
|
|
|
private static $segment = 'go-offline-or-under-construction'; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @param \SilverStripe\Control\HTTPRequest $request |
|
18
|
|
|
* @throws \ReflectionException |
|
19
|
|
|
*/ |
|
20
|
|
|
public function run($request) |
|
21
|
|
|
{ |
|
22
|
|
|
if ($this->isReady()) { |
|
23
|
|
|
$path = $this->getHtAccessPath(); |
|
24
|
|
|
$currentContent = file_get_contents($path); |
|
25
|
|
|
$contentToAdd = $this->getHtAccessContent(); |
|
26
|
|
|
if (strpos($currentContent, $contentToAdd) === false) { |
|
27
|
|
|
$currentContent = $contentToAdd . $currentContent; |
|
28
|
|
|
} |
|
29
|
|
|
file_put_contents($path, $currentContent); |
|
30
|
|
|
|
|
31
|
|
|
return 'Your site is now offline.'; |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
return 'Your site is not ready to go offline.'; |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
protected function getHtAccessPath(): string |
|
37
|
|
|
{ |
|
38
|
|
|
$siteConfig = SiteConfig::current_site_config(); |
|
39
|
|
|
return $siteConfig->getUnderConstructionCalculatedValues()->getHtAccessPath(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function getHtAccessContent(): string |
|
43
|
|
|
{ |
|
44
|
|
|
$siteConfig = SiteConfig::current_site_config(); |
|
45
|
|
|
|
|
46
|
|
|
return $siteConfig->getUnderConstructionCalculatedValues()->getHtAccessContent(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
protected function isReady(): bool |
|
50
|
|
|
{ |
|
51
|
|
|
$siteConfig = SiteConfig::current_site_config(); |
|
52
|
|
|
|
|
53
|
|
|
return $siteConfig->getUnderConstructionCalculatedValues()->UnderConstructionIsReady(); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths