This is starting to make me nuts. I’m sure it’s something simple, but I can’t find it. I had it working at one point, but something went wrong when I decided to clean up the script for use in a tutorial (and didn’t back it up -- doh). Please save me from complete insanity.
This script is running parseSchema() on a simple schema file with objects pasted from the MODx schema.
It’s finding the schema file, writing all the appropriate objects, and reporting success -- but the object classes are basically empty:
<?php
class modSystemSetting extends xPDOObject {}
Here’s the script:
<?php
if (!defined('MODX_CORE_PATH')) {
define(MODX_CORE_PATH, 'c:/xampp/htdocs/test/core/');
include_once MODX_CORE_PATH . '/model/modx/modx.class.php';
$modx= new modX();
$modx->initialize('mgr');
}
$pkg = 'test';
$sources = array(
'package' => MODX_CORE_PATH . 'components/' . $pkg . '/',
'core' => MODX_CORE_PATH . 'components/'. $pkg . '/core/',
'model' => MODX_CORE_PATH. 'components/' . $pkg . '/core/model/',
'schema' => MODX_CORE_PATH . 'components/' . $pkg . '/core/model/schema/',
);
if (! file_exists($sources['package'])) {
mkdir($sources['package']);
}
if (! file_exists($sources['core'])) {
mkdir($sources['core']);
}
if (! file_exists($sources['model'])) {
mkdir($sources['model']);
}
if (! file_exists($sources['schema'])) {
mkdir($sources['schema']);
}
$xpdo= new xPDO('mysql:host=localhost;dbname=test','BobRay','biteme','modx_');
$xpdo->setLogLevel(xPDO::LOG_LEVEL_INFO);
$xpdo->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
$manager= $xpdo->getManager();
$generator= $manager->getGenerator();
$file = $sources['schema'] . $pkg . '.mysql.schema.xml';
if ($generator->parseSchema($file, $sources['model'])) {
$xpdo->log(xPDO::LOG_LEVEL_INFO, 'Schema file parsed. Files written to '. $sources['model']);
} else {
$xpdo->log(xPDO::LOG_LEVEL_INFO, 'Error parsing schema file');
}
$xpdo->log(xPDO::LOG_LEVEL_INFO, 'FINISHED');
Here’s the schema file:
<?xml version="1.0" encoding="UTF-8"?>
<model package="test" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM">
<object class="modSystemSetting" table="system_settings" extends="xPDOObject">
<field key="key" dbtype="varchar" precision="50" phptype="string" null="false" default="" index="pk" />
<field key="value" dbtype="text" phptype="string" null="false" default="" />
<field key="xtype" dbtype="varchar" precision="75" phptype="string" null="false" default="textfield" />
<field key="namespace" dbtype="varchar" precision="40" phptype="string" null="false" default="core" />
<field key="area" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
<field key="editedon" dbtype="timestamp" phptype="timestamp" null="false" attributes="ON UPDATE CURRENT_TIMESTAMP" />
<aggregate alias="ContextSetting" class="modContextSetting" local="key" foreign="key" cardinality="one" owner="local" />
<aggregate alias="Namespace" class="modNamespace" local="namespace" foreign="name" cardinality="one" owner="foreign" />
</object>
<object class="modAccessContext" table="access_context" extends="modAccess">
<aggregate alias="Target" class="modContext" local="target" foreign="key" owner="foreign" cardinality="one" />
</object>
</model>