X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FCodeGen%2FSpecification.php;h=63119cf49eb5eadfce80ed25c50b95116013af18;hb=2a5c9b4d3d8c7ec41d930979cfe21921e5b4b4cf;hp=2a94606859b04cf3beefd79a7ac5506379ce0bd6;hpb=d1c80ef846ab873f75b9eedbddf6a9dba70526d2;p=civicrm-core.git diff --git a/CRM/Core/CodeGen/Specification.php b/CRM/Core/CodeGen/Specification.php index 2a94606859..63119cf49e 100644 --- a/CRM/Core/CodeGen/Specification.php +++ b/CRM/Core/CodeGen/Specification.php @@ -242,13 +242,13 @@ class CRM_Core_CodeGen_Specification { $this->getIndex($indexXML, $fields, $index); } + CRM_Core_BAO_SchemaHandler::addIndexSignature($name, $index); $table['index'] = &$index; } 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 +282,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': @@ -361,6 +361,7 @@ class CRM_Core_CodeGen_Specification { $field['headerPattern'] = $this->value('headerPattern', $fieldXML); $field['dataPattern'] = $this->value('dataPattern', $fieldXML); $field['uniqueName'] = $this->value('uniqueName', $fieldXML); + $field['serialize'] = $this->value('serialize', $fieldXML); $field['html'] = $this->value('html', $fieldXML); if (!empty($field['html'])) { $validOptions = array( @@ -463,26 +464,56 @@ class CRM_Core_CodeGen_Specification { } /** - * @param $primaryXML - * @param $fields - * @param $table + * @param object $primaryXML + * @param array $fields + * @param array $table */ public function getPrimaryKey(&$primaryXML, &$fields, &$table) { $name = trim((string ) $primaryXML->name); - /** need to make sure there is a field of type name */ - if (!array_key_exists($name, $fields)) { - echo "primary key $name in $table->name does not have a field definition, ignoring\n"; - return; - } - // set the autoincrement property of the field $auto = $this->value('autoincrement', $primaryXML); + if (isset($fields[$name])) { + $fields[$name]['autoincrement'] = $auto; + } $fields[$name]['autoincrement'] = $auto; $primaryKey = array( 'name' => $name, 'autoincrement' => $auto, ); + + // populate fields + foreach ($primaryXML->fieldName as $v) { + $fieldName = (string) ($v); + $length = (string) ($v['length']); + if (strlen($length) > 0) { + $fieldName = "$fieldName($length)"; + } + $primaryKey['field'][] = $fieldName; + } + + // when field array is empty set it to the name of the primary key. + if (empty($primaryKey['field'])) { + $primaryKey['field'][] = $name; + } + + // all fieldnames have to be defined and should exist in schema. + foreach ($primaryKey['field'] as $fieldName) { + if (!$fieldName) { + echo "Invalid field defination for index $name\n"; + return; + } + $parenOffset = strpos($fieldName, '('); + if ($parenOffset > 0) { + $fieldName = substr($fieldName, 0, $parenOffset); + } + if (!array_key_exists($fieldName, $fields)) { + echo "Table does not contain $fieldName\n"; + print_r($fields); + exit(); + } + } + $table['primaryKey'] = &$primaryKey; } @@ -524,9 +555,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";