コード例 #1
0
 /**
  * Rebuilds a db as described by the doctrine models
  *
  */
 public function buildDBFromModels()
 {
     $icinga = $this->project->getUserProperty("PATH_Icinga");
     $modelPath = $icinga . "/app/modules/" . $this->project->getUserProperty("MODULE_Name") . "/lib/";
     $appKitPath = $this->project->getUserProperty("PATH_AppKit");
     Doctrine::loadModels($icinga . "/" . $appKitPath . "database/models/generated/");
     Doctrine::loadModel($icinga . "/" . $appKitPath . "database/models/");
     $tables = Doctrine::getLoadedModels();
     $tableList = array();
     foreach ($tables as $table) {
         $tableList[] = Doctrine::getTable($table)->getTableName();
     }
     Doctrine::createTablesFromModels(array($this->models . '/generated', $this->models));
     file_put_contents($modelPath . "/.models.cfg", implode(",", $tableList));
 }
コード例 #2
0
ファイル: AllTests.php プロジェクト: rdohms/ugDirectory
 public function setUp()
 {
     try {
         //Load path configs
         $root_path = str_replace('test', '', dirname(__FILE__));
         $docCfg = Zend_Registry::get('config')->doctrine->toArray();
         foreach ($docCfg as &$cfg) {
             $cfg = str_replace("{ROOT_PATH}", $root_path, $cfg);
         }
         //Generate Database structure for tests
         $this->tearDown();
         Doctrine::createDatabases();
         Doctrine::createTablesFromModels($docCfg['models_path']);
         Doctrine::loadModel($docCfg['models_path']);
         Doctrine::loadData($docCfg['data_fixtures_path']);
         Util_Log::get()->UnitTests()->debug('Executed Env SetUp');
     } catch (Exception $e) {
         Util_Log::get()->UnitTests()->debug('Failed Setting up environment');
         Util_Log::get()->UnitTests()->err($e->getMessage());
     }
 }
コード例 #3
0
ファイル: Builder.php プロジェクト: silky/littlesis
 /**
  * writeDefinition
  *
  * @param array $options
  * @param array $columns
  * @param array $relations
  * @param array $indexes
  * @param array $attributes
  * @param array $templates
  * @param array $actAs
  * @return void
  */
 public function writeDefinition(array $definition)
 {
     $definitionCode = $this->buildDefinition($definition);
     $fileName = $definition['className'] . $this->_suffix;
     $packagesPath = $this->_packagesPath ? $this->_packagesPath : $this->_path;
     // If this is a main class that either extends from Base or Package class
     if (isset($definition['is_main_class']) && $definition['is_main_class']) {
         // If is package then we need to put it in a package subfolder
         if (isset($definition['is_package']) && $definition['is_package']) {
             $writePath = $this->_path . DIRECTORY_SEPARATOR . $definition['package_name'];
             // Otherwise lets just put it in the root of the path
         } else {
             $writePath = $this->_path;
         }
         if ($this->generateTableClasses()) {
             $this->writeTableDefinition($definition['tableClassName'], $writePath, array('extends' => $definition['inheritance']['tableExtends']));
         }
     } else {
         if (isset($definition['is_package_class']) && $definition['is_package_class']) {
             if (isset($definition['package_custom_path'])) {
                 $writePath = $definition['package_custom_path'];
             } else {
                 $writePath = $packagesPath . DIRECTORY_SEPARATOR . $definition['package_path'];
             }
             if ($this->generateTableClasses()) {
                 $this->writeTableDefinition($definition['tableClassName'], $writePath, array('extends' => $definition['inheritance']['tableExtends']));
             }
         } else {
             if (isset($definition['is_base_class']) && $definition['is_base_class']) {
                 // If it is a part of a package then we need to put it in a package subfolder
                 if (isset($definition['is_package']) && $definition['is_package']) {
                     $basePath = $this->_path . DIRECTORY_SEPARATOR . $definition['package_name'];
                     $writePath = $basePath . DIRECTORY_SEPARATOR . $this->_baseClassesDirectory;
                     // Otherwise lets just put it in the root generated folder
                 } else {
                     $writePath = $this->_path . DIRECTORY_SEPARATOR . $this->_baseClassesDirectory;
                 }
             }
         }
     }
     // If we have a writePath from the if else conditionals above then use it
     if (isset($writePath)) {
         Doctrine_Lib::makeDirectories($writePath);
         $writePath .= DIRECTORY_SEPARATOR . $fileName;
         // Otherwise none of the conditions were met and we aren't generating base classes
     } else {
         Doctrine_Lib::makeDirectories($this->_path);
         $writePath = $this->_path . DIRECTORY_SEPARATOR . $fileName;
     }
     $code = "<?php" . PHP_EOL;
     if (isset($definition['connection']) && $definition['connection']) {
         $code .= "// Connection Component Binding" . PHP_EOL;
         $code .= "Doctrine_Manager::getInstance()->bindComponent('" . $definition['connectionClassName'] . "', '" . $definition['connection'] . "');" . PHP_EOL;
     }
     $code .= PHP_EOL . $definitionCode;
     if (isset($definition['generate_once']) && $definition['generate_once'] === true) {
         if (!file_exists($writePath)) {
             $bytes = file_put_contents($writePath, $code);
         }
     } else {
         $bytes = file_put_contents($writePath, $code);
     }
     if (isset($bytes) && $bytes === false) {
         throw new Doctrine_Import_Builder_Exception("Couldn't write file " . $writePath);
     }
     Doctrine::loadModel($definition['className'], $writePath);
 }
コード例 #4
0
ファイル: DoctrineTool.php プロジェクト: KasaiDot/FansubCMS
 /**
  * Let doctrine load its models
  * 
  * @return void
  */
 protected function _loadDoctrineModels()
 {
     $models = $this->_getModels();
     foreach ($models as $model) {
         $cleanModel = str_replace($this->getModulePath() . DIRECTORY_SEPARATOR, '', $model);
         $cleanModel = str_replace('.php', '', $cleanModel);
         /*
          * 0 => modulename
          * 1 => models
          * 2 => model base name
          */
         $classnameParts = explode(DIRECTORY_SEPARATOR, $cleanModel);
         $classname = ucfirst($classnameParts[0]) . '_Model_' . $classnameParts[2];
         if (class_exists($classname) && is_subclass_of($classname, 'Doctrine_Record')) {
             Doctrine::loadModel($classname, $model);
         }
     }
 }