aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/db/migration/data
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-10-02 15:09:34 +0200
committerJoas Schilling <nickvergessen@gmx.de>2014-10-02 16:04:33 +0200
commit3d9b257597d2bf24c8f6d4ebd53a5e0113d7e251 (patch)
tree3e35fd19b0058236c95b808b853a4e853b2fdbfb /phpBB/phpbb/db/migration/data
parent40cd7570e6f4da7cc60d83a3e99c72a2fb99e3f7 (diff)
downloadforums-3d9b257597d2bf24c8f6d4ebd53a5e0113d7e251.tar
forums-3d9b257597d2bf24c8f6d4ebd53a5e0113d7e251.tar.gz
forums-3d9b257597d2bf24c8f6d4ebd53a5e0113d7e251.tar.bz2
forums-3d9b257597d2bf24c8f6d4ebd53a5e0113d7e251.tar.xz
forums-3d9b257597d2bf24c8f6d4ebd53a5e0113d7e251.zip
[ticket/13033] Fix "Duplicate entry 'notification.type.*' for key 'type'"
Caused by the solution of PHPBB3-12990 PHPBB3-13033
Diffstat (limited to 'phpBB/phpbb/db/migration/data')
-rw-r--r--phpBB/phpbb/db/migration/data/v310/notifications_use_full_name.php78
1 files changed, 70 insertions, 8 deletions
diff --git a/phpBB/phpbb/db/migration/data/v310/notifications_use_full_name.php b/phpBB/phpbb/db/migration/data/v310/notifications_use_full_name.php
index f749b32119..112c1e85e8 100644
--- a/phpBB/phpbb/db/migration/data/v310/notifications_use_full_name.php
+++ b/phpBB/phpbb/db/migration/data/v310/notifications_use_full_name.php
@@ -92,10 +92,41 @@ class notifications_use_full_name extends \phpbb\db\migration\migration
foreach ($this->notification_types as $notification_type)
{
- $sql = 'UPDATE ' . NOTIFICATION_TYPES_TABLE . "
- SET notification_type_name = 'notification.type.{$notification_type}'
- WHERE notification_type_name = '{$notification_type}'";
- $this->db->sql_query($sql);
+ $sql = 'SELECT notification_type_id
+ FROM ' . NOTIFICATION_TYPES_TABLE . "
+ WHERE notification_type_name = 'notification.type.{$notification_type}'";
+ $result = $this->db->sql_query($sql);
+ $new_type_id = (int) $this->db->sql_fetchfield('notification_type_id');
+ $this->db->sql_freeresult($result);
+
+ if ($new_type_id)
+ {
+ // New type name already exists,
+ // so we delete the old type and update the type id of existing entries.
+ $sql = 'SELECT notification_type_id
+ FROM ' . NOTIFICATION_TYPES_TABLE . "
+ WHERE notification_type_name = '{$notification_type}'";
+ $result = $this->db->sql_query($sql);
+ $old_type_id = (int) $this->db->sql_fetchfield('notification_type_id');
+ $this->db->sql_freeresult($result);
+
+ $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . '
+ SET notification_type_id = ' . (int) $new_type_id . '
+ WHERE notification_type_id = ' . (int) $old_type_id;
+ $this->db->sql_query($sql);
+
+ $sql = 'DELETE FROM ' . NOTIFICATION_TYPES_TABLE . "
+ WHERE notification_type_name = '{$notification_type}'";
+ $this->db->sql_query($sql);
+ }
+ else
+ {
+ // Otherwise we just update the name
+ $sql = 'UPDATE ' . NOTIFICATION_TYPES_TABLE . "
+ SET notification_type_name = 'notification.type.{$notification_type}'
+ WHERE notification_type_name = '{$notification_type}'";
+ $this->db->sql_query($sql);
+ }
$sql = 'UPDATE ' . USER_NOTIFICATIONS_TABLE . "
SET item_type = 'notification.type.{$notification_type}'
@@ -108,10 +139,41 @@ class notifications_use_full_name extends \phpbb\db\migration\migration
{
foreach ($this->notification_types as $notification_type)
{
- $sql = 'UPDATE ' . NOTIFICATION_TYPES_TABLE . "
- SET notification_type_name = '{$notification_type}'
- WHERE notification_type_name = 'notification.type.{$notification_type}'";
- $this->db->sql_query($sql);
+ $sql = 'SELECT notification_type_id
+ FROM ' . NOTIFICATION_TYPES_TABLE . "
+ WHERE notification_type_name = '{$notification_type}'";
+ $result = $this->db->sql_query($sql);
+ $new_type_id = (int) $this->db->sql_fetchfield('notification_type_id');
+ $this->db->sql_freeresult($result);
+
+ if ($new_type_id)
+ {
+ // New type name already exists,
+ // so we delete the old type and update the type id of existing entries.
+ $sql = 'SELECT notification_type_id
+ FROM ' . NOTIFICATION_TYPES_TABLE . "
+ WHERE notification_type_name = 'notification.type.{$notification_type}'";
+ $result = $this->db->sql_query($sql);
+ $old_type_id = (int) $this->db->sql_fetchfield('notification_type_id');
+ $this->db->sql_freeresult($result);
+
+ $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . '
+ SET notification_type_id = ' . (int) $new_type_id . '
+ WHERE notification_type_id = ' . (int) $old_type_id;
+ $this->db->sql_query($sql);
+
+ $sql = 'DELETE FROM ' . NOTIFICATION_TYPES_TABLE . "
+ WHERE notification_type_name = 'notification.type.{$notification_type}'";
+ $this->db->sql_query($sql);
+ }
+ else
+ {
+ // Otherwise we just update the name
+ $sql = 'UPDATE ' . NOTIFICATION_TYPES_TABLE . "
+ SET notification_type_name = '{$notification_type}'
+ WHERE notification_type_name = 'notification.type.{$notification_type}'";
+ $this->db->sql_query($sql);
+ }
$sql = 'UPDATE ' . USER_NOTIFICATIONS_TABLE . "
SET item_type = '{$notification_type}'