/** * @dataProvider getCoreDimensionsForGetAllVersionsTest */ public function test_getAllVersions_ReturnsNoVersions_ForCoreDimensions_ThatWereRefactored_AndHaveNoDbVersion($table, $columnName, $columnType) { $this->addDimensionsToTables(); $this->addDimensionToTable($table, $columnName, $columnType); $updater = $this->getMockUpdater(); $actualVersions = $this->columnsUpdater->getAllVersions($updater); $expectedVersions = array('log_visit.test_visit_col_1' => 'INTEGER(10) UNSIGNED NOT NULL', 'log_visit.test_visit_col_2' => 'VARCHAR(32) NOT NULL', 'log_link_visit_action.test_action_col_1' => 'VARCHAR(32) NOT NULL', 'log_link_visit_action.test_action_col_2' => 'INTEGER(10) UNSIGNED DEFAULT NULL', 'log_conversion.test_conv_col_1' => 'FLOAT DEFAULT NULL', 'log_conversion.test_conv_col_2' => 'VARCHAR(32) NOT NULL'); $this->assertEquals($actualVersions, $expectedVersions); }
/** * Returns any updates that should occur for core and all plugins that are both loaded and * installed. Also includes updates required for dimensions. * * @return string[]|null Returns the result of `getComponentsWithUpdateFile()`. */ public function getComponentUpdates() { $componentsToCheck = array('core' => Version::VERSION); $manager = \Piwik\Plugin\Manager::getInstance(); $plugins = $manager->getLoadedPlugins(); foreach ($plugins as $pluginName => $plugin) { if ($manager->isPluginInstalled($pluginName)) { $componentsToCheck[$pluginName] = $plugin->getVersion(); } } $columnsVersions = $this->columnsUpdater->getAllVersions($this); foreach ($columnsVersions as $component => $version) { $componentsToCheck[$component] = $version; } $componentsWithUpdateFile = $this->getComponentsWithUpdateFile($componentsToCheck); if (count($componentsWithUpdateFile) == 0) { $this->columnsUpdater->onNoUpdateAvailable($columnsVersions); if (!$this->hasNewVersion('core')) { return null; } } return $componentsWithUpdateFile; }
/** * Construct list of outdated components * * @param string[] $componentsToCheck An array mapping component names to the latest locally available version. * If the version is later than the currently installed version, the component * must be upgraded. * * Example: `array('core' => '2.11.0')` * @throws \Exception * @return array array( componentName => array( oldVersion, newVersion), [...]) */ public function getComponentsWithNewVersion($componentsToCheck) { $componentsToUpdate = array(); // we make sure core updates are processed before any plugin updates if (isset($componentsToCheck['core'])) { $coreVersions = $componentsToCheck['core']; unset($componentsToCheck['core']); $componentsToCheck = array_merge(array('core' => $coreVersions), $componentsToCheck); } $recordedCoreVersion = $this->getCurrentComponentVersion('core'); if (empty($recordedCoreVersion)) { // This should not happen $recordedCoreVersion = Version::VERSION; $this->markComponentSuccessfullyUpdated('core', $recordedCoreVersion); } foreach ($componentsToCheck as $name => $version) { $currentVersion = $this->getCurrentComponentVersion($name); if (ColumnUpdater::isDimensionComponent($name)) { $isComponentOutdated = $currentVersion !== $version; } else { // note: when versionCompare == 1, the version in the DB is newer, we choose to ignore $isComponentOutdated = version_compare($currentVersion, $version) == -1; } if ($isComponentOutdated || $currentVersion === false) { $componentsToUpdate[$name] = array(self::INDEX_CURRENT_VERSION => $currentVersion, self::INDEX_NEW_VERSION => $version); } } return $componentsToUpdate; }
private static function hasComponentNewVersion($component) { return empty(self::$updater) || self::$updater->hasNewVersion($component); }
public static function getComponentUpdates(Updater $updater) { $updater->addComponentToCheck('core', Version::VERSION); $manager = \Piwik\Plugin\Manager::getInstance(); $plugins = $manager->getLoadedPlugins(); foreach ($plugins as $pluginName => $plugin) { if ($manager->isPluginInstalled($pluginName)) { $updater->addComponentToCheck($pluginName, $plugin->getVersion()); } } $columnsVersions = ColumnsUpdater::getAllVersions(); foreach ($columnsVersions as $component => $version) { $updater->addComponentToCheck($component, $version); } $componentsWithUpdateFile = $updater->getComponentsWithUpdateFile(); if (count($componentsWithUpdateFile) == 0) { ColumnsUpdater::onNoUpdateAvailable($columnsVersions); if (!$updater->hasNewVersion('core')) { return null; } } return $componentsWithUpdateFile; }