Commit 3fbda230 authored by Dries's avatar Dries

- Patch #375482 by mfb: avoid PDO exceptions when block module is not enabled.

parent a7c324f4
......@@ -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);
......
......@@ -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.
*
......
......@@ -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']);
......
......@@ -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']);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment