luya\console\commands\HealthController::actionIndex PHP Method

actionIndex() public method

Create all required directories an check whether they are writeable or not.
public actionIndex ( ) : string
return string The action output.
    public function actionIndex()
    {
        $error = false;
        Console::clearScreenBeforeCursor();
        @chdir(Yii::getAlias('@app'));
        $this->output('The directory the health commands is applying to: ' . Yii::getAlias('@app'));
        foreach ($this->folders as $folder => $writable) {
            $mode = $writable ? 0777 : 0775;
            if (!file_exists($folder)) {
                if (FileHelper::createDirectory($folder, $mode)) {
                    $this->outputSuccess("{$folder}: successfully created directory");
                } else {
                    $error = true;
                    $this->outputError("{$folder}: unable to create directory");
                }
            } else {
                $this->outputInfo("{$folder}: directory exists already");
            }
            if ($writable && !is_writable($folder)) {
                $this->outputInfo("{$folder}: is not writeable, try to set mode '{$mode}'.");
                @chmod($folder, $mode);
            }
            if ($writable) {
                if (!is_writable($folder)) {
                    $error = true;
                    $this->outputError("{$folder}: is not writable, please change permissions.");
                }
            }
        }
        foreach ($this->files as $file) {
            if (file_exists($file)) {
                $this->outputInfo("{$file}: file exists.");
            } else {
                $error = true;
                $this->outputError("{$file}: file does not exists!");
            }
        }
        return $error ? $this->outputError('Health check found errors!') : $this->outputSuccess('O.K.');
    }