From 175ffa869be0d353156e2e332136f63ade30a043 Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Thu, 18 Oct 2018 13:01:29 +0200 Subject: [ticket/15850] Fix "Duplicate entry" for notification types PHPBB3-15850 --- phpBB/phpbb/notification/manager.php | 31 +++++++++---------------------- phpBB/phpbb/notification/method/board.php | 2 +- 2 files changed, 10 insertions(+), 23 deletions(-) (limited to 'phpBB') diff --git a/phpBB/phpbb/notification/manager.php b/phpBB/phpbb/notification/manager.php index ac6bb3c6da..52c650df5d 100644 --- a/phpBB/phpbb/notification/manager.php +++ b/phpBB/phpbb/notification/manager.php @@ -899,32 +899,19 @@ class manager */ public function get_notification_type_id($notification_type_name) { - $notification_type_ids = $this->cache->get('notification_type_ids'); - - $this->db->sql_transaction('begin'); - - if ($notification_type_ids === false) + $sql = 'SELECT notification_type_id, notification_type_name + FROM ' . $this->notification_types_table; + $result = $this->db->sql_query($sql, 604800); // cache for one week + while ($row = $this->db->sql_fetchrow($result)) { - $notification_type_ids = array(); - - $sql = 'SELECT notification_type_id, notification_type_name - FROM ' . $this->notification_types_table; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $notification_type_ids[$row['notification_type_name']] = (int) $row['notification_type_id']; - } - $this->db->sql_freeresult($result); - - $this->cache->put('notification_type_ids', $notification_type_ids); + $notification_type_ids[$row['notification_type_name']] = (int) $row['notification_type_id']; } + $this->db->sql_freeresult($result); if (!isset($notification_type_ids[$notification_type_name])) { if (!isset($this->notification_types[$notification_type_name]) && !isset($this->notification_types['notification.type.' . $notification_type_name])) { - $this->db->sql_transaction('rollback'); - throw new \phpbb\notification\exception('NOTIFICATION_TYPE_NOT_EXIST', array($notification_type_name)); } @@ -934,13 +921,13 @@ class manager )); $this->db->sql_query($sql); + // expose new notification type ID for this request $notification_type_ids[$notification_type_name] = (int) $this->db->sql_nextid(); - $this->cache->put('notification_type_ids', $notification_type_ids); + // destroy cache, we have a new addition which we have to to load next time + $this->cache->destroy('sql', $this->notification_types_table); } - $this->db->sql_transaction('commit'); - return $notification_type_ids[$notification_type_name]; } diff --git a/phpBB/phpbb/notification/method/board.php b/phpBB/phpbb/notification/method/board.php index 931b252daa..faa53576e0 100644 --- a/phpBB/phpbb/notification/method/board.php +++ b/phpBB/phpbb/notification/method/board.php @@ -394,6 +394,6 @@ class board extends \phpbb\notification\method\base WHERE notification_type_id = ' . (int) $notification_type_id; $this->db->sql_query($sql); - $this->cache->destroy('notification_type_ids'); + $this->cache->destroy('sql', $this->notification_types_table); } } -- cgit v1.2.1