Page 1 of 1

[Bugfix] ItemId not calculated correctly

Posted: Mon Mar 12, 2007 7:30 am
by rjonker
According to my findings in this thread I would like to share this part of code. For a more detailed description of the problem please see my original thread. The bug I found affects 1.0.12 (and most probably, 1.0.11 as well).

In index.php (around line 99) a value of 99999999 gets assigned to $Itemid if none is found:

Code: Select all

if ( !$Itemid ) {
// when no Itemid give a default value
	$Itemid = 99999999;
}
This causes two if statements a couple of lines ahead to be never executed (index.php, around line 111):

Code: Select all

// checking if we can find the Itemid thru the content
if ( $option == 'com_content' && $Itemid === 0 ) {
	$id 	= intval( mosGetParam( $_REQUEST, 'id', 0 ) );
	$Itemid = $mainframe->getItemid( $id );
}

/** do we have a valid Itemid yet?? */
if ( $Itemid === 0 ) {
	/** Nope, just use the homepage then. */
	$query = "SELECT id"
	. "\n FROM #__menu"
	. "\n WHERE menutype = 'mainmenu'"
	. "\n AND published = 1"
	. "\n ORDER BY parent, ordering"
	;
	$database->setQuery( $query, 0, 1 );
	$Itemid = $database->loadResult();
}
Because these if conditions never return true the inner code is unreachable. I haven't investigated the impact of this on the rest of the code. What I do know is that it caused the problem in my thread here.

The solution to this is simple. Just move the first snippet of code to below the second if condition (I moved it to line 127). This causes the $Itemid to be set correctly and solve my problem (and maybe/probably other problems as well).

I hope I described this clearly. If needed, I can provide a diff file.

Best regards,
Robert Jonker

Re: [Bugfix] ItemId not calculated correctly

Posted: Mon Mar 12, 2007 1:15 pm
by Robin
[Q&T Note] Also linking to Q&T forum, see http://forum.joomla.org/index.php/topic,149558.0.html