On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • 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>






      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
    • no "exit();" ?

      (really I don’t know why not mention "exit();" can influence the writing of the classes, but that’s the only difference I see with some others build script I’ve read...)
      Cheers
      • Quote from: anso at Oct 14, 2010, 07:53 PM

        no "exit();" ?

        (really I don’t know why not mention "exit();" can influence the writing of the classes, but that’s the only difference I see with some others build script I’ve read...)
        Cheers
        It would have been nice, but no effect. Thanks anyway.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
        • Man, talk about chasing red herrings. I knew it would be something simple, but I’ve never seen this one before.

          There was a problem in the snippet I was using to test the classes I generated. It was so simple and it ran without error so I never looked at it in all the time I was trying to debug this.

          Amazingly, this code didn’t throw a PHP error:

          $quotations = $modx->getCollection('Quotations' array('topic'=>'Science'));
          
          ( foreach($quotations as $quote) {
          
              $output .= '<br />' . $quote->get('author');
          
          }
          return $output;
          


          The extra parend at the beginning of the second line just made it run for a long time and display no output at all. Go figure.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
          • An imperfection. Bob, I’m shocked. tongue
              lo9on.com

              MODx Evolution/Revolution | Remote Desktop Training | Development
            • Quote from: cyclissmo at Oct 15, 2010, 05:07 AM

              An imperfection. Bob, I’m shocked. tongue

              LOL. You must not be paying attention. wink
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting