<![CDATA[ Build script: Reverse-engineering tables / forward-engineering classes / maps - My Forums]]> https://forums.modx.com/thread/?thread=31778 <![CDATA[Build script: Reverse-engineering tables / forward-engineering classes / maps]]> https://forums.modx.com/thread/31778/build-script-reverse-engineering-tables-forward-engineering-classes-maps#dis-post-171797
Here is the build script used to reverse-engineer ($generator->writeSchema()) and forward-engineer ($generator->parseSchema()) the MODx database for 0.9.7 as an example.
<?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 ();
?>
]]>
opengeek Jul 15, 2007, 12:21 PM https://forums.modx.com/thread/31778/build-script-reverse-engineering-tables-forward-engineering-classes-maps#dis-post-171797