function nodequeue_generate_rehash in Nodequeue 7.3
Same name and namespace in other branches
- 5.2 nodequeue_generate.module \nodequeue_generate_rehash()
- 6.2 nodequeue_generate.module \nodequeue_generate_rehash()
- 7.2 nodequeue_generate.module \nodequeue_generate_rehash()
Rebuild all smartqueue_taxonomy queues. Useful after a data migration has wiped your terms. When more smartqueue modules arrive, revisit this function.
Parameters
vids: An array of vocabulary ids.
4 calls to nodequeue_generate_rehash()
- drush_nodequeue_generate in ./
nodequeue_generate.drush.inc - Re-populates specified nodequeues with random nodes.
- drush_nodequeue_generate_all in ./
nodequeue_generate.drush.inc - Re-populates all nodequeues with random nodes.
- drush_nodequeue_generate_rehash in ./
nodequeue_generate.drush.inc - Rehashes smartqueue subqueues for taxonomy smartqueue.
- nodequeue_generate_form_submit in ./
nodequeue_generate.module
File
- ./
nodequeue_generate.module, line 126
Code
function nodequeue_generate_rehash() {
// Delete existing smartqueue taxonomy subqueues
db_query("DELETE ns FROM {nodequeue_subqueue} ns INNER JOIN {nodequeue_queue} nq ON ns.name = nq.name WHERE nq.owner = 'smartqueue_taxonomy'");
// Get all queues, owned by Smartqueue taxonomy.
$queues = db_select('nodequeue_queue', 'nq')
->fields('nq', array(
'name',
))
->condition('owner', 'smartqueue_taxonomy')
->execute()
->fetchAll();
foreach ($queues as $name) {
$queue = nodequeue_load($name->name);
$fields = explode('-', $queue->reference);
$tids = array();
$nids = array();
foreach ($fields as $field) {
// Get all possible tids from this field.
$query = db_select('field_data_' . $field, 'f');
$query
->condition('f.entity_type', 'node')
->condition('f.bundle', $queue->types, 'IN')
->condition('f.deleted', FALSE)
->addField('f', $field . '_tid', 'tid');
$query = $query
->distinct();
$query = $query
->execute();
$tids += $query
->fetchAll();
// Rehash for each tid.
foreach ($tids as $tid) {
$query = db_select('field_data_' . $field, 'f');
$query
->condition('f.entity_type', 'node')
->condition('f.bundle', $queue->types, 'IN')
->condition('f.deleted', FALSE)
->condition('f.' . $field . '_tid', $tid->tid)
->fields('f', array(
'entity_id',
))
->range(0, 1);
$query = $query
->execute();
while ($item = $query
->fetchAssoc()) {
$nids[] = $item;
}
}
foreach ($nids as $nid) {
$node = node_load($nid['entity_id']);
nodequeue_api_subqueues($queue, $node);
}
}
}
}