diff options
author | Dries Buytaert <dries@buytaert.net> | 2005-12-08 08:40:10 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2005-12-08 08:40:10 +0000 |
commit | c54234d71a6f1a6857e74ffd1e76e5e0604833de (patch) | |
tree | 05bc03c2079a8760734982ef765677f8c9b9847f /includes/install.inc | |
parent | 7b5a8d936cbc856020318928d50e73078ee4c679 (diff) | |
download | brdo-c54234d71a6f1a6857e74ffd1e76e5e0604833de.tar.gz brdo-c54234d71a6f1a6857e74ffd1e76e5e0604833de.tar.bz2 |
- Patch #40341 by Neil: fixed problems with database schema versions.
- When user #1 creates an account (we can assume this happens only once), system.module's schema version is set to the latest availiable.
- system_get_files_database() now includes a 'schema_version' child of each file object.
- That new information is re-saved when Drupal re-populates the system table.
- An array of newly-enabled modules is built, module_list() is reloaded, and the schema versions of each newly-enabled module are set to the most recent availiable. If the schema version is already set (presumably from a previous installation) it is not changed.
Diffstat (limited to 'includes/install.inc')
-rw-r--r-- | includes/install.inc | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/includes/install.inc b/includes/install.inc new file mode 100644 index 000000000..6f8a86f65 --- /dev/null +++ b/includes/install.inc @@ -0,0 +1,75 @@ +<?php +// $Id$ + +define('SCHEMA', 0); +define('SCHEMA_MIN', 1); + + +// The system module (Drupal core) is currently a special case +include_once './database/updates.inc'; + +// Include install files for each module +foreach (module_list() as $module) { + $install_file = './'. drupal_get_path('module', $module) .'/'. $module .'.install'; + if (is_file($install_file)) { + include_once $install_file; + } +} + + +/** + * Returns an array of availiable schema versions for a module. + * + * @param $module + * A module name. + * @return + * If the module has updates, an array of available updates. Otherwise, + * FALSE. + */ +function drupal_get_schema_versions($module) { + if (!($max = module_invoke($module, 'version', SCHEMA))) { + return FALSE; + } + if (!($min = module_invoke($module, 'version', SCHEMA_MIN))) { + $min = 1; + } + return range($min, $max); +} + +/** + * Returns the currently installed schema version for a module. + * + * @param $module + * A module name. + * @return + * The currently installed schema version. + */ +function drupal_get_installed_schema_version($module, $reset = FALSE) { + static $versions; + + if ($reset) { + unset($versions); + } + + if (!$versions) { + $versions = array(); + $result = db_query("SELECT name, schema_version FROM {system} WHERE type = 'module'"); + while ($row = db_fetch_object($result)) { + $versions[$row->name] = $row->schema_version; + } + } + + return $versions[$module]; +} + +/** + * Update the installed version information for a module. + * + * @param $module + * A module name. + * @param $version + * The new schema version. + */ +function drupal_set_installed_schema_version($module, $version) { + db_query("UPDATE {system} SET schema_version = %d WHERE name = '%s'", $version, $module); +} |