You are here

function _linkchecker_cleanup_links in Link checker 5.2

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

Run perodically via cron and delete all links without a references.

For speed reasons and check results we keep the links for some time as they may be reused by other new content.

1 call to _linkchecker_cleanup_links()
linkchecker_cron in ./linkchecker.module
Implementation of hook_cron().

File

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

Code

function _linkchecker_cleanup_links() {

  // Remove disabled node types no longer in use.
  $node_types = array_keys(array_filter(variable_get('linkchecker_scan_nodetypes', array())));
  $placeholders = implode(',', array_fill(0, count($node_types), "'%s'"));
  if (!empty($node_types)) {
    db_query('DELETE FROM {linkchecker_nodes} WHERE nid IN (SELECT nid FROM {node} n WHERE n.type NOT IN (' . $placeholders . '))', $node_types);

    // FIXME: Remove comment references of unpublished nodes.

    //db_query('DELETE FROM {linkchecker_comments} WHERE cid IN (SELECT nid FROM {node} n WHERE n.type NOT IN (' . $placeholders . '))', $node_types);
  }
  else {
    db_query('DELETE FROM {linkchecker_nodes}');

    // FIXME: Remove comment references of unpublished nodes.
  }

  // Remove comment links if comment scanning is disabled.
  // TODO: Remove comment references of unpublished nodes.
  if (variable_get('linkchecker_scan_comments', 0) == 0) {
    db_query('DELETE FROM {linkchecker_comments}');
  }

  // Remove block links if block scanning is disabled.
  if (variable_get('linkchecker_scan_blocks', 0) == 0) {
    db_query('DELETE FROM {linkchecker_boxes}');
  }

  // TODO: Requires MySQL 5.x for subselects. Untested with pgsql.
  db_query('DELETE FROM {linkchecker_links}
            WHERE lid NOT IN (
              SELECT DISTINCT lid FROM {linkchecker_boxes}
              UNION
              SELECT DISTINCT lid FROM {linkchecker_comments}
              UNION
              SELECT DISTINCT lid FROM {linkchecker_nodes}
            )');
}