function views_natural_sort_rebuild_index in Views Natural Sort 6
Same name and namespace in other branches
- 8.2 views_natural_sort.module \views_natural_sort_rebuild_index()
- 7.2 views_natural_sort.admin.inc \views_natural_sort_rebuild_index()
- 7 views_natural_sort.admin.inc \views_natural_sort_rebuild_index()
Batch API callback for rebuild_index.
1 string reference to 'views_natural_sort_rebuild_index'
- views_natural_sort_rebuild_index_submit in ./
views_natural_sort.admin.inc - Submit handler that triggers the rebuild_index batch.
File
- ./
views_natural_sort.admin.inc, line 97 - Callbacks for managing Views Natural Sort.
Code
function views_natural_sort_rebuild_index(&$context) {
// Alias sandbox for easier referencing.
$sandbox =& $context['sandbox'];
// Initialize our context.
if (!isset($sandbox['max'])) {
$sandbox['progress'] = 0;
$sandbox['max'] = db_result(db_query('SELECT MAX(nid) FROM {node}'));
$sandbox['total'] = db_result(db_query('SELECT COUNT(nid) FROM {node} WHERE nid <= %d', $sandbox['max']));
$sandbox['current'] = 0;
$context['results']['nodes'] = 0;
}
if ($sandbox['total'] == 0) {
$context['finished'] = 1;
return;
}
$results = db_query_range('SELECT nid, title FROM {node} WHERE nid > %d AND nid <= %d', $sandbox['current'], $sandbox['max'], 0, 10);
$title = '';
while ($row = db_fetch_object($results)) {
_views_natural_sort_store_node($row);
++$sandbox['progress'];
$sandbox['current'] = $row->nid;
$title = $row->title;
++$context['results']['nodes'];
}
$context['message'] = t('Processing node %title', array(
'%title' => $title,
));
$context['finished'] = $sandbox['progress'] / $sandbox['total'];
}