diff options
Diffstat (limited to 'phpBB')
| -rw-r--r-- | phpBB/phpbb/db/migration/data/v310/notifications_use_full_name.php | 78 | 
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}' | 
