function _nat_sync_associations in Node Auto Term [NAT] 7.2
Same name and namespace in other branches
- 5 nat.module \_nat_sync_associations()
- 6.2 nat.admin.inc \_nat_sync_associations()
- 6 nat.admin.inc \_nat_sync_associations()
- 7 nat.admin.inc \_nat_sync_associations()
Synchronize NAT node-term relationships. Create associated terms for node where missing.
Parameters
$associations: Associative array denoting the node-vocabulary pair that is to be synced.
1 call to _nat_sync_associations()
- nat_sync_form_submit in ./
nat.admin.inc - Process NAT sync form submissions.
File
- ./
nat.admin.inc, line 326 - NAT module administrative forms.
Code
function _nat_sync_associations($associations) {
$counter = 0;
foreach ($associations as $association) {
$association = explode('|', $association);
$vocabulary = taxonomy_vocabulary_machine_name_load($association[1]);
// This query can possibly be improved.
$result = db_query("SELECT n.nid FROM {node} n LEFT JOIN {nat} n1 ON (n.nid = n1.nid AND n1.vid = :vid) LEFT JOIN {nat} n2 ON (n.nid = n2.nid AND n2.nid <> n1.nid) WHERE n.type = :type AND n1.nid IS NULL", array(
':vid' => $vocabulary->vid,
':type' => $association[0],
));
foreach ($result as $node) {
// We need to execute a node_load in order to load field information.
$node = node_load($node->nid);
// Add node title as terms.
$terms = _nat_add_terms($node, array(
$vocabulary->vid,
));
// Save node-term association in the NAT table.
_nat_save_association($node->nid, $terms);
$counter++;
}
}
drupal_set_message(t('NAT sync complete: %count nodes synced.', array(
'%count' => $counter,
)));
}