We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15454
    • 17 Posts
    My site suddenly developed this weird problem - not sure how. What happens is, I log in as a web user and am directed to the page I have permissions to view on the web and this is all good. THEN I navigate away to most other pages and this mysql error comes up:

    « MODx Parse Error »
    MODx encountered the following error while attempting to parse the requested resource:
    « Execution of a query to the database failed - Unknown column '$docgrp' in 'where clause' »
    SQL: SELECT DISTINCT `sc`.`id`, `pagetitle`, `description`, editedon AS pubDate FROM `ses`.`modx_site_content` `sc` LEFT JOIN `ses`.`modx_document_groups` `dg` on `dg`.`document` = `sc`.`id` WHERE (`sc`.`privateweb`="0" OR dg.document_group IN ($docgrp)) AND `parent` IN (25,26,27,43,44,54,45,47,55) AND `sc`.`published` = "1" AND `sc`.`hidemenu`="0" AND `sc`.`deleted`="0" ORDER BY editedon DESC LIMIT 10;

    The only place I could find the sql was in the siteCache.idx.php file. I know I'm not supposed to but I edited this file to check what was happening. The $docgrp variable was being set ok, but for some reason the line in siteCache.idx.php had to be changed from OR dg.document_group IN ($docgrp) to OR dg.document_group IN ("$docgrp") before the site would read the variable's value instead of the variable name. I have NO idea why this is happening.

    Of course, siteCache.idx.php is a dynamic script and is overwritten as things change, so editing the file doesn't help me in the long run.

    Can anyone shed some light on either what has caused this problem or may be causing this problem (all still working fine on another install of the site and all I've changed on this install is a few member groups) and/or where I can permanently add "$docgrp" so that it is written like that into the siteCache.idx.php file?

    Thank you for your time,

    Kathy smiley
    • What version of MODX are you running?
        • 15454
        • 17 Posts
        I'm running Evolution 1.0.5 on a MAMP set up. No issues previously - just this sudden failure to read the $docgrp as a variable.
        • I'd be somewhat concerned about running an older and vulnerable version of MODX -- I've seen a couple sites get hacked pretty quickly running 1.0.5. Can you make a backup and update to 1.0.8? It would be a good time to scan for malware too. I don't know if that has anything to do with the behavior you're seeing though.

          Can you grep through your code base to see which Snippet (?) is failing to populate the $docgrp variable?
          • MAMP is usually a localhost environment; I doubt he needs to worry about it being hacked. But it should certainly be upgraded in any case.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 15454
              • 17 Posts
              Yes it is a localhost but soon won't be so upgrading is probably a good idea. I hope there are not too many transition issues with snippets etc.

              The variable is passed. If I type echo $docgrp; into the siteCache file it returns a valid document group number (and the number I would expect to be passed based on the logged in user's groups) - it is to do with the syntax for some reason. All of a sudden, the code won't work unless I put " " around the call to the variable. This is silly too - it isn't '$docgrp' or `$docgrp` - it has to be "$docgrp". I can't figure it out.
                • 15454
                • 17 Posts
                Okay well I just did an upgrade to 1.0.8 and this problem is still occurring there anyway.
                  • 15454
                  • 17 Posts
                  So if there is no obvious fix, can anyone tell me how I can put the " " around the $docgrp variable before the siteCache.idx.php file is generated? The code must come from somewhere. I have found similar code in a few files but I'm not sure if it is even in a file or in the database somewhere.
                    • 15454
                    • 17 Posts
                    This is the code generated in the siteCache.idx.php file:

                    Line: 4617 - 4621
                    //get document groups for current user
                    if($docgrp = $modx->getUserDocGroups()) $docgrp=implode(",",$docgrp);
                    $access = " (".($modx->isFrontend() ? "sc.privateweb=0":"1=\'".$_SESSION[\'mgrRole\']."\' OR sc.privatemgr=0").
                    (!$docgrp ? "":" OR dg.document_group IN ($docgrp)").") AND ";


                    and for some reason it only works if line 4621 is:

                    (!$docgrp ? "":" OR dg.document_group IN ("$docgrp").") AND ";
                      • 15454
                      • 17 Posts
                      I found it - the code is from ListIndexer. I have added the " " to the code there and this has fixed the problem. I consider this a less than ideal solution though - anyone got any ideas on why I would suddenly need to add " " around $docgrp? I didn't upgrade anything like the PHP or MYSQL version.

                      On the plus side, I understand a lot more about siteCache.idx.php works.