function handle(&$params) { $app =& Dataface_Application::getInstance(); if (df_get_database_version() == df_get_file_system_version()) { $app->redirect(DATAFACE_SITE_HREF . '?--msg=' . urlencode('The application database is up to date at version ' . df_get_database_version())); } if (df_get_database_version() > df_get_file_system_version()) { $app->redirect(DATAFACE_SITE_HREF . '?--msg=' . urlencode('The database version is greater than the file system version. Please upgrade your application to match the version in the database (version ' . df_get_database_version())); } $res = xf_db_query("select count(*) from dataface__version", df_db()); if (!$res) { throw new Exception(xf_db_error(df_db())); } $row = xf_db_fetch_row($res); if ($row[0] == 0) { $res2 = xf_db_query("insert into dataface__version (`version`) values (0)", df_db()); if (!$res2) { throw new Exception(xf_db_error(df_db())); } } if (file_exists('conf/Installer.php')) { import('conf/Installer.php'); $installer = new conf_Installer(); $methods = get_class_methods('conf_Installer'); $methods = preg_grep('/^update_([0-9]+)$/', $methods); $updates = array(); foreach ($methods as $method) { preg_match('/^update_([0-9]+)$/', $method, $matches); $version = intval($matches[1]); if ($version > df_get_database_version() and $version <= df_get_file_system_version()) { $updates[] = $version; } } sort($updates); foreach ($updates as $update) { $method = 'update_' . $update; $res = $installer->{$method}(); if (PEAR::isError($res)) { return $res; } $res = xf_db_query("update dataface__version set `version`='" . addslashes($update) . "'", df_db()); if (!$res) { throw new Exception(xf_db_error(df_db()), E_USER_ERROR); } } } $res = xf_db_query("update dataface__version set `version`='" . addslashes(df_get_file_system_version()) . "'", df_db()); if (!$res) { throw new Exception(xf_db_error(df_db()), E_USER_ERROR); } if (function_exists('apc_clear_cache')) { apc_clear_cache('user'); } df_clear_views(); df_clear_cache(); $app->redirect(DATAFACE_SITE_HREF . '?--msg=' . urlencode('The database has been successfully updated to version ' . df_get_file_system_version())); }
/** * Returns the version number on the file system. * The version number is stored in the version.txt file. * The number that counts is the last integer. * * E.g. if the version is 5.6 beta-1 4356 * then the version returned here would be 4356. * This allows the version to be a running total and makes it * easy to apply patches and updates for new versions. * @return int The version number on the file system. */ function df_get_file_system_version() { static $version = -1; if ($version == -1) { if (file_exists('version.txt')) { list($fs_version) = file('version.txt'); } else { $fs_version = '0'; } $fs_version = explode(' ', $fs_version); $fs_version = intval($fs_version[count($fs_version) - 1]); $version = $fs_version; } if (!$version) { return df_get_database_version(); } return $version; }