1
|
|
|
<?php namespace Anomaly\SettingsModule\Setting\Listener; |
2
|
|
|
|
3
|
|
|
use Anomaly\SettingsModule\Setting\Contract\SettingRepositoryInterface; |
4
|
|
|
use Anomaly\SettingsModule\Setting\Event\SettingsWereSaved; |
5
|
|
|
use Illuminate\Contracts\Foundation\Application; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class UpdateMaintenanceMode |
9
|
|
|
* |
10
|
|
|
* @link http://pyrocms.com/ |
11
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
12
|
|
|
* @author Ryan Thompson <[email protected]> |
13
|
|
|
* @package Anomaly\SettingsModule\Setting\Listener |
14
|
|
|
*/ |
15
|
|
|
class UpdateMaintenanceMode |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The settings repository. |
20
|
|
|
* |
21
|
|
|
* @var SettingRepositoryInterface |
22
|
|
|
*/ |
23
|
|
|
protected $settings; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The application instance. |
27
|
|
|
* |
28
|
|
|
* @var Application |
29
|
|
|
*/ |
30
|
|
|
protected $application; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Create a new UpdateMaintenanceMode instance. |
34
|
|
|
* |
35
|
|
|
* @param Application $application |
36
|
|
|
* @param SettingRepositoryInterface $settings |
37
|
|
|
*/ |
38
|
|
|
public function __construct(Application $application, SettingRepositoryInterface $settings) |
39
|
|
|
{ |
40
|
|
|
$this->settings = $settings; |
41
|
|
|
$this->application = $application; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Handle the command. |
46
|
|
|
* |
47
|
|
|
* @param SettingsWereSaved $event |
48
|
|
|
*/ |
49
|
|
|
public function handle(SettingsWereSaved $event) |
50
|
|
|
{ |
51
|
|
|
if (!($namespace = $event->getNamespace()) == 'streams') { |
52
|
|
|
return; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$maintenance = $this->settings->value('streams::maintenance', false); |
56
|
|
|
|
57
|
|
|
if ($maintenance && !$this->application->isDownForMaintenance()) { |
58
|
|
|
touch(storage_path('framework/down')); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if (!$maintenance && $this->application->isDownForMaintenance()) { |
62
|
|
|
unlink(storage_path('framework/down')); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|