From: Alex Barth
Date: Mon, 27 Jul 2009 17:21:02 +0000 (+0000)
Subject: Move data_alter_table() back into data_ui as it requires too specific arguments ...
X-Git-Tag: 6.x-1.0-alpha1~15
X-Git-Url: http://drupalcode.org/project/data.git/commitdiff_plain/7fa8a6aa6f45c5ef7550b2f1b466fa292188b11b
Move data_alter_table() back into data_ui as it requires too specific arguments - clearly a helper function.
---
diff --git a/data.module b/data.module
index 09ca8c5..d45a4b0 100644
--- a/data.module
+++ b/data.module
@@ -305,50 +305,6 @@ function data_build_index_array($field_name, $spec) {
}
/**
- * Helper function for adjusting a table's real schema.
- * @todo: this should live in schema module and should use better defined $reason keys.
- */
-function data_alter_table($table, $field, $reason) {
- $schema = $table->get('table_schema');
-
- switch ($reason) {
- case 'not in database':
- if (isset($schema['fields'][$field])) {
- return $table->addField($field, $schema['fields'][$field]);
- }
- return FALSE;
-
- case 'missing in database':
- list($type, $field) = explode(' ', $field);
- // @todo: support multiple keys.
- if ($type == 'indexes') {
- return $table->addIndex($field);
- }
- elseif ($type == 'unique keys') {
- return $table->addUniqueKey($field);
- }
- elseif ($type == 'primary key') {
- return $table->addPrimaryKey($schema['primary keys']);
- }
- return FALSE;
-
- case 'primary key:
declared': // @todo: yikes!
- $table->dropPrimaryKey();
- return $table->changePrimaryKey($schema['primary keys']);
- case 'missing in schema':
- if ($field == 'primary key') {
- return $table->dropPrimaryKey();
- }
- return FALSE;
-
- case 'unexpected column in database':
- return $this->dropField($field);
-
- }
- return FALSE;
-}
-
-/**
* Export a data table. This does not export the content of a table - only its schema
* and any meta information (title, name, meta...).
*
diff --git a/data_ui/data_ui.admin.inc b/data_ui/data_ui.admin.inc
index 16bde8a..e174556 100644
--- a/data_ui/data_ui.admin.inc
+++ b/data_ui/data_ui.admin.inc
@@ -167,8 +167,7 @@ function data_ui_adjust_form_submit_alter_table($form, &$form_state) {
$resolved = $resolved = array();
if (isset($form['#comparison']['reasons'])) {
foreach ($form['#comparison']['reasons'] as $field_reason) {
- list($field, $reason) = explode(': ', $field_reason);
- if (data_alter_table($form['#table'], $field, $reason)) {
+ if (_data_ui_alter_table($form['#table'], $field_reason)) {
$resolved[] = $field_reason;
}
else {
@@ -779,3 +778,48 @@ function _data_ui_get_join($join, $field) {
}
return FALSE;
}
+
+/**
+ * Helper function for adjusting a table's real schema.
+ * @todo: this should live in schema module and should use better defined $reason keys.
+ */
+function _data_ui_alter_table($table, $field_reason) {
+ list($field, $reason) = explode(': ', $field_reason);
+ $schema = $table->get('table_schema');
+
+ switch ($reason) {
+ case 'not in database':
+ if (isset($schema['fields'][$field])) {
+ return $table->addField($field, $schema['fields'][$field]);
+ }
+ return FALSE;
+
+ case 'missing in database':
+ list($type, $field) = explode(' ', $field);
+ // @todo: support multiple keys.
+ if ($type == 'indexes') {
+ return $table->addIndex($field);
+ }
+ elseif ($type == 'unique keys') {
+ return $table->addUniqueKey($field);
+ }
+ elseif ($type == 'primary key') {
+ return $table->addPrimaryKey($schema['primary keys']);
+ }
+ return FALSE;
+
+ case 'primary key:
declared': // @todo: yikes!
+ $table->dropPrimaryKey();
+ return $table->changePrimaryKey($schema['primary keys']);
+ case 'missing in schema':
+ if ($field == 'primary key') {
+ return $table->dropPrimaryKey();
+ }
+ return FALSE;
+
+ case 'unexpected column in database':
+ return $this->dropField($field);
+
+ }
+ return FALSE;
+}