You are here

function _nat_sync_associations in Node Auto Term [NAT] 6

Same name and namespace in other branches
  1. 5 nat.module \_nat_sync_associations()
  2. 6.2 nat.admin.inc \_nat_sync_associations()
  3. 7.2 nat.admin.inc \_nat_sync_associations()
  4. 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 144
NAT module administrative forms.

Code

function _nat_sync_associations($associations) {
  $nat_config = _nat_variable_get();
  $counter = 0;
  foreach ($associations as $association) {
    $association = explode('|', $association);

    // This query can possibly be improved.
    $result = db_query("SELECT n.nid, n.type, n.title, nr.body FROM {node} n INNER JOIN {node_revisions} nr USING (vid) LEFT JOIN {nat} n1 ON (n.nid = n1.nid AND n1.vid = %d) LEFT JOIN {nat} n2 ON (n.nid = n2.nid AND n2.nid <> n1.nid) WHERE n.type = '%s' AND n1.nid IS NULL", $association[1], $association[0]);
    while ($node = db_fetch_object($result)) {

      // Add node title as terms.
      $terms = _nat_add_terms($node, array(
        $association[1],
      ));

      // 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,
  )));
}