We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • I’m taking a crack at what Shaun did here:
    http://modxcms.com/about/blog/shaun-mccormick/storefinder.html

    But it’s confusing... this takes an XML schema and then uses it to create a database table. That’s cool... but I’d like to reverse engineer the XML based on existing tables -- if I were using CakePHP, I could run the "bake" script and generate the Model’s ORM files.

    How does xPDO handle this? Are there any other tutorials out there? Defining the model in any ORM is a huge time suck... is there a magic way to do this?

    I also stumbled on this:
    http://modxcms.com/forums/index.php/topic,12895.0/wap2.html

    but I’m still struggling with it...
      • 26903
      • 1,336 Posts
      Have a look at this script, its from one of the revo forum topics from a while back, sorry can’t remember where :-
      <?php
      $mtime= microtime();
      $mtime= explode(" ", $mtime);
      $mtime= $mtime[1] + $mtime[0];
      $tstart= $mtime;
      
      //Customize this line based on the location of your script
      include_once (strtr(realpath(dirname(__FILE__)) . '/../../xpdo/xpdo.class.php', '\\', '/'));
      
      $xpdo= new xPDO('mysql:host=localhost;dbname=modx','username','password','modx_');
      
      // Set the package name and root path of that package
      $xpdo->setPackage('modx', XPDO_CORE_PATH . '../model/');
      
      $xpdo->setDebug(true);
      
      $manager= $xpdo->getManager();
      $generator= $manager->getGenerator();
      
      //Use this to create a schema from an existing database
      $xml= $generator->writeSchema(XPDO_CORE_PATH . '../model/schema/modx.mysql.schema.xml', 'modx', 'xPDOObject', 'modx_');
      
      //Use this to generate classes and maps from your schema
      // NOTE: by default, only maps are overwritten; delete class files if you want to regenerate classes
      //$generator->parseSchema(XPDO_CORE_PATH . '../model/schema/modx.mysql.schema.xml', XPDO_CORE_PATH . '../model/');
      
      $mtime= microtime();
      $mtime= explode(" ", $mtime);
      $mtime= $mtime[1] + $mtime[0];
      $tend= $mtime;
      $totalTime= ($tend - $tstart);
      $totalTime= sprintf("%2.4f s", $totalTime);
      
      echo "\nExecution time: {$totalTime}\n";
      
      exit ();
      ?>


      You end up with an xml schema of an existing database. I have used this and it does seem to work.
        Use MODx, or the cat gets it!
        • 28215
        • 4,149 Posts
        Note that the xml schema outputted doesn’t define the aggregates/composites (i think it does the indexes, but you’ll have to check).

        You’ll have to define the relationships in the XML yourself. It doesn’t take that long, though. smiley
          shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • Ok, thanks. I’ll give that a try. There are some empty pages here that almost look like dead links: http://www.xpdo.org/api/li_xpdo.html but it seems that the docs are here: http://www.xpdo.org/api/xpdo/xPDO.html

          If I put together a more detailed step-by-step for how to do this, any thoughts on where I should post it?
            • 28215
            • 4,149 Posts
            Quote from: Everett at Sep 22, 2009, 04:08 PM

            Ok, thanks. I’ll give that a try. There are some empty pages here that almost look like dead links: http://www.xpdo.org/api/li_xpdo.html but it seems that the docs are here: http://www.xpdo.org/api/xpdo/xPDO.html

            If I put together a more detailed step-by-step for how to do this, any thoughts on where I should post it?

            The xPDO site is quite out-of-date.

            I would recommend looking here for your docs:
            http://svn.modxcms.com/docs/display/XPDO10/Home

            And here for the xPDO API docs:
            http://api.modxcms.com/

            If you do write a more thorough post, send me an email at [email protected] and I’ll get you Confluence access so you can post it to the Confluence xPDO docs.
              shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
              • 26903
              • 1,336 Posts
              Shaun, sorry to jump threads here but I need confluence access also, from my last e-mails from you you’ve granted this to me but I still can’t log in with my JIRA creds.
                Use MODx, or the cat gets it!
                • 28215
                • 4,149 Posts
                Steve, no problem. Check your googlemail inbox.
                  shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                  • 22019
                  • 390 Posts
                  Are there any limits to be aware of in terms of numbers of tables / total rows etc when using this script or the parseschema method?
                  http://rtfm.modx.com/display/revolution20/Reverse+Engineer+xPDO+Classes+from+Existing+Database+Table

                  I’ve just spent an hour using this and XDBedit to try and generate classes from 14 tables (together as one package). Eleven of those tables will work in one go, but it won’t generate the class/map files if I include the other three tables (which all look innocent enough to me). Most odd - and frustrating.

                    Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86
                  • Quote from: odeclas at Jan 19, 2011, 03:21 PM

                    Are there any limits to be aware of in terms of numbers of tables / total rows etc when using this script or the parseschema method?
                    http://rtfm.modx.com/display/revolution20/Reverse+Engineer+xPDO+Classes+from+Existing+Database+Table

                    I’ve just spent an hour using this and XDBedit to try and generate classes from 14 tables (together as one package). Eleven of those tables will work in one go, but it won’t generate the class/map files if I include the other three tables (which all look innocent enough to me). Most odd - and frustrating.
                    What is the schema for the three tables that are not getting generated?
                      • 22019
                      • 390 Posts
                      writeSchema generates this for one of the tables that it won’t class:
                      	<object class="AdaptiveAccounts" table="adaptive_accounts" extends="xPDOSimpleObject">
                      		<field key="first_name" dbtype="varchar" precision="75" phptype="string" null="true" />
                      		<field key="last_name" dbtype="varchar" precision="75" phptype="string" null="true" />
                      		<field key="verify_sign" dbtype="varchar" precision="255" phptype="string" null="true" />
                      		<field key="account_key" dbtype="varchar" precision="100" phptype="string" null="true" />
                      		<field key="confirmation_code" dbtype="varchar" precision="100" phptype="string" null="true" />
                      		<field key="charset" dbtype="varchar"0 phptype="string" null="true" />
                      	</object>



                        Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86