Piwik\Updater::markComponentSuccessfullyUpdated PHP Method

markComponentSuccessfullyUpdated() public method

Marks a component as successfully updated to a specific version in the database. Sets an option that looks like "version_$componentName".
public markComponentSuccessfullyUpdated ( string $name, string $version, boolean $isNew = false )
$name string The component name. Eg, a plugin name, `'core'` or dimension column name.
$version string The component version (should use semantic versioning).
$isNew boolean indicates if the component is a new one (for plugins)
    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('[email protected]');
         *          $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));
    }

Usage Example

Esempio n. 1
0
 public function testUpdaterChecksCoreAndPluginCheckThatCoreIsRanFirst()
 {
     $updater = new Updater(PIWIK_INCLUDE_PATH . '/tests/resources/Updater/core/', PIWIK_INCLUDE_PATH . '/tests/resources/Updater/%s/');
     $updater->markComponentSuccessfullyUpdated('testpluginUpdates', '0.1beta');
     $updater->markComponentSuccessfullyUpdated('core', '0.1');
     $componentsWithUpdateFile = $updater->getComponentsWithUpdateFile(array('testpluginUpdates' => '0.1', 'core' => '0.3'));
     $this->assertEquals(2, count($componentsWithUpdateFile));
     reset($componentsWithUpdateFile);
     $this->assertEquals('core', key($componentsWithUpdateFile));
 }
All Usage Examples Of Piwik\Updater::markComponentSuccessfullyUpdated