Created
March 7, 2018 17:58
-
-
Save alexfinnarn/e41a467021a94517f5c22751e175aacc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Ignore slave database briefly. | |
variable_set('maximum_replication_lag', 300); | |
db_ignore_slave(); | |
// Remove all links from the links array already in the database and only | |
// add missing links to database. | |
$missing_links = _linkchecker_bean_links_missing($bean->bid, $links); | |
// Only add unique links to database that do not exist. | |
$i = 0; | |
foreach ($missing_links as $url) { | |
$urlhash = drupal_hash_base64($url); | |
$link = db_query('SELECT lid FROM {linkchecker_link} WHERE urlhash = :urlhash', | |
array(':urlhash' => $urlhash))->fetchObject(); | |
if (!$link) { | |
$link = new stdClass(); | |
$link->urlhash = $urlhash; | |
$link->url = $url; | |
$link->status = _linkchecker_link_check_status_filter($url); | |
drupal_write_record('linkchecker_link', $link); | |
} | |
$txn = db_transaction(); | |
try { | |
db_insert('linkchecker_bean') | |
->fields(array( | |
'bid' => $bean->bid, | |
'lid' => $link->lid, | |
)) | |
->execute(); | |
} | |
catch (Exception $e) { | |
$txn->rollback(); | |
watchdog_exception('linkchecker_bean', $e); | |
} | |
// Go back to using the slave database. | |
// db_ignore_slave() sets this session variable that another function uses to see if the slave should be ignored. | |
unset($_SESSION['ignore_slave_server']); | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment