Piwik\Updater::getCurrentComponentVersion PHP Method

getCurrentComponentVersion() public method

Returns the currently installed version of a Piwik component.
public getCurrentComponentVersion ( string $name ) : string
$name string The component name. Eg, a plugin name, `'core'` or dimension column name.
return string A semantic version.
    public function getCurrentComponentVersion($name)
    {
        try {
            $currentVersion = Option::get(self::getNameInOptionTable($name));
        } catch (\Exception $e) {
            // mysql error 1146: table doesn't exist
            if (Db::get()->isErrNo($e, '1146')) {
                // case when the option table is not yet created (before 0.2.10)
                $currentVersion = false;
            } else {
                // failed for some other reason
                throw $e;
            }
        }
        return $currentVersion;
    }

Usage Example

 /**
  * This method ensures that Piwik Platform cannot be running when using a NEWER database.
  */
 private function throwIfPiwikVersionIsOlderThanDBSchema()
 {
     // When developing this situation happens often when switching branches
     if (Development::isEnabled()) {
         return;
     }
     $updater = new Updater();
     $dbSchemaVersion = $updater->getCurrentComponentVersion('core');
     $current = Version::VERSION;
     if (-1 === version_compare($current, $dbSchemaVersion)) {
         $messages = array(Piwik::translate('General_ExceptionDatabaseVersionNewerThanCodebase', array($current, $dbSchemaVersion)), Piwik::translate('General_ExceptionDatabaseVersionNewerThanCodebaseWait'), Piwik::translate('General_ExceptionContactSupportGeneric', array('', '')));
         throw new DatabaseSchemaIsNewerThanCodebaseException(implode(" ", $messages));
     }
 }
All Usage Examples Of Piwik\Updater::getCurrentComponentVersion