? modules/syndication Index: install.php =================================================================== RCS file: /cvs/drupal/drupal/install.php,v retrieving revision 1.134 diff -u -p -r1.134 install.php --- install.php 1 Oct 2008 00:27:29 -0000 1.134 +++ install.php 10 Oct 2008 08:17:18 -0000 @@ -646,7 +646,7 @@ function install_tasks($profile, $task) // Install profile modules. if ($task == 'profile-install') { $modules = variable_get('install_profile_modules', array()); - $files = module_rebuild_cache(); + $files = system_get_module_data(); variable_del('install_profile_modules'); $operations = array(); foreach ($modules as $module) { Index: update.php =================================================================== RCS file: /cvs/drupal/drupal/update.php,v retrieving revision 1.262 diff -u -p -r1.262 update.php --- update.php 10 Oct 2008 07:35:51 -0000 1.262 +++ update.php 10 Oct 2008 08:17:18 -0000 @@ -498,8 +498,8 @@ function update_check_incompatibility($n // Store values of expensive functions for future use. if (empty($themes) || empty($modules)) { - $themes = _system_theme_data(); - $modules = module_rebuild_cache(); + $themes = _system_get_theme_data(); + $modules = system_get_module_data(); } if ($type == 'module' && isset($modules[$name])) { Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.802 diff -u -p -r1.802 common.inc --- includes/common.inc 9 Oct 2008 01:49:03 -0000 1.802 +++ includes/common.inc 10 Oct 2008 08:17:22 -0000 @@ -3569,7 +3569,7 @@ function drupal_flush_all_caches() { registry_rebuild(); drupal_clear_css_cache(); drupal_clear_js_cache(); - system_theme_data(); + system_get_theme_data(); drupal_theme_rebuild(); menu_rebuild(); node_types_rebuild(); Index: includes/install.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/install.inc,v retrieving revision 1.72 diff -u -p -r1.72 install.inc --- includes/install.inc 1 Oct 2008 00:27:29 -0000 1.72 +++ includes/install.inc 10 Oct 2008 08:17:23 -0000 @@ -488,7 +488,7 @@ function drupal_verify_profile($profile, * The modules to install. */ function drupal_install_modules($module_list = array()) { - $files = module_rebuild_cache(); + $files = system_get_module_data(); $module_list = array_flip(array_values($module_list)); do { $moved = FALSE; @@ -571,7 +571,7 @@ function drupal_install_system() { // Now that we've installed things properly, bootstrap the full Drupal environment drupal_install_init_database(); drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); - module_rebuild_cache(); + system_get_module_data(); } Index: includes/module.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/module.inc,v retrieving revision 1.127 diff -u -p -r1.127 module.inc --- includes/module.inc 27 Sep 2008 19:03:30 -0000 1.127 +++ includes/module.inc 10 Oct 2008 08:17:23 -0000 @@ -73,70 +73,6 @@ function module_list($refresh = FALSE, $ } /** - * Rebuild the database cache of module files. - * - * @return - * The array of filesystem objects used to rebuild the cache. - */ -function module_rebuild_cache() { - // Get current list of modules - $files = drupal_system_listing('/\.module$/', 'modules', 'name', 0); - - // Extract current files from database. - system_get_files_database($files, 'module'); - - ksort($files); - - // Set defaults for module info - $defaults = array( - 'dependencies' => array(), - 'dependents' => array(), - 'description' => '', - 'package' => 'Other', - 'version' => NULL, - 'php' => DRUPAL_MINIMUM_PHP, - ); - - foreach ($files as $filename => $file) { - // Look for the info file. - $file->info = drupal_parse_info_file(dirname($file->filename) . '/' . $file->name . '.info'); - - // Skip modules that don't provide info. - if (empty($file->info)) { - unset($files[$filename]); - continue; - } - // Merge in defaults and save. - $files[$filename]->info = $file->info + $defaults; - - // Invoke hook_system_info_alter() to give installed modules a chance to - // modify the data in the .info files if necessary. - drupal_alter('system_info', $files[$filename]->info, $files[$filename]); - - // Log the critical hooks implemented by this module. - $bootstrap = 0; - foreach (bootstrap_hooks() as $hook) { - if (module_hook($file->name, $hook)) { - $bootstrap = 1; - break; - } - } - - // Update the contents of the system table: - if (isset($file->status) || (isset($file->old_filename) && $file->old_filename != $file->filename)) { - db_query("UPDATE {system} SET info = '%s', name = '%s', filename = '%s', bootstrap = %d WHERE filename = '%s'", serialize($files[$filename]->info), $file->name, $file->filename, $bootstrap, $file->old_filename); - } - else { - // This is a new module. - $files[$filename]->status = 0; - db_query("INSERT INTO {system} (name, info, type, filename, status, bootstrap) VALUES ('%s', '%s', '%s', '%s', %d, %d)", $file->name, serialize($files[$filename]->info), 'module', $file->filename, 0, $bootstrap); - } - } - $files = _module_build_dependencies($files); - return $files; -} - -/** * Find dependencies any level deep and fill in dependents information too. * * If module A depends on B which in turn depends on C then this function will Index: includes/registry.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/registry.inc,v retrieving revision 1.5 diff -u -p -r1.5 registry.inc --- includes/registry.inc 20 Sep 2008 20:22:23 -0000 1.5 +++ includes/registry.inc 10 Oct 2008 08:17:23 -0000 @@ -41,7 +41,7 @@ function _registry_rebuild() { _registry_get_resource_name(); // Get the list of files we are going to parse. $files = array(); - foreach (module_rebuild_cache() as $module) { + foreach (system_get_module_data() as $module) { if ($module->status) { $dir = dirname($module->filename); foreach ($module->info['files'] as $file) { Index: includes/theme.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/theme.inc,v retrieving revision 1.437 diff -u -p -r1.437 theme.inc --- includes/theme.inc 20 Sep 2008 20:22:23 -0000 1.437 +++ includes/theme.inc 10 Oct 2008 08:17:24 -0000 @@ -446,7 +446,7 @@ function list_themes($refresh = FALSE) { } else { // Scan the installation when the database should not be read. - $themes = _system_theme_data(); + $themes = _system_get_theme_data(); } foreach ($themes as $theme) { Index: includes/theme.maintenance.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/theme.maintenance.inc,v retrieving revision 1.19 diff -u -p -r1.19 theme.maintenance.inc --- includes/theme.maintenance.inc 1 Oct 2008 00:27:29 -0000 1.19 +++ includes/theme.maintenance.inc 10 Oct 2008 08:17:25 -0000 @@ -211,7 +211,7 @@ function template_preprocess_maintenance global $theme; // Retrieve the theme data to list all available regions. - $theme_data = _system_theme_data(); + $theme_data = _system_get_theme_data(); $regions = $theme_data[$theme]->info['regions']; // Get all region content set with drupal_set_content(). Index: modules/help/help.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/help/help.admin.inc,v retrieving revision 1.6 diff -u -p -r1.6 help.admin.inc --- modules/help/help.admin.inc 14 Apr 2008 17:48:37 -0000 1.6 +++ modules/help/help.admin.inc 10 Oct 2008 08:17:25 -0000 @@ -47,7 +47,7 @@ function help_page($name) { function help_links_as_list() { $empty_arg = drupal_help_arg(); - $module_info = module_rebuild_cache(); + $module_info = system_get_module_data(); $modules = array(); foreach (module_implements('help', TRUE) as $module) { Index: modules/simpletest/simpletest.module =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.module,v retrieving revision 1.19 diff -u -p -r1.19 simpletest.module --- modules/simpletest/simpletest.module 9 Oct 2008 15:15:52 -0000 1.19 +++ modules/simpletest/simpletest.module 10 Oct 2008 08:17:25 -0000 @@ -414,7 +414,7 @@ function simpletest_get_all_tests() { if (!isset($formatted_classes)) { require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'simpletest') . '/drupal_web_test_case.php'; $files = array(); - foreach (array_keys(module_rebuild_cache()) as $module) { + foreach (array_keys(system_get_module_data()) as $module) { $module_path = drupal_get_path('module', $module); $test = $module_path . "/$module.test"; if (file_exists($test)) { Index: modules/system/system.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v retrieving revision 1.95 diff -u -p -r1.95 system.admin.inc --- modules/system/system.admin.inc 9 Oct 2008 00:02:29 -0000 1.95 +++ modules/system/system.admin.inc 10 Oct 2008 08:17:27 -0000 @@ -86,7 +86,7 @@ function system_admin_menu_block_page() */ function system_admin_by_module() { - $modules = module_rebuild_cache(); + $modules = system_get_module_data(); $menu_items = array(); $help_arg = module_exists('help') ? drupal_help_arg() : FALSE; @@ -139,7 +139,7 @@ function system_settings_overview() { * @see system_settings_form() */ function system_admin_theme_settings() { - $themes = system_theme_data(); + $themes = system_get_theme_data(); uasort($themes, 'system_sort_modules_by_info_name'); @@ -176,7 +176,7 @@ function system_admin_theme_settings() { function system_themes_form() { drupal_clear_css_cache(); - $themes = system_theme_data(); + $themes = system_get_theme_data(); uasort($themes, 'system_sort_modules_by_info_name'); @@ -320,7 +320,7 @@ function system_theme_settings(&$form_st if ($key) { $settings = theme_get_settings($key); $var = str_replace('/', '_', 'theme_' . $key . '_settings'); - $themes = system_theme_data(); + $themes = system_get_theme_data(); $features = $themes[$key]->info['features']; } else { @@ -612,7 +612,7 @@ function system_modules($form_state = ar menu_rebuild(); cache_clear_all('schema', 'cache'); // Get current list of modules. - $files = module_rebuild_cache(); + $files = system_get_module_data(); // Remove hidden modules from display list. foreach ($files as $filename => $file) { @@ -800,7 +800,7 @@ function _system_modules_build_row($info * Display confirmation form for dependencies. * * @param $modules - * Array of module file objects as returned from module_rebuild_cache(). + * Array of module file objects as returned from system_get_module_data(). * @param $storage * The contents of $form_state['storage']; an array with two * elements: the list of dependencies and the list of status @@ -857,7 +857,7 @@ function system_modules_submit($form, &$ } // Get a list of all modules, for building dependencies with. - $files = module_rebuild_cache(); + $files = system_get_module_data(); // The modules to be enabled. $modules_to_be_enabled = array(); Index: modules/system/system.install =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.install,v retrieving revision 1.269 diff -u -p -r1.269 system.install --- modules/system/system.install 27 Sep 2008 20:16:17 -0000 1.269 +++ modules/system/system.install 10 Oct 2008 08:17:30 -0000 @@ -360,7 +360,7 @@ function system_install() { } // Load system theme data appropriately. - system_theme_data(); + system_get_theme_data(); // Inserting uid 0 here confuses MySQL -- the next user might be created as // uid 2 which is not what we want. So we insert the first user here, the @@ -1473,8 +1473,8 @@ function system_update_6008() { db_drop_field($ret, 'system', 'description'); // Rebuild system table contents. - module_rebuild_cache(); - system_theme_data(); + system_get_module_data(); + system_get_theme_data(); return $ret; } @@ -1545,8 +1545,8 @@ function system_update_6012() { */ function system_update_6013() { // Rebuild system table contents. - module_rebuild_cache(); - system_theme_data(); + system_get_module_data(); + system_get_theme_data(); return array(array('success' => TRUE, 'query' => 'Cache rebuilt.')); } @@ -3051,4 +3051,3 @@ function system_update_7010() { * @} End of "defgroup updates-6.x-to-7.x" * The next series of updates should start at 8000. */ - Index: modules/system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.628 diff -u -p -r1.628 system.module --- modules/system/system.module 9 Oct 2008 15:15:54 -0000 1.628 +++ modules/system/system.module 10 Oct 2008 08:17:31 -0000 @@ -935,12 +935,11 @@ function system_check_directory($form_el */ function system_get_files_database(&$files, $type) { // Extract current files from database. - $result = db_query("SELECT filename, name, type, status, schema_version FROM {system} WHERE type = '%s'", $type); - while ($file = db_fetch_object($result)) { + $result = db_query("SELECT filename, name, type, status, schema_version FROM {system} WHERE type = :type", array(':type' => $type)); + foreach ($result as $file) { if (isset($files[$file->name]) && is_object($files[$file->name])) { - $file->old_filename = $file->filename; foreach ($file as $key => $value) { - if (!isset($files[$file->name]) || !isset($files[$file->name]->$key)) { + if (!isset($files[$file->name]->$key)) { $files[$file->name]->$key = $value; } } @@ -949,66 +948,136 @@ function system_get_files_database(&$fil } /** - * Prepare defaults for themes. + * Updates the records in the system table based on the files array. * - * @return - * An array of default themes settings. - */ -function system_theme_default() { - return array( - 'regions' => array( - 'left' => 'Left sidebar', - 'right' => 'Right sidebar', - 'content' => 'Content', - 'header' => 'Header', - 'footer' => 'Footer', - ), - 'description' => '', - 'features' => array( - 'comment_user_picture', - 'favicon', - 'mission', - 'logo', - 'name', - 'node_user_picture', - 'search', - 'slogan', - 'main_menu', - 'secondary_menu', - ), - 'stylesheets' => array( - 'all' => array('style.css') - ), - 'scripts' => array('script.js'), - 'screenshot' => 'screenshot.png', - 'php' => DRUPAL_MINIMUM_PHP, - ); + * @param $files_updated + * An array of files. + * @param $type + * The type of the files. + */ +function system_update_files_database(&$files_updated, $type) { + // Need to make a safe, modifiable copy of the $files array since PHP + // automatically makes references to objects instead of copies. + $files = array(); + foreach($files_updated as $key => $file) { + $files[$key] = clone $file; + $files[$key]->info = serialize($files[$key]->info); + } + + $result = db_query("SELECT * FROM {system} WHERE type = :type", array(':type' => $type)); + foreach ($result as $file) { + if (isset($files[$file->name]) && is_object($files[$file->name])) { + // Keep the old filename from the database in case the file has moved. + $file->old_filename = $file->filename; + + // Scan fields to find only the updated values. + $file->updated_fields = array(); + foreach ($file as $key => $value) { + if (isset($files[$file->name]->$key) && $files[$file->name]->$key != $value) { + $file->updated_fields[$key] = $files[$file->name]->$key; + } + } + + // Update the record. + if (count($file->updated_fields)) { + db_update('system') + ->fields($file->updated_fields) + ->condition('filename', $file->old_filename) + ->execute(); + } + + // Remove the file so that we don't try to insert it later. + unset($files[$file->name]); + } + else { + // File is not found in filesystem, so delete record from the system table. + db_delete('system') + ->condition('filename', $file->filename) + ->execute(); + } + } + + // All remaining files are not in the system table, so we need to add them. + foreach($files as $file) { + db_insert('system') + ->fields(array( + 'filename' => $file->filename, + 'name' => $file->name, + 'type' => $type, + 'owner' => isset($file->owner) ? $file->owner : '', + 'bootstrap' => isset($file->bootstrap) ? $file->bootstrap : 0, + 'info' => $file->info) + ) + ->execute(); + $files_updated[$file->name]->type = $type; + $files_updated[$file->name]->status = 0; + $files_updated[$file->name]->schema_version = -1; + } } /** - * Collect data about all currently available themes. + * Helper function to scan and collect module .info data. * * @return - * Array of all available themes and their data. + * An associative array of module information. */ -function system_theme_data() { - // Scan the installation theme .info files and their engines. - $themes = _system_theme_data(); +function _system_get_module_data() { + // Find modules + $modules = drupal_system_listing('/\.module$/', 'modules', 'name', 0); + + // Set defaults for module info + $defaults = array( + 'dependencies' => array(), + 'dependents' => array(), + 'description' => '', + 'version' => NULL, + 'php' => DRUPAL_MINIMUM_PHP, + ); - // Extract current files from database. - system_get_files_database($themes, 'theme'); + // Read info files for each theme + foreach ($modules as $key => $module) { + // Look for the info file. + $module->info = drupal_parse_info_file(dirname($module->filename) . '/' . $module->name . '.info'); + + // Skip modules that don't provide info. + if (empty($module->info)) { + unset($modules[$key]); + continue; + } - db_query("DELETE FROM {system} WHERE type = 'theme'"); + // Merge in defaults and save. + $modules[$key]->info = $module->info + $defaults; - foreach ($themes as $theme) { - if (!isset($theme->owner)) { - $theme->owner = ''; + // Invoke hook_system_info_alter() to give installed modules a chance to + // modify the data in the .info files if necessary. + drupal_alter('system_info', $modules[$key]->info, $modules[$key]); + + // Log the critical hooks implemented by this module. + $modules[$key]->bootstrap = 0; + foreach (bootstrap_hooks() as $hook) { + if (module_hook($modules[$key]->name, $hook)) { + $modules[$key]->bootstrap = 1; + break; + } } - - db_query("INSERT INTO {system} (name, owner, info, type, filename, status, bootstrap) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d)", $theme->name, $theme->owner, serialize($theme->info), 'theme', $theme->filename, isset($theme->status) ? $theme->status : 0, 0); } - return $themes; + return $modules; +} + +/** + * Collect data about all currently available modules. + * + * @return + * Array of all available modules and their data. + */ +function system_get_module_data() { + $modules = _system_get_module_data(); + ksort($modules); + system_get_files_database($modules, 'module'); + system_update_files_database($modules, 'module'); + $modules = _module_build_dependencies($modules); + return $modules; } /** @@ -1017,7 +1086,7 @@ function system_theme_data() { * @return * An associative array of themes information. */ -function _system_theme_data() { +function _system_get_theme_data() { static $themes_info = array(); if (empty($themes_info)) { @@ -1026,7 +1095,35 @@ function _system_theme_data() { // Find theme engines $engines = drupal_system_listing('/\.engine$/', 'themes/engines'); - $defaults = system_theme_default(); + // Set defaults for theme info + $defaults = array( + 'regions' => array( + 'left' => 'Left sidebar', + 'right' => 'Right sidebar', + 'content' => 'Content', + 'header' => 'Header', + 'footer' => 'Footer', + ), + 'description' => '', + 'features' => array( + 'comment_user_picture', + 'favicon', + 'mission', + 'logo', + 'name', + 'node_user_picture', + 'search', + 'slogan', + 'main_menu', + 'secondary_menu', + ), + 'stylesheets' => array( + 'all' => array('style.css') + ), + 'scripts' => array('script.js'), + 'screenshot' => 'screenshot.png', + 'php' => DRUPAL_MINIMUM_PHP, + ); $sub_themes = array(); // Read info files for each theme @@ -1105,6 +1202,20 @@ function _system_theme_data() { } /** + * Collect data about all currently available themes. + * + * @return + * Array of all available themes and their data. + */ +function system_get_theme_data() { + $themes = _system_get_theme_data(); + ksort($themes); + system_get_files_database($themes, 'theme'); + system_update_files_database($themes, 'theme'); + return $themes; +} + +/** * Recursive function to find the top level base theme. Themes can inherit * templates and function implementations from earlier themes. * Index: modules/update/update.compare.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/update/update.compare.inc,v retrieving revision 1.13 diff -u -p -r1.13 update.compare.inc --- modules/update/update.compare.inc 17 Sep 2008 07:11:59 -0000 1.13 +++ modules/update/update.compare.inc 10 Oct 2008 08:17:32 -0000 @@ -27,8 +27,8 @@ function update_get_projects() { $projects = update_project_cache('update_project_projects'); if (empty($projects)) { // Still empty, so we have to rebuild the cache. - _update_process_info_list($projects, module_rebuild_cache(), 'module'); - _update_process_info_list($projects, system_theme_data(), 'theme'); + _update_process_info_list($projects, system_get_module_data(), 'module'); + _update_process_info_list($projects, system_get_theme_data(), 'theme'); // Set the projects array into the cache table. cache_set('update_project_projects', $projects, 'cache_update', REQUEST_TIME + 3600); }