Maintain a list of core DAOs
authorAdam Roses Wight <awight@wikimedia.org>
Tue, 23 Apr 2013 23:56:57 +0000 (16:56 -0700)
committerAdam Roses Wight <awight@wikimedia.org>
Thu, 25 Apr 2013 18:05:56 +0000 (11:05 -0700)
This is an improvement on CRM/Core/DAO/listAll.php, wrapping in a class
and making the table names available as well.

.gitignore
api/api.php
api/v3/utils.php
xml/GenCode.php
xml/templates/listAll.tpl [new file with mode: 0644]

index c4c9f8f4604ca417e187c3c5ff3d81191eb16dc0..2a6a5f922fbb8432b22f2f70654b589c06b0cf1c 100644 (file)
@@ -20,6 +20,7 @@ CRM/Contact/DAO/RelationshipType.php
 CRM/Contact/DAO/SavedSearch.php
 CRM/Contact/DAO/SubscriptionHistory.php
 CRM/Contribute/DAO
+CRM/Core/AllCoreTables.php
 CRM/Core/DAO/.listAll.php
 CRM/Core/DAO/listAll.php
 CRM/Core/DAO/ActionLog.php
index 84f0a99330271d1c1d65c8400e1695c153354f52..a494d28635c0a5e283cfe07bc8d95057d1d6fc53 100644 (file)
@@ -540,11 +540,7 @@ function _civicrm_api_get_entity_name_from_camel($entity) {
  */
 function _civicrm_api_get_entity_name_from_dao($bao){
   $daoName = str_replace("BAO", "DAO", get_class($bao));
-  $dao = array();
-  require ('CRM/Core/DAO/listAll.php');
-  $daos = array_flip($dao);
-  return _civicrm_api_get_entity_name_from_camel($daos[$daoName]);
-
+  return _civicrm_api_get_entity_name_from_camel(CRM_Core_AllCoreTables::getFullName($daoName));
 }
 
 
index e1d468d714259f2a7ff7193429a40ff56516dffc..0fce1b7ccf6a2a253e0bace65665d08ae583e8ff 100644 (file)
@@ -269,11 +269,6 @@ function _civicrm_api3_load_DAO($entity) {
  * eg. "civicrm_api3_contact_create" or "Contact" will return "CRM_Contact_BAO_Contact"
  */
 function _civicrm_api3_get_DAO($name) {
-  static $dao = NULL;
-  if (!$dao) {
-    require ('CRM/Core/DAO/listAll.php');
-  }
-
   if (strpos($name, 'civicrm_api3') !== FALSE) {
     $last = strrpos($name, '_');
     // len ('civicrm_api3_') == 13
@@ -306,7 +301,7 @@ function _civicrm_api3_get_DAO($name) {
   }
 
 
-  return CRM_Utils_Array::value(_civicrm_api_get_camel_name($name, 3), $dao);
+  return CRM_Core_AllCoreTables::getFullName(_civicrm_api_get_camel_name($name, 3));
 }
 
 /**
index 2306149725bdcc9bff382f42e0eae00427b338d2..70a2f4bbafbb14dc94bd6517db6a9de27dc44358 100644 (file)
@@ -187,22 +187,9 @@ Alternatively you can get a version of CiviCRM that matches your PHP version
   }
 
   function generateListAll($tables) {
-    $allDAO = "<?php\n\$dao = array ();";
-    $dao = array();
-
-    foreach ($tables as $table) {
-      $base = $table['base'] . $table['objectName'];
-      if (!array_key_exists($table['objectName'], $dao)) {
-        $dao[$table['objectName']] = str_replace('/', '_', $base);
-        $allDAO .= "\n\$dao['" . $table['objectName'] . "'] = '" . str_replace('/', '_', $base) . "';";
-      }
-      else {
-        $allDAO .= "\n//NAMESPACE ERROR: " . $table['objectName'] . " already used . " . str_replace('/', '_', $base) . " ignored.";
-      }
-    }
-
-    // TODO deal with the BAO's too ?
-    file_put_contents($this->CoreDAOCodePath . "listAll.php", $allDAO);
+    $this->smarty->clear_all_assign();
+    $this->smarty->assign('tables', $tables);
+    file_put_contents($this->CoreDAOCodePath . "../AllCoreTables.php", $this->smarty->fetch('listAll.tpl'));
   }
 
   function generateCiviTestTruncate($tables) {
diff --git a/xml/templates/listAll.tpl b/xml/templates/listAll.tpl
new file mode 100644 (file)
index 0000000..ef29f7a
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.3                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ * $Id$
+ *
+ */
+
+class CRM_Core_AllCoreTables {ldelim}
+
+  static protected $tables = array(
+{foreach from=$tables key=tableName item=table}
+    '{$tableName}' => '{$table.className}',
+{/foreach} {* tables *}
+  );
+
+  static protected $daoToClass = array(
+{foreach from=$tables item=table}
+    '{$table.objectName}' => '{$table.className}',
+{/foreach} {* tables *}
+  );
+
+  static public function getCoreTables() {ldelim}
+    return self::$tables;
+  {rdelim}
+
+  static public function isCoreTable($tableName) {ldelim}
+    return FALSE !== array_search($tableName, self::$tables);
+  {rdelim}
+
+  static public function getClasses() {ldelim}
+    return array_values(self::$tables);
+  {rdelim}
+
+  static public function getClassForTable($tableName) {ldelim}
+    return CRM_Utils_Array::value($tableName, self::$tables);
+  {rdelim}
+
+  static public function getFullName($daoName) {ldelim}
+    return CRM_Utils_Array::value($daoName, self::$daoToClass);
+  {rdelim}
+
+{rdelim}