function taxonomy_entity_index_reindex_entity_type in Taxonomy Entity Index 7
Same name and namespace in other branches
- 8 taxonomy_entity_index.module \taxonomy_entity_index_reindex_entity_type()
Batch callback; re-index all the terms for a given entity type.
2 string references to 'taxonomy_entity_index_reindex_entity_type'
- drush_taxonomy_entity_index_rebuild in ./
taxonomy_entity_index.drush.inc - Clear cache raw command callback.
- taxonomy_entity_index_admin_form_submit in ./
taxonomy_entity_index.admin.inc - Form submit handler for the batch reindexing form. Processes the batch.
File
- ./
taxonomy_entity_index.module, line 205
Code
function taxonomy_entity_index_reindex_entity_type($entity_type, &$context) {
if (empty($context['sandbox'])) {
$context['sandbox'] = array();
$context['sandbox']['progress'] = 0;
$context['sandbox']['current_id'] = 0;
$context['sandbox']['bundles'] = array_keys(taxonomy_entity_index_get_taxonomy_field_names($entity_type));
// Clear out any records for this type.
db_delete('taxonomy_entity_index')
->condition('entity_type', $entity_type)
->execute();
// Calculate the maximum number of entities.
if (!empty($context['sandbox']['bundles'])) {
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', $entity_type);
if ($entity_type != 'user') {
$query
->entityCondition('bundle', $context['sandbox']['bundles'], 'IN');
}
$query
->entityCondition('entity_id', 0, '>');
$query
->count();
$context['sandbox']['max'] = (int) $query
->execute();
}
if (empty($context['sandbox']['max'])) {
$context['finished'] = TRUE;
return;
}
}
$limit = 25;
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', $entity_type);
if ($entity_type != 'user') {
$query
->entityCondition('bundle', $context['sandbox']['bundles'], 'IN');
}
$query
->entityCondition('entity_id', $context['sandbox']['current_id'], '>');
$query
->entityOrderBy('entity_id', 'ASC');
$query
->range(0, $limit);
$results = $query
->execute();
$entities = entity_load($entity_type, array_keys($results[$entity_type]));
foreach ($entities as $id => $entity) {
taxonomy_entity_index_field_attach_update($entity_type, $entity);
$context['sandbox']['current_id'] = $id;
$context['message'] = t('Updating taxonomy entity index data for @type @id.', array(
'@type' => $entity_type,
'@id' => $id,
));
}
// In case any of the entities fail to load, increase the progress by the
// stub entity count.
$context['sandbox']['progress'] += count($results[$entity_type]);
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] >= $context['sandbox']['max'];
}
}