コード例 #1
0
 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();
 }
コード例 #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);
 }
コード例 #3
0
 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.');
     }
 }
コード例 #4
0
 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;
 }
コード例 #5
0
ファイル: generate.php プロジェクト: patrix/oraculum
<?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!";
}
コード例 #6
0
/**
 * Generate Models from Database Tables
 */
function doctrine_create_models_db()
{
    Doctrine::generateModelsFromDb(MODELS_DIRECTORY);
}
コード例 #7
0
ファイル: Diff.php プロジェクト: hasanozgan/kissabe
 /**
  * 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());
         }
     }
 }
コード例 #8
0
ファイル: doctrine.php プロジェクト: adnanali/munch
<?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 />


コード例 #9
0
<?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');
コード例 #10
0
ファイル: GenerateModelsDb.php プロジェクト: walterfrs/mladek
 public function execute()
 {
     Doctrine::generateModelsFromDb($this->getArgument('models_path'), (array) $this->getArgument('connection'));
     $this->dispatcher->notify('Generated models successfully from databases');
 }
コード例 #11
0
ファイル: generateModelFromSQL.php プロジェクト: nachovz/EAC
$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));
コード例 #12
0
<?php

include '../core/codon.config.php';
Doctrine::generateModelsFromDb(DOCTRINE_MODELS, array('doctrine'), array('generateTableClasses' => true));
コード例 #13
0
ファイル: Doctrine.php プロジェクト: kirvin/the-nerdery
 /**
  * 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;
 }
コード例 #14
0
ファイル: Builder.php プロジェクト: prismhdd/victorioussecret
 /**
  * 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;
 }
コード例 #15
0
#!/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);
コード例 #16
0
ファイル: Doctrine.php プロジェクト: OmondiKevin/ADT_MTRH
 /**
  * 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;
 }
コード例 #17
0
<?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();
}