function taxonomy_term_depth_batch_callbacks_update_term_depth in Taxonomy Term Depth 7
Same name and namespace in other branches
- 8.2 taxonomy_term_depth.batch.inc \taxonomy_term_depth_batch_callbacks_update_term_depth()
- 8 taxonomy_term_depth.batch.inc \taxonomy_term_depth_batch_callbacks_update_term_depth()
2 string references to 'taxonomy_term_depth_batch_callbacks_update_term_depth'
File
- ./
taxonomy_term_depth.batch.inc, line 44
Code
function taxonomy_term_depth_batch_callbacks_update_term_depth($options, &$context) {
$sandbox =& $context['sandbox'];
// Build query
$query = db_select('taxonomy_term_data', 'ttd');
$query
->fields('ttd', array(
'tid',
));
$query
->groupBy('ttd.tid');
// Count ALL elements and save the value for further usage
if (!isset($sandbox['count'])) {
// Clear all depths first
db_update('taxonomy_term_data')
->fields(array(
'depth' => NULL,
))
->execute();
$sandbox['count'] = $query
->countQuery()
->execute()
->fetchField();
}
$sandbox += array(
'position' => 0,
'bunch' => 20,
);
//$sandbox['position'] += $sandbox['bunch'];
$query
->range($sandbox['position'], $sandbox['bunch']);
foreach ($query
->execute() as $row) {
// Forcely rebuild data in database
taxonomy_term_depth_get_by_tid($row->tid, TRUE);
$sandbox['position']++;
}
$context['finished'] = $sandbox['count'] ? $sandbox['position'] / $sandbox['count'] : 1;
$context['finished'] = $context['finished'] > 1 ? 1 : $context['finished'];
}