Page 1 of 2
unable to read resource
Posted: Tue Sep 07, 2004 1:42 am
by ben
Hello,
I've just installed cms 0.6 onto a debian stable/testing box (using posgresql 7.2). The install is pretty slick and went very smoothly. but, i'm getting the following errors when I attempt to view any site page, other than than the default index.php:
Warning: Smarty error: unable to read resource: "db:frequently-asked-questions" in /mnt/hdb2/pavedearth/smarty/Smarty.class.php on line 1083
The admin interface works great, so the database connection seems to be working ok. I spent a while messing around with the database permissions and even attempted upgrading to postgres 7.4, but that wreaked havoc with the sites being hosted on the box, so I went back to 7.2.
any advice you can offer would be much appreciated. let me know if you need any more info.
thanks,
ben
Re: unable to read resource
Posted: Tue Sep 07, 2004 12:01 pm
by Ted
ben wrote:Hello,
I've just installed cms 0.6 onto a debian stable/testing box (using posgresql 7.2). The install is pretty slick and went very smoothly. but, i'm getting the following errors when I attempt to view any site page, other than than the default index.php:
Warning: Smarty error: unable to read resource: "db:frequently-asked-questions" in /mnt/hdb2/pavedearth/smarty/Smarty.class.php on line 1083
The admin interface works great, so the database connection seems to be working ok. I spent a while messing around with the database permissions and even attempted upgrading to postgres 7.4, but that wreaked havoc with the sites being hosted on the box, so I went back to 7.2.
any advice you can offer would be much appreciated. let me know if you need any more info.
thanks,
ben
Hello,
Can you do me a favor? Set debug = true in the config.php file, try it again and paste the results (if there are any)? Though, what's weird is that there should be a generic 404 error instead of an error message.
wishy
unable to read resource
Posted: Tue Sep 07, 2004 1:16 pm
by ben
here's what I get:
Warning: Smarty error: unable to read resource: "db:frequently-asked-questions" in /mnt/hdb2/pavedearth/smarty/Smarty.class.php on line 1083
SELECT * FROM cms_modules
SELECT sitepref_name, sitepref_value from cms_siteprefs
SELECT * FROM cms_userplugins
SELECT p.page_id, p.page_content, p.page_title, p.page_type, p.head_tags, t.template_id, t.stylesheet, t.template_content FROM cms_pages p INNER JOIN cms_templates t ON p.template_id = t.template_id WHERE (p.page_id = 'frequently-asked-questions' OR p.page_alias='frequently-asked-questions') AND p.active = 1
SELECT p.page_id, t.modified_date as template_date, p.modified_date as page_date, p.page_type FROM cms_pages p INNER JOIN cms_templates t ON t.template_id = p.template_id WHERE (p.page_id = 'frequently-asked-questions' OR p.page_alias='frequently-asked-questions') AND p.active = 1
unable to read resource
Posted: Tue Sep 07, 2004 1:33 pm
by ben
when i run those sql queries manually in psql, I get this error on the 2 big ones:
ERROR: pg_atoi: error in "frequently-asked-questions": can't parse "frequently-asked-questions"
I changed them to not include "p.page_id = 'frequently-asked-questions' OR" :
SELECT p.page_id, t.modified_date as template_date, p.modified_date as page_date, p.page_type FROM cms_pages p INNER JOIN cms_templates t ON t.template_id = p.template_id WHERE (p.page_alias='frequently-asked-questions') AND p.active = 1;
and they worked. So it appears that postgres is choking on attempting to pull an integer column using a string.
unable to read resource
Posted: Tue Sep 07, 2004 1:45 pm
by ben
a little if/then in lib/content.functions.php checking to see if the passed page is an int seems to fix it:
(starting at line 89):
if (is_int($db->qstr($tpl_name)))
{
$query = "SELECT p.page_id, p.page_content, p.page_title, p.page_type, p.head_tags, t.template_id, t.stylesheet, t.template_content FROM ".cms_db_prefix()."pages p INNER JOIN ".cms_db_prefix()."templates t ON p.template_id = t.template_id WHERE (p.page_id = ".$db->qstr($tpl_name)." OR p.page_alias=".$db->qstr($tpl_name).") AND p.active = 1";
}
else
{
$query = "SELECT p.page_id, p.page_content, p.page_title, p.page_type, p.head_tags, t.template_id, t.stylesheet, t.template_content FROM ".cms_db_prefix()."pages p INNER JOIN ".cms_db_prefix()."templates t ON p.template_id = t.template_id WHERE p.page_alias=".$db->qstr($tpl_name)." AND p.active = 1";
}
$result = $db->Execute($query);
unable to read resource
Posted: Tue Sep 07, 2004 2:09 pm
by Ted
ben wrote:a little if/then in lib/content.functions.php checking to see if the passed page is an int seems to fix it:
(starting at line 89):
if (is_int($db->qstr($tpl_name)))
{
$query = "SELECT p.page_id, p.page_content, p.page_title, p.page_type, p.head_tags, t.template_id, t.stylesheet, t.template_content FROM ".cms_db_prefix()."pages p INNER JOIN ".cms_db_prefix()."templates t ON p.template_id = t.template_id WHERE (p.page_id = ".$db->qstr($tpl_name)." OR p.page_alias=".$db->qstr($tpl_name).") AND p.active = 1";
}
else
{
$query = "SELECT p.page_id, p.page_content, p.page_title, p.page_type, p.head_tags, t.template_id, t.stylesheet, t.template_content FROM ".cms_db_prefix()."pages p INNER JOIN ".cms_db_prefix()."templates t ON p.template_id = t.template_id WHERE p.page_alias=".$db->qstr($tpl_name)." AND p.active = 1";
}
$result = $db->Execute($query);
Awesome work! I'll put that in trunk as soon as I can and it'll be in the next version.
wishy
unable to read resource
Posted: Tue Sep 07, 2004 3:08 pm
by ben
cool, thanks.
unable to read resource
Posted: Wed Sep 08, 2004 8:40 pm
by ben
i've got the same errors happening again, but I can't figure out why this time. If I change either the default page to a different page, or the alias of the default page (from cms-install-successful.. to home-page for instance) I get the following when I go to index.php (debug info included):
Warning: Smarty error: unable to read resource: "db:1" in /mnt/hdb2/pavedearth/smarty/Smarty.class.php on line 1083
SELECT * FROM cms_modules
SELECT sitepref_name, sitepref_value from cms_siteprefs
SELECT * FROM cms_userplugins
SELECT page_id FROM cms_pages WHERE default_page = 1
SELECT p.page_id, t.modified_date as template_date, p.modified_date as page_date, p.page_type FROM cms_pages p INNER JOIN cms_templates t ON t.template_id = p.template_id WHERE (p.page_id = '1' OR p.page_alias='1') AND p.active = 1
It works correctly when called with a page (index.php?page=home-page).
unable to read resource
Posted: Wed Sep 08, 2004 8:48 pm
by ben
update: it now just returns a generic 404 not found error:
Not Found
The requested URL was not found on this server.
unable to read resource
Posted: Wed Sep 08, 2004 9:36 pm
by ben
I changed the function db_get_default_page in lib/content.functions.php to pull the page_alias instead of the page_id if auto-aliasing is on. It seemed to be having problems pulling by the page_id. If auto-aliasing is off in config.php (does it really need to be an option? is there any benefit to not auto-aliasing?), then this would probably break, at least when using postgres. Here's my new db_get_default_page():
Code: Select all
function db_get_default_page () {
global $gCms;
$db = $gCms->db;
$config = $gCms->config;
$result = "";
if ($config["auto_alias_content"] == true)
{
$query = "SELECT page_alias as i FROM ".cms_db_prefix()."pages WHERE default_page = 1";
}
else
{
// seems to break when using postgresql
$query = "SELECT page_id as i FROM ".cms_db_prefix()."pages WHERE default_page = 1";
}
$dbresult = $db->Execute($query);
if ($dbresult) {
$line = $dbresult->FetchRow();
$result = $line["i"];
}
#We have no default. Just get something!!!
if ($result == "") {
if ($config["auto_alias_content"] == true)
{
$query = "SELECT page_alias as i FROM ".cms_db_prefix()."pages";
}
else
{
// seems to break when using postgresql
$query = "SELECT page_id as i froM ".cms_db_prefix()."pages";
}
$dbresult = $db->SelectLimit($query, 1);
if ($dbresult) {
$line = $dbresult->FetchRow();
$result = $line["i"];
}
}
return $result;
}
unable to read resource
Posted: Wed Sep 08, 2004 10:41 pm
by Ted
ben wrote:(does it really need to be an option? is there any benefit to not auto-aliasing?)
Well, the opposite of auto-aliasing is manual aliasing, which definatly has a purpose. If the title of my page is "Frequently Asked Questions" and I was using mod_rewrite, I'd sure like it to be faq.shtml instead of frequently-asked-questions.shtml...
Actually, there is a quick fix to this...
Code: Select all
$query = "SELECT p.page_id, p.page_content, p.page_title, p.page_type, p.head_tags, t.template_id, t.stylesheet, t.template_content FROM ".cms_db_prefix()."pages p INNER JOIN ".cms_db_prefix()."templates t ON p.template_id = t.template_id WHERE (p.page_id = ".$tpl_name." OR p.page_alias=".$db->qstr($tpl_name).") AND p.active = 1";
The difference? Take the qstr out from around the p.page_id in the first query. I guess postgres doesn't like the single quotes around the first number.
wishy
unable to read resource
Posted: Thu Sep 09, 2004 12:50 am
by ben
Awesome, that fixed it. Way cleaner than my hack, too. Thanks.
I completely agree that manual aliasing is required. But, if the user doesn't set an alias manually, is there any harm in always auto-aliasing? I didn't mean to suggest that manual aliasing be disallowed.
unable to read resource
Posted: Thu Sep 09, 2004 1:09 am
by Ted
Good point. I'll make sure that's changed to do that.
unable to read resource
Posted: Thu Sep 09, 2004 1:32 am
by ben
cool, thanks.
gotta say, I really like cms. it's a perfect fit for the site I'm working on. just the cms I'd been looking for.
thanks for all your help.
unable to read resource
Posted: Thu Sep 09, 2004 10:01 am
by Ted
You code in now in svn. The ended up changing two things:
Code: Select all
if (is_numeric($tpl_name) && strpos($tpl_name,'.') === FALSE && strpos($tpl_name,',') === FALSE)
Just because I'm paranoid.
I also had to do the same logic around the timestamp function query around line 219.
Thanks again!
wishy