function index()
 {
     spl_autoload_register(array('Doctrine', 'autoload'));
     $manager = Doctrine_Manager::getInstance();
     $conn = Doctrine_Manager::connection('mysql://*****:*****@localhost/moqold', 'doctrine');
     Doctrine::generateModelsFromDb('system/application/models', array('moqold'), array('generateTableClasses' => true));
     echo Doctrine::getPath();
 }
Example #2
0
 /**
  * Main entry point for task
  */
 public function main()
 {
     if (empty($this->_dir)) {
         throw new Exception("Dir not configured ");
     }
     $manager = Doctrine_Manager::getInstance();
     // Set up validation
     $manager->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_ALL);
     $conn = Doctrine_Manager::connection($this->_dsn->_toString());
     $conn->setAttribute('portability', Doctrine::PORTABILITY_ALL);
     $conn->setAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER, true);
     Doctrine::generateModelsFromDb($this->_dir, array(), $this->_options);
 }
 public function generateAction()
 {
     //auto-generate models
     //these files will be saved under c:/tmp/models
     $path = '/tmp/models';
     $result = Doctrine::generateModelsFromDb($path, array('doctrine'), array('classPrefix' => 'Webteam_Model_'));
     if ($result) {
         $this->_helper->getHelper('FlashMessenger')->addMessage('The models were successfully generated under the folder ' . $path);
         $this->_redirect('/admin/doctrine/success');
     } else {
         throw new Zend_Controller_Action_Exception('Error while generating models.');
     }
 }
 public function index()
 {
     if ($this->input->post("generate")) {
         // drop unnecessary auto-generated tables
         $statement = "DROP TABLE IF EXISTS `doctrine_lock_tracking`;";
         Doctrine_Manager::connection()->execute($statement);
         $path = APPPATH . 'models/doctrine';
         Doctrine::generateModelsFromDb($path, array(Doctrine_Manager::connection()->getName()));
         Session::instance()->set("message", "process completed: connection " . Doctrine_Manager::connection()->getName());
         url::redirect(url::current(true));
     }
     $session_message = Session::instance()->get_once("message");
     $view = $session_message ? "<p><strong>" . $session_message . "</strong></p>" : null;
     $view .= "<form action=\"" . url::current(true) . "\" method=\"post\">";
     $view .= "<input type=\"submit\" name=\"generate\" value=\"click to generate: connection " . Doctrine_Manager::connection()->getName() . "\" />";
     $view .= "</form>";
     echo $view;
 }
Example #5
0
<?php

spl_autoload_register(array("Doctrine", "autoload"));
//$conn=Doctrine_Manager::connection();
$dirdb = dirname(__FILE__) . "/../../../tmp/db/" . $project;
if (file_exists($dirdb)) {
    Oraculum_Scaffolding::rmdirrec($dirdb);
}
mkdir($dirdb);
if (Doctrine::generateModelsFromDb($dirdb)) {
    $dirdbdest = dirname(__FILE__) . "/../../../apps/" . $project . "/models/entidades";
    if (file_exists($dirdbdest)) {
        Oraculum_Scaffolding::rmdirrec($dirdbdest);
    }
    if (rename(dirname(__FILE__) . "/../../../tmp/db/" . $project, $dirdbdest)) {
        echo "Classes geradas com sucesso!";
    } else {
        echo "Classes geradas com sucesso!";
        echo "<br />Por&eacute;m n&atilde;o foi poss&iacute;vel move-las para a pasta do projeto";
        echo "<br />Copie o conte&uacute;do da pasta <code>./tmp/db/" . $project . "</code> para ";
        echo "<code>./apps/" . $project . "/models/entidades</code>";
    }
} else {
    echo "N&atilde;o foi poss&iacute;vel gerar as classes da camada de modelo do projeto!";
}
/**
 * Generate Models from Database Tables
 */
function doctrine_create_models_db()
{
    Doctrine::generateModelsFromDb(MODELS_DIRECTORY);
}
Example #7
0
 /**
  * Generate a set of models for the schema information source
  *
  * @param  string $prefix  Prefix to generate the models with
  * @param  mixed  $item    The item to generate the models from
  * @return string $path    The path where the models were generated
  * @throws Doctrine_Migration_Exception $e
  */
 protected function _generateModels($prefix, $item)
 {
     $path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . strtolower($prefix) . '_doctrine_tmp_dirs';
     $options = array('classPrefix' => $prefix);
     if (is_string($item) && file_exists($item)) {
         if (is_dir($item)) {
             $files = glob($item . DIRECTORY_SEPARATOR . '*.*');
         } else {
             $files = array($item);
         }
         if (isset($files[0])) {
             $pathInfo = pathinfo($files[0]);
             $extension = $pathInfo['extension'];
         }
         if ($extension === 'yml') {
             Doctrine::generateModelsFromYaml($item, $path, $options);
             return $path;
         } else {
             if ($extension === 'php') {
                 Doctrine_Lib::copyDirectory($item, $path);
                 return $path;
             } else {
                 throw new Doctrine_Migration_Exception('No php or yml files found at path: "' . $item . '"');
             }
         }
     } else {
         try {
             Doctrine::generateModelsFromDb($path, (array) $item, $options);
             return $path;
         } catch (Exception $e) {
             throw new Doctrine_Migration_Exception('Could not generate models from connection: ' . $e->getMessage());
         }
     }
 }
Example #8
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 />


<?php

require_once('doctrine/lib/Doctrine.php');

spl_autoload_register(array('Doctrine', 'autoload'));
$ini_array = parse_ini_file('settings.ini');
define('DSN', 'pgsql://' . $ini_array['username'] . ':'. $ini_array['password'] .'@localhost/artist_alert');
Doctrine_Manager::connection(DSN);

// import method takes one parameter: the import directory (the directory where
// the generated record files will be put in
Doctrine::generateModelsFromDb('classes');
Example #10
0
 public function execute()
 {
     Doctrine::generateModelsFromDb($this->getArgument('models_path'), (array) $this->getArgument('connection'));
     $this->dispatcher->notify('Generated models successfully from databases');
 }
Example #11
0
$manager = Doctrine_Manager::getInstance();
//Le digo a doctrine que exporte constrains, tablas y todo lo que pueda
$manager->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_ALL);
//Le digo a doctrine que realice todas las validaciones de integridad: valores nulos, constrains, etc.
$manager->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_ALL);
//Permito los override en las clases
$manager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
if ($GLOBALS["BDLazyMode"]) {
    $manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE);
} else {
    $manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_AGGRESSIVE);
}
//Cargo todo el modelo
if (file_exists('../../model/generated')) {
    Doctrine::loadModels('../../model/generated');
} else {
    if ($GLOBALS["debugMode"]) {
        echo "No se ha encontrador el directorio 'model/generated'";
    }
}
if (file_exists('../../model')) {
    Doctrine::loadModels('../../model');
} else {
    if ($GLOBALS["debugMode"]) {
        echo "No se ha encontrador el directorio 'model'";
    }
}
//Debo hace un aggressive loadin de manera obligarotia, sino no se cargan todas las clases
$manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_AGGRESSIVE);
Doctrine::generateModelsFromDb('../../model', array($GLOBALS["dbName"]), array('generateTableClasses' => true));
<?php

include '../core/codon.config.php';
Doctrine::generateModelsFromDb(DOCTRINE_MODELS, array('doctrine'), array('generateTableClasses' => true));
Example #13
0
 /**
  * generateYamlFromDb
  *
  * Generates models from database to temporary location then uses those models to generate a yaml schema file.
  * This should probably be fixed. We should write something to generate a yaml schema file directly from the database.
  *
  * @param string $yamlPath Path to write oyur yaml schema file to
  * @return void
  */
 public static function generateYamlFromDb($yamlPath)
 {
     $directory = '/tmp/tmp_doctrine_models';
     Doctrine::generateModelsFromDb($directory);
     $export = new Doctrine_Export_Schema();
     $result = $export->exportSchema($yamlPath, 'yml', $directory);
     exec('rm -rf ' . $directory);
     return $result;
 }
Example #14
0
 /**
  * generateMigrationsFromDb
  *
  * @return void
  */
 public function generateMigrationsFromDb()
 {
     $directory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tmp_doctrine_models';
     Doctrine::generateModelsFromDb($directory);
     $result = $this->generateMigrationsFromModels($directory, Doctrine::MODEL_LOADING_CONSERVATIVE);
     Doctrine_Lib::removeDirectories($directory);
     return $result;
 }
#!/usr/bin/php
<?php 
require_once dirname(dirname(__FILE__)) . '/lib/doctrine/lib/Doctrine.php';
spl_autoload_register(array('Doctrine', 'autoload'));
$stdin = fopen('php://stdin', 'r');
$queries = array('db_host', 'db_name', 'db_user', 'db_passwd', 'target_dir');
foreach ($queries as $var) {
    ${$var} = null;
}
foreach ($queries as $var) {
    echo '$' . $var . ':';
    ${$var} = trim(fgets($stdin));
}
if (!file_exists($target_dir)) {
    mkdir($target_dir, 0755, true);
}
echo "\nDUMP:\n";
foreach ($queries as $var) {
    echo "- \${$var}=" . ${$var} . chr(10);
}
echo "\n";
Doctrine_Manager::connection("mysql://{$db_user}:{$db_passwd}@{$db_host}/{$db_name}", 'default');
Doctrine::generateModelsFromDb($target_dir, array('default'), array('generateTableClasses' => true));
fclose($stdin);
Example #16
0
 /**
  * Generates models from database to temporary location then uses those models to generate a yaml schema file.
  * This should probably be fixed. We should write something to generate a yaml schema file directly from the database.
  *
  * @param string $yamlPath Path to write oyur yaml schema file to
  * @param array  $options Array of options
  * @return void
  */
 public static function generateYamlFromDb($yamlPath, array $databases = array(), array $options = array())
 {
     $directory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tmp_doctrine_models';
     $options['generateBaseClasses'] = isset($options['generateBaseClasses']) ? $options['generateBaseClasses'] : false;
     $result = Doctrine::generateModelsFromDb($directory, $databases, $options);
     if (empty($result) && !is_dir($directory)) {
         throw new Doctrine_Exception('No models generated from your databases');
     }
     $export = new Doctrine_Export_Schema();
     $result = $export->exportSchema($yamlPath, 'yml', $directory);
     Doctrine_Lib::removeDirectories($directory);
     return $result;
 }
<?php

require "config.php";
try {
    Doctrine::generateModelsFromDb('../../../app', array('doctrine'), array('generateTableClasses' => true));
    echo "Modelo importado!!!";
} catch (Exception $e) {
    echo "Falha ao importar modelo.<p>";
    echo $e->getMessage();
}