aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2014-10-06 02:07:52 +0200
committerNils Adermann <naderman@naderman.de>2014-10-06 02:07:52 +0200
commit5e86c89989b537c8a685841a139345d9cb6f6564 (patch)
tree4278acaf48c479c457d343f0d79a644aefaa7bb3 /phpBB/phpbb
parentce4cb9c91759f8f1da5a5e7927114e0499999b6f (diff)
parent3d9b257597d2bf24c8f6d4ebd53a5e0113d7e251 (diff)
downloadforums-5e86c89989b537c8a685841a139345d9cb6f6564.tar
forums-5e86c89989b537c8a685841a139345d9cb6f6564.tar.gz
forums-5e86c89989b537c8a685841a139345d9cb6f6564.tar.bz2
forums-5e86c89989b537c8a685841a139345d9cb6f6564.tar.xz
forums-5e86c89989b537c8a685841a139345d9cb6f6564.zip
Merge pull request #3017 from nickvergessen/ticket/13033
[ticket/13033] Fix "Duplicate entry 'notification.type.*' for key 'type'"
Diffstat (limited to 'phpBB/phpbb')
-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}'