Administer › Site configuration › Link checker

Pressing 'Analyze content for links' button brings me to this page:

Scanning for links

An error has occurred.
Please continue to the error page

An error occurred. /batch?id=71&op=do <br /> <b>Fatal error</b>: Cannot redeclare file_read_csv() (previously declared in /usr/share/drupal-6.12/includes/common.inc(1645) : eval()'d code:20) in <b>/usr/share/drupal-6.12/includes/common.inc(1645) : eval()'d code</b> on line <b>27</b><br /> 

Also, the 'Please continue to the error page' link points back to the "Administer › Site configuration › Link checker" page.

Comments

silurius’s picture

Same result using the 'Clear link data and analyze content for links' button.

hass’s picture

Category: bug » support
Status: Active » Fixed
Issue tags: +PHP evaluator

I believe you have one or more bad nodes with PHP code. See #538004: PHP based content crashes cron or #586708: Linkchecker may hang cron when "drupal_goto()" is encountered in a node.

Remove the duplicate declaration of file_read_csv() in your PHP nodes.

silurius’s picture

Huh, thanks. Since I'm positive I didn't add the bad PHP myself, I'll have to comb through everything to find the problem. Any chance the offending node gets logged somewhere?

Also, the 'Please continue to the error page' link points back to the "Administer › Site configuration › Link checker" page. Is this supposed to direct me to an actual error page or was I just confused by the link text?

hass’s picture

Hmmm... if someone have an idea how... I also wished to have this when it happened... The main problem is - this is a PHP error and I have no idea how to catch this and only log if a php error occurred. Cron is in a WSOD situation... :-(

If there is a patch I can add it...

silurius’s picture

Sorry, hass, that kind of patch is probably beyond my present abilities. I would if I could!

Also, I was hoping a database search for the string "file_read" might help, but nothing whatsoever turned up.

hass’s picture

Who have written your nodes or who have more permissions than you? :-)

Try this to find your active nodes having PHP code:

SELECT n.nid, nr.body, nr.teaser FROM node n
INNER JOIN node_revisions nr ON nr.vid = n.vid
INNER JOIN filters f ON f.format = nr.format
WHERE f.module = 'php' AND (nr.body LIKE '%<?php%' OR nr.teaser LIKE '%<?php%')
ORDER BY nr.nid
hass’s picture

Oh, this is much more easier... and only gives your the erroring nodes:

SELECT n.nid, nr.body, nr.teaser FROM node n
INNER JOIN node_revisions nr ON nr.vid = n.vid
INNER JOIN filters f ON f.format = nr.format
WHERE f.module = 'php' AND (nr.body LIKE '%file_read_csv(%' OR nr.teaser LIKE '%file_read_csv(%')
ORDER BY nr.nid
silurius’s picture

Found it! Thanks for the SQL help.

Here's the PHP code (modified a bit to be more 'exampleish') from the node in question:

<?

	$arrClassifcations['loremipsum1'] = 'Lorem ipsum 1';
	$arrClassifcations['loremipsum2'] = 'Lorem ipsum 2';
	$arrClassifcations['loremipsum3'] = 'Lorem ipsum 3';
	$arrClassifcations['loremipsum4'] = 'Lorem ipsum 4';

	$rows = 25;
	$cols = 19;

	$arrTerms[2009]['summer'] = "Summer 2009";
	$year = ( isset($arrTerms[$_REQUEST['year']]) ) ? $_REQUEST['year'] : 2009;
	$term = ( isset($arrTerms[$year][$_REQUEST['timeperiod']]) ) ? $_REQUEST['timeperiod'] : 'summer';

	$is_valid = ( isset($_REQUEST['type']) );
	$is_valid = ( $is_valid && array_key_exists($_REQUEST['type'], $arrClassifcations) );
	$is_valid = ( $is_valid && $_REQUEST['lorem'] >= 0 && $_REQUEST['lorem'] < $cols );
	$is_valid = ( $is_valid && $_REQUEST['ipsum'] >= 0 && $_REQUEST['ipsum'] < $rows );

	function file_read_csv($file, $delim=',') {
		if ( ($arrFile = file($file)) === false ) return false;
		$arr = array();
		foreach ($arrFile as $line) {
			$arr[] = explode($delim, $line);
		}
		return $arr;
	}

	if ($is_valid) {
		$arrData = file_read_csv("/examplepath/{$term}_{$_REQUEST['type']}.csv");
		$rate = '$'.number_format($arrData[$_REQUEST['ipsum']][$_REQUEST['lorem']]);
	} else {
		$rate = '?';
	}

?>

This was old even when I first inherited it and I'm not surprised to hear that it may have issues. However, as you can see the file_read_csv function is used only once, and then it is referenced a few lines down in an if statement. Is that what you meant by "duplicate function"?

hass’s picture

Have you executed the SQL statement in #7? It gives you the node(s) you are searching for.

silurius’s picture

Yes, sorry hass, you must have posted #9 as I was nuking and revising #8. :)

hass’s picture

The problem is the function may exist in core or in a second or more nodes... this is why you have the error. You could simply move this function into your themes template.php and you are done. I would suggest - never define functions in nodes - if there is a chance that this function name may be used somewhere else, too. Or rename function to _node_[nid]_file_read_csv() to make them unique per node.

function file_read_csv($file, $delim=',') {
if ( ($arrFile = file($file)) === false ) return false;
$arr = array();
foreach ($arrFile as $line) {
$arr[] = explode($delim, $line);
}
return $arr;
}
silurius’s picture

Oh, now I understand the duplication reference. This code was scheduled to be integrated into template.php but it hadn't been done yet. You are totally correct about that being best practice.

Guess you can close out the issue now. Thanks for the help.

silurius’s picture

Hass,

Thanks again for your help earlier. It appears that even after temporarily removing the offending node, the fatal error is still triggered by those buttons.

Even worse, I could not even save node changes today, all of a sudden. No error was produced by that, but the scanner popped up automatically, did its thing, and then took me back to the node/edit page each time.

To remedy, first I tried unpublishing the node containing the file_read_csv code, but the problem remained - couldn't edit and the analyze buttons still failed in the same way.

An error has occurred.
Please continue to the error page

An error occurred. /batch?id=83&op=do <br /> <b>Fatal error</b>: Cannot redeclare get_file_array() (previously declared in /DRUPALPATH/includes/common.inc(1645) : eval()'d code:18) in <b>/DRUPALPATH/includes/common.inc(1645) : eval()'d code</b> on line <b>27</b><br /> 

Next I removed all contents from the node and cleared the site cache. No change to the problem.

Next I disabled Link checker, and was now able to save the edited node I wasn't able to save earlier. But when I re-enable Link checker, these issues remain.

hass’s picture

The function name is now a different one get_file_array()...

silurius’s picture

Ah, gotcha. Should have noticed that.

Strange that this is only starting to happen this week, when these nodes have existed for six months and Link Checker has been running for two months. I suppose it must not have progressed far enough in its scans until now.

Thanks again.

silurius’s picture

Hass,

I realize this extends somewhat outside the scope of this module, so apologies in advance if this is starting to get annoying.

Template.php is tied up at the moment due to various project-related factors and complications, and it's simpler to rename the two functions for the time being. I renamed the functions to node_45_file_read_csv and node_93_get_file_array respectively. The nodes are working fine individually, but the following appears when I run the scanner from the Broken Links admin page:

An error has occurred.
Please continue to the error page

An error occurred. /batch?id=88&op=do <br /> <b>Fatal error</b>: Cannot redeclare node_93_get_file_array() (previously declared in /DRUPALPATH/includes/common.inc(1645) : eval()'d code:18) in <b>/DRUPALPATH/includes/common.inc(1645) : eval()'d code</b> on line <b>27</b><br /> 

Why might this function show up as redeclared? I'm positive it is unique.

hass’s picture

Support for php stuff was a new feature in 2.3... this may explain why it worked in past :-)

hass’s picture

You make like to install DEV and disable the PHP filter... :-(

silurius’s picture

You mean to help debug the "redeclared-but-not-really-redeclared" function, or to prevent people from putting PHP in my nodes? I am interested in working around the issue by renaming functions on a case by case basis. I can't take drastic action with regards to PHP in nodes just yet.

Thanks again.

silurius’s picture

Oh wait, you were referring to linkchecker 6.x-2.x-dev. I thought you meant devel. Not sure what you meant by disabling the PHP filter, though.

hass’s picture

Yes, DEV. It will not solve the issues in general, but remove the errors/fails... you should better fix the bugs :-)

silurius’s picture

Right, now I'm with you, and I agree 100%. Will give that a shot soon.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

hass’s picture