$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;
*/
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':
$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(
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;
}
$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";