We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14883 ☆ A M B ☆
    • 450 Posts
    I’m trying to follow the Custom Database Tables example in Bob’s Guides (http://www.bobsguides.com/custom-db-tables.html).


    • In my MODx database, I created a table called summit_proposal & added records to it.
    • I added the snippet CreateXpdoClasses exactly as it appears in the tutorial.
    • [li]Created a resource that calls the snippet like this:
    [[CreateXpdoClasses? &myPackage=`proposals` &myPrefix=`summit_`]]
      [/li]

    When I call the resource to create the schema and classes, I get output that looks like its working:
    [2010-11-10 17:06:34] (INFO) Schema file written to {...}/core/components/proposals/schema/proposals.mysql.schema.xml [2010-11-10 17:06:34] (INFO) Schema file parsed -- Files written to {...}/core/components/proposals/model/ [2010-11-10 17:06:34] (INFO) FINISHED 


    The directory structure is created, but no files are written into the /model directory or subdirectories. The schema file is created but is just skeletal; it doesn’t contain any information about my table:
    <?xml version="1.0" encoding="UTF-8"?>
    <model package="proposals" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM">
    </model>


    The only thing showing up in the error log are some PHP warnings:
    [2010-11-10 17:06:34] (ERROR @ /srv/zenith/web_pages/www/core/cache/elements/modsnippet/45.include.cache.php : 135) PHP warning: file_exists() expects exactly 1 parameter, 2 given
    [2010-11-10 17:06:34] (ERROR @ /srv/zenith/web_pages/www/core/cache/elements/modsnippet/45.include.cache.php : 136) PHP warning: mkdir(): File exists
    [2010-11-10 17:06:34] (ERROR @ /srv/zenith/web_pages/www/core/cache/elements/modsnippet/45.include.cache.php : 139) PHP warning: file_exists() expects exactly 1 parameter, 2 given
    [2010-11-10 17:06:34] (ERROR @ /srv/zenith/web_pages/www/core/cache/elements/modsnippet/45.include.cache.php : 140) PHP warning: mkdir(): File exists
    [2010-11-10 17:06:34] (ERROR @ /srv/zenith/web_pages/www/core/cache/elements/modsnippet/45.include.cache.php : 142) PHP warning: file_exists() expects exactly 1 parameter, 2 given
    [2010-11-10 17:06:34] (ERROR @ /srv/zenith/web_pages/www/core/cache/elements/modsnippet/45.include.cache.php : 143) PHP warning: mkdir(): File exists


    Am I doing something wrong?
      • 3749
      • 24,544 Posts
      I don’t see anything wrong, but here are a few things to try:

      Delete the existing schema file and rerun the snippet.
      Look in the database and make sure the table exists and is named summit_proposal.

      The errors you see are from a stupid mistake on my part, the second argument to file_exists() was meant to be the second argument to mkdir(). I don’t think they would cause your problem, but I’ll be fixing them in the next few minutes. The .ZIP file is correct.

      Sorry about the trouble.

      Bob
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 14883 ☆ A M B ☆
        • 450 Posts
        I think the problem is with my mysql setup. I wasn’t even able to generate a schema when calling the snippet with no arguments. I can do that on other installations.

        I was unable to install Revolution on this box with the host set to ’localhost’ - I think due to not having sufficiently researched a problem with the path to the mysql.sock file. So I installed with the full hostname specified. Could that be part of the problem?

          • 3749
          • 24,544 Posts
          Quote from: jrotering at Nov 11, 2010, 11:35 AM

          I think the problem is with my mysql setup. I wasn’t even able to generate a schema when calling the snippet with no arguments. I can do that on other installations.

          I was unable to install Revolution on this box with the host set to ’localhost’ - I think due to not having sufficiently researched a problem with the path to the mysql.sock file. So I installed with the full hostname specified. Could that be part of the problem?

          It does sound like there’s a problem with the SQL connection. The symptoms you’re seeing usually mean that the script can’t find any tables, but not finding the DB might cause the same problem. You might throw in a test or two at the beginning of the snippet -- something like this (assuming that there is a resource with an ID of 1):

          <?php
          if (! $modx->getObject('modResource', '1')) {
          
           die ('Get Object Failed.');
          
          
          }
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 14883 ☆ A M B ☆
            • 450 Posts
            After about 6 total hours of lost-in-the-wilderness debugging, I’ve finally figured out the problems:

            1. My revo database was called "modx-production". The xPDO generator was choking on this (the dash), because it wasn’t surrounding the database name with backticks. I’ve filed a bug: http://bugs.modx.com/issues/2788

            2. The CreateXpdoClasses snippet also has a bug: when no prefix is specified, the argument that gets passed to writeSchema() for $prefixRequired should be ’false’ rather than true.

            /* table prefix; must match the prefix of the tables you want to process */
            $myPrefix = empty ($myPrefix)? '' : $myPrefix;
            $prefixRequired = ($myPrefix === '') ? false : true;
            
            ....
            
              $xml= $generator->writeSchema($file,
                            $myPackage, '',$myPrefix,$prefixRequired,$myTables);
            


            This is because of the way the ’getTableName’ function is written (in xpdogenerator.class.php) - it will return an empty string if the prefix is empty but prefixRequired is set to ’true’:

            public function getTableName($string, $prefix= '', $prefixRequired= false) {
                    if (!empty($prefix) && strpos($string, $prefix) === 0) {
                        $string= substr($string, strlen($prefix));
                    }
                    elseif ($prefixRequired) {
                        $string= '';
                    }
                    return $string;
                }
            


            That could arguably be considered a bug itself -- I’d probably make the case that an empty prefix + "prefixRequired=true" really ought to just be treated the same as "prefixRequired=false" -- but I’m not sure and my brain hurts.

            At any rate, I’ve got my schema and class files now smiley

              • 3749
              • 24,544 Posts
              Good work! smiley

              Could you report those as a bugs using the Bugs & Requests link at the top of this page so it doesn’t fall through the cracks?

              You might also suggest a sanity check for hyphens in the database name.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting