-
- 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!
-
- 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!
-
- 4,149 Posts
Steve, no problem. Check your googlemail inbox.
shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect |
github |
splittingred.com
-
- 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
-
- 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