You are here

function subscriptions_taxonomy_update_2 in Subscriptions 6

Same name and namespace in other branches
  1. 5.2 subscriptions_taxonomy.install \subscriptions_taxonomy_update_2()

Database update function 2 (replaces update function 1!).

Remove taxonomy subscriptions left over from deleted terms.

File

./subscriptions_taxonomy.install, line 19
Subscriptions Taxonomy module installation.

Code

function subscriptions_taxonomy_update_2() {
  $result = db_query("SELECT s.value AS tid FROM {subscriptions_queue} s LEFT JOIN {term_data} t ON s.value = " . ($GLOBALS['db_type'] == 'pgsql' ? 'CAST(' : '') . "t.tid" . ($GLOBALS['db_type'] == 'pgsql' ? ' AS VARCHAR)' : '') . " WHERE s.module = 'node' AND s.field = 'tid' AND t.tid IS NULL");
  while ($orphan = db_fetch_array($result)) {
    $orphans[] = $orphan['tid'];
  }
  if (isset($orphans)) {
    db_query("DELETE FROM {subscriptions_queue} WHERE module = 'node' AND field = 'tid' AND value IN (" . db_placeholders($orphans, 'varchar') . ")", $orphans);
    $orphans = NULL;
  }
  $result = db_query("SELECT s.value AS tid FROM {subscriptions} s LEFT JOIN {term_data} t ON s.value = " . ($GLOBALS['db_type'] == 'pgsql' ? 'CAST(' : '') . "t.tid" . ($GLOBALS['db_type'] == 'pgsql' ? ' AS VARCHAR)' : '') . " WHERE s.module = 'node' AND s.field = 'tid' AND t.tid IS NULL");
  while ($orphan = db_fetch_array($result)) {
    $orphans[] = $orphan['tid'];
  }
  if (isset($orphans)) {
    db_query("DELETE FROM {subscriptions} WHERE module = 'node' AND field = 'tid' AND value IN (" . db_placeholders($orphans, 'varchar') . ")", $orphans);
  }
  return array();
}