From b97dd4ec75ea4f4dfd13070205e1e7f1e016e06c Mon Sep 17 00:00:00 2001 From: kurund Date: Fri, 21 Feb 2014 16:13:25 +0530 Subject: [PATCH] CRM-14241, more fixes to entity generation ---------------------------------------- * CRM-14241: setup new repo for doctrine integration work http://issues.civicrm.org/jira/browse/CRM-14241 --- CRM/Core/CodeGen/EntitySpecification.php | 41 ++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/CRM/Core/CodeGen/EntitySpecification.php b/CRM/Core/CodeGen/EntitySpecification.php index 5da3fccae8..ba2c412096 100644 --- a/CRM/Core/CodeGen/EntitySpecification.php +++ b/CRM/Core/CodeGen/EntitySpecification.php @@ -75,10 +75,35 @@ class CRM_Core_CodeGen_EntitySpecification { } function getTables($dbXML, &$database) { + // skip entity generation for tables where manual changes are needed. + $skipTables = array( + 'civicrm_acl_entity_role', + 'civicrm_action_log', + 'civicrm_campaign_group', + 'civicrm_entity_batch', + 'civicrm_entity_file', + 'civicrm_entity_financial_account', + 'civicrm_entity_financial_trxn', + 'civicrm_entity_tag', + 'civicrm_line_item', + 'civicrm_log', + 'civicrm_mailing_group', + 'civicrm_note', + 'civicrm_pcp_block', + 'civicrm_pledge_block', + 'civicrm_prevnext_cache', + 'civicrm_price_set_entity', + 'civicrm_tell_friend', + 'civicrm_uf_join', + ); + $tables = array(); foreach ($dbXML->tables as $tablesXML) { foreach ($tablesXML->table as $tableXML) { - if ($this->value('drop', $tableXML, 0) > 0 and $this->value('drop', $tableXML, 0) <= $this->buildVersion) { + if (($this->value('drop', $tableXML, 0) > 0 AND $this->value('drop', $tableXML, 0) <= $this->buildVersion) + OR in_array($tableXML->name, $skipTables) + ) { + echo "Skipping entity generation for " .$tableXML->name . "\n"; continue; } @@ -118,7 +143,13 @@ class CRM_Core_CodeGen_EntitySpecification { $targetEntity = str_replace('CRM', 'Civi', str_replace('_', '\\', $classNames[$ftable])); $tables[$name]['fields'][$fkey]['columnType'] = '\\' . $targetEntity; $tables[$name]['fields'][$fkey]['columnInfo'] = '@ORM\ManyToOne(targetEntity="' . $targetEntity . '")'; - $tables[$name]['fields'][$fkey]['columnJoin'] = '@ORM\JoinColumns({@ORM\JoinColumn(name="' . $tables[$name]['foreignKey'][$fkey]['name'] . '", referencedColumnName="' . $tables[$name]['foreignKey'][$fkey]['key'] . '")})'; + $tables[$name]['fields'][$fkey]['columnJoin'] = '@ORM\JoinColumns({@ORM\JoinColumn(name="' . $tables[$name]['foreignKey'][$fkey]['name'] . '", referencedColumnName="' . $tables[$name]['foreignKey'][$fkey]['key'] . '"'; + + if (!empty($tables[$name]['foreignKey'][$fkey]['onDelete'])) { + $tables[$name]['fields'][$fkey]['columnJoin'] .= ', onDelete="' . $tables[$name]['foreignKey'][$fkey]['onDelete'] . '"'; + } + + $tables[$name]['fields'][$fkey]['columnJoin'] .= ')})'; $tables[$name]['fields'][$fkey]['setFunctionInput'] = "{$tables[$name]['fields'][$fkey]['columnType']} \${$tables[$name]['fields'][$fkey]['propertyName']} = null"; } @@ -215,12 +246,16 @@ class CRM_Core_CodeGen_EntitySpecification { $field['columnInfo'] .= ', nullable=true'; } + if (!empty($field['default'])) { + $field['default'] = str_replace("'", "", $field['default']); + } + $field['columnInfo'] .= ')'; $field['columnType'] = $field['phpType']; $field['columnJoin'] = ''; - $field['setFunctionInput'] = $field['propertyName']; + $field['setFunctionInput'] = '$' . $field['propertyName']; } if ($this->value('primaryKey', $tableXML)) { -- 2.25.1