// Generate a log message for the node_revisions table, visible on the node's revisions tab.
// Generate a log message for the node_revisions table, visible on the node's revisions tab.
$node->log=t('Changed permanently moved link in %node from %src to %dst.',array('%node'=>url('node/'.$row->nid),'%src'=>$link->url,'%dst'=>$response->redirect_url));
$node->log=t('Changed permanently moved link in %node from %src to %dst.',array('%node'=>url('node/'.$row->nid),'%src'=>$link->url,'%dst'=>$response->redirect_url));
// Save changed node and update the node link list.
// Save changed node and update the node link list.
node_save($node);
node_save($node);
watchdog('linkchecker','Changed permanently moved link in %node from %src to %dst.',array('%node'=>url('node/'.$row->nid),'%src'=>$link->url,'%dst'=>$response->redirect_url),WATCHDOG_INFO);
watchdog('linkchecker','Changed permanently moved link in %node from %src to %dst.',array('%node'=>url('node/'.$row->nid),'%src'=>$link->url,'%dst'=>$response->redirect_url),WATCHDOG_INFO);
}
else{
watchdog('linkchecker','Link update in node failed. Permanently moved link %src not found in node %node. Manual fix required.',array('%node'=>url('node/'.$row->nid),'%src'=>$link->url),WATCHDOG_WARNING);
}
}
}
else{
else{
watchdog('linkchecker','Link update in node failed. Permanently moved link %src not found in node %node. Manual fix required.',array('%node'=>url('node/'.$row->nid),'%src'=>$link->url),WATCHDOG_WARNING);
watchdog('linkchecker','Loading node %node for update failed. Manual fix required.',array('%node'=>$row->nid),WATCHDOG_ERROR);
}
}
}
}
// COMMENTS: Autorepair all comments having this outdated link.
// COMMENTS: Autorepair all comments having this outdated link.
if(module_exists('comment')){
$res=db_query("SELECT * FROM {linkchecker_comments} WHERE lid = %d",$link->lid);
$res=db_query("SELECT * FROM {linkchecker_comments} WHERE lid = %d",$link->lid);
while($row=db_fetch_object($res)){
while($row=db_fetch_object($res)){
$comment=_linkchecker_comment_load($row->cid);
$comment=_linkchecker_comment_load($row->cid);
$comment_original=drupal_clone($comment);
// Has the custom comment array loaded successfully?
if(!empty($comment)){
$comment_original=$comment;
// Create array of comment fields to scan (for e.g. $comment->subject, $comment->comment).
// Create array of comment fields to scan (for e.g. $comment->subject, $comment->comment).
$text_items=array();
$text_items=array();
...
@@ -621,7 +630,8 @@ function _linkchecker_status_handling(&$response, $link) {
...
@@ -621,7 +630,8 @@ function _linkchecker_status_handling(&$response, $link) {
}
}
// Save changed comment and update the comment link list.
// Save changed comment and update the comment link list.
watchdog('linkchecker','Changed permanently moved link in comment %comment from %src to %dst.',array('%comment'=>$comment['cid'],'%src'=>$link->url,'%dst'=>$response->redirect_url),WATCHDOG_INFO);
watchdog('linkchecker','Changed permanently moved link in comment %comment from %src to %dst.',array('%comment'=>$comment['cid'],'%src'=>$link->url,'%dst'=>$response->redirect_url),WATCHDOG_INFO);
}
}
...
@@ -629,35 +639,46 @@ function _linkchecker_status_handling(&$response, $link) {
...
@@ -629,35 +639,46 @@ function _linkchecker_status_handling(&$response, $link) {
watchdog('linkchecker','Link update in comment failed. Permanently moved link %src not found in comment %comment. Manual fix required.',array('%comment'=>$comment['cid'],'%src'=>$link->url),WATCHDOG_WARNING);
watchdog('linkchecker','Link update in comment failed. Permanently moved link %src not found in comment %comment. Manual fix required.',array('%comment'=>$comment['cid'],'%src'=>$link->url),WATCHDOG_WARNING);
}
}
}
}
else{
watchdog('linkchecker','Loading comment %comment for update failed. Manual fix required.',array('%comment'=>$comment['cid']),WATCHDOG_ERROR);
}
}
}
// BOXES: Autorepair all boxes having this outdated link.
// BOXES: Autorepair all boxes having this outdated link.
$res=db_query("SELECT * FROM {linkchecker_boxes} WHERE lid = %d",$link->lid);
$res=db_query("SELECT * FROM {linkchecker_boxes} WHERE lid = %d",$link->lid);
while($row=db_fetch_object($res)){
while($row=db_fetch_object($res)){
$box=block_box_get($row->bid);
$box=block_box_get($row->bid);
$box_original=drupal_clone($box);
// Create array of box fields to scan.
// Has the custom block array loaded successfully?
$text_items=array();
if(!empty($box)){
$text_items[]='info';
$box_original=$box;
$text_items[]='body';
// Now replace the outdated link with the permanently moved one in all
watchdog('linkchecker','Changed permanently moved link in box %bid from %src to %dst.',array('%bid'=>$row->bid,'%src'=>$link->url,'%dst'=>$response->redirect_url),WATCHDOG_INFO);
$box_diff=array_diff($box,$box_original);
if(!empty($box_diff)){
// Save changed box and update the box link list.
block_box_save($box,$row->bid);
// There is no hook that fires on block_box_save(), therefore do link
// extraction programmatically.
_linkchecker_add_box_links($box,$row->bid);
watchdog('linkchecker','Changed permanently moved link in box %bid from %src to %dst.',array('%bid'=>$row->bid,'%src'=>$link->url,'%dst'=>$response->redirect_url),WATCHDOG_INFO);
}
else{
watchdog('linkchecker','Link update in block failed. Permanently moved link %src not found in block %bid. Manual fix required.',array('%bid'=>$row->bid,'%src'=>$link->url),WATCHDOG_WARNING);
}
}
}
else{
else{
watchdog('linkchecker','Link update in block failed. Permanently moved link %src not found in block %bid. Manual fix required.',array('%bid'=>$row->bid,'%src'=>$link->url),WATCHDOG_WARNING);
watchdog('linkchecker','Loading block %bid for update failed. Manual fix required.',array('%bid'=>$row->bid),WATCHDOG_ERROR);