CRM-14241, fixes to generate both DAO and entities
authorkurund <kurund@civicrm.org>
Thu, 20 Feb 2014 07:32:24 +0000 (13:02 +0530)
committerkurund <kurund@civicrm.org>
Thu, 20 Feb 2014 07:32:24 +0000 (13:02 +0530)
----------------------------------------
* CRM-14241: setup new repo for doctrine integration work
  http://issues.civicrm.org/jira/browse/CRM-14241

CRM/Core/CodeGen/DAO.php
CRM/Core/CodeGen/Entity.php
CRM/Core/CodeGen/EntitySpecification.php
CRM/Core/CodeGen/Main.php
xml/GenCode.php

index 5ee51d9c0ba4b5b96786bb30d9536407a71097cb..6b31f0440654e77b6802f57f4c8855aeecc17556 100644 (file)
@@ -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";
index 2b8afb62e2dd20e0fd1978aeabf624dce852f13f..e1ccc3c0370bbce5390c6d53f78db55bebcfbe04 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * Create DAO ORM classes.
+ * Create ORM entities
  */
 class CRM_Core_CodeGen_Entity extends CRM_Core_CodeGen_BaseTask {
   function run() {
@@ -10,14 +10,14 @@ class CRM_Core_CodeGen_Entity extends CRM_Core_CodeGen_BaseTask {
 
   function generateEntitys() {
     foreach (array_keys($this->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'];
index ab009fa086d0309794def23f2f0ffeadf8a3e169..b9b1d83095af67c11a5c6c62bcc0a4314a363e7c 100644 (file)
@@ -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']),
index fd0a2167f1c5c8ff41cf6dbb084ee99c3625f67a..30de693f35cb15f725aae4500728b0f0f4d13994 100644 (file)
@@ -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;
   }
index d3d4ff17624829321c0fd2d0e4ac829ceacf59a1..285582a9c07b7d519f4c34274b6790086bd5803f 100644 (file)
@@ -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();