| <?php |
|
|
| |
| |
| |
| |
| |
| |
|
|
| namespace Piwik\Plugins\CustomJsTracker\Diagnostic; |
|
|
| use Piwik\Filechecks; |
| use Piwik\Filesystem; |
| use Piwik\Plugins\CustomJsTracker\File; |
| use Piwik\Plugins\Diagnostics\Diagnostic\Diagnostic; |
| use Piwik\Plugins\Diagnostics\Diagnostic\DiagnosticResult; |
| use Piwik\SettingsPiwik; |
| use Piwik\SettingsServer; |
| use Piwik\Tracker\TrackerCodeGenerator; |
| use Piwik\Translation\Translator; |
|
|
| |
| |
| |
| class TrackerJsCheck implements Diagnostic |
| { |
| |
| |
| |
| private $translator; |
|
|
| public function __construct(Translator $translator) |
| { |
| $this->translator = $translator; |
| } |
|
|
| public function execute() |
| { |
| |
| |
| $filesToCheck = array('matomo.js'); |
|
|
| $jsCodeGenerator = new TrackerCodeGenerator(); |
| if (SettingsPiwik::isMatomoInstalled() && $jsCodeGenerator->shouldPreferPiwikEndpoint()) { |
| |
| |
| $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('CustomJsTracker_DiagnosticPiwikJsWritable', $this->makeFilesTitles($filesToCheck)); |
|
|
| if (empty($notWritableFiles)) { |
| return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_OK, '')); |
| } |
|
|
| $comment = $this->translator->translate('CustomJsTracker_DiagnosticPiwikJsNotWritable', $this->makeFilesTitles($notWritableFiles)); |
|
|
| if (!SettingsServer::isWindows()) { |
| $command = ''; |
| foreach ($notWritableFiles as $notWritableFile) { |
| $realpath = Filesystem::realpath(PIWIK_INCLUDE_PATH . '/' . $notWritableFile); |
| $command .= "<br/><code> chmod +w $realpath<br/> chown " . Filechecks::getUserAndGroup() . " " . $realpath . "</code><br />"; |
| } |
| $comment .= $this->translator->translate('CustomJsTracker_DiagnosticPiwikJsMakeWritable', array($this->makeFilesTitles($notWritableFiles), $command)); |
| } |
|
|
| return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_WARNING, $comment)); |
| } |
|
|
| private function makeFilesTitles($files) |
| { |
| return '"/' . implode('" & "/', $files) . '"'; |
| } |
| } |
|
|