From 7db08f5064b67dccf1ee25e356c219e9355b65f7 Mon Sep 17 00:00:00 2001 From: Aidan Saunders Date: Wed, 5 Apr 2017 13:19:50 +1200 Subject: [PATCH] CRM-20312 add field localisation data to DAO. Towards index reconciliation --- CRM/Core/CodeGen/DAO.php | 1 + CRM/Core/CodeGen/Specification.php | 6 +----- tests/phpunit/CRM/Core/DAO/AllCoreTablesTest.php | 5 +++++ xml/templates/dao.tpl | 1 + 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CRM/Core/CodeGen/DAO.php b/CRM/Core/CodeGen/DAO.php index 8db0b9d36b..83c2c449d7 100644 --- a/CRM/Core/CodeGen/DAO.php +++ b/CRM/Core/CodeGen/DAO.php @@ -109,6 +109,7 @@ class CRM_Core_CodeGen_DAO extends CRM_Core_CodeGen_BaseTask { */ protected function getTableChecksum() { if (!$this->tableChecksum) { + $flat = array(); CRM_Utils_Array::flatten($this->tables[$this->name], $flat); ksort($flat); $this->tableChecksum = md5(json_encode($flat)); diff --git a/CRM/Core/CodeGen/Specification.php b/CRM/Core/CodeGen/Specification.php index f4333ec338..34d43015f0 100644 --- a/CRM/Core/CodeGen/Specification.php +++ b/CRM/Core/CodeGen/Specification.php @@ -248,7 +248,6 @@ class CRM_Core_CodeGen_Specification { if ($this->value('foreignKey', $tableXML)) { $foreign = array(); foreach ($tableXML->foreignKey as $foreignXML) { - // print_r($foreignXML); if ($this->value('drop', $foreignXML, 0) > 0 and $this->value('drop', $foreignXML, 0) <= $this->buildVersion) { continue; @@ -282,7 +281,7 @@ class CRM_Core_CodeGen_Specification { */ public function getField(&$fieldXML, &$fields) { $name = trim((string ) $fieldXML->name); - $field = array('name' => $name, 'localizable' => $fieldXML->localizable); + $field = array('name' => $name, 'localizable' => ((bool) $fieldXML->localizable) ? 1 : 0); $type = (string ) $fieldXML->type; switch ($type) { case 'varchar': @@ -554,9 +553,6 @@ class CRM_Core_CodeGen_Specification { $index['unique'] = TRUE; } - //echo "\$index = \n"; - //print_r($index); - // field array cannot be empty if (empty($index['field'])) { echo "No fields defined for index $indexName\n"; diff --git a/tests/phpunit/CRM/Core/DAO/AllCoreTablesTest.php b/tests/phpunit/CRM/Core/DAO/AllCoreTablesTest.php index ab9819b37b..e93c8b1d79 100644 --- a/tests/phpunit/CRM/Core/DAO/AllCoreTablesTest.php +++ b/tests/phpunit/CRM/Core/DAO/AllCoreTablesTest.php @@ -35,6 +35,11 @@ class CRM_Core_DAO_AllCoreTablesTest extends CiviUnitTestCase { $this->assertTrue(is_array($exports['contact_id'])); } + /** + * Implements hook_civicrm_entityTypes(). + * + * @param array $entityTypes + */ public function _hook_civicrm_entityTypes(&$entityTypes) { $entityTypes['CRM_Core_DAO_Email']['fields_callback'][] = function ($class, &$fields) { $fields['location_type_id']['foo'] = 'bar'; diff --git a/xml/templates/dao.tpl b/xml/templates/dao.tpl index c38b82441e..22720d039a 100644 --- a/xml/templates/dao.tpl +++ b/xml/templates/dao.tpl @@ -166,6 +166,7 @@ class {$table.className} extends CRM_Core_DAO {ldelim} 'table_name' => '{$table.name}', 'entity' => '{$table.entity}', 'bao' => '{$table.bao}', + 'localizable' => {if ($field.localizable)}{1}{else}{0}{/if}, {if $field.FKClassName} 'FKClassName' => '{$field.FKClassName}', -- 2.25.1