We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19554
    • 59 Posts
    Version: 0.9.5 beta 2

    Error when openning document in public view:
    « Execution of a query to the database failed - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ’WHERE `modx`.modx_site_content.pub_date < 1159218383 AND `modx` »

    UPDATE `modx`.modx_site_content SET published=1, publishedon=1159185983, publishedby= WHERE `modx`.modx_site_content.pub_date < 1159218383 AND `modx`.modx_site_content.pub_date!=0

    Steps to reproduce
    1. For existing document set:
    - Published to true (checked out)
    - Published date to today

    Can anyone confirm this?
      • 727
      • 502 Posts
      Yep. In 0.9.2.1 at least. Search on here for the solution. You have to modify the document parser. I also posted on the subject regarding a confused bug report.

      See here:

      http://modxcms.com/forums/index.php/topic,6850.msg47974.html#msg47974

      Andy
        • 19554
        • 59 Posts
        Unfortunately, problems reported in http://modxcms.com/forums/index.php/topic,6850.msg47974.html#msg47974 somehow did not catch enough attention.


        Here is what I can confirm in beta 2 (rev 1417)

        1. manager/includes/document.parser.class.inc.php, line 497, col 108
            *** there is spelling error publihsedby

        2. manager/includes/document.parser.class.inc.php, line 491, col 136
           *** $this->getLoginUserID() is used in SQL statement

          ", publishedby=" . $this->getLoginUserID()

           obviously, when user is not logged in, it causes problem reported in bugs #406 and #539

           One of the possible solutions to this would be checking value returned by getLoginUserID() and setting it to 0 if function
           returns empty value, like this

           ", publishedby=" . ($this->getLoginUserID()?$this->getLoginUserID():0)

           Of course, I am not experienced with performance issues and coding style of this project and PHP in general,
           but I am sure some of Core coders could produce something similar in effect and surely better.

          Anyway, introduction of this quick fix seems to solve problem with Scheduled Publishing (for now).

        Could someone with permissions commit this into SVN please?

        EDIT: Maybe better solution would be to change function getLoginUserID() to something like this

            # Returns current user id
            function getLoginUserID() {
                if ($this->isFrontend() && isset ($_SESSION[’webValidated’])) {
                    return $_SESSION[’webInternalKey’];
                } else
                    if ($this->isBackend() && isset ($_SESSION[’mgrValidated’])) {
                        return $_SESSION[’mgrInternalKey’];
                    }
                else
                    return 0
            }

        if, of course, value 0 means that user is not logged. However, I did not go deep enough into code to see if ’0’ stands for
        status ’not logged’.
        BTW, it would be good if someone could comb code in search for "dangling" cases like this. By the practices of good programming, conditional branching should always cover all possible cases. Leaving some cases unprocessed could be very unpleasant time bomb that could be activated by some future (currently unplanned) use of functions containing such code.
          • 29577
          • 11 Posts
          I confirm the problem. Although I would change the code to state:

           $sql = "UPDATE ".$this->getFullTableName("site_content")." SET published=1, publishedon=".time()." WHERE ".$this->getFullTableName("site_content").".pub_date < $timeNow AND ".$this->getFullTableName("site_content").".pub_date!=0";
          


          Infact I don’t see why the publisher should be changed to the current user if that user only happened to be logged in at the time of publishing.
          Actually this solution was already proposed by Susan in thread: http://modxcms.com/forums/index.php/topic,6850.msg47974.html#msg47974

          EDIT: You may also change the SQL statement in
           $sql = "UPDATE ".$this->getFullTableName("site_content")." SET published=1, publishedon=".time().", publishedby=createdby WHERE ".$this->getFullTableName("site_content").".pub_date < $timeNow AND ".$this->getFullTableName("site_content").".pub_date!=0";
          

          or if you really want to get fancy in:
           $sql = "UPDATE ".$this->getFullTableName("site_content")." SET published=1, publishedon=".time().", publishedby=IF(editedby<>0,editedby,createdby) WHERE ".$this->getFullTableName("site_content").".pub_date < $timeNow AND ".$this->getFullTableName("site_content").".pub_date!=0";
          

          The later will result in the publishedby set to the latest editor of the post.

          Ronald
            • 19554
            • 59 Posts
            Exactly! This is one step further - not just debugging existing code, but fixing logic too.
            Actually, it is wrong to transfer "ownership" to currently logged user that "just happens there" where publishing occurs.
            Last editor stratefy is something that could be acceptable, but we should hear other members of community too. Okay with me, anyway.
              • 25663 MODX Staff
              • 12,272 Posts
              I tracked down where this was reintroduced. It was originally fixed in 1199, and slipped back in at 1213 when we reverted a few experimental changes to the core. Thanks for identifying this issue and offering solutions. We’ll get the fixes in the next beta release (hopefully today).
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 22303 MODX Staff
                • 10,725 Posts
                The fix has been re-applied in 1521, please double-check I did this correctly; since I never use this feature, I don’t have an easy setup to test it. I chose the path of least resistance, opting to leave the publishedby field alone on the auto-publishing update statements.
                  • 727
                  • 502 Posts
                  Quote from: OpenGeek at Sep 26, 2006, 10:20 AM

                  The fix has been re-applied in 1521, please double-check I did this correctly; since I never use this feature, I don’t have an easy setup to test it. I chose the path of least resistance, opting to leave the publishedby field alone on the auto-publishing update statements.

                  It’s a very cool feature and has saved me a lot of time. It has 1000’s of uses and is easy to test. I’ll try when I get chance but here is how to do it:

                  1. Make a note of your server’s current time in relation to your PC clock
                  2. Create a new document that will appear on the menu
                  3. Set the document to unpublished and set the publish time to today but a couple of minutes from now
                  4. Refresh your site - document should not show.
                  5. Wait a couple of minutes then refresh and it should now show.

                  Andy
                    • 25663 MODX Staff
                    • 12,272 Posts
                    Seems to be working perfectly as verified by Andy’s test instructions.
                      Ryan Thrash, MODX Co-Founder
                      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me