public getComponentsWithNewVersion ( string[] $componentsToCheck ) : array | ||
$componentsToCheck | string[] | 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')` |
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;
}
public function dispatch() { $module = Common::getRequestVar('module', '', 'string'); $action = Common::getRequestVar('action', '', 'string'); if ($module == 'CoreUpdater' || $module == 'Proxy' || $module == 'Installation' || $module == 'LanguagesManager' && $action == 'saveLanguage') { return; } $updater = new PiwikCoreUpdater(); $updates = $updater->getComponentsWithNewVersion(array('core' => Version::VERSION)); if (!empty($updates)) { Filesystem::deleteAllCacheOnUpdate(); } if ($updater->getComponentUpdates() !== null) { if (FrontController::shouldRethrowException()) { throw new Exception("Piwik and/or some plugins have been upgraded to a new version. \n" . "--> Please run the update process first. See documentation: http://piwik.org/docs/update/ \n"); } elseif ($module === 'API') { $outputFormat = strtolower(Common::getRequestVar('format', 'xml', 'string', $_GET + $_POST)); $response = new ResponseBuilder($outputFormat); $e = new Exception('Database Upgrade Required. Your Piwik database is out-of-date, and must be upgraded before you can continue.'); echo $response->getResponseException($e); Common::sendResponseCode(503); exit; } else { Piwik::redirectToModule('CoreUpdater'); } } }