function _linkchecker_add_node_links in Link checker 6.2
Same name and namespace in other branches
- 5.2 linkchecker.module \_linkchecker_add_node_links()
- 7 linkchecker.module \_linkchecker_add_node_links()
Add node links to database.
Parameters
$node: The fully populated node object.
$skip_missing_links_detection: To prevent endless batch loops the value need to be TRUE. With FALSE the need for content re-scans is detected by the number of missing links.
3 calls to _linkchecker_add_node_links()
- linkchecker_nodeapi in ./
linkchecker.module - _linkchecker_batch_node_import_op in includes/
linkchecker.batch.inc - Batch operation: Scan ony by one node for links.
- _linkchecker_batch_single_node_import_op in includes/
linkchecker.batch.inc
File
- ./
linkchecker.module, line 991 - This module periodically check links in given node types, blocks, cck fields, etc.
Code
function _linkchecker_add_node_links($node, $skip_missing_links_detection = FALSE) {
$links = array_keys(_linkchecker_extract_node_links($node));
// Node have links.
if (!empty($links)) {
// Remove all links from the links array already in the database
// and only add missing links to database.
$missing_links = _linkchecker_node_links_missing($node->nid, $links);
// Only add links to database that do not exists.
$i = 0;
foreach ($missing_links as $url) {
$urlhash = md5($url);
$link = db_fetch_object(db_query("SELECT lid FROM {linkchecker_links} WHERE urlhash = '%s'", $urlhash));
if (!$link) {
$link = new stdClass();
$link->urlhash = $urlhash;
$link->url = $url;
$link->status = _linkchecker_link_check_status_filter($url);
drupal_write_record('linkchecker_links', $link);
}
db_query("INSERT INTO {linkchecker_nodes} (nid, lid) VALUES (%d, %d)", $node->nid, $link->lid);
// Break processing if max links limit per run has been reached.
$i++;
if ($i >= LINKCHECKER_SCAN_MAX_LINKS_PER_RUN) {
break;
}
}
// The first chunk of links not yet found in the {linkchecker_links} table
// have now been imported by the above code. If the number of missing links
// still exceeds the scan limit defined in LINKCHECKER_SCAN_MAX_LINKS_PER_RUN
// the content need to be re-scanned until all links have been collected and
// saved in {linkchecker_links} table.
//
// Above code has already scanned a number of LINKCHECKER_SCAN_MAX_LINKS_PER_RUN
// links and need to be substracted from the number of missing links to
// calculate the correct number of re-scan rounds.
//
// To prevent endless loops the $skip_missing_links_detection need to be TRUE.
// This value will be set by the calling batch process that already knows
// that it is running a batch job and the number of required re-scan rounds.
$missing_links_count = count($missing_links) - LINKCHECKER_SCAN_MAX_LINKS_PER_RUN;
if (!$skip_missing_links_detection && $missing_links_count > 0) {
module_load_include('inc', 'linkchecker', '/includes/linkchecker.batch');
batch_set(_linkchecker_batch_import_single_node($node->nid, $missing_links_count));
// If batches were set in the submit handlers, we process them now,
// possibly ending execution. We make sure we do not react to the batch
// that is already being processed (if a batch operation performs a
// drupal_execute).
if (($batch =& batch_get()) && !isset($batch['current_set'])) {
batch_process('node/' . $node->nid);
}
}
}
// Remove dead link references for cleanup reasons as very last step.
_linkchecker_cleanup_node_references($node->nid, $links);
}