From 18ebac87cab135e21e2bf8e0cca5cc3c40ad2be3 Mon Sep 17 00:00:00 2001 From: colemanw Date: Fri, 15 Dec 2023 19:06:12 -0500 Subject: [PATCH] DAO - Remove fieldKeys(), getLog() and getTableName() from template In 2020, 9d89b14 added these functions to the base class, effectively making them redundant in the generated DAO files. But out of an abundance of caution, they were not immediatetly removed from the DAO template. This was so that extensions that generate DAOs with civix (which uses the same template from core) would not immediately lose backward-compat with prior versions of Civi. At this point enough time has gone by. The functions were added to 5.31 which is quite a few ESR-releases old now. Any extension wishing to generate DAO files compatible with versions < 5.31 can do so by using an older version of core when running civix:generate. --- CRM/Core/DAO.php | 5 +++-- xml/templates/dao.tpl | 35 ----------------------------------- 2 files changed, 3 insertions(+), 37 deletions(-) diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index bb6fcada9f..9735820e2c 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -3354,10 +3354,11 @@ SELECT contact_id * Return a mapping from field-name to the corresponding key (as used in fields()). * * @return array - * Array(string $name => string $uniqueName). + * [string $name => string $uniqueName] */ public static function fieldKeys() { - return array_flip(CRM_Utils_Array::collect('name', static::fields())); + $fields = static::fields(); + return array_combine(array_column($fields, 'name'), array_keys($fields)); } /** diff --git a/xml/templates/dao.tpl b/xml/templates/dao.tpl index d56d62fcec..0432e69b67 100644 --- a/xml/templates/dao.tpl +++ b/xml/templates/dao.tpl @@ -253,41 +253,6 @@ class {$table.className} extends CRM_Core_DAO {ldelim} return Civi::$statics[__CLASS__]['fields']; {rdelim} - /** - * 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( ) {ldelim} - if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {ldelim} - Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields())); - {rdelim} - return Civi::$statics[__CLASS__]['fieldKeys']; - {rdelim} - - /** - * Returns the names of this table - * - * @return string - */ - public static function getTableName( ) {ldelim} - {if $table.localizable} - return CRM_Core_DAO::getLocaleTableName( self::$_tableName ); - {else} - return self::$_tableName; - {/if} - {rdelim} - - /** - * Returns if this table needs to be logged - * - * @return bool - */ - public function getLog( ) {ldelim} - return self::$_log; - {rdelim} - /** * Returns the list of fields that can be imported * -- 2.25.1