CRM-14885 - CRM_Core_CodeGen_DAO - Separate instances for each DAO file
authorTim Otten <totten@civicrm.org>
Wed, 27 Jul 2016 05:29:41 +0000 (22:29 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 28 Jul 2016 00:20:16 +0000 (17:20 -0700)
CRM/Core/CodeGen/DAO.php
CRM/Core/CodeGen/Main.php

index ea04ce845999517ef8f3dd02df365ad4e8d7de7d..13cffd5250d58bea5e897eb945aef4c53a8b7be0 100644 (file)
@@ -4,26 +4,33 @@
  * Create DAO ORM classes.
  */
 class CRM_Core_CodeGen_DAO extends CRM_Core_CodeGen_BaseTask {
-  public function run() {
-    $this->generateDAOs();
+
+  /**
+   * @var string
+   */
+  public $name;
+
+  public function __construct($config, $name) {
+    parent::__construct($config);
+    $this->name = $name;
   }
 
-  public function generateDAOs() {
-    foreach (array_keys($this->tables) as $name) {
-      echo "Generating $name as " . $this->tables[$name]['fileName'] . "\n";
+  public function run() {
+    $name = $this->name;
+    echo "Generating $name as " . $this->tables[$name]['fileName'] . "\n";
 
-      if (empty($this->tables[$name]['base'])) {
-        echo "No base defined for $name, skipping output generation\n";
-        continue;
-      }
+    if (empty($this->tables[$name]['base'])) {
+      echo "No base defined for $name, skipping output generation\n";
+      return;
+    }
 
-      $template = new CRM_Core_CodeGen_Util_Template('php');
-      $template->assign('table', $this->tables[$name]);
+    $template = new CRM_Core_CodeGen_Util_Template('php');
+    $template->assign('table', $this->tables[$name]);
 
-      $directory = $this->config->phpCodePath . $this->tables[$name]['base'];
-      CRM_Core_CodeGen_Util_File::createDir($directory);
+    $directory = $this->config->phpCodePath . $this->tables[$name]['base'];
+    CRM_Core_CodeGen_Util_File::createDir($directory);
 
-      $template->run('dao.tpl', $directory . $this->tables[$name]['fileName']);
-    }
+    $template->run('dao.tpl', $directory . $this->tables[$name]['fileName']);
   }
+
 }
index 99ce0e153a199ca3f6b2f9cca85bb591420580ad..0c3674fb9e106fb0b2aef23f76457050c308a051 100644 (file)
@@ -102,7 +102,9 @@ Alternatively you can get a version of CiviCRM that matches your PHP version
     $tasks[] = new CRM_Core_CodeGen_Config($this);
     $tasks[] = new CRM_Core_CodeGen_Reflection($this);
     $tasks[] = new CRM_Core_CodeGen_Schema($this);
-    $tasks[] = new CRM_Core_CodeGen_DAO($this);
+    foreach (array_keys($this->tables) as $name) {
+      $tasks[] = new CRM_Core_CodeGen_DAO($this, $name);
+    }
     $tasks[] = new CRM_Core_CodeGen_I18n($this);
     return $tasks;
   }