From: kurund Date: Thu, 20 Feb 2014 07:32:24 +0000 (+0530) Subject: CRM-14241, fixes to generate both DAO and entities X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b972ac60d38af42dd73e97270f7739068dc91fa2;p=civicrm-core.git CRM-14241, fixes to generate both DAO and entities ---------------------------------------- * CRM-14241: setup new repo for doctrine integration work http://issues.civicrm.org/jira/browse/CRM-14241 --- diff --git a/CRM/Core/CodeGen/DAO.php b/CRM/Core/CodeGen/DAO.php index 5ee51d9c0b..6b31f04406 100644 --- a/CRM/Core/CodeGen/DAO.php +++ b/CRM/Core/CodeGen/DAO.php @@ -10,7 +10,7 @@ class CRM_Core_CodeGen_DAO extends CRM_Core_CodeGen_BaseTask { function generateDAOs() { foreach (array_keys($this->tables) as $name) { - echo "Generating $name as " . $this->tables[$name]['fileName'] . "\n"; + echo "Generating DAO " . $this->tables[$name]['fileName'] . " for $name \n"; if (empty($this->tables[$name]['base'])) { echo "No base defined for $name, skipping output generation\n"; diff --git a/CRM/Core/CodeGen/Entity.php b/CRM/Core/CodeGen/Entity.php index 2b8afb62e2..e1ccc3c037 100644 --- a/CRM/Core/CodeGen/Entity.php +++ b/CRM/Core/CodeGen/Entity.php @@ -1,7 +1,7 @@ tables) as $name) { - echo "Generating $name as " . $this->tables[$name]['fileName'] . "\n"; + echo "Generating entity " . $this->tables[$name]['fileName'] ." for $name \n"; if (empty($this->tables[$name]['base'])) { echo "No base defined for $name, skipping output generation\n"; continue; } - $template = new CRM_Core_CodeGen_Util_Template('php'); + $template = new CRM_Core_CodeGen_Util_Template(''); $template->assign('table', $this->tables[$name]); $directory = $this->config->phpCodePath . $this->tables[$name]['base']; diff --git a/CRM/Core/CodeGen/EntitySpecification.php b/CRM/Core/CodeGen/EntitySpecification.php index ab009fa086..b9b1d83095 100644 --- a/CRM/Core/CodeGen/EntitySpecification.php +++ b/CRM/Core/CodeGen/EntitySpecification.php @@ -152,7 +152,6 @@ class CRM_Core_CodeGen_EntitySpecification { $klass = trim((string ) $tableXML->class); $base = $this->value('base', $tableXML); $sourceFile = "xml/schema/{$base}/{$klass}.xml"; - //$daoPath = "{$base}/DAO/"; $daoPath = "{$base}" . DIRECTORY_SEPARATOR; $pre = str_replace('/', '_', $daoPath); $this->classNames[$name] = $pre . $klass; @@ -167,13 +166,11 @@ class CRM_Core_CodeGen_EntitySpecification { $table = array( 'name' => $name, - //'base' => $daoPath, - 'base' => 'src2'. DIRECTORY_SEPARATOR .str_replace('CRM', 'Civi', $daoPath), + 'base' => str_replace('CRM', 'Civi', $daoPath), 'sourceFile' => $sourceFile, 'fileName' => $klass . '.php', 'objectName' => $klass, 'labelName' => substr($name, 8), - //'className' => $this->classNames[$name], 'className' => $klass, 'attributes_simple' => trim($database['tableAttributes_simple']), 'attributes_modern' => trim($database['tableAttributes_modern']), diff --git a/CRM/Core/CodeGen/Main.php b/CRM/Core/CodeGen/Main.php index fd0a2167f1..30de693f35 100644 --- a/CRM/Core/CodeGen/Main.php +++ b/CRM/Core/CodeGen/Main.php @@ -78,13 +78,7 @@ Alternatively you can get a version of CiviCRM that matches your PHP version exit(); } - if (defined('CIVICRM_GEN_ENTITY') && CIVICRM_GEN_ENTITY) { - $specification = new CRM_Core_CodeGen_EntitySpecification(); - } - else { - $specification = new CRM_Core_CodeGen_Specification(); - } - + $specification = new CRM_Core_CodeGen_Specification(); $specification->parse($this->schemaPath, $this->buildVersion); # cheese: $this->database = $specification->database; @@ -101,6 +95,14 @@ Alternatively you can get a version of CiviCRM that matches your PHP version // TODO: This configuration can be manipulated dynamically. $components = $this->getTasks(); foreach ($components as $component) { + // special handling for entity generation + if ($component == 'CRM_Core_CodeGen_Entity') { + $specification = new CRM_Core_CodeGen_EntitySpecification(); + $specification->parse($this->schemaPath, $this->buildVersion); + $this->database = $specification->database; + $this->tables = $specification->tables; + } + $task = new $component($this); if (is_a($task, 'CRM_Core_CodeGen_ITask')) { @@ -122,9 +124,9 @@ Alternatively you can get a version of CiviCRM that matches your PHP version 'CRM_Core_CodeGen_Reflection', 'CRM_Core_CodeGen_Schema', 'CRM_Core_CodeGen_DAO', - 'CRM_Core_CodeGen_Entity', 'CRM_Core_CodeGen_Test', 'CRM_Core_CodeGen_I18n', + 'CRM_Core_CodeGen_Entity', ); return $components; } diff --git a/xml/GenCode.php b/xml/GenCode.php index d3d4ff1762..285582a9c0 100644 --- a/xml/GenCode.php +++ b/xml/GenCode.php @@ -17,9 +17,6 @@ date_default_timezone_set('UTC'); // avoid php warnings if timezone is not set - define('CIVICRM_UF', 'Drupal'); -// this should be true if you want to generate entities instead of DAO -define('CIVICRM_GEN_ENTITY', FALSE); - require_once 'CRM/Core/ClassLoader.php'; CRM_Core_ClassLoader::singleton()->register();