From 4d1d7aca9c440dca7d021bf419c384543e0cd3aa Mon Sep 17 00:00:00 2001 From: Adam Roses Wight Date: Tue, 23 Apr 2013 16:56:57 -0700 Subject: [PATCH] Maintain a list of core DAOs This is an improvement on CRM/Core/DAO/listAll.php, wrapping in a class and making the table names available as well. --- api/api.php | 6 +--- api/v3/utils.php | 7 +---- xml/GenCode.php | 19 ++---------- xml/templates/listAll.tpl | 63 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 27 deletions(-) create mode 100644 xml/templates/listAll.tpl diff --git a/api/api.php b/api/api.php index 84f0a99330..00cb2ea3da 100644 --- a/api/api.php +++ b/api/api.php @@ -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_DAO_AllCoreTables::getFullName($daoName)); } diff --git a/api/v3/utils.php b/api/v3/utils.php index e1d468d714..255a9cf4c4 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -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_DAO_AllCoreTables::getFullName(_civicrm_api_get_camel_name($name, 3)); } /** diff --git a/xml/GenCode.php b/xml/GenCode.php index 2306149725..bd892066df 100644 --- a/xml/GenCode.php +++ b/xml/GenCode.php @@ -187,22 +187,9 @@ Alternatively you can get a version of CiviCRM that matches your PHP version } function generateListAll($tables) { - $allDAO = "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 index 0000000000..f461779834 --- /dev/null +++ b/xml/templates/listAll.tpl @@ -0,0 +1,63 @@ + '{$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 getFullName($daoName) {ldelim} + return CRM_Utils_Array::value($daoName, self::$daoToClass); + {rdelim} + +{rdelim} -- 2.25.1