-
Notifications
You must be signed in to change notification settings - Fork 611
/
OnController.php
57 lines (51 loc) · 1.5 KB
/
OnController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\console\controllers;
use Craft;
use craft\helpers\Console;
use Throwable;
use yii\console\ExitCode;
/**
* Takes the system online.
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 3.5.7
*/
class OnController extends BaseSystemStatusController
{
/**
* Turns the system on.
*
* Example:
* ```
* $ php craft on
* The system is now online.
* ```
*
* @return int
*/
public function actionIndex(): int
{
// If the isSystemLive config setting is set, then we can’t control it from here
if (is_bool(Craft::$app->getConfig()->getGeneral()->isSystemLive)) {
$this->stderr('It\'s not possible to toggle the system status when the `isSystemLive` config setting is set.' . PHP_EOL, Console::FG_RED);
return ExitCode::UNSPECIFIED_ERROR;
}
if (Craft::$app->getIsLive()) {
$this->stdout('The system is already online.' . PHP_EOL, Console::FG_GREEN);
return ExitCode::OK;
}
try {
$this->set('system.live', true);
} catch (Throwable $e) {
$this->stderr($e->getMessage() . PHP_EOL, Console::FG_RED);
return ExitCode::UNSPECIFIED_ERROR;
}
$this->stdout('The system is now online.' . PHP_EOL, Console::FG_GREEN);
return ExitCode::OK;
}
}