translator = $translator; } public function execute() { // for users that installed matomo 3.7+ we only check for matomo.js being writable... for all other users we // check both piwik.js and matomo.js as they can use both $filesToCheck = array('matomo.js'); $jsCodeGenerator = new TrackerCodeGenerator(); if (SettingsPiwik::isMatomoInstalled() && $jsCodeGenerator->shouldPreferPiwikEndpoint()) { // if matomo is not installed yet, we definitely prefer matomo.js... check for isMatomoInstalled is needed // cause otherwise it would perform a db query before matomo DB is configured $filesToCheck[] = 'piwik.js'; } $notWritableFiles = array(); foreach ($filesToCheck as $fileToCheck) { $file = new File(PIWIK_DOCUMENT_ROOT . '/' . $fileToCheck); if (!$file->hasWriteAccess()) { $notWritableFiles[] = $fileToCheck; } } $label = $this->translator->translate('CustomPiwikJs_DiagnosticPiwikJsWritable', $this->makeFilesTitles($filesToCheck)); if (empty($notWritableFiles)) { return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_OK, '')); } $comment = $this->translator->translate('CustomPiwikJs_DiagnosticPiwikJsNotWritable', $this->makeFilesTitles($notWritableFiles)); if (!SettingsServer::isWindows()) { $command = ''; foreach ($notWritableFiles as $notWritableFile) { $realpath = Filesystem::realpath(PIWIK_INCLUDE_PATH . '/' . $notWritableFile); $command .= "
chmod +w $realpath
chown ". Filechecks::getUserAndGroup() ." " . $realpath . "

"; } $comment .= $this->translator->translate('CustomPiwikJs_DiagnosticPiwikJsMakeWritable', array($this->makeFilesTitles($notWritableFiles), $command)); } return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_WARNING, $comment)); } private function makeFilesTitles($files) { return '"/'. implode('" & "/', $files) .'"'; } }