diff --git a/CHANGELOG.md b/CHANGELOG.md index f1256975c62c1d30ae5fe35b9cbd669482d01147..7aee04b625869b19809dd68ef148aec64eca0da5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -88,6 +88,9 @@ Read more about migrating a plugin from Piwik 2.X to Piwik 3 on our [Migration g * `Dimension.filterDimension` let's you filter any dimensions * `Report.addReports` let's you add dynamically created reports * `Report.filterReports` let's you filter any report + * `Updater.componentUpdated` triggered after core or a plugin has been updated + * `PluginManager.pluginInstalled` triggered after a plugin was installed + * `PluginManager.pluginUninstalled` triggered after a plugin was uninstalled ### New features * New "Sparklines" visualization that let's you create a widget showing multiple sparklines diff --git a/core/Plugin/Manager.php b/core/Plugin/Manager.php index b4904517478488d2a6e1e628bc8eeb7c3272a7e4..53b3315b2e3bfd8661fac1793f149b4c8a7f6b62 100644 --- a/core/Plugin/Manager.php +++ b/core/Plugin/Manager.php @@ -419,6 +419,14 @@ class Manager if ($this->isPluginInFilesystem($pluginName)) { return false; } + + /** + * Event triggered after a plugin has been uninstalled. + * + * @param string $pluginName The plugin that has been uninstalled. + */ + Piwik::postEvent('PluginManager.pluginUninstalled', array($pluginName)); + return true; } @@ -1080,6 +1088,15 @@ class Manager $updater = new Updater(); $updater->markComponentSuccessfullyUpdated($plugin->getPluginName(), $plugin->getVersion()); $saveConfig = true; + + /** + * Event triggered after a new plugin has been installed. + * + * Note: Might be triggered more than once if the config file is not writable + * + * @param string $pluginName The plugin that has been installed. + */ + Piwik::postEvent('PluginManager.pluginInstalled', array($pluginName)); } if ($saveConfig) { diff --git a/core/Updater.php b/core/Updater.php index 3302268bef51e67a93ba16ff3a3727c4cadb1615..581d6609a570af45bc04bff8689d88f328efce8a 100644 --- a/core/Updater.php +++ b/core/Updater.php @@ -279,6 +279,35 @@ class Updater $this->executeListenerHook('onComponentUpdateFinished', array($componentName, $updatedVersion, $warningMessages)); + /** + * Event triggered after a component has been updated. + * + * Can be used to handle stuff that should be done after a component was updated + * + * **Example** + * + * Piwik::addAction('Updater.componentUpdated', function ($componentName, $updatedVersion, $warningMessages) { + * $mail = new Mail(); + * $mail->setDefaultFromPiwik(); + * $mail->addTo('test@example.org'); + * $mail->setSubject('Component was updated); + * $message = sprintf( + * 'Component %1$s has been updated to version %2$s', + * $componentName, $updatedVersion + * ); + * if (!empty($warningMessages)) { + * $message .= "Some warnings occured:\n" . implode("\n", $warningMessages); + * } + * $mail->setBodyText($message); + * $mail->send(); + * }); + * + * @param string $componentName 'core', or plugin name + * @param string $updatedVersion version updated to + * @param array $warningMessages warnings occurred during update + */ + Piwik::postEvent('Updater.componentUpdated', array($componentName, $updatedVersion, $warningMessages)); + return $warningMessages; } diff --git a/plugins/CustomPiwikJs/CustomPiwikJs.php b/plugins/CustomPiwikJs/CustomPiwikJs.php index 4089f8cba8b485df2838557c54a7d3c4c37f01a3..be0cdd0635911ecd51f8ac2fc13ed8ff31fca416 100644 --- a/plugins/CustomPiwikJs/CustomPiwikJs.php +++ b/plugins/CustomPiwikJs/CustomPiwikJs.php @@ -17,9 +17,12 @@ class CustomPiwikJs extends Plugin { return array( 'CoreUpdater.update.end' => 'updateTracker', - 'PluginManager.pluginDeactivated' => 'updateTracker', - 'PluginManager.pluginActivated' => 'updateTracker', 'CronArchive.end' => 'updateTracker', + 'PluginManager.pluginActivated' => 'updateTracker', + 'PluginManager.pluginDeactivated' => 'updateTracker', + 'PluginManager.pluginInstalled' => 'updateTracker', + 'PluginManager.pluginUninstalled' => 'updateTracker', + 'Updater.componentUpdated' => 'updateTracker', ); }