You are here

function _linkchecker_cleanup_links in Link checker 6.2

Same name and namespace in other branches
  1. 5.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 1325
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())));
  if (!empty($node_types)) {
    db_query('DELETE FROM {linkchecker_nodes} WHERE nid IN (SELECT nid FROM {node} n WHERE n.type NOT IN (' . db_placeholders($node_types, 'varchar') . '))', $node_types);

    // FIXME: Remove comments

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

    // FIXME: Remove comments
  }

  // Remove comment link references if comment scanning is disabled.
  // TODO: Remove comments of unpublished nodes.
  if (variable_get('linkchecker_scan_comments', 0) == 0) {
    db_query('TRUNCATE TABLE {linkchecker_comments}');
  }

  // Remove block link references if block scanning is disabled.
  if (variable_get('linkchecker_scan_blocks', 0) == 0) {
    db_query('TRUNCATE TABLE {linkchecker_boxes}');
  }

  // Remove dead links without references.
  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}
            )');
}