Merge branch '3.2.x'

This commit is contained in:
Marc Alexander 2018-10-27 22:26:36 +02:00
commit 11dfe7f18e
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
2 changed files with 10 additions and 23 deletions

View file

@ -899,32 +899,19 @@ class manager
*/ */
public function get_notification_type_id($notification_type_name) 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)
{
$notification_type_ids = array();
$sql = 'SELECT notification_type_id, notification_type_name $sql = 'SELECT notification_type_id, notification_type_name
FROM ' . $this->notification_types_table; FROM ' . $this->notification_types_table;
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql, 604800); // cache for one week
while ($row = $this->db->sql_fetchrow($result)) while ($row = $this->db->sql_fetchrow($result))
{ {
$notification_type_ids[$row['notification_type_name']] = (int) $row['notification_type_id']; $notification_type_ids[$row['notification_type_name']] = (int) $row['notification_type_id'];
} }
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
$this->cache->put('notification_type_ids', $notification_type_ids);
}
if (!isset($notification_type_ids[$notification_type_name])) 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])) 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)); throw new \phpbb\notification\exception('NOTIFICATION_TYPE_NOT_EXIST', array($notification_type_name));
} }
@ -934,13 +921,13 @@ class manager
)); ));
$this->db->sql_query($sql); $this->db->sql_query($sql);
// expose new notification type ID for this request
$notification_type_ids[$notification_type_name] = (int) $this->db->sql_nextid(); $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]; return $notification_type_ids[$notification_type_name];
} }

View file

@ -394,6 +394,6 @@ class board extends \phpbb\notification\method\base
WHERE notification_type_id = ' . (int) $notification_type_id; WHERE notification_type_id = ' . (int) $notification_type_id;
$this->db->sql_query($sql); $this->db->sql_query($sql);
$this->cache->destroy('notification_type_ids'); $this->cache->destroy('sql', $this->notification_types_table);
} }
} }