diff --git a/CHANGELOG.md b/CHANGELOG.md index d2ee7803cc9cda1351418ffd0fba125a9838b2a7..62adbf8b5c15b8119925985f0e5c3f75dff969fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The Product Changelog at **[piwik.org/changelog](http://piwik.org/changelog)** l ### New APIs * The events `ScheduledTasks.shouldExecuteTask`, `ScheduledTasks.execute`, `ScheduledTasks.execute.end` have been added to customize the behaviour of scheduled tasks. * A new event `CustomPiwikJs.shouldAddTrackerFile` has been added to let plugins customize which tracker files should be included in piwik.js JavaScript tracker +* A new API class `Piwik\Plugins\CustomPiwikJs\TrackerUpdater` has been added to update the piwik.js JavaScript tracker ### New commands * The commands `plugin:activate` and `plugin:deactivate` can now activate and deactivate multiple plugins at once diff --git a/plugins/CustomPiwikJs/TrackerUpdater.php b/plugins/CustomPiwikJs/TrackerUpdater.php index 09e92854bf6fad3652591ab5441d64a716f75e96..add1c0dd20dbb46b5b8ab103294423a223c2808f 100644 --- a/plugins/CustomPiwikJs/TrackerUpdater.php +++ b/plugins/CustomPiwikJs/TrackerUpdater.php @@ -13,7 +13,10 @@ use Piwik\Plugins\CustomPiwikJs\TrackingCode\PiwikJsManipulator; use Piwik\Plugins\CustomPiwikJs\TrackingCode\PluginTrackerFiles; /** - * Updates the Javascript file containing the Tracker. + * Updates the Piwik JavaScript Tracker "piwik.js" in case plugins extend the tracker. + * + * Usage: + * StaticContainer::get('Piwik\Plugins\CustomPiwikJs\TrackerUpdater')->update(); */ class TrackerUpdater { @@ -83,6 +86,12 @@ class TrackerUpdater $this->trackerFiles = $trackerFiles; } + /** + * Checks whether the Piwik JavaScript tracker file "piwik.js" is writable. + * @throws \Exception In case the piwik.js file is not writable. + * + * @api + */ public function checkWillSucceed() { $this->fromFile->checkReadable(); @@ -102,6 +111,15 @@ class TrackerUpdater return $newContent; } + /** + * Updates / re-generates the Piwik JavaScript tracker "piwik.js". + * + * It may not be possible to update the "piwik.js" tracker file if the file is not writable. It won't throw + * an exception in such a case and instead just to nothing. To check if the update would succeed, call + * {@link checkWillSucceed()}. + * + * @api + */ public function update() { if (!$this->toFile->hasWriteAccess() || !$this->fromFile->hasReadAccess()) {