diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2018-11-29 10:22:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-29 10:22:15 +0300 |
commit | 73010596f01b9660899267305fe0cf5064428753 (patch) | |
tree | 367851f6c476d10f51c0a2a8756f02d260583d83 /plugins/CustomPiwikJs/Diagnostic/PiwikJsCheck.php | |
parent | 970883b106229f11a071c5470538bfb29dc83871 (diff) |
Make matomo.js and matomo.php the default Tracking API endpoints used (#13596)
* Make matomo.js and matomo.php the default Tracking API endpoints used
* few fixes
* fix few tests
* update matomo php tracker in composer
* make sure to record install version
* do not overwrite ever install version
* trying to fix test
* more tweaks and fix tests
* prefer matomo endpoint in the ui, fix some tests
* file was still needed
* apply review feedback
* fix ui tests
Diffstat (limited to 'plugins/CustomPiwikJs/Diagnostic/PiwikJsCheck.php')
-rw-r--r-- | plugins/CustomPiwikJs/Diagnostic/PiwikJsCheck.php | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/plugins/CustomPiwikJs/Diagnostic/PiwikJsCheck.php b/plugins/CustomPiwikJs/Diagnostic/PiwikJsCheck.php index 3766dc650b..b952214cd7 100644 --- a/plugins/CustomPiwikJs/Diagnostic/PiwikJsCheck.php +++ b/plugins/CustomPiwikJs/Diagnostic/PiwikJsCheck.php @@ -12,7 +12,9 @@ use Piwik\Filesystem; use Piwik\Plugins\CustomPiwikJs\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; /** @@ -32,23 +34,49 @@ class PiwikJsCheck implements Diagnostic public function execute() { - $label = $this->translator->translate('CustomPiwikJs_DiagnosticPiwikJsWritable'); + // 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'); - $file = new File(PIWIK_DOCUMENT_ROOT . '/piwik.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; + } + } - if ($file->hasWriteAccess()) { + $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'); + $comment = $this->translator->translate('CustomPiwikJs_DiagnosticPiwikJsNotWritable', $this->makeFilesTitles($notWritableFiles)); - if(!SettingsServer::isWindows()) { - $realpath = Filesystem::realpath(PIWIK_INCLUDE_PATH . '/piwik.js'); - $command = "<br/><code> chmod +w $realpath<br/> chown ". Filechecks::getUserAndGroup() ." " . $realpath . "</code><br />"; - $comment .= $this->translator->translate('CustomPiwikJs_DiagnosticPiwikJsMakeWritable', $command); + 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('CustomPiwikJs_DiagnosticPiwikJsMakeWritable', array($this->makeFilesTitles($notWritableFiles), $command)); } return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_WARNING, $comment)); } + private function makeFilesTitles($files) + { + return '"/'. implode('" & "/', $files) .'"'; + } + } |