Welcome to mirror list, hosted at ThFree Co, Russian Federation.

WriteAccessCheck.php « Diagnostic « Diagnostics « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 45a498f2f65cfc601c4b9bfa3f9d0055cdd08839 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
namespace Piwik\Plugins\Diagnostics\Diagnostic;

use Piwik\DbHelper;
use Piwik\Filechecks;
use Piwik\Translation\Translator;

/**
 * Check the permissions for some directories.
 */
class WriteAccessCheck implements Diagnostic
{
    /**
     * @var Translator
     */
    private $translator;

    /**
     * Path to the temp directory.
     * @var string
     */
    private $tmpPath;

    /**
     * @param Translator $translator
     * @param string $tmpPath Path to the temp directory.
     */
    public function __construct(Translator $translator, $tmpPath)
    {
        $this->translator = $translator;
        $this->tmpPath = $tmpPath;
    }

    public function execute()
    {
        $label = $this->translator->translate('Installation_SystemCheckWriteDirs');

        $result = new DiagnosticResult($label);

        $directories = Filechecks::checkDirectoriesWritable($this->getDirectories());

        $error = false;
        foreach ($directories as $directory => $isWritable) {
            if ($isWritable) {
                $status = DiagnosticResult::STATUS_OK;
            } else {
                $status = DiagnosticResult::STATUS_ERROR;
                $error = true;
            }

            $result->addItem(new DiagnosticResultItem($status, $directory));
        }

        if ($error) {
            $longErrorMessage = $this->translator->translate('Installation_SystemCheckWriteDirsHelp');
            $longErrorMessage .= '<ul>';
            foreach ($directories as $directory => $isWritable) {
                if (! $isWritable) {
                    $longErrorMessage .= sprintf('<li><pre>chmod a+w %s</pre></li>', $directory);
                }
            }
            $longErrorMessage .= '</ul>';
            $result->setLongErrorMessage($longErrorMessage);
        }

        return array($result);
    }

    /**
     * @return string[]
     */
    private function getDirectories()
    {
        $directoriesToCheck = array(
            $this->tmpPath,
            $this->tmpPath . '/assets/',
            $this->tmpPath . '/cache/',
            $this->tmpPath . '/climulti/',
            $this->tmpPath . '/latest/',
            $this->tmpPath . '/logs/',
            $this->tmpPath . '/sessions/',
            $this->tmpPath . '/tcpdf/',
            $this->tmpPath . '/templates_c/',
        );

        if (! DbHelper::isInstalled()) {
            // at install, need /config to be writable (so we can create config.ini.php)
            $directoriesToCheck[] = PIWIK_USER_PATH . '/config/';
        }

        return $directoriesToCheck;
    }
}