aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/db
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-04-14 17:21:53 +0200
committerJoas Schilling <nickvergessen@gmx.de>2014-04-17 11:35:09 +0200
commit7dc163f2b7f483e4abb46015c0e41b47cddfd757 (patch)
tree8341aec552f9717433faa93c9795a96de703ef3d /phpBB/phpbb/db
parent540384890258a22860d655086521c968b30bcbea (diff)
downloadforums-7dc163f2b7f483e4abb46015c0e41b47cddfd757.tar
forums-7dc163f2b7f483e4abb46015c0e41b47cddfd757.tar.gz
forums-7dc163f2b7f483e4abb46015c0e41b47cddfd757.tar.bz2
forums-7dc163f2b7f483e4abb46015c0e41b47cddfd757.tar.xz
forums-7dc163f2b7f483e4abb46015c0e41b47cddfd757.zip
[ticket/12012] Drop and recreate indexes when removing columns
PHPBB3-12012
Diffstat (limited to 'phpBB/phpbb/db')
-rw-r--r--phpBB/phpbb/db/tools.php35
1 files changed, 33 insertions, 2 deletions
diff --git a/phpBB/phpbb/db/tools.php b/phpBB/phpbb/db/tools.php
index 113059900a..bc505010ba 100644
--- a/phpBB/phpbb/db/tools.php
+++ b/phpBB/phpbb/db/tools.php
@@ -1846,15 +1846,46 @@ class tools
case 'mssql':
case 'mssqlnative':
+ // We need the data here
+ $old_return_statements = $this->return_statements;
+ $this->return_statements = true;
+
$indexes = $this->mssql_get_existing_indexes($table_name, $column_name);
+ // Drop any indexes
+ $recreate_indexes = array();
if (!empty($indexes))
{
- trigger_error("Column '$column_name' on table '$table_name' is still part of an index and can not be removed: " . implode(', ', array_keys($indexes)), E_USER_ERROR);
+ foreach ($indexes as $index_name => $index_data)
+ {
+ $result = $this->sql_index_drop($table_name, $index_name);
+ $statements = array_merge($statements, $result);
+ if (sizeof($index_data) > 1)
+ {
+ // Remove this column from the index and recreate it
+ $recreate_indexes[$index_name] = array_diff($index_data, array($column_name));
+ }
+ }
}
- $statements = $this->mssql_drop_default_constraints($table_name, $column_name);
+ // Drop default value constraint
+ $result = $this->mssql_drop_default_constraints($table_name, $column_name);
+ $statements = array_merge($statements, $result);
+
+ // Remove the column
$statements[] = 'ALTER TABLE [' . $table_name . '] DROP COLUMN [' . $column_name . ']';
+
+ if (!empty($recreate_indexes))
+ {
+ // Recreate indexes after we removed the column
+ foreach ($recreate_indexes as $index_name => $index_data)
+ {
+ $result = $this->sql_create_index($table_name, $index_name, $index_data);
+ $statements = array_merge($statements, $result);
+ }
+ }
+
+ $this->return_statements = $old_return_statements;
break;
case 'mysql_40':