[ticket/11413] Undo editing the user_notifications table

item_type is not equivalent to notification_type_name, it can be a generic
string (typically used to be able to subscribe to multiple notification
types while only subscribing to one item

PHPBB3-11413
This commit is contained in:
Nathaniel Guse 2013-04-29 21:22:07 -05:00
parent 4c5e51e379
commit 33287a7360
14 changed files with 69 additions and 82 deletions

View file

@ -1819,11 +1819,11 @@ function get_schema_struct()
$schema_data['phpbb_user_notifications'] = array(
'COLUMNS' => array(
'notification_type_id' => array('USINT', 0),
'item_id' => array('UINT', 0),
'user_id' => array('UINT', 0),
'method' => array('VCHAR:255', ''),
'notify' => array('BOOL', 1),
'item_type' => array('VCHAR:255', ''),
'item_id' => array('UINT', 0),
'user_id' => array('UINT', 0),
'method' => array('VCHAR:255', ''),
'notify' => array('BOOL', 1),
),
);

View file

@ -20,7 +20,6 @@ class phpbb_db_migration_data_310_notifications2 extends phpbb_db_migration
'drop_tables' => array(
$this->table_prefix . 'notification_types',
$this->table_prefix . 'notifications',
$this->table_prefix . 'user_notifications',
),
'add_tables' => array(
$this->table_prefix . 'notification_types' => array(
@ -51,20 +50,6 @@ class phpbb_db_migration_data_310_notifications2 extends phpbb_db_migration
'user' => array('INDEX', array('user_id', 'notification_read')),
),
),
$this->table_prefix . 'user_notifications' => array(
'COLUMNS' => array(
'notification_type_id' => array('USINT', 0),
'item_id' => array('UINT', 0),
'user_id' => array('UINT', 0),
'method' => array('VCHAR:255', ''),
'notify' => array('BOOL', 1),
),
'PRIMARY_KEY' => array(
'notification_type_id',
'item_id',
'user_id',
),
),
),
);
}
@ -75,7 +60,6 @@ class phpbb_db_migration_data_310_notifications2 extends phpbb_db_migration
'drop_tables' => array(
$this->table_prefix . 'notification_types',
$this->table_prefix . 'notifications',
$this->table_prefix . 'user_notifications',
),
'add_tables' => array(
$this->table_prefix . 'notification_types' => array(
@ -102,15 +86,6 @@ class phpbb_db_migration_data_310_notifications2 extends phpbb_db_migration
'user' => array('INDEX', array('user_id', 'notification_read')),
),
),
$this->table_prefix . 'user_notifications' => array(
'COLUMNS' => array(
'item_type' => array('VCHAR:255', ''),
'item_id' => array('UINT', 0),
'user_id' => array('UINT', 0),
'method' => array('VCHAR:255', ''),
'notify' => array('BOOL', 1),
),
),
),
);
}
@ -126,6 +101,9 @@ class phpbb_db_migration_data_310_notifications2 extends phpbb_db_migration
{
$insert_table = $this->table_prefix . 'user_notifications';
$sql = 'DELETE FROM ' . $insert_table;
$this->db->sql_query($sql);
$sql = 'SELECT user_id, user_notify_type, user_notify_pm
FROM ' . USERS_TABLE;
$result = $this->db->sql_query($sql);

View file

@ -632,25 +632,25 @@ class phpbb_notification_manager
/**
* Add a subscription
*
* @param string $notification_type_name Type identifier of the subscription
* @param string $item_type Type identifier of the subscription
* @param int $item_id The id of the item
* @param string $method The method of the notification e.g. '', 'email', or 'jabber'
* @param bool|int $user_id The user_id to add the subscription for (bool false for current user)
*/
public function add_subscription($notification_type_name, $item_id = 0, $method = '', $user_id = false)
public function add_subscription($item_type, $item_id = 0, $method = '', $user_id = false)
{
if ($method !== '')
{
$this->add_subscription($notification_type_name, $item_id, '', $user_id);
// Make sure to subscribe them to the base subscription
$this->add_subscription($item_type, $item_id, '', $user_id);
}
$notification_type_id = $this->get_notification_type_id($notification_type_name);
$user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id;
$sql = 'SELECT notify
FROM ' . $this->user_notifications_table . '
WHERE notification_type_id = ' . (int) $notification_type_name . '
AND item_id = ' . (int) $item_id . '
FROM ' . $this->user_notifications_table . "
WHERE item_type = '" . $this->db->sql_escape($item_type) . "'
AND item_id = " . (int) $item_id . '
AND user_id = ' .(int) $user_id . "
AND method = '" . $this->db->sql_escape($method) . "'";
$this->db->sql_query($sql);
@ -661,7 +661,7 @@ class phpbb_notification_manager
{
$sql = 'INSERT INTO ' . $this->user_notifications_table . ' ' .
$this->db->sql_build_array('INSERT', array(
'notification_type_id' => $notification_type_id,
'item_type' => $item_type,
'item_id' => (int) $item_id,
'user_id' => (int) $user_id,
'method' => $method,
@ -671,10 +671,10 @@ class phpbb_notification_manager
}
else if (!$current)
{
$sql = 'UPDATE ' . $this->user_notifications_table . '
$sql = 'UPDATE ' . $this->user_notifications_table . "
SET notify = 1
WHERE notification_type_id = ' . (int) $notification_type_id . '
AND item_id = ' . (int) $item_id . '
WHERE item_type = '" . $this->db->sql_escape($item_type) . "'
AND item_id = " . (int) $item_id . '
AND user_id = ' .(int) $user_id . "
AND method = '" . $this->db->sql_escape($method) . "'";
$this->db->sql_query($sql);
@ -684,23 +684,22 @@ class phpbb_notification_manager
/**
* Delete a subscription
*
* @param string $notification_type_name Type identifier of the subscription
* @param string $item_type Type identifier of the subscription
* @param int $item_id The id of the item
* @param string $method The method of the notification e.g. '', 'email', or 'jabber'
* @param bool|int $user_id The user_id to add the subscription for (bool false for current user)
*/
public function delete_subscription($notification_type_name, $item_id = 0, $method = '', $user_id = false)
public function delete_subscription($item_type, $item_id = 0, $method = '', $user_id = false)
{
$notification_type_id = $this->get_notification_type_id($notification_type_name);
$user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id;
// If no method, make sure that no other notification methods for this item are selected before deleting
if ($method === '')
{
$sql = 'SELECT COUNT(*) as num_notifications
FROM ' . $this->user_notifications_table . '
WHERE notification_type_id = ' . (int) $notification_type_id . '
AND item_id = ' . (int) $item_id . '
FROM ' . $this->user_notifications_table . "
WHERE item_type = '" . $this->db->sql_escape($item_type) . "'
AND item_id = " . (int) $item_id . '
AND user_id = ' .(int) $user_id . "
AND method <> ''
AND notify = 1";
@ -714,10 +713,10 @@ class phpbb_notification_manager
}
}
$sql = 'UPDATE ' . $this->user_notifications_table . '
$sql = 'UPDATE ' . $this->user_notifications_table . "
SET notify = 0
WHERE notification_type_id = ' . (int) $notification_type_id . '
AND item_id = '. (int) $item_id . '
WHERE item_type = '" . $this->db->sql_escape($item_type) . "'
AND item_id = " . (int) $item_id . '
AND user_id = ' .(int) $user_id . "
AND method = '" . $this->db->sql_escape($method) . "'";
$this->db->sql_query($sql);
@ -726,7 +725,7 @@ class phpbb_notification_manager
{
$sql = 'INSERT INTO ' . $this->user_notifications_table . ' ' .
$this->db->sql_build_array('INSERT', array(
'notification_type_id' => (int) $notification_type_id,
'item_type' => $item_type,
'item_id' => (int) $item_id,
'user_id' => (int) $user_id,
'method' => $method,

View file

@ -68,11 +68,19 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
*/
public static $notification_option = false;
/**
* The notification_type_id, set upon creation of the class
* This is the notification_type_id from the notification_types table
*
* @var int
*/
protected $notification_type_id;
/**
* Indentification data
* item_type - Type of the item (translates to the notification type)
* item_id - ID of the item (e.g. post_id, msg_id)
* item_parent_id - Parent item id (ex: for topic => forum_id, for post => topic_id, etc)
* notification_type_id - ID of the item type (auto generated, from notification types table)
* item_id - ID of the item (e.g. post_id, msg_id)
* item_parent_id - Parent item id (ex: for topic => forum_id, for post => topic_id, etc)
* user_id
* notification_read
* notification_time
@ -124,6 +132,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
public function set_notification_manager(phpbb_notification_manager $notification_manager)
{
$this->notification_manager = $notification_manager;
$this->notification_type_id = $this->notification_manager->get_notification_type_id($this->get_type());
}
/**
@ -211,7 +221,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
// Defaults
$this->data = array_merge(array(
'item_id' => static::get_item_id($type_data),
'item_type' => $this->get_type(),
'notification_type_id' => $this->notification_type_id,
'item_parent_id' => static::get_item_parent_id($type_data),
'notification_time' => time(),
@ -460,7 +470,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
$this->notification_read = (bool) !$unread;
$where = array(
"item_type = '" . $this->db->sql_escape($this->item_type) . "'",
'notification_type_id = ' . (int) $this->notification_type_id,
'item_id = ' . (int) $this->item_id,
'user_id = ' . (int) $this->user_id,
);

View file

@ -103,11 +103,11 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post
// Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications
$update_notifications = array();
$sql = 'SELECT n.*
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt
WHERE n.item_type = '" . $this->get_type() . "'
AND n.item_parent_id = " . (int) self::get_item_parent_id($post) . '
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
WHERE n.notification_type_id = ' . (int) $this->notification_type_id . '
AND n.item_parent_id = ' . (int) self::get_item_parent_id($post) . '
AND n.notification_read = 0
AND nt.notification_type = n.item_type
AND nt.notification_type_id = n.notification_type_id
AND nt.notification_type_enabled = 1';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))

View file

@ -138,11 +138,11 @@ class phpbb_notification_type_post extends phpbb_notification_type_base
// Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications
$update_notifications = array();
$sql = 'SELECT n.*
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt
WHERE n.item_type = '" . $this->get_type() . "'
AND n.item_parent_id = " . (int) self::get_item_parent_id($post) . '
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
WHERE n.notification_type_id = ' . (int) $this->notification_type_id . '
AND n.item_parent_id = ' . (int) self::get_item_parent_id($post) . '
AND n.notification_read = 0
AND nt.notification_type = n.item_type
AND nt.notification_type_id = n.notification_type_id
AND nt.notification_type_enabled = 1';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))

View file

@ -122,11 +122,11 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post
// Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications
$update_notifications = array();
$sql = 'SELECT n.*
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt
WHERE n.item_type = '" . $this->get_type() . "'
AND n.item_parent_id = " . (int) self::get_item_parent_id($post) . '
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
WHERE n.notification_type_id = ' . (int) $this->notification_type_id . '
AND n.item_parent_id = ' . (int) self::get_item_parent_id($post) . '
AND n.notification_read = 0
AND nt.notification_type = n.item_type
AND nt.notification_type_id = n.notification_type_id
AND nt.notification_type_enabled = 1';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
@ -154,10 +154,10 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post
{
$old_notifications = array();
$sql = 'SELECT n.user_id
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt
WHERE n.item_type = '" . $this->get_type() . "'
AND n.item_id = " . self::get_item_id($post) . '
AND nt.notification_type = n.item_type
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
WHERE n.notification_type_id = ' . (int) $this->notification_type_id . '
AND n.item_id = ' . self::get_item_id($post) . '
AND nt.notification_type_id = n.notification_type_id
AND nt.notification_type_enabled = 1';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
@ -185,9 +185,9 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post
// Remove the necessary notifications
if (!empty($remove_notifications))
{
$sql = 'DELETE FROM ' . $this->notifications_table . "
WHERE item_type = '" . $this->get_type() . "'
AND item_id = " . self::get_item_id($post) . '
$sql = 'DELETE FROM ' . $this->notifications_table . '
WHERE notification_type_id = ' . (int) $this->notification_type_id . '
AND item_id = ' . self::get_item_id($post) . '
AND ' . $this->db->sql_in_set('user_id', $remove_notifications);
$this->db->sql_query($sql);
}

View file

@ -1303,7 +1303,7 @@ CREATE INDEX phpbb_topics_watch_notify_stat ON phpbb_topics_watch(notify_status)
# Table: 'phpbb_user_notifications'
CREATE TABLE phpbb_user_notifications (
notification_type_id INTEGER DEFAULT 0 NOT NULL,
item_type VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL,
item_id INTEGER DEFAULT 0 NOT NULL,
user_id INTEGER DEFAULT 0 NOT NULL,
method VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL,

View file

@ -1591,7 +1591,7 @@ GO
Table: 'phpbb_user_notifications'
*/
CREATE TABLE [phpbb_user_notifications] (
[notification_type_id] [int] DEFAULT (0) NOT NULL ,
[item_type] [varchar] (255) DEFAULT ('') NOT NULL ,
[item_id] [int] DEFAULT (0) NOT NULL ,
[user_id] [int] DEFAULT (0) NOT NULL ,
[method] [varchar] (255) DEFAULT ('') NOT NULL ,

View file

@ -913,7 +913,7 @@ CREATE TABLE phpbb_topics_watch (
# Table: 'phpbb_user_notifications'
CREATE TABLE phpbb_user_notifications (
notification_type_id smallint(4) UNSIGNED DEFAULT '0' NOT NULL,
item_type varbinary(255) DEFAULT '' NOT NULL,
item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
method varbinary(255) DEFAULT '' NOT NULL,

View file

@ -913,7 +913,7 @@ CREATE TABLE phpbb_topics_watch (
# Table: 'phpbb_user_notifications'
CREATE TABLE phpbb_user_notifications (
notification_type_id smallint(4) UNSIGNED DEFAULT '0' NOT NULL,
item_type varchar(255) DEFAULT '' NOT NULL,
item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
method varchar(255) DEFAULT '' NOT NULL,

View file

@ -1720,7 +1720,7 @@ CREATE INDEX phpbb_topics_watch_notify_stat ON phpbb_topics_watch (notify_status
Table: 'phpbb_user_notifications'
*/
CREATE TABLE phpbb_user_notifications (
notification_type_id number(4) DEFAULT '0' NOT NULL,
item_type varchar2(255) DEFAULT '' ,
item_id number(8) DEFAULT '0' NOT NULL,
user_id number(8) DEFAULT '0' NOT NULL,
method varchar2(255) DEFAULT '' ,

View file

@ -1175,7 +1175,7 @@ CREATE INDEX phpbb_topics_watch_notify_stat ON phpbb_topics_watch (notify_status
Table: 'phpbb_user_notifications'
*/
CREATE TABLE phpbb_user_notifications (
notification_type_id INT2 DEFAULT '0' NOT NULL CHECK (notification_type_id >= 0),
item_type varchar(255) DEFAULT '' NOT NULL,
item_id INT4 DEFAULT '0' NOT NULL CHECK (item_id >= 0),
user_id INT4 DEFAULT '0' NOT NULL CHECK (user_id >= 0),
method varchar(255) DEFAULT '' NOT NULL,

View file

@ -884,7 +884,7 @@ CREATE INDEX phpbb_topics_watch_notify_stat ON phpbb_topics_watch (notify_status
# Table: 'phpbb_user_notifications'
CREATE TABLE phpbb_user_notifications (
notification_type_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
item_type varchar(255) NOT NULL DEFAULT '',
item_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
user_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
method varchar(255) NOT NULL DEFAULT '',