From df49d91f6796531933cae5b2279b95fead841a20 Mon Sep 17 00:00:00 2001 From: kurund Date: Thu, 12 Dec 2013 15:41:34 -0800 Subject: [PATCH] CRM-13938, added table info ---------------------------------------- * CRM-13938: Create Annotations for entity files http://issues.civicrm.org/jira/browse/CRM-13938 --- CRM/Core/CodeGen/EntitySpecification.php | 37 ++++++++++++++++++++++++ xml/templates/entity.tpl | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/CRM/Core/CodeGen/EntitySpecification.php b/CRM/Core/CodeGen/EntitySpecification.php index f4d194a0a6..6a701e5c25 100644 --- a/CRM/Core/CodeGen/EntitySpecification.php +++ b/CRM/Core/CodeGen/EntitySpecification.php @@ -262,6 +262,43 @@ class CRM_Core_CodeGen_EntitySpecification { $table['dynamicForeignKey'] = $dynamicForeign; } + // create tags for indexes + $table['indexes'] = ''; + $table['uniqueConstraints'] = ''; + $indexElements = array(); + if (!empty($table['index'])) { + $uniqueElements = array(); + foreach($table['index'] as $value) { + $indexElements[] = '@ORM\Index(name="' . $value['name'] . '", columns={"' . implode(',', $value['field']) . '"})'; + if (isset($value['unique'])) { + $uniqueElements[] = '@ORM\UniqueConstraint(name="' . $value['name'] . '", columns={"' . implode(',', $value['field']) . '"})'; + } + } + } + + // note that we explicitly create indexes for all foreign keys + if (!empty($table['foreignKey'])) { + foreach($table['foreignKey'] as $value) { + $indexElements[] = '@ORM\Index(name="' . $value['uniqName'] . '", columns={"' . $value['name'] . '"})'; + } + } + + //build table annotation + $tableInfo = '@ORM\Table(name="' . $name . '"'; + // add unique constraints if any + if (!empty($uniqueElements)) { + $tableInfo .= ', uniqueConstraints={' . implode(',', $uniqueElements) . '}'; + } + + // add indexes if any + if (!empty($uniqueElements)) { + $tableInfo .= ', indexes={' . implode(',', $indexElements) . '}'; + } + + $tableInfo .= ')'; + + $table['tableInfo'] = $tableInfo; + $tables[$name] = &$table; return; } diff --git a/xml/templates/entity.tpl b/xml/templates/entity.tpl index 6035a06422..74b97c4c52 100644 --- a/xml/templates/entity.tpl +++ b/xml/templates/entity.tpl @@ -41,7 +41,7 @@ use Doctrine\ORM\Mapping as ORM; /** * {$table.className} * - * @ORM\Table(name="{$table.name}", {literal}uniqueConstraints={@ORM\UniqueConstraint(name="UI_name", columns={"name"})}{/literal}) + * {$table.tableInfo} * @ORM\Entity */ class {$table.className} extends \Civi\Core\Entity {ldelim} -- 2.25.1