protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $tmpdir = sfConfig::get('sf_cache_dir') . '/models_tmp';
     $ymlTmp = $tmpdir . '/yaml';
     $modelTmp = $tmpdir . '/model';
     $this->getFileSystem()->mkdirs($ymlTmp);
     $this->getFileSystem()->mkdirs($modelTmp);
     $migrationsPath = sfConfig::get('sf_data_dir') . '/migrations/generated';
     $config = $this->getCliConfig();
     $manager = Doctrine_Manager::getInstance();
     $oldAttr = $manager->getAttribute(Doctrine::ATTR_MODEL_LOADING);
     $manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_AGGRESSIVE);
     sfSimpleAutoload::unregister();
     Doctrine::generateYamlFromDb($ymlTmp . '/from.yml', array(), array('generateBaseClasses' => false));
     sfSimpleAutoload::register();
     $manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, $oldAttr);
     $models = sfFinder::type('file')->name('*.php')->in($config['models_path']);
     foreach ($models as $model) {
         $dirname = basename(dirname($model));
         $filename = basename($model);
         if ('base' !== $dirname) {
             continue;
         }
         $normalModelName = str_replace('Base', '', basename($model, '.class.php'));
         $normalModelRefClass = new ReflectionClass($normalModelName);
         if ($normalModelRefClass && $normalModelRefClass->isAbstract()) {
             continue;
         }
         $content = file_get_contents($model);
         $content = str_replace('abstract class Base', 'class ToPrfx', $content);
         $content = str_replace('extends opDoctrineRecord', 'extends Doctrine_Record', $content);
         $matches = array();
         if (preg_match('/\\$this->setTableName\\(\'([^\']+)\'\\);/', $content, $matches)) {
             $tableName = $matches[1];
             $content = preg_replace('/class [a-zA-Z0-9_]+/', 'class ToPrfx' . Doctrine_Inflector::classify($tableName), $content);
             file_put_contents($modelTmp . '/ToPrfx' . Doctrine_Inflector::classify($tableName) . '.class.php', $content);
         } else {
             file_put_contents($modelTmp . '/' . str_replace('Base', 'ToPrfx', $filename), $content);
         }
     }
     $migration = new Doctrine_Migration($migrationsPath);
     $diff = new opMigrationDiff($ymlTmp . '/from.yml', $modelTmp, $migration);
     $changes = $diff->generateMigrationClasses();
     $this->getFileSystem()->remove($ymlTmp);
     $this->getFileSystem()->remove($modelTmp);
     $numChanges = count($changes, true) - count($changes);
     if (!$numChanges) {
         throw new Doctrine_Task_Exception('Could not generate migration classes from difference');
     } else {
         $this->dispatcher->notify(new sfEvent($this, 'command.log', array($this->formatter->formatSection('doctrine', 'Generated migration classes successfully from difference'))));
     }
 }
Example #2
0
 public function execute()
 {
     Doctrine::generateYamlFromDb($this->getArgument('yaml_schema_path'));
     $this->dispatcher->notify('Generate YAML schema successfully from database');
 }
Example #3
0
<?php

require dirname(__FILE__) . '/../application/global.php';
#$cli = new Doctrine_Cli(Zend_Registry::get('doctrine_config'));
$dconfig = Zend_Registry::get('doctrine_config');
if (isset($_GET['arg'])) {
    if ($_GET['arg'] == 'gen_models') {
        echo "Generating Models <br />\n";
        echo Doctrine::generateModelsFromDb($dconfig["models_path"]);
        //echo Doctrine::generateModelsFromDb();
    } else {
        if ($_GET['arg'] == 'gen_yaml_from_db') {
            echo "Generating Yaml From DB <br />\n";
            echo Doctrine::generateYamlFromDb($dconfig["yaml_schema_path"]);
        }
    }
}
#var_dump ($dconfig);
?>

<br />
<br />
<a href="/ds.php?arg=gen_models">gen_models</a> <br />
<a href="/ds.php?arg=gen_yaml_from_db">gen_yaml_from_db</a> <br />


Example #4
0
<?php

require_once '../Plans.php';
Doctrine::generateYamlFromDb('../db/schema.yaml');