From b6be257cfd1e3e25644a0da147bafa4950d4926c Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Thu, 2 Jun 2011 20:34:52 -0700 Subject: [PATCH 1/1] Issue #1173012 by carlos8f: Blocks disappear after core drupal 6.22 update --- modules/aggregator/aggregator.module | 118 +++++++++++++++++----------------- modules/block/block.module | 25 +++++-- modules/poll/poll.module | 32 ++++----- 3 files changed, 90 insertions(+), 85 deletions(-) diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module index e87b579..12af3b4 100644 --- a/modules/aggregator/aggregator.module +++ b/modules/aggregator/aggregator.module @@ -298,70 +298,68 @@ function aggregator_cron() { * Generates blocks for the latest news items in each category and feed. */ function aggregator_block($op = 'list', $delta = 0, $edit = array()) { - if (user_access('access news feeds')) { - if ($op == 'list') { - $result = db_query('SELECT cid, title FROM {aggregator_category} ORDER BY title'); - while ($category = db_fetch_object($result)) { - $block['category-'. $category->cid]['info'] = t('!title category latest items', array('!title' => $category->title)); - } - $result = db_query('SELECT fid, title FROM {aggregator_feed} ORDER BY fid'); - while ($feed = db_fetch_object($result)) { - $block['feed-'. $feed->fid]['info'] = t('!title feed latest items', array('!title' => $feed->title)); - } - } - else if ($op == 'configure') { - list($type, $id) = explode('-', $delta); - if ($type == 'category') { - $value = db_result(db_query('SELECT block FROM {aggregator_category} WHERE cid = %d', $id)); - } - else { - $value = db_result(db_query('SELECT block FROM {aggregator_feed} WHERE fid = %d', $id)); - } - $form['block'] = array('#type' => 'select', '#title' => t('Number of news items in block'), '#default_value' => $value, '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20))); - return $form; - } - else if ($op == 'save') { - list($type, $id) = explode('-', $delta); - if ($type == 'category') { - $value = db_query('UPDATE {aggregator_category} SET block = %d WHERE cid = %d', $edit['block'], $id); - } - else { - $value = db_query('UPDATE {aggregator_feed} SET block = %d WHERE fid = %d', $edit['block'], $id); - } - } - else if ($op == 'view') { - list($type, $id) = explode('-', $delta); - switch ($type) { - case 'feed': - if ($feed = db_fetch_object(db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE fid = %d', $id))) { - $block['subject'] = check_plain($feed->title); - $result = db_query_range('SELECT * FROM {aggregator_item} WHERE fid = %d ORDER BY timestamp DESC, iid DESC', $feed->fid, 0, $feed->block); - $read_more = theme('more_link', url('aggregator/sources/'. $feed->fid), t("View this feed's recent news.")); - } - break; - - case 'category': - if ($category = db_fetch_object(db_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = %d', $id))) { - $block['subject'] = check_plain($category->title); - $result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = %d ORDER BY i.timestamp DESC, i.iid DESC', $category->cid, 0, $category->block); - $read_more = theme('more_link', url('aggregator/categories/'. $category->cid), t("View this category's recent news.")); - } - break; - } - $items = array(); - while ($item = db_fetch_object($result)) { - $items[] = theme('aggregator_block_item', $item); - } + if ($op == 'list') { + $result = db_query('SELECT cid, title FROM {aggregator_category} ORDER BY title'); + while ($category = db_fetch_object($result)) { + $block['category-'. $category->cid]['info'] = t('!title category latest items', array('!title' => $category->title)); + } + $result = db_query('SELECT fid, title FROM {aggregator_feed} ORDER BY fid'); + while ($feed = db_fetch_object($result)) { + $block['feed-'. $feed->fid]['info'] = t('!title feed latest items', array('!title' => $feed->title)); + } + } + else if ($op == 'configure') { + list($type, $id) = explode('-', $delta); + if ($type == 'category') { + $value = db_result(db_query('SELECT block FROM {aggregator_category} WHERE cid = %d', $id)); + } + else { + $value = db_result(db_query('SELECT block FROM {aggregator_feed} WHERE fid = %d', $id)); + } + $form['block'] = array('#type' => 'select', '#title' => t('Number of news items in block'), '#default_value' => $value, '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20))); + return $form; + } + else if ($op == 'save') { + list($type, $id) = explode('-', $delta); + if ($type == 'category') { + $value = db_query('UPDATE {aggregator_category} SET block = %d WHERE cid = %d', $edit['block'], $id); + } + else { + $value = db_query('UPDATE {aggregator_feed} SET block = %d WHERE fid = %d', $edit['block'], $id); + } + } + else if ($op == 'view' && user_access('access news feeds')) { + list($type, $id) = explode('-', $delta); + switch ($type) { + case 'feed': + if ($feed = db_fetch_object(db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE fid = %d', $id))) { + $block['subject'] = check_plain($feed->title); + $result = db_query_range('SELECT * FROM {aggregator_item} WHERE fid = %d ORDER BY timestamp DESC, iid DESC', $feed->fid, 0, $feed->block); + $read_more = theme('more_link', url('aggregator/sources/'. $feed->fid), t("View this feed's recent news.")); + } + break; - // Only display the block if there are items to show. - if (count($items) > 0) { - $block['content'] = theme('item_list', $items) . $read_more; - } + case 'category': + if ($category = db_fetch_object(db_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = %d', $id))) { + $block['subject'] = check_plain($category->title); + $result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = %d ORDER BY i.timestamp DESC, i.iid DESC', $category->cid, 0, $category->block); + $read_more = theme('more_link', url('aggregator/categories/'. $category->cid), t("View this category's recent news.")); + } + break; } - if (isset($block)) { - return $block; + $items = array(); + while ($item = db_fetch_object($result)) { + $items[] = theme('aggregator_block_item', $item); + } + + // Only display the block if there are items to show. + if (count($items) > 0) { + $block['content'] = theme('item_list', $items) . $read_more; } } + if (isset($block)) { + return $block; + } } /** diff --git a/modules/block/block.module b/modules/block/block.module index 9eecda7..0d2a6ff 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -301,8 +301,12 @@ function _block_rehash($theme = NULL) { // Remove blocks that are no longer defined by the code from the database. foreach ($old_blocks as $module => $old_module_blocks) { - foreach ($old_module_blocks as $delta => $block) { - db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $module, $delta, $theme); + // This cleanup does not apply to disabled modules, to avoid configuration + // being lost when modules are disabled. + if (module_exists($module)) { + foreach ($old_module_blocks as $delta => $block) { + db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $module, $delta, $theme); + } } } return $blocks; @@ -312,12 +316,17 @@ function _block_rehash($theme = NULL) { * Implementation of hook_flush_caches(). */ function block_flush_caches() { - // Rehash blocks for active themes. We don't use list_themes() here, - // because if MAINTENANCE_MODE is defined it skips reading the database, - // and we can't tell which themes are active. - $result = db_query("SELECT name FROM {system} WHERE type = 'theme' AND status = 1"); - while ($theme = db_result($result)) { - _block_rehash($theme); + global $user; + // Avoid anonymous rehash which could cause problems with user_access() + // inside hook_block(). + if ($user->uid) { + // Rehash blocks for active themes. We don't use list_themes() here, + // because if MAINTENANCE_MODE is defined it skips reading the database, + // and we can't tell which themes are active. + $result = db_query("SELECT name FROM {system} WHERE type = 'theme' AND status = 1"); + while ($theme = db_result($result)) { + _block_rehash($theme); + } } } diff --git a/modules/poll/poll.module b/modules/poll/poll.module index a312eca..7bc5587 100644 --- a/modules/poll/poll.module +++ b/modules/poll/poll.module @@ -127,26 +127,24 @@ function _poll_menu_access($node, $perm, $inspect_allowvotes) { * Generates a block containing the latest poll. */ function poll_block($op = 'list', $delta = 0) { - if (user_access('access content')) { - if ($op == 'list') { - $blocks[0]['info'] = t('Most recent poll'); - return $blocks; - } - else if ($op == 'view') { - // Retrieve the latest poll. - $sql = db_rewrite_sql("SELECT MAX(n.created) FROM {node} n INNER JOIN {poll} p ON p.nid = n.nid WHERE n.status = 1 AND p.active = 1"); - $timestamp = db_result(db_query($sql)); - if ($timestamp) { - $poll = node_load(array('type' => 'poll', 'created' => $timestamp, 'status' => 1)); + if ($op == 'list') { + $blocks[0]['info'] = t('Most recent poll'); + return $blocks; + } + else if ($op == 'view' && user_access('access content')) { + // Retrieve the latest poll. + $sql = db_rewrite_sql("SELECT MAX(n.created) FROM {node} n INNER JOIN {poll} p ON p.nid = n.nid WHERE n.status = 1 AND p.active = 1"); + $timestamp = db_result(db_query($sql)); + if ($timestamp) { + $poll = node_load(array('type' => 'poll', 'created' => $timestamp, 'status' => 1)); - if ($poll->nid) { - $poll = poll_view($poll, TRUE, FALSE, TRUE); - } + if ($poll->nid) { + $poll = poll_view($poll, TRUE, FALSE, TRUE); } - $block['subject'] = t('Poll'); - $block['content'] = drupal_render($poll->content); - return $block; } + $block['subject'] = t('Poll'); + $block['content'] = drupal_render($poll->content); + return $block; } } -- 1.7.4.1