unable to read resource

Help with getting the CMS CORE package up and running. This does not include 3rd party modules, PHP scripts, anything downloaded via module manager or from any external source.
ben

unable to read resource

Post 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
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: unable to read resource

Post 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
ben

unable to read resource

Post 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
ben

unable to read resource

Post 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.
ben

unable to read resource

Post 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);
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

unable to read resource

Post 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
ben

unable to read resource

Post by ben »

cool, thanks.
ben

unable to read resource

Post 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).
ben

unable to read resource

Post by ben »

update: it now just returns a generic 404 not found error:

Not Found

The requested URL was not found on this server.
ben

unable to read resource

Post 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;
}
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

unable to read resource

Post 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
ben

unable to read resource

Post 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.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

unable to read resource

Post by Ted »

Good point. I'll make sure that's changed to do that.
ben

unable to read resource

Post 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.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

unable to read resource

Post 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
Locked

Return to “[locked] Installation, Setup and Upgrade”