You are here

function _linkchecker_cleanup_node_references in Link checker 7

Same name and namespace in other branches
  1. 5.2 linkchecker.module \_linkchecker_cleanup_node_references()
  2. 6.2 linkchecker.module \_linkchecker_cleanup_node_references()

Cleanup no longer used node references to links in the linkchecker_node table.

Parameters

int $nid: The node ID.

array $links:

1 call to _linkchecker_cleanup_node_references()
_linkchecker_add_node_links in ./linkchecker.module
Add node links to database.

File

./linkchecker.module, line 1559
This module periodically check links in given node types, blocks etc.

Code

function _linkchecker_cleanup_node_references($nid = 0, $links = array()) {
  if (empty($links)) {

    // Node do not have links. Delete all references if exists.
    db_delete('linkchecker_node')
      ->condition('nid', $nid)
      ->execute();
  }
  else {

    // The node still have more than one link, but other links may have been
    // removed and links no longer in the content need to be deleted from the
    // linkchecker_node reference table.
    $subquery = db_select('linkchecker_link')
      ->fields('linkchecker_link', array(
      'lid',
    ))
      ->condition('urlhash', array_map('drupal_hash_base64', $links), 'IN');
    db_delete('linkchecker_node')
      ->condition('nid', $nid)
      ->condition('lid', $subquery, 'NOT IN')
      ->execute();
  }
}