aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r--phpBB/phpbb/db/migration/data/v32x/user_notifications_table_index_p1.php46
-rw-r--r--phpBB/phpbb/db/migration/data/v32x/user_notifications_table_index_p2.php46
-rw-r--r--phpBB/phpbb/db/migration/data/v32x/user_notifications_table_index_p3.php46
-rw-r--r--phpBB/phpbb/db/migration/data/v32x/user_notifications_table_reduce_column_sizes.php48
-rw-r--r--phpBB/phpbb/db/migration/data/v32x/user_notifications_table_remove_duplicates.php55
-rw-r--r--phpBB/phpbb/db/migration/data/v32x/user_notifications_table_unique_index.php46
-rw-r--r--phpBB/phpbb/db/tools/tools.php61
7 files changed, 335 insertions, 13 deletions
diff --git a/phpBB/phpbb/db/migration/data/v32x/user_notifications_table_index_p1.php b/phpBB/phpbb/db/migration/data/v32x/user_notifications_table_index_p1.php
new file mode 100644
index 0000000000..93ff31ec6c
--- /dev/null
+++ b/phpBB/phpbb/db/migration/data/v32x/user_notifications_table_index_p1.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\db\migration\data\v32x;
+
+class user_notifications_table_index_p1 extends \phpbb\db\migration\migration
+{
+ static public function depends_on()
+ {
+ return array(
+ '\phpbb\db\migration\data\v32x\cookie_notice_p2',
+ );
+ }
+
+ public function update_schema()
+ {
+ return array(
+ 'add_index' => array(
+ $this->table_prefix . 'user_notifications' => array(
+ 'user_id' => array('user_id'),
+ ),
+ ),
+ );
+ }
+
+ public function revert_schema()
+ {
+ return array(
+ 'drop_keys' => array(
+ $this->table_prefix . 'user_notifications' => array(
+ 'user_id',
+ ),
+ ),
+ );
+ }
+}
diff --git a/phpBB/phpbb/db/migration/data/v32x/user_notifications_table_index_p2.php b/phpBB/phpbb/db/migration/data/v32x/user_notifications_table_index_p2.php
new file mode 100644
index 0000000000..0a471766a0
--- /dev/null
+++ b/phpBB/phpbb/db/migration/data/v32x/user_notifications_table_index_p2.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\db\migration\data\v32x;
+
+class user_notifications_table_index_p2 extends \phpbb\db\migration\migration
+{
+ static public function depends_on()
+ {
+ return array(
+ '\phpbb\db\migration\data\v32x\user_notifications_table_index_p1',
+ );
+ }
+
+ public function update_schema()
+ {
+ return array(
+ 'add_index' => array(
+ $this->table_prefix . 'user_notifications' => array(
+ 'uid_itm_id' => array('user_id', 'item_id'),
+ ),
+ ),
+ );
+ }
+
+ public function revert_schema()
+ {
+ return array(
+ 'drop_keys' => array(
+ $this->table_prefix . 'user_notifications' => array(
+ 'uid_itm_id',
+ ),
+ ),
+ );
+ }
+}
diff --git a/phpBB/phpbb/db/migration/data/v32x/user_notifications_table_index_p3.php b/phpBB/phpbb/db/migration/data/v32x/user_notifications_table_index_p3.php
new file mode 100644
index 0000000000..1636b3024a
--- /dev/null
+++ b/phpBB/phpbb/db/migration/data/v32x/user_notifications_table_index_p3.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\db\migration\data\v32x;
+
+class user_notifications_table_index_p3 extends \phpbb\db\migration\migration
+{
+ static public function depends_on()
+ {
+ return array(
+ '\phpbb\db\migration\data\v32x\user_notifications_table_index_p2',
+ );
+ }
+
+ public function update_schema()
+ {
+ return array(
+ 'add_index' => array(
+ $this->table_prefix . 'user_notifications' => array(
+ 'usr_itm_tpe' => array('user_id', 'item_type', 'item_id'),
+ ),
+ ),
+ );
+ }
+
+ public function revert_schema()
+ {
+ return array(
+ 'drop_keys' => array(
+ $this->table_prefix . 'user_notifications' => array(
+ 'usr_itm_tpe',
+ ),
+ ),
+ );
+ }
+}
diff --git a/phpBB/phpbb/db/migration/data/v32x/user_notifications_table_reduce_column_sizes.php b/phpBB/phpbb/db/migration/data/v32x/user_notifications_table_reduce_column_sizes.php
new file mode 100644
index 0000000000..c2efb8fd4f
--- /dev/null
+++ b/phpBB/phpbb/db/migration/data/v32x/user_notifications_table_reduce_column_sizes.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\db\migration\data\v32x;
+
+class user_notifications_table_reduce_column_sizes extends \phpbb\db\migration\migration
+{
+ static public function depends_on()
+ {
+ return array(
+ '\phpbb\db\migration\data\v32x\user_notifications_table_remove_duplicates',
+ );
+ }
+
+ public function update_schema()
+ {
+ return array(
+ 'change_columns' => array(
+ $this->table_prefix . 'user_notifications' => array(
+ 'item_type' => array('VCHAR:165', ''),
+ 'method' => array('VCHAR:165', ''),
+ ),
+ ),
+ );
+ }
+
+ public function revert_schema()
+ {
+ return array(
+ 'change_columns' => array(
+ $this->table_prefix . 'user_notifications' => array(
+ 'item_type' => array('VCHAR:255', ''),
+ 'method' => array('VCHAR:255', ''),
+ ),
+ ),
+ );
+ }
+}
diff --git a/phpBB/phpbb/db/migration/data/v32x/user_notifications_table_remove_duplicates.php b/phpBB/phpbb/db/migration/data/v32x/user_notifications_table_remove_duplicates.php
new file mode 100644
index 0000000000..371cdf9b3a
--- /dev/null
+++ b/phpBB/phpbb/db/migration/data/v32x/user_notifications_table_remove_duplicates.php
@@ -0,0 +1,55 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\db\migration\data\v32x;
+
+class user_notifications_table_remove_duplicates extends \phpbb\db\migration\migration
+{
+ static public function depends_on()
+ {
+ return array(
+ '\phpbb\db\migration\data\v32x\user_notifications_table_index_p3',
+ );
+ }
+
+ public function update_data()
+ {
+ return array(
+ array('custom', array(array($this, 'remove_duplicates'))),
+ );
+ }
+
+ public function remove_duplicates()
+ {
+ $insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, $this->table_prefix . 'user_notifications');
+
+ $sql = "SELECT item_type, item_id, user_id, method, MAX(notify) AS notify
+ FROM {$this->table_prefix}user_notifications
+ GROUP BY item_type, item_id, user_id, method
+ HAVING COUNT(item_type) > 1";
+
+ $result = $this->sql_query($sql);
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ // Delete the duplicate entries
+ $this->sql_query("DELETE FROM {$this->table_prefix}user_notifications
+ WHERE user_id = {$row['user_id']}
+ AND item_type = '{$row['item_type']}'
+ AND method = '{$row['method']}'");
+
+ // And re-insert as a single one
+ $insert_buffer->insert($row);
+ }
+ $this->db->sql_freeresult($result);
+ }
+}
diff --git a/phpBB/phpbb/db/migration/data/v32x/user_notifications_table_unique_index.php b/phpBB/phpbb/db/migration/data/v32x/user_notifications_table_unique_index.php
new file mode 100644
index 0000000000..e46c231b7b
--- /dev/null
+++ b/phpBB/phpbb/db/migration/data/v32x/user_notifications_table_unique_index.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\db\migration\data\v32x;
+
+class user_notifications_table_unique_index extends \phpbb\db\migration\migration
+{
+ static public function depends_on()
+ {
+ return array(
+ '\phpbb\db\migration\data\v32x\user_notifications_table_reduce_column_sizes',
+ );
+ }
+
+ public function update_schema()
+ {
+ return array(
+ 'add_unique_index' => array(
+ $this->table_prefix . 'user_notifications' => array(
+ 'itm_usr_mthd' => array('item_type', 'item_id', 'user_id', 'method'),
+ ),
+ ),
+ );
+ }
+
+ public function revert_schema()
+ {
+ return array(
+ 'drop_keys' => array(
+ $this->table_prefix . 'user_notifications' => array(
+ 'itm_usr_mthd',
+ ),
+ ),
+ );
+ }
+}
diff --git a/phpBB/phpbb/db/tools/tools.php b/phpBB/phpbb/db/tools/tools.php
index 9273d69cd6..76036554d2 100644
--- a/phpBB/phpbb/db/tools/tools.php
+++ b/phpBB/phpbb/db/tools/tools.php
@@ -946,7 +946,20 @@ class tools implements tools_interface
{
case 'oracle':
case 'sqlite3':
- $row[$col] = substr($row[$col], strlen($table_name) + 1);
+ $index_name = $this->check_index_name_length($table_name, $table_name . '_' . $index_name, false);
+ $table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config)
+
+ if (strpos($index_name , $table_name) === false)
+ {
+ if (strpos($index_name, $table_prefix) !== false)
+ {
+ $row[$col] = substr($row[$col], strlen($table_prefix) + 1);
+ }
+ else
+ {
+ $row[$col] = substr($row[$col], strlen($table_name) + 1);
+ }
+ }
break;
}
@@ -1359,12 +1372,14 @@ class tools implements tools_interface
{
case 'mysql_40':
case 'mysql_41':
+ $index_name = $this->check_index_name_length($table_name, $index_name, false);
$statements[] = 'DROP INDEX ' . $index_name . ' ON ' . $table_name;
break;
case 'oracle':
case 'sqlite3':
- $statements[] = 'DROP INDEX ' . $table_name . '_' . $index_name;
+ $index_name = $this->check_index_name_length($table_name, $table_name . '_' . $index_name, false);
+ $statements[] = 'DROP INDEX ' . $index_name;
break;
}
@@ -1487,17 +1502,17 @@ class tools implements tools_interface
{
$statements = array();
- $this->check_index_name_length($table_name, $index_name);
-
switch ($this->sql_layer)
{
case 'oracle':
case 'sqlite3':
- $statements[] = 'CREATE UNIQUE INDEX ' . $table_name . '_' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';
+ $index_name = $this->check_index_name_length($table_name, $table_name . '_' . $index_name);
+ $statements[] = 'CREATE UNIQUE INDEX ' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';
break;
case 'mysql_40':
case 'mysql_41':
+ $index_name = $this->check_index_name_length($table_name, $index_name);
$statements[] = 'ALTER TABLE ' . $table_name . ' ADD UNIQUE INDEX ' . $index_name . '(' . implode(', ', $column) . ')';
break;
}
@@ -1512,8 +1527,6 @@ class tools implements tools_interface
{
$statements = array();
- $this->check_index_name_length($table_name, $index_name);
-
// remove index length unless MySQL4
if ('mysql_40' != $this->sql_layer)
{
@@ -1524,7 +1537,8 @@ class tools implements tools_interface
{
case 'oracle':
case 'sqlite3':
- $statements[] = 'CREATE INDEX ' . $table_name . '_' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';
+ $index_name = $this->check_index_name_length($table_name, $table_name . '_' . $index_name);
+ $statements[] = 'CREATE INDEX ' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';
break;
case 'mysql_40':
@@ -1539,6 +1553,7 @@ class tools implements tools_interface
}
// no break
case 'mysql_41':
+ $index_name = $this->check_index_name_length($table_name, $index_name);
$statements[] = 'ALTER TABLE ' . $table_name . ' ADD INDEX ' . $index_name . ' (' . implode(', ', $column) . ')';
break;
}
@@ -1551,15 +1566,35 @@ class tools implements tools_interface
*
* @param string $table_name
* @param string $index_name
+ * @param bool $throw_error
+ * @return string The index name, shortened if too long
*/
- protected function check_index_name_length($table_name, $index_name)
+ protected function check_index_name_length($table_name, $index_name, $throw_error = true)
{
- $table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config)
- if (strlen($table_name . $index_name) - strlen($table_prefix) > 24)
+ if (strlen($index_name) > 30)
{
- $max_length = strlen($table_prefix) + 24;
- trigger_error("Index name '{$table_name}_$index_name' on table '$table_name' is too long. The maximum is $max_length characters.", E_USER_ERROR);
+ // Try removing the table prefix if it's at the beginning
+ $table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config)
+ if (strpos($index_name, $table_prefix) === 0)
+ {
+ $index_name = substr($index_name, strlen($table_prefix) + 1);
+ return $this->check_index_name_length($table_name, $index_name);
+ }
+
+ // Try removing the table name then
+ if (strpos($index_name, $table_name) === 0)
+ {
+ $index_name = substr($index_name, strlen($table_name) + 1);
+ return $this->check_index_name_length($table_name, $index_name);
+ }
+
+ if ($throw_error)
+ {
+ trigger_error("Index name '$index_name' on table '$table_name' is too long. The maximum is 30 characters.", E_USER_ERROR);
+ }
}
+
+ return $index_name;
}
/**