We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7231
    • 4,205 Posts
    Added the mod to verify if MySQL is version 5.0.51, and also added a verification for strict mode. This second one was a bit tricky and not easy for me to test since it checks the session.sql_mode variable which will only reset once the session ends so even turning on/off strict mode it will give whaky results. I also have a hard time testing this since my MAMP over writes my edits to my.cnf when I restart the server so I cant turn strict mode on physically, I can only set it to on via a query. There are other ways to test for strict, for example to use the || in a query will fail in strict, and using the auto_increment with a blank value will fail in strict. But for those test a table needs to be created and altered then dropped. Not sure if that is the way to go, then again why not. So if what I cam up with does not work there is an alternative.

    So if those of you who have access to a strict mode MySQL server please give this a check and report.

    I am attaching the files to test in a zip file. The files affected are action.connection.php and action.summary.php. In action.connection.php I added the check as part of the Test Connection process, and in action.summary.php it is part of the verify db section. I tried my best to code in the same style as the existing code to keep it coherent. For now I have hard coded the messages to make it easy to test.

    To test the version check, change the code to check for your current version. I did not make the version check block the installation, it is a warning but the user can continue. Strict mode check is a fail.

    Now here is the code added to action.connection.php (adding php tags to get syntax coloring, and make it look cool). I inserted this at about line 34, before the end of the test db section:
    <?php
        // Mysql version check
        $status .= "... Checking MySQL version: ";
        if ( version_compare(mysql_get_server_info(), '5.0.51', '=') ) {
        	$status .= "Atention: The MySQL server version is 5.0.51 ...";
        	$color = '#ff0000';
    	} else {
            $status .= $_lang['status_passed'];
            $color = '#007700';
        }	
    	
    	// Mode check
        $mysqlmode = @ mysql_query("SELECT @@session.sql_mode");
        if (mysql_num_rows($mysqlmode) > 0){
        	$modes = mysql_fetch_array($mysqlmode, MYSQL_NUM);
        	foreach ($modes as $mode) {
        		if (strtoupper($mode) == "STRICT_TRANS_TABLES") {
        			$mysqlAlert .= "Atention: The MySQL server is in Strict Mode ";
        			$colorMysql = '#ff0000';
        		}
        	}
        } else { 
        	$mysqlAlert .= "MySQL server is not in Strict Mode "; 
        }
    ?>
    Also need to make a mod where the error message shows, I kept them apart to keep it clear but they could be displayed together with the others.

    And here is the code that was added to action.summary.php, added at @ line 169:
    <?php
    // check mysql version
    if ($conn) {
    	echo "<p>Checking MySQL version: ";
    	if ( version_compare(mysql_get_server_info(), '5.0.51', '=') ) {
        	echo "<span class=\"notok\">" . $_lang['failed'] . "</span></b> 5.0.51</p>";
    		//$errors += 1; Not an error, just  warning?
    		echo "<p>There are known issues with MySQL 5.0.51. It is recommended that you upgrade before continuing.</p>"; 
    	} else {
    		echo "Your MySQL version is ".mysql_get_server_info()." <span class=\"ok\">" . $_lang['ok'] . "</span></p>";
        }
    }
    
    // check for strict mode - Edited 250208
    if ($conn) {
    	echo "<p>Checking MySQL for strict mode: ";
    	$mysqlmode = @ mysql_query("SELECT @@global.sql_mode");
        if (mysql_num_rows($mysqlmode) > 0){
        	$modes = mysql_fetch_array($mysqlmode, MYSQL_NUM);
        	foreach ($modes as $mode) {
        		if (strtoupper($mode) == "STRICT_TRANS_TABLES") {
        			echo "<span class=\"notok\">" . $_lang['failed'] . "</span></b> MySQL is in Strict Mode</p>";
        			$errors += 1;
        			echo "<p><span class=\"notok\">MODx requires that strict mode be disabled. You can set the MySQL mode by editing the my.cnf file or contact your server administrator.</span></p>"; // add to lang file
        		} else {
        			echo "<span class=\"ok\">" . $_lang['ok'] . "</span></p>";
        		}
        	}	
        } else {
        	echo "<span class=\"ok\">" . $_lang['ok'] . "</span></p>";
        }
    }
    ?>
    I was not sure about the different $installMode options so may need to tweak this for all options. Uptdate: I tested all options and works as is.

    Feel free to toss stones at the code if needed, no ego issues here. I am happy learn from my mistakes grin

    EDIT: Updated the code to fix a bug I found. New files attached
      [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

      Something is happening here, but you don&#39;t know what it is.
      Do you, Mr. Jones? - [bob dylan]
      • 7231
      • 4,205 Posts
      I was able to figure out how to activate strict-mode on my local and found a bug in my logic. It is now fixed and I am confident that it is working as expected.

      The files attached above are the working copy for testing grin grin grin

      FYI - If anyone is wondering to set MAMP’s mysql in to strict mode you need to add a my.cnf to the applications/mamp/library directory with including the sql-mode="STRICT_TRANS_TABLES" in the [mysqld] section.
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 22303 MODX Staff
        • 10,725 Posts
        Can this differentiate between 5.0.51 and 5.0.51a (which is patched and I believe works)?
          • 7231
          • 4,205 Posts
          Yes. I tested this and it is an exact match for 5.0.51 that triggers it, any variations (ex: 5.0.51a) will not match.

          You can test this:
          <?php echo version_compare("5.0.51", "5.0.51a", "="); ?>
          this will return -1 or false. We can use == rather than = to be more specific.

            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don&#39;t know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 22303 MODX Staff
            • 10,725 Posts
            Just curious, have you ever worked with Subversion and if so, do you know how to prepare a patch?
              • 7231
              • 4,205 Posts
              Quote from: OpenGeek at Feb 25, 2008, 10:21 AM

              Just curious, have you ever worked with Subversion and if so, do you know how to prepare a patch?
              Sorry, I do not know how to handle subversion, tried once briefly and was a total flop. I am sure I can figure it out with a bit more effort but have not ventured there yet, just haven’t had the time these last few months. It IS a high priority on my list of things to learn.

              BTW - out of curiosity I just tested the strict mode check with mysql4 (which does not support strict mode) and there were no problems. It is looking good so far grin
                [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                Something is happening here, but you don&#39;t know what it is.
                Do you, Mr. Jones? - [bob dylan]
                • 25663 MODX Staff
                • 12,272 Posts
                Very cool work dev_cw. This should be a big boon to new installs and upgrades to 0962, stopping a ton of support requests before they make it to the forums. smiley
                  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
                  Quote from: dev_cw at Feb 25, 2008, 10:42 AM

                  Sorry, I do not know how to handle subversion, tried once briefly and was a total flop. I am sure I can figure it out with a bit more effort but have not ventured there yet, just haven’t had the time these last few months. It IS a high priority on my list of things to learn.
                  Not a problem; I’m working up a contributor’s guide that describes how to create and submit patches in our new fancy development infrastructure. I’ll get it out to the team for review as soon as possible, and before I go public with it, but basically users can sign up on Jira, create an issue (or find an existing one), then create/attach a Crucible review from a patch file they can upload. This will allow users to contribute without committing to team membership, and will allow us to easily review and comment on the contribution before committing it anywhere.

                  And you don’t need subversion to create simple patches, plain old diff will work.

                  See http://wiki.creativecommons.org/HOWTO_Patch for a very generalized view of how to create a patch.
                    • 25663 MODX Staff
                    • 12,272 Posts
                    Hello Shane, as it turns out it seems that any version of 5.0.51 (straight-up, "a" or otherwise) fails. Let’s get the language strings pulled into the language file and prepare a patch using the guide above to attach to MODX-141. This should definitely be in the 0962 release!

                    (BTW, Subversion is really simple even for me when using a decent GUI client. If I can manage it, anyone can!)
                      Ryan Thrash, MODX Co-Founder
                      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                      • 27708 MODX Staff
                      • 2,502 Posts
                      @dev_cw On Subversion: I have subversion running on my XP notebook and use TortoiseSVN for a client. Here is a great primer for SVN (mac centric but you can figure it out): http://blog.circlesixdesign.com/2007/04/10/beginning-svn-journey/

                      Cheers,

                      Jay
                        Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub