Parsing Error

MODX_CORE_PATH not defined! Did you include the correct config file?

'); exit; } require_once MODX_CORE_PATH . 'config/config.inc.php'; $xpdo_path = strtr(MODX_CORE_PATH . 'xpdo/xpdo.class.php', '\\', '/'); include_once ( $xpdo_path ); // A few definitions of files/folders: $package_dir = MODX_CORE_PATH . "components/$package_name/"; $model_dir = MODX_CORE_PATH . "components/$package_name/model/"; $class_dir = MODX_CORE_PATH . "components/$package_name/model/$package_name"; $schema_dir = MODX_CORE_PATH . "components/$package_name/model/schema"; $mysql_class_dir = MODX_CORE_PATH . "components/$package_name/model/$package_name/mysql"; $xml_schema_file = MODX_CORE_PATH . "components/$package_name/model/schema/$package_name.mysql.schema.xml"; // A few variables used to track execution times. $mtime= microtime(); $mtime= explode(' ', $mtime); $mtime= $mtime[1] + $mtime[0]; $tstart= $mtime; // Validations if ( empty($package_name) ) { print_msg('

Parsing Error

The $package_name cannot be empty! Please adjust the configuration and try again.

'); exit; } // Create directories if necessary $dirs = array($package_dir, $schema_dir ,$mysql_class_dir, $class_dir); foreach ($dirs as $d) { if ( !file_exists($d) ) { if ( !mkdir($d, 0777, true) ) { print_msg( sprintf('

Parsing Error

Error creating %s

Create the directory (and its parents) and try again.

' , $d )); exit; } } if ( !is_writable($d) ) { print_msg( sprintf('

Parsing Error

The %s directory is not writable by PHP.

Adjust the permissions and try again.

' , $d)); exit; } } print_msg( sprintf('
Ok: The necessary directories exist and have the correct permissions inside of
%s', $package_dir)); if (file_exists($xml_schema_file)) { print_msg( sprintf('
Ok: Using existing XML schema file:
%s',$xml_schema_file)); } $xpdo = new xPDO("mysql:host=$database_server;dbname=$dbase", $database_user, $database_password, $table_prefix); $xpdo->setLogLevel(xPDO::LOG_LEVEL_INFO); $xpdo->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML'); $manager = $xpdo->getManager(); $generator = $manager->getGenerator(); // Use this to generate classes and maps from your schema if ($regenerate_classes) { print_msg('
Attempting to remove/regenerate class files...'); delete_class_files($class_dir); delete_class_files($mysql_class_dir); } $generator->parseSchema($xml_schema_file,$model_dir,$my_table_prefix); $mtime= microtime(); $mtime= explode(" ", $mtime); $mtime= $mtime[1] + $mtime[0]; $tend= $mtime; $totalTime= ($tend - $tstart); $totalTime= sprintf("%2.4f s", $totalTime); print_msg("

Finished! Execution time: {$totalTime}
"); print_msg("
Check $class_dir for your newly generated class files!"); exit(); //------------------------------------------------------------------------------ //! FUNCTIONS //------------------------------------------------------------------------------ /** * Deletes the MODX class files in a given directory. * * @param string $dir: full path to directory containing class files you wish to delete. * @return void */ function delete_class_files($dir) { global $verbose; $all_files = scandir($dir); foreach ( $all_files as $f ) { if ( preg_match('#\.class\.php$#i', $f) || preg_match('#\.map\.inc\.php$#i', $f)) { if ( unlink("$dir/$f") ) { if ($verbose) { print_msg( sprintf('
Deleted file: %s/%s',$dir,$f) ); } } else { print_msg( sprintf('
Failed to delete file: %s/%s',$dir,$f) ); } } } } /** * Formats/prints messages. HTML is stripped if this is run via the command line. * * @param string $msg to be printed * @return void this actually prints data to stdout */ function print_msg($msg) { if ( php_sapi_name() == 'cli' ) { $msg = preg_replace('##i', "\n", $msg); $msg = preg_replace('#

#i', '== ', $msg); $msg = preg_replace('#

#i', ' ==', $msg); $msg = preg_replace('#

#i', '=== ', $msg); $msg = preg_replace('#

#i', ' ===', $msg); $msg = strip_tags($msg) . "\n"; } print $msg; }