Index: modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.806 diff -u -r1.806 node.module --- modules/node/node.module 30 Apr 2007 17:03:26 -0000 1.806 +++ modules/node/node.module 30 Apr 2007 23:49:21 -0000 @@ -1078,8 +1078,7 @@ * Handler for wipe confirmation */ function node_configure_rebuild_confirm_submit($form_id, &$form) { - node_access_rebuild(); - drupal_set_message(t('The node access table has been rebuilt.')); + batch_set(node_access_rebuild_batch()); return 'admin/content/node-settings'; } @@ -2957,14 +2956,13 @@ db_query("DELETE FROM {node_access}"); // only recalculate if site is using a node_access module if (count(module_implements('node_grants'))) { - // 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)) { - node_access_acquire_grants(node_load($node->nid, NULL, TRUE)); - } + $batch = array( + 'title' => t('Rebuilding'), + 'operations' => array( + array('node_access_rebuild_batch_operation', array()), + ), + ); + batch_set($batch); } else { // not using any node_access modules. add the default grant. @@ -2972,6 +2970,63 @@ } cache_clear_all(); } + +function node_access_rebuild_batch() { + db_query("DELETE FROM {node_access}"); + // only recalculate if site is using a node_access module + if (count(module_implements('node_grants'))) { + $batch = array( + 'title' => t('Rebuilding'), + 'operations' => array( + array('node_access_rebuild_batch_operation', array()), + array('cache_clear_all', array(NULL, NULL, FALSE)), + ), + 'finished' => 'node_access_rebuild_batch_finished' + ); + return $batch; + } + else { + // not using any node_access modules. add the default grant. + db_query("INSERT INTO {node_access} VALUES (0, 0, 'all', 1, 0, 0)"); + cache_clear_all(); + } +} +/** + * Batch operation : Rebuild the access grants for all nodes 5 by 5. + */ +function node_access_rebuild_batch_operation(&$context) { + if (empty($context['sandbox'])) { + $context['sandbox']['progress'] = 0; + $context['sandbox']['current_node'] = 0; + $context['sandbox']['max'] = db_result(db_query('SELECT COUNT(DISTINCT nid) FROM {node}')); + } + $limit = 5; + $result = db_query_range("SELECT nid FROM {node} WHERE nid > %d ORDER BY nid ASC", $context['sandbox']['current_node'], 0, $limit); + while ($row = db_fetch_array($result)) { + $node = node_load($row['nid']); + node_access_acquire_grants($node); + $context['results'][] = $node->nid; + $context['sandbox']['progress']++; + $context['sandbox']['current_node'] = $node->nid; + $context['message'] = $node->title; + } + if ($context['sandbox']['progress'] != $context['sandbox']['max']) { + $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; + } + else { + cache_clear_all(); + } +} + +function node_access_rebuild_batch_finished($success, $results, $operations) { + if ($success) { + drupal_set_message(t('The content access table has been rebuilt.')); + } + else { + drupal_set_message(t('The content access table could not be rebuilt.'), 'error'); + } +} + /** * @} End of "defgroup node_access". */