Page 1 of 1
[Solved] Search broken if template includes {content assign=X}
Posted: Thu Sep 10, 2009 8:21 am
by arr28
[Title edited to reflect the problem as determined later]
--
(This is my first forum post, so please go easy on me if, despite reading the documentation, reading the forum rules, searching the forums, etc. I still get something wrong.)
Versions
CMSMS 1.6.5 (upgraded from 1.6.4, upgraded from 1.6)
Captcha 0.4
CMSMailer 1.73.14
CustomContent 1.5.3
FileManager 1.0.1
FrontEndUsers 1.6.9
MenuManager 1.6.2
ModuleManager 1.3.1
News 2.10.3
nuSOAP 1.0.1
Printing 1.0.3
Search 1.6.1
ThemeManager 1.1.1
TinyMCE 2.5.4
Ubuntu dapper
Apache/2.0.55
Problem
Every time I submit a search, I get the following error message.
Fatal error: Cannot redeclare class searchitemcollection in /var/www/vhosts/charlottechapel.org/httpdocs/arr/cmsms/modules/Search/action.dosearch.php on line 5
Reproducible simply by doing a search. It doesn't matter what the search terms are - the result is always the same.
What have I tried?
Resetting search statistics
Reindexing all content
Resetting search template
Resetting result template
I also tried downgrading Search to 1.5.4 (as recommended in another forum post). This fixed the problem above but introduced other problems instead (e.g. unsupported parameters on the {search} tag).
Additional information
This used to work fine in 1.6. I can't be certain that I ever tried using site search whilst I had 1.6.4 installed. I get the error above in 1.6.5.
Workaround
Whilst waiting to discover what I've done wrong, I've done a hackaround. I've edited modules/Search/action.dosearch.php and surrounded the definition of the SearchItemCollection class with the following.
if (!class_exists('SearchItemCollection'))
{
...
}
This fixes the problem. However, it leaves me with a hacked installation, which I'd rather not have because (a) my hack almost certainly isn't correct in all circumstances, (b) I won't get support for other problems and (c) it'll get overwritten every time I upgrade.
Request
Please could you assist me in finding a way to fix site search without resorting to hacking my installation?
Many thanks,
Andrew
Re: Search broken after upgrading from 1.6 to 1.6.4 to 1.6.5
Posted: Thu Sep 10, 2009 8:44 am
by RonnyK
Do you have a link?
Ronny
Re: Search broken after upgrading from 1.6 to 1.6.4 to 1.6.5
Posted: Thu Sep 10, 2009 8:50 am
by arr28
> Do you have a link?
Currently running with my workaround at
http://www.charlottechapel.org/arr/cmsms. (On Saturday 12th September, it will move to
http://www.charlottechapel.org/) Search is top-right. If you need me to remove the workaround, let me know.
Some further information that might be relevant too...
- My first attempt at a hack was if() exit. With that, the header parts of the site displayed - up to the point where the search box would normally be displayed. Then nothing more (presumably because adding the search box caused the file to be included for a second time, which triggered the 'exit').
Re: Search broken after upgrading from 1.6 to 1.6.4 to 1.6.5
Posted: Thu Sep 10, 2009 7:56 pm
by calguy1000
Hmmm.
Thank you for the well explained post. One more question: What version of PHP are you running? Also, check your cms_modules table in the database and see if Search isn't mentioned twice. If it is, delete the second one.
If that still isn't the problem, then your solution is decent, but it is strange that this problem hasn't been reported by anybody else. Normally when there's a problem like that, there are all kinds of posts about it on this forum.
Re: Search broken after upgrading from 1.6 to 1.6.4 to 1.6.5
Posted: Thu Sep 10, 2009 10:21 pm
by arr28
PHP = 5.1.2
Only one copy of Search in the modules table. (Copy-and-paste from phpMyAdmin, sorry for poor formatting...)
SQL query:
SELECT *
FROM `modules`
ORDER BY `modules`.`module_name` ASC
LIMIT 0 , 30
Edit Delete Captcha installed 0.4 0 1
Edit Delete CMSMailer installed 1.73.14 0 1
Edit Delete CustomContent installed 1.5.3 0 1
Edit Delete FileManager installed 1.0.1 0 1
Edit Delete FrontEndUsers installed 1.6.9 0 1
Edit Delete MenuManager installed 1.6.2 0 1
Edit Delete ModuleManager installed 1.3.1 1 1
Edit Delete News installed 2.10.3 0 1
Edit Delete nuSOAP installed 1.0.1 1 1
Edit Delete Printing installed 1.0.3 0 1
Edit Delete Search installed 1.6.1 0 1
Edit Delete ThemeManager installed 1.1.1 1 1
Edit Delete TinyMCE installed 2.5.4 0 1
Could it be my page template that is causing the problem? Do you have any feel for how many people present a search box on the search results page? Enough to cause a flood of forum posts if it was broken for all? (I'm guessing so, but you obviously have much more experience.)
Also, my CMSMS installation isn't at the site root. I think I read in the PHP docs that require/include_once does it once per filename (incl. path - i.e. if you include the same file twice but specify it using different relative paths that get you to the same location, you still get it included twice.) I wonder if that might be the problem when the installation isn't at the site root? Presumably non-site-root installations are much more rare.
If my fix is the way to go, should I submit a patch (to avoid the various negative consequences of a hacked installation that I mentioned above)? How do I go about doing that?
Re: Search broken after upgrading from 1.6 to 1.6.4 to 1.6.5
Posted: Fri Sep 11, 2009 8:54 am
by arr28
Ah-ha! Ignore my speculations in the last post, they're all rubbish.
I have a minimal repro. scenario.
- Install 1.6.5 with sample content
- Modify the NCleanBlue (home page) template
- Insert {content assign=dummy} near the top
- Visit the home page
- Perform a search
See "Fatal error: Cannot redeclare class searchitemcollection in /var/www/vhosts/charlottechapel.org/httpdocs/arr/cmsms/modules/Search/action.dosearch.php on line 5"
So, it's got something to do with assigning the default content to a variable.
I inserted some additional diagnostic code to print a stack backtrace (which is what tipped me off to the problem). I've included the output here in case it helps solve the problem. This is the abbreviated output of debug_print_backtrace inserted near the top of action.dosearch.php (along with a note of whether my hack caused the class declaration to be included or skipped).
[***INCLUDED***]
#0 include() called at [/var/www/vhosts/charlottechapel.org/httpdocs/arr/cmsms/lib/classes/class.module.inc.php:1549]
#1 CMSModule->DoAction(
dosearch,
cntnt01,
Array (
[returnid] => 107,
[searchinput] => students,
[origreturnid] => 15,
[action] => dosearch),
107) called at [/var/www/vhosts/charlottechapel.org/httpdocs/arr/cmsms/lib/classes/class.module.inc.php:1585]
#2 CMSModule->DoActionBase(
dosearch,
cntnt01,
Array (
[returnid] => 107,
[searchinput] => students,
[origreturnid] => 15),
107) called at [/var/www/vhosts/charlottechapel.org/httpdocs/arr/cmsms/plugins/function.content.php:98]
#3 smarty_cms_function_content() called at [/var/www/vhosts/charlottechapel.org/httpdocs/arr/cmsms/tmp/templates_c/%%E8^E85^E855A813%%tpl_body%3A25.php:85]
#4 include(/var/www/vhosts/charlottechapel.org/httpdocs/arr/cmsms/tmp/templates_c/%%E8^E85^E855A813%%tpl_body%3A25.php) called at [/var/www/vhosts/charlottechapel.org/httpdocs/arr/cmsms/lib/smarty/Smarty.class.php:1283]
#5 Smarty->fetch(tpl_body:25) called at [/var/www/vhosts/charlottechapel.org/httpdocs/arr/cmsms/index.php:324]
[***SKIPPED***]
#0 include() called at [/var/www/vhosts/charlottechapel.org/httpdocs/arr/cmsms/lib/classes/class.module.inc.php:1549]
#1 CMSModule->DoAction(
dosearch,
cntnt01,
Array (
[assign] => dummy,
[returnid] => 107,
[searchinput] => students,
[origreturnid] => 15,
[action] => dosearch),
107) called at [/var/www/vhosts/charlottechapel.org/httpdocs/arr/cmsms/lib/classes/class.module.inc.php:1585]
#2 CMSModule->DoActionBase(
dosearch,
cntnt01,
Array (
[assign] => dummy,
[returnid] => 107,
[searchinput] => students,
[origreturnid] => 15),
107) called at [/var/www/vhosts/charlottechapel.org/httpdocs/arr/cmsms/plugins/function.content.php:98]
#3 smarty_cms_function_content() called at [/var/www/vhosts/charlottechapel.org/httpdocs/arr/cmsms/tmp/templates_c/%%87^872^872DD409%%tpl_head%3A25.php:14]
#4 include(/var/www/vhosts/charlottechapel.org/httpdocs/arr/cmsms/tmp/templates_c/%%87^872^872DD409%%tpl_head%3A25.php) called at [/var/www/vhosts/charlottechapel.org/httpdocs/arr/cmsms/lib/smarty/Smarty.class.php:1283]
#5 Smarty->fetch(tpl_head:25) called at [/var/www/vhosts/charlottechapel.org/httpdocs/arr/cmsms/index.php:325]
------
So, although it isn't solved, I can live with this. I was only doing {content assign=dummy} to force the primary content input box to the top on the "Edit page" admin page. (The "Edit page" page puts the content boxes in the order found in the template. Some editors were making mistakes because the Sidebar input box appeared before the Content input box - because it appeared before it it in the template.)
I've discovered than {* {content assign=dummy} *} is my friend in multiple ways...
- It's a workaround for this bug
- It presumably decreases page load time (because it isn't parsing the contents twice)
- I still get my input boxes in the order my editors want (presumably because the code for the edit page does a rough-and-ready parse of the template, not a full smarty parse, when determining the order of the input boxes)
Re: Search broken if template includes {content assign=X}
Posted: Fri Sep 11, 2009 1:48 pm
by calguy1000
ah, yeah, that will cause all sorts of problems.
You can't have two 'default' content blocks in your template.
You need to supply names to all but one. i.e {content block='foo'}
for your solution to work properly you should have one
{content assign='foo'} block at the top of your template (inside the body section though).
and then use {$foo} where you want the content to be displayed.
Re: [Solved] Search broken if template includes {content assign=X}
Posted: Fri Sep 11, 2009 2:09 pm
by arr28
Many thanks.
Andrew
Re: [Solved] Search broken if template includes {content assign=X}
Posted: Mon Sep 21, 2009 4:02 pm
by Russ
So what happens if you want something like...
{capture assign='albumcontent'}{content}{/capture}
{if isset($albumpagetitle)}
{capture assign='pagetitle'}{title} - {$albumpagetitle}{/capture}
{capture assign='h2title'}{title}{/capture}
{/if}
{capture assign='eventcontent'}{content}{/capture}
{if isset($eventdetails)}
{capture assign='pagetitle'}{title} - {$eventdetails}{/capture}
{capture assign='h2title'}{$eventdetails}{/capture}
{/if}
{capture assign='newscontent}{content}{/capture}
{if isset($newsarticle)}
{capture assign='pagetitle'}{title} - {$newsarticle}{/capture}
{capture assign='h2title'}{$newsarticle}{/capture}
{/if}
and perhaps more?
Re: [Solved] Search broken if template includes {content assign=X}
Posted: Mon Sep 21, 2009 4:35 pm
by calguy1000
Read up... it's answered.
Re: [Solved] Search broken if template includes {content assign=X}
Posted: Tue Sep 22, 2009 7:33 am
by Russ
Sorry calguy, not sure how I missed that... thanks...
Anyway, what works for me is something like below...
1. Is this what you meant calguy?
2. Is there a better way of doing it?
I didn't want more content blocks, only one, I was just trying to feed module stuff to page titles and headers etc.
In header
{content assign='page_content'}
Then....
{if isset($newsarticle)}
{capture assign='pagetitle'}{title} - {$newsarticle}{/capture}
{capture assign='h2title'}{$newsarticle}{/capture}
{/if}
In Body
For a h2 heading (for example)
{if isset($pagetitle)}
{$h2title}
{else}
{title}
{/if}
Where you want content to appear, instead of {content}
{$page_content}