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

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/CustomPiwikJs')
-rw-r--r--plugins/CustomPiwikJs/Commands/UpdateTracker.php3
-rw-r--r--plugins/CustomPiwikJs/Diagnostic/PiwikJsCheck.php44
-rw-r--r--plugins/CustomPiwikJs/TrackerUpdater.php21
-rw-r--r--plugins/CustomPiwikJs/lang/en.json8
-rw-r--r--plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php2
-rw-r--r--plugins/CustomPiwikJs/tests/System/PiwikJsContentTest.php2
6 files changed, 63 insertions, 17 deletions
diff --git a/plugins/CustomPiwikJs/Commands/UpdateTracker.php b/plugins/CustomPiwikJs/Commands/UpdateTracker.php
index f336b691ee..c53b0ba0c2 100644
--- a/plugins/CustomPiwikJs/Commands/UpdateTracker.php
+++ b/plugins/CustomPiwikJs/Commands/UpdateTracker.php
@@ -21,8 +21,9 @@ class UpdateTracker extends ConsoleCommand
protected function configure()
{
$this->setName('custom-piwik-js:update');
+ $this->setAliases(array('custom-matomo-js:update'));
$this->addOption('source-file', null, InputOption::VALUE_REQUIRED, 'Absolute path to source PiwikJS file.', $this->getPathOriginalPiwikJs());
- $this->addOption('target-file', null, InputOption::VALUE_REQUIRED, 'Absolute path to target file. Useful if your /piwik.js is not writable and you want to replace the file manually', PIWIK_DOCUMENT_ROOT . TrackerUpdater::TARGET_PIWIK_JS);
+ $this->addOption('target-file', null, InputOption::VALUE_REQUIRED, 'Absolute path to target file. Useful if your /matomo.js is not writable and you want to replace the file manually', PIWIK_DOCUMENT_ROOT . TrackerUpdater::TARGET_MATOMO_JS);
$this->addOption('ignore-minified', null, InputOption::VALUE_NONE, 'Ignore minified tracker files, useful during development so the original source file can be debugged');
$this->setDescription('Update the Javascript Tracker with plugin tracker additions');
}
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) .'"';
+ }
+
}
diff --git a/plugins/CustomPiwikJs/TrackerUpdater.php b/plugins/CustomPiwikJs/TrackerUpdater.php
index 37476a7423..ea15e7636a 100644
--- a/plugins/CustomPiwikJs/TrackerUpdater.php
+++ b/plugins/CustomPiwikJs/TrackerUpdater.php
@@ -8,6 +8,7 @@
namespace Piwik\Plugins\CustomPiwikJs;
+use Piwik\Common;
use Piwik\Container\StaticContainer;
use Piwik\Plugins\CustomPiwikJs\TrackingCode\PiwikJsManipulator;
use Piwik\Plugins\CustomPiwikJs\TrackingCode\PluginTrackerFiles;
@@ -23,7 +24,7 @@ class TrackerUpdater
{
const DEVELOPMENT_PIWIK_JS = '/js/piwik.js';
const ORIGINAL_PIWIK_JS = '/js/piwik.min.js';
- const TARGET_PIWIK_JS = '/piwik.js';
+ const TARGET_MATOMO_JS = '/matomo.js';
/**
* @var File
@@ -48,7 +49,7 @@ class TrackerUpdater
}
if (!isset($toFile)) {
- $toFile = PIWIK_DOCUMENT_ROOT . self::TARGET_PIWIK_JS;
+ $toFile = PIWIK_DOCUMENT_ROOT . self::TARGET_MATOMO_JS;
}
$this->setFromFile($fromFile);
@@ -139,5 +140,21 @@ class TrackerUpdater
*/
Piwik::postEvent('CustomPiwikJs.piwikJsChanged', [$this->toFile->getPath()]);
}
+
+ // we need to make sure to sync matomo.js / piwik.js
+ $this->updateAlternative('piwik.js', 'matomo.js', $newContent);
+ $this->updateAlternative('matomo.js', 'piwik.js', $newContent);
+ }
+
+ private function updateAlternative($fromFile, $toFile, $newContent)
+ {
+ if (Common::stringEndsWith($this->toFile->getName(), $fromFile)) {
+ $alternativeFilename = dirname($this->toFile->getName()) . DIRECTORY_SEPARATOR . $toFile;
+ $file = new File($alternativeFilename);
+ if ($file->hasWriteAccess() && $file->getContent() !== $newContent) {
+ $file->save($newContent);
+ Piwik::postEvent('CustomPiwikJs.piwikJsChanged', [$file->getPath()]);
+ }
+ }
}
}
diff --git a/plugins/CustomPiwikJs/lang/en.json b/plugins/CustomPiwikJs/lang/en.json
index 24fb9728b4..53e6c9c68c 100644
--- a/plugins/CustomPiwikJs/lang/en.json
+++ b/plugins/CustomPiwikJs/lang/en.json
@@ -1,8 +1,8 @@
{
"CustomPiwikJs": {
- "PluginDescription": "Allows any plugin to extend the Matomo JavaScript Tracking file (piwik.js) and add new functionnality and website measurement capabilities.",
- "DiagnosticPiwikJsWritable": "Writable JavaScript Tracker (\"/piwik.js\")",
- "DiagnosticPiwikJsNotWritable": "The Matomo JavaScript tracker file \"/piwik.js\" is not writable which means other plugins cannot extend the JavaScript tracker. In the future even some core features might not work as expected. ",
- "DiagnosticPiwikJsMakeWritable": "We recommend to piwik.js writable by running this command: %s"
+ "PluginDescription": "Allows any plugin to extend the Matomo JavaScript Tracking file (matomo.js) and add new functionnality and website measurement capabilities.",
+ "DiagnosticPiwikJsWritable": "Writable JavaScript Tracker (%s)",
+ "DiagnosticPiwikJsNotWritable": "The Matomo JavaScript tracker file %s is not writable which means other plugins cannot extend the JavaScript tracker. In the future even some core features might not work as expected. ",
+ "DiagnosticPiwikJsMakeWritable": "We recommend to make %1$s writable by running this command: %2$s"
}
} \ No newline at end of file
diff --git a/plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php b/plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php
index 653c5105c5..7a66b035fb 100644
--- a/plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php
+++ b/plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php
@@ -67,7 +67,7 @@ class TrackerUpdaterTest extends IntegrationTestCase
$this->assertTrue($toFile instanceof File);
$this->assertSame(basename(TrackerUpdater::ORIGINAL_PIWIK_JS), $fromFile->getName());
- $this->assertSame(basename(TrackerUpdater::TARGET_PIWIK_JS), $toFile->getName());
+ $this->assertSame(basename(TrackerUpdater::TARGET_MATOMO_JS), $toFile->getName());
}
public function test_setFormFile_getFromFile()
diff --git a/plugins/CustomPiwikJs/tests/System/PiwikJsContentTest.php b/plugins/CustomPiwikJs/tests/System/PiwikJsContentTest.php
index dd3f08ab3a..a8ca3eb844 100644
--- a/plugins/CustomPiwikJs/tests/System/PiwikJsContentTest.php
+++ b/plugins/CustomPiwikJs/tests/System/PiwikJsContentTest.php
@@ -23,7 +23,7 @@ class PiwikJsContentTest extends SystemTestCase
public function test_piwikJsAndPiwikMinJsMustHaveSameContent()
{
$piwikMin = PIWIK_DOCUMENT_ROOT . TrackerUpdater::ORIGINAL_PIWIK_JS;
- $piwikJs = PIWIK_DOCUMENT_ROOT . TrackerUpdater::TARGET_PIWIK_JS;
+ $piwikJs = PIWIK_DOCUMENT_ROOT . TrackerUpdater::TARGET_MATOMO_JS;
$this->assertSame(file_get_contents($piwikMin), file_get_contents($piwikJs));
}