From 2dc389c936eb22fbb3e74b86c51501059fd5c1a6 Mon Sep 17 00:00:00 2001 From: BorisBerdichevski Date: Sun, 15 Jun 2014 14:15:42 -0500 Subject: [ticket/12643] Ensure that similarly named columns are not removed PHPBB3-12643 --- phpBB/phpbb/db/tools.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB') diff --git a/phpBB/phpbb/db/tools.php b/phpBB/phpbb/db/tools.php index 3d065ede8e..3b329b47bc 100644 --- a/phpBB/phpbb/db/tools.php +++ b/phpBB/phpbb/db/tools.php @@ -1996,7 +1996,7 @@ class tools $columns = implode(',', $column_list); - $new_table_cols = trim(preg_replace('/' . $column_name . '[^,]+(?:,|$)/m', '', $new_table_cols)); + $new_table_cols = trim(preg_replace('/' . $column_name . '\b[^,]+(?:,|$)/m', '', $new_table_cols)); if (substr($new_table_cols, -1) === ',') { // Remove the comma from the last entry again -- cgit v1.2.1 From 754e36e378e9d5d744fcfd6d447bd1e48d2052c3 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Sun, 15 Jun 2014 14:52:05 -0500 Subject: [ticket/12643] Properly handle changing columns on tables with constraints PHPBB3-12643 --- phpBB/phpbb/db/tools.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'phpBB') diff --git a/phpBB/phpbb/db/tools.php b/phpBB/phpbb/db/tools.php index 3b329b47bc..2ee842eace 100644 --- a/phpBB/phpbb/db/tools.php +++ b/phpBB/phpbb/db/tools.php @@ -2561,7 +2561,18 @@ class tools foreach ($old_table_cols as $key => $declaration) { - $entities = preg_split('#\s+#', trim($declaration)); + $declaration = trim($declaration); + + // Check for the beginning of the constraint section and stop + if (preg_match('/[^\(]*\s*PRIMARY KEY\s+\(/', $declaration) || + preg_match('/[^\(]*\s*UNIQUE\s+\(/', $declaration) || + preg_match('/[^\(]*\s*FOREIGN KEY\s+\(/', $declaration) || + preg_match('/[^\(]*\s*CHECK\s+\(/', $declaration)) + { + break; + } + + $entities = preg_split('#\s+#', $declaration); $column_list[] = $entities[0]; if ($entities[0] == $column_name) { -- cgit v1.2.1