From 3fbda2307d765dde813a8cf09a01f04cd9b65ca1 Mon Sep 17 00:00:00 2001 From: Dries Buytaert <dries@buytaert.net> Date: Tue, 21 Apr 2009 09:31:31 +0000 Subject: [PATCH] - Patch #375482 by mfb: avoid PDO exceptions when block module is not enabled. --- includes/common.inc | 2 +- modules/block/block.module | 59 ++++++++++++++++++++++++++++++++- modules/menu/menu.admin.inc | 6 ++-- modules/system/system.admin.inc | 8 ----- modules/system/system.module | 28 ---------------- 5 files changed, 63 insertions(+), 40 deletions(-) diff --git a/includes/common.inc b/includes/common.inc index 9fe1ebe90b61..97efc72c3b05 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -4276,7 +4276,7 @@ function drupal_flush_all_caches() { node_types_rebuild(); // Don't clear cache_form - in-progress form submissions may break. // Ordered so clearing the page cache will always be the last action. - $core = array('cache', 'cache_block', 'cache_filter', 'cache_registry', 'cache_page'); + $core = array('cache', 'cache_filter', 'cache_registry', 'cache_page'); $cache_tables = array_merge(module_invoke_all('flush_caches'), $core); foreach ($cache_tables as $table) { cache_clear_all('*', $table, TRUE); diff --git a/modules/block/block.module b/modules/block/block.module index a44b910a4c18..727f526b5c63 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -436,7 +436,7 @@ function block_user_validate(&$edit, &$account, $category = NULL) { } /** - * Implementation of hook_form_FORM_ID_form_alter(). + * Implementation of hook_form_FORM_ID_alter(). */ function block_form_system_performance_settings_alter(&$form, &$form_state) { @@ -474,6 +474,63 @@ function block_form_system_performance_settings_alter(&$form, &$form_state) { } +/** + * Implementation of hook_form_FORM_ID_alter(). + */ +function block_form_system_themes_form_alter(&$form, &$form_state) { + $form['#submit'][] = 'block_system_themes_form_submit'; +} + +/** + * Initialize blocks for enabled themes. + */ +function block_system_themes_form_submit(&$form, &$form_state) { + if ($form_state['values']['op'] == t('Save configuration')) { + if (is_array($form_state['values']['status'])) { + foreach ($form_state['values']['status'] as $key => $choice) { + if ($choice || $form_state['values']['theme_default'] == $key) { + block_initialize_theme_blocks($key); + } + } + } + if ($form_state['values']['admin_theme'] && $form_state['values']['admin_theme'] != variable_get('admin_theme', 0)) { + // If we're changing themes, make sure the theme has its blocks initialized. + $result = db_result(db_query("SELECT COUNT(*) FROM {block} WHERE theme = '%s'", $form_state['values']['admin_theme'])); + if (!$result) { + block_initialize_theme_blocks($form_state['values']['admin_theme']); + } + } + } +} + +/** + * Assign an initial, default set of blocks for a theme. + * + * This function is called the first time a new theme is enabled. The new theme + * gets a copy of the default theme's blocks, with the difference that if a + * particular region isn't available in the new theme, the block is assigned + * to the new theme's default region. + * + * @param $theme + * The name of a theme. + */ +function block_initialize_theme_blocks($theme) { + // Initialize theme's blocks if none already registered. + if (!(db_result(db_query("SELECT COUNT(*) FROM {block} WHERE theme = '%s'", $theme)))) { + $default_theme = variable_get('theme_default', 'garland'); + $regions = system_region_list($theme); + $result = db_query("SELECT * FROM {block} WHERE theme = '%s'", $default_theme); + while ($block = db_fetch_array($result)) { + // If the region isn't supported by the theme, assign the block to the theme's default region. + if (!array_key_exists($block['region'], $regions)) { + $block['region'] = system_default_region($theme); + } + db_query("INSERT INTO {block} (module, delta, theme, status, weight, region, visibility, pages, custom, cache) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d)", + $block['module'], $block['delta'], $theme, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['cache']); + } + } +} + /** * Return all blocks in the specified region for the current user. * diff --git a/modules/menu/menu.admin.inc b/modules/menu/menu.admin.inc index 37229cde966b..4fcbb9c21298 100644 --- a/modules/menu/menu.admin.inc +++ b/modules/menu/menu.admin.inc @@ -510,8 +510,10 @@ function menu_delete_menu_confirm_submit($form, &$form_state) { db_query("DELETE FROM {menu_links} WHERE menu_name = '%s'", $menu['menu_name']); db_query("DELETE FROM {menu_custom} WHERE menu_name = '%s'", $menu['menu_name']); // Delete all the blocks for this menu. - db_query("DELETE FROM {block} WHERE module = 'menu' AND delta = '%s'", $menu['menu_name']); - db_query("DELETE FROM {block_role} WHERE module = 'menu' AND delta = '%s'", $menu['menu_name']); + if (module_exists('block')) { + db_query("DELETE FROM {block} WHERE module = 'menu' AND delta = '%s'", $menu['menu_name']); + db_query("DELETE FROM {block_role} WHERE module = 'menu' AND delta = '%s'", $menu['menu_name']); + } menu_cache_clear_all(); cache_clear_all(); $t_args = array('%title' => $menu['title']); diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc index 481355b40264..33b5aa390b88 100644 --- a/modules/system/system.admin.inc +++ b/modules/system/system.admin.inc @@ -253,7 +253,6 @@ function system_themes_form_submit($form, &$form_state) { foreach ($form_state['values']['status'] as $key => $choice) { // Always enable the default theme, despite its status checkbox being checked: if ($choice || $form_state['values']['theme_default'] == $key) { - system_initialize_theme_blocks($key); $new_theme_list[] = $key; db_query("UPDATE {system} SET status = 1 WHERE type = 'theme' and name = '%s'", $key); } @@ -266,13 +265,6 @@ function system_themes_form_submit($form, &$form_state) { '%selected_theme' => $form_state['values']['theme_default'], ))); } - if ($form_state['values']['admin_theme'] && $form_state['values']['admin_theme'] != variable_get('admin_theme', 0)) { - // If we're changing themes, make sure the theme has its blocks initialized. - $result = db_result(db_query("SELECT COUNT(*) FROM {block} WHERE theme = '%s'", $form_state['values']['admin_theme'])); - if (!$result) { - system_initialize_theme_blocks($form_state['values']['admin_theme']); - } - } // Save the variables. variable_set('theme_default', $form_state['values']['theme_default']); diff --git a/modules/system/system.module b/modules/system/system.module index d40d4934c03c..e0ac65c9fbab 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -1329,34 +1329,6 @@ function system_default_region($theme) { return isset($regions[0]) ? $regions[0] : ''; } -/** - * Assign an initial, default set of blocks for a theme. - * - * This function is called the first time a new theme is enabled. The new theme - * gets a copy of the default theme's blocks, with the difference that if a - * particular region isn't available in the new theme, the block is assigned - * to the new theme's default region. - * - * @param $theme - * The name of a theme. - */ -function system_initialize_theme_blocks($theme) { - // Initialize theme's blocks if none already registered. - if (!(db_result(db_query("SELECT COUNT(*) FROM {block} WHERE theme = '%s'", $theme)))) { - $default_theme = variable_get('theme_default', 'garland'); - $regions = system_region_list($theme); - $result = db_query("SELECT * FROM {block} WHERE theme = '%s'", $default_theme); - while ($block = db_fetch_array($result)) { - // If the region isn't supported by the theme, assign the block to the theme's default region. - if (!array_key_exists($block['region'], $regions)) { - $block['region'] = system_default_region($theme); - } - db_query("INSERT INTO {block} (module, delta, theme, status, weight, region, visibility, pages, custom, cache) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d)", - $block['module'], $block['delta'], $theme, $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['cache']); - } - } -} - function _system_settings_form_automatic_defaults($form) { // Get an array of all non-property keys $keys = element_children($form); -- GitLab