From 9d89b14d9daeb7ab2a1b8df02434bc74cfec5938 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 16 Sep 2020 10:57:26 -0400 Subject: [PATCH] Ensure DAO base class contains functions to be removed from generated DAO files. The functions fieldKeys(), getLog(), and getTableName() are redundant in the generated DAO files, we don't need 50 copies of each function. This preliminary commit ensures they are present in the parent class, and in the future we can regenerate the DAOs without them. --- CRM/Core/DAO.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index ee3cfaeebb..f29b13cca9 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -147,10 +147,21 @@ class CRM_Core_DAO extends DB_DataObject { } /** - * Empty definition for virtual function. + * Returns the name of this table + * + * @return string */ public static function getTableName() { - return NULL; + return self::getLocaleTableName(static::$_tableName ?? NULL); + } + + /** + * Returns if this table needs to be logged + * + * @return bool + */ + public function getLog() { + return static::$_log ?? FALSE; } /** @@ -2727,11 +2738,11 @@ SELECT contact_id */ public function getFieldSpec($fieldName) { $fields = $this->fields(); - $fieldKeys = $this->fieldKeys(); // Support "unique names" as well as sql names $fieldKey = $fieldName; if (empty($fields[$fieldKey])) { + $fieldKeys = $this->fieldKeys(); $fieldKey = $fieldKeys[$fieldName] ?? NULL; } // If neither worked then this field doesn't exist. Return false. @@ -3130,4 +3141,14 @@ SELECT contact_id } } + /** + * Return a mapping from field-name to the corresponding key (as used in fields()). + * + * @return array + * Array(string $name => string $uniqueName). + */ + public static function fieldKeys() { + return array_flip(CRM_Utils_Array::collect('name', static::fields())); + } + } -- 2.25.1