Drupal API

node_access_rebuild

  • Drupal 5
  • Drupal 6
Говорят, каждое переведенное предложение документации продлевает жизнь разработчика на 17 минут. Скорее всего это выдумки, но мы бы были все-равно рады твоей помощи с переводами!

modules/node/node.module, строка 2305

Версии
5
node_access_rebuild()
6
node_access_rebuild($batch_mode = FALSE)

Rebuild the node access database. This is occasionally needed by modules that make system-wide changes to access levels.

When the rebuild is required by an admin-triggered action (e.g module settings form), calling node_access_needs_rebuild(TRUE) instead of node_access_rebuild() lets the user perform his changes and actually rebuild only once he is done.

Note : As of Drupal 6, node access modules are not required to (and actually should not) call node_access_rebuild() in hook_enable/disable anymore.

See also

node_access_needs_rebuild()

Параметры

$batch_mode Set to TRUE to process in 'batch' mode, spawning processing over several HTTP requests (thus avoiding the risk of PHP timeout if the site has a large number of nodes). hook_update_N and any form submit handler are safe contexts to use the 'batch mode'. Less decidable cases (such as calls from hook_user, hook_taxonomy, hook_node_type...) might consider using the non-batch mode.

Связанные темы

▸ 2 функции вызывают node_access_rebuild()

▾ 2 функции вызывают node_access_rebuild()

module_disable in includes/module.inc
Отключает заданный набор модулей.
node_configure_rebuild_confirm_submit in modules/node/node.admin.inc
Handler for wipe confirmation

Код

<?php
function node_access_rebuild($batch_mode = FALSE) {
  db_query("DELETE FROM {node_access}");
  // Only recalculate if the site is using a node_access module.
  if (count(module_implements('node_grants'))) {
    if ($batch_mode) {
      $batch = array(
        'title' => t('Rebuilding content access permissions'),
        'operations' => array(
          array('_node_access_rebuild_batch_operation', array()),
        ),
        'finished' => '_node_access_rebuild_batch_finished'
      );
      batch_set($batch);
    }
    else {
      // If not in 'safe mode', increase the maximum execution time.
      if (!ini_get('safe_mode')) {
        set_time_limit(240);
      }
      $result = db_query("SELECT nid FROM {node}");
      while ($node = db_fetch_object($result)) {
        $loaded_node = node_load($node->nid, NULL, TRUE);
        // To preserve database integrity, only aquire grants if the node
        // loads successfully.
        if (!empty($loaded_node)) {
          node_access_acquire_grants($loaded_node);
        }
      }
    }
  }
  else {
    // Not using any node_access modules. Add the default grant.
    db_query("INSERT INTO {node_access} VALUES (0, 0, 'all', 1, 0, 0)");
  }
  if (!isset($batch)) {
    drupal_set_message(t('Content permissions have been rebuilt.'));
    node_access_needs_rebuild(FALSE);
    cache_clear_all();
  }
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему

Что такое OpenID?
  • Регистрация
  • Забыли пароль?

Документация

  • Drupal 6
  • Константы
  • Файлы
  • Функции
  • Глобальные переменные
  • Разделы