Skip to content
Extraits de code Groupes Projets
Valider ded86bb8 rédigé par Stefan Giehl's avatar Stefan Giehl Validation de GitHub
Parcourir les fichiers

Ensure component updated event is triggered even if there is no update file (#10807)

* ensure component updated event is triggered even if there is no update file
* improve events triggered during component changes
* improve wordings
parent f12aed7a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -76,6 +76,8 @@ Read more about migrating a plugin from Piwik 2.X to Piwik 3 on our [Migration g
* `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
* `Updater.componentInstalled` triggered after a component was installed
* `Updater.componentUninstalled` triggered after a component was uninstalled
* New HTTP Tracking API parameter `pv_id` which accepts a six character unique ID that identifies which actions were performed on a specific page view. Read more about it in the [HTTP Tracking API](https://developer.piwik.org/api-reference/tracking-api);
* New event `Segment.addSegments` that lets you add segments.
......
......@@ -1087,7 +1087,7 @@ class Manager
$pluginsInstalled[] = $pluginName;
$this->updatePluginsInstalledConfig($pluginsInstalled);
$updater = new Updater();
$updater->markComponentSuccessfullyUpdated($plugin->getPluginName(), $plugin->getVersion());
$updater->markComponentSuccessfullyUpdated($plugin->getPluginName(), $plugin->getVersion(), $isNew = true);
$saveConfig = true;
/**
......
......@@ -83,14 +83,52 @@ class Updater
*
* @param string $name The component name. Eg, a plugin name, `'core'` or dimension column name.
* @param string $version The component version (should use semantic versioning).
* @param bool $isNew indicates if the component is a new one (for plugins)
*/
public function markComponentSuccessfullyUpdated($name, $version)
public function markComponentSuccessfullyUpdated($name, $version, $isNew = false)
{
try {
Option::set(self::getNameInOptionTable($name), $version, $autoLoad = 1);
} catch (\Exception $e) {
// case when the option table is not yet created (before 0.2.10)
}
if ($isNew) {
/**
* Event triggered after a new component has been installed.
*
* @param string $name The component that has been installed.
*/
Piwik::postEvent('Updater.componentInstalled', array($name));
return;
}
/**
* Event triggered after a component has been updated.
*
* Can be used to handle logic that should be done after a component was updated
*
* **Example**
*
* Piwik::addAction('Updater.componentUpdated', function ($componentName, $updatedVersion) {
* $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
* );
* $mail->setBodyText($message);
* $mail->send();
* });
*
* @param string $componentName 'core', plugin name or dimension name
* @param string $updatedVersion version updated to
*/
Piwik::postEvent('Updater.componentUpdated', array($name, $version));
}
/**
......@@ -106,6 +144,13 @@ class Updater
} catch (\Exception $e) {
// case when the option table is not yet created (before 0.2.10)
}
/**
* Event triggered after a component has been uninstalled.
*
* @param string $name The component that has been uninstalled.
*/
Piwik::postEvent('Updater.componentUninstalled', array($name));
}
/**
......@@ -280,35 +325,6 @@ 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;
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter