_block_rehash

Versions
4.6
_block_rehash($order_by = array('weight'))
4.7 – 6
_block_rehash()
7
_block_rehash($theme = NULL)

Update the 'blocks' DB table with the blocks currently exported by modules.

Parameters

$order_by php <a href="http://www.php.net/manual/en/function.array-multisort.php">array_multisort()</a> style sort ordering, eg. "weight", SORT_ASC, SORT_STRING.

Return value

Blocks currently exported by modules, sorted by $order_by.

Code

modules/block.module, line 133

<?php
function _block_rehash($order_by = array('weight')) {
  $result = db_query('SELECT * FROM {blocks} ');
  while ($old_block = db_fetch_object($result)) {
    $old_blocks[$old_block->module][$old_block->delta] = $old_block;
  }

  db_query('DELETE FROM {blocks} ');

  foreach (module_list() as $module) {
    $module_blocks = module_invoke($module, 'block', 'list');
    if ($module_blocks) {
      foreach ($module_blocks as $delta => $block) {
        $block['module'] = $module;
        $block['delta']  = $delta;
        if ($old_blocks[$module][$delta]) {
          $block['status'] = $old_blocks[$module][$delta]->status;
          $block['weight'] = $old_blocks[$module][$delta]->weight;
          $block['region'] = $old_blocks[$module][$delta]->region;
          $block['visibility'] = $old_blocks[$module][$delta]->visibility;
          $block['pages'] = $old_blocks[$module][$delta]->pages;
          $block['custom'] = $old_blocks[$module][$delta]->custom;
          $block['throttle'] = $old_blocks[$module][$delta]->throttle;
          $block['types'] = $old_blocks[$module][$delta]->types;
        }
        else {
          $block['status'] = $block['weight'] = $block['region'] = $block['custom'] = 0;
          $block['pages'] = $block['types'] = '';
        }

        // reinsert blocks into table
        db_query("INSERT INTO {blocks} (module, delta, status, weight, region, visibility, pages, custom, throttle, types) VALUES ('%s', '%s', %d, %d, %d, %d, '%s', %d, %d, '%s')",
          $block['module'], $block['delta'], $block['status'], $block['weight'], $block['region'], $block['visibility'], $block['pages'], $block['custom'], $block['throttle'], $block['types']);

        $blocks[] = $block;

        // build array to sort on
        $order[$order_by[0]][] = $block[$order_by[0]];
      }
    }
  }

  // sort
  array_multisort($order[$order_by[0]], $order_by[1] ? $order_by[1] : SORT_ASC, $order_by[2] ? $order_by[2] : SORT_REGULAR, $blocks);

  return $blocks;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.