[ticket/11103] unread -> notification_read

PHPBB3-11103
This commit is contained in:
Nathan Guse 2012-12-15 21:08:26 -06:00
parent 47bed33216
commit fad6bc5a7e
16 changed files with 51 additions and 44 deletions

View file

@ -1310,14 +1310,14 @@ function get_schema_struct()
'item_id' => array('UINT', 0),
'item_parent_id' => array('UINT', 0),
'user_id' => array('UINT', 0),
'unread' => array('BOOL', 1),
'notification_read' => array('BOOL', 0),
'notification_time' => array('TIMESTAMP', 1),
'data' => array('TEXT_UNI', ''),
),
'PRIMARY_KEY' => 'notification_id',
'KEYS' => array(
'item_ident' => array('INDEX', array('item_type', 'item_id')),
'user' => array('INDEX', array('user_id', 'unread')),
'user' => array('INDEX', array('user_id', 'notification_read')),
),
);

View file

@ -128,8 +128,13 @@ class phpbb_notification_manager
$sql = 'SELECT COUNT(n.notification_id) AS unread_count
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
WHERE n.user_id = ' . (int) $options['user_id'] . '
<<<<<<< HEAD
AND n.unread = 1
AND nt.notification_type = n.item_type
=======
AND n.notification_read = 0
AND nt.notification_type = n.notification_type
>>>>>>> 5cedca0... [ticket/11103] unread -> notification_read
AND nt.notification_type_enabled = 1';
$result = $this->db->sql_query($sql);
$unread_count = (int) $this->db->sql_fetchfield('unread_count', $result);
@ -175,7 +180,7 @@ class phpbb_notification_manager
$sql = 'SELECT n.*
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
WHERE n.user_id = ' . (int) $options['user_id'] . '
AND n.unread = 1
AND n.notification_read = 0
AND ' . $this->db->sql_in_set('n.notification_id', array_keys($rowset), true) . '
AND nt.notification_type = n.item_type
AND nt.notification_type_enabled = 1
@ -237,7 +242,7 @@ class phpbb_notification_manager
$time = ($time !== false) ? $time : time();
$sql = 'UPDATE ' . $this->notifications_table . "
SET unread = 0
SET notification_read = 1
WHERE notification_time <= " . $time .
(($item_type !== false) ? ' AND ' . (is_array($item_type) ? $this->db->sql_in_set('item_type', $item_type) : " item_type = '" . $this->db->sql_escape($item_type) . "'") : '') .
(($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : '') .
@ -267,8 +272,10 @@ class phpbb_notification_manager
$time = ($time !== false) ? $time : time();
$sql = 'UPDATE ' . $this->notifications_table . "
SET unread = 0
SET notification_read = 1
WHERE item_type = '" . $this->db->sql_escape($item_type) . "'
SET notification_read = 1
WHERE notification_type = '" . $this->db->sql_escape($notification_type) . "'
AND notification_time <= " . $time .
(($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id) : 'item_parent_id = ' . (int) $item_parent_id) : '') .
(($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : '');
@ -286,7 +293,7 @@ class phpbb_notification_manager
$time = ($time !== false) ? $time : time();
$sql = 'UPDATE ' . $this->notifications_table . "
SET unread = 0
SET notification_read = 1
WHERE notification_time <= " . $time . '
AND ' . ((is_array($notification_id)) ? $this->db->sql_in_set('notification_id', $notification_id) : 'notification_id = ' . (int) $notification_id);
$this->db->sql_query($sql);

View file

@ -168,8 +168,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
'item_type' => $this->get_type(),
'item_parent_id' => static::get_item_parent_id($type_data),
'notification_time' => time(),
'unread' => true,
'notification_time' => time(),
'notification_read' => false,
'data' => array(),
), $this->data);
@ -197,7 +197,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
unset(
$data['notification_time'], // Also unsetting time, since it always tries to change the time to current (if you actually need to change the time, over-ride this function)
$data['notification_id'],
$data['unread'],
$data['notification_read'],
$data['user_id']
);
@ -252,9 +252,9 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
'URL' => $this->get_url(),
'TIME' => $this->user->format_date($this->notification_time),
'UNREAD' => $this->unread,
'UNREAD' => !$this->notification_read,
'U_MARK_READ' => ($this->unread) ? $u_mark_read : '',
'U_MARK_READ' => (!$this->notification_read) ? $u_mark_read : '',
);
}
@ -402,7 +402,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
*/
protected function mark($unread = true, $return = false)
{
$this->unread = (bool) $unread;
$this->notification_read = (bool) !$unread;
$where = array(
"item_type = '" . $this->db->sql_escape($this->item_type) . "'",
@ -417,7 +417,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
}
$sql = 'UPDATE ' . $this->notifications_table . '
SET unread = ' . (int) $this->unread . '
SET notification_read = ' . (int) $this->notification_read . '
WHERE ' . $where;
$this->db->sql_query($sql);
}

View file

@ -105,7 +105,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post
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) . '
AND n.unread = 1
AND n.notification_read = 0
AND nt.notification_type = n.item_type
AND nt.notification_type_enabled = 1';
$result = $this->db->sql_query($sql);

View file

@ -126,7 +126,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base
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) . '
AND n.unread = 1
AND n.notification_read = 0
AND nt.notification_type = n.item_type
AND nt.notification_type_enabled = 1';
$result = $this->db->sql_query($sql);
@ -326,7 +326,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base
// Make sure that if the user has read the topic, it's marked as read in the notification
if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->notification_time)
{
$this->unread = false;
$this->notification_read = true;
}
return parent::create_insert_array($post, $pre_create_data);

View file

@ -124,7 +124,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post
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) . '
AND n.unread = 1
AND n.notification_read = 0
AND nt.notification_type = n.item_type
AND nt.notification_type_enabled = 1';
$result = $this->db->sql_query($sql);

View file

@ -267,7 +267,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base
// Make sure that if the user has read the topic, it's marked as read in the notification
if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->notification_time)
{
$this->unread = false;
$this->notification_read = true;
}
return parent::create_insert_array($post, $pre_create_data);

View file

@ -1197,7 +1197,7 @@ function database_update_info()
'item_id' => array('UINT', 0),
'item_parent_id' => array('UINT', 0),
'user_id' => array('UINT', 0),
'unread' => array('BOOL', 1),
'notification_read' => array('BOOL', 0),
'is_enabled' => array('BOOL', 1),
'notification_time' => array('TIMESTAMP', 1),
'data' => array('TEXT_UNI', ''),
@ -1205,7 +1205,7 @@ function database_update_info()
'PRIMARY_KEY' => 'notification_id',
'KEYS' => array(
'item_ident' => array('INDEX', array('item_type', 'item_id')),
'user' => array('INDEX', array('user_id', 'unread')),
'user' => array('INDEX', array('user_id', 'notification_read')),
),
),
USER_NOTIFICATIONS_TABLE => array(

View file

@ -634,7 +634,7 @@ CREATE TABLE phpbb_notifications (
item_id INTEGER DEFAULT 0 NOT NULL,
item_parent_id INTEGER DEFAULT 0 NOT NULL,
user_id INTEGER DEFAULT 0 NOT NULL,
unread INTEGER DEFAULT 1 NOT NULL,
notification_read INTEGER DEFAULT 0 NOT NULL,
notification_time INTEGER DEFAULT 1 NOT NULL,
data BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL
);;
@ -642,7 +642,7 @@ CREATE TABLE phpbb_notifications (
ALTER TABLE phpbb_notifications ADD PRIMARY KEY (notification_id);;
CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications(item_type, item_id);;
CREATE INDEX phpbb_notifications_user ON phpbb_notifications(user_id, unread);;
CREATE INDEX phpbb_notifications_user ON phpbb_notifications(user_id, notification_read);;
CREATE GENERATOR phpbb_notifications_gen;;
SET GENERATOR phpbb_notifications_gen TO 0;;

View file

@ -778,7 +778,7 @@ CREATE TABLE [phpbb_notifications] (
[item_id] [int] DEFAULT (0) NOT NULL ,
[item_parent_id] [int] DEFAULT (0) NOT NULL ,
[user_id] [int] DEFAULT (0) NOT NULL ,
[unread] [int] DEFAULT (1) NOT NULL ,
[notification_read] [int] DEFAULT (0) NOT NULL ,
[notification_time] [int] DEFAULT (1) NOT NULL ,
[data] [varchar] (4000) DEFAULT ('') NOT NULL
) ON [PRIMARY]
@ -794,7 +794,7 @@ GO
CREATE INDEX [item_ident] ON [phpbb_notifications]([item_type], [item_id]) ON [PRIMARY]
GO
CREATE INDEX [user] ON [phpbb_notifications]([user_id], [unread]) ON [PRIMARY]
CREATE INDEX [user] ON [phpbb_notifications]([user_id], [notification_read]) ON [PRIMARY]
GO

View file

@ -445,12 +445,12 @@ CREATE TABLE phpbb_notifications (
item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
item_parent_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
unread tinyint(1) UNSIGNED DEFAULT '1' NOT NULL,
notification_read tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
notification_time int(11) UNSIGNED DEFAULT '1' NOT NULL,
data blob NOT NULL,
PRIMARY KEY (notification_id),
KEY item_ident (item_type, item_id),
KEY user (user_id, unread)
KEY user (user_id, notification_read)
);

View file

@ -445,12 +445,12 @@ CREATE TABLE phpbb_notifications (
item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
item_parent_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
unread tinyint(1) UNSIGNED DEFAULT '1' NOT NULL,
notification_read tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
notification_time int(11) UNSIGNED DEFAULT '1' NOT NULL,
data text NOT NULL,
PRIMARY KEY (notification_id),
KEY item_ident (item_type, item_id),
KEY user (user_id, unread)
KEY user (user_id, notification_read)
) CHARACTER SET `utf8` COLLATE `utf8_bin`;

View file

@ -860,7 +860,7 @@ CREATE TABLE phpbb_notifications (
item_id number(8) DEFAULT '0' NOT NULL,
item_parent_id number(8) DEFAULT '0' NOT NULL,
user_id number(8) DEFAULT '0' NOT NULL,
unread number(1) DEFAULT '1' NOT NULL,
notification_read number(1) DEFAULT '0' NOT NULL,
notification_time number(11) DEFAULT '1' NOT NULL,
data clob DEFAULT '' ,
CONSTRAINT pk_phpbb_notifications PRIMARY KEY (notification_id)
@ -869,7 +869,7 @@ CREATE TABLE phpbb_notifications (
CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications (item_type, item_id)
/
CREATE INDEX phpbb_notifications_user ON phpbb_notifications (user_id, unread)
CREATE INDEX phpbb_notifications_user ON phpbb_notifications (user_id, notification_read)
/
CREATE SEQUENCE phpbb_notifications_seq

View file

@ -617,14 +617,14 @@ CREATE TABLE phpbb_notifications (
item_id INT4 DEFAULT '0' NOT NULL CHECK (item_id >= 0),
item_parent_id INT4 DEFAULT '0' NOT NULL CHECK (item_parent_id >= 0),
user_id INT4 DEFAULT '0' NOT NULL CHECK (user_id >= 0),
unread INT2 DEFAULT '1' NOT NULL CHECK (unread >= 0),
notification_read INT2 DEFAULT '0' NOT NULL CHECK (notification_read >= 0),
notification_time INT4 DEFAULT '1' NOT NULL CHECK (notification_time >= 0),
data varchar(4000) DEFAULT '' NOT NULL,
PRIMARY KEY (notification_id)
);
CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications (item_type, item_id);
CREATE INDEX phpbb_notifications_user ON phpbb_notifications (user_id, unread);
CREATE INDEX phpbb_notifications_user ON phpbb_notifications (user_id, notification_read);
/*
Table: 'phpbb_poll_options'

View file

@ -432,13 +432,13 @@ CREATE TABLE phpbb_notifications (
item_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
item_parent_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
user_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
unread INTEGER UNSIGNED NOT NULL DEFAULT '1',
notification_read INTEGER UNSIGNED NOT NULL DEFAULT '0',
notification_time INTEGER UNSIGNED NOT NULL DEFAULT '1',
data text(65535) NOT NULL DEFAULT ''
);
CREATE INDEX phpbb_notifications_item_ident ON phpbb_notifications (item_type, item_id);
CREATE INDEX phpbb_notifications_user ON phpbb_notifications (user_id, unread);
CREATE INDEX phpbb_notifications_user ON phpbb_notifications (user_id, notification_read);
# Table: 'phpbb_poll_options'
CREATE TABLE phpbb_poll_options (

View file

@ -205,7 +205,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'item_id' => 1,
'item_parent_id' => 1,
'user_id' => 0,
'unread' => 1,
'notification_read' => 0,
'notification_time' => 1349413321,
'data' => array(),
),
@ -214,7 +214,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'item_id' => 2,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'notification_read' => 0,
'notification_time' => 1349413322,
'data' => array(),
),
@ -223,7 +223,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'item_id' => 3,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'notification_read' => 0,
'notification_time' => 1349413323,
'data' => array(),
),
@ -232,7 +232,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'item_id' => 4,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'notification_read' => 0,
'notification_time' => 1349413324,
'data' => array(
'poster_id' => 2,
@ -248,7 +248,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'item_id' => 5,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'notification_read' => 0,
'notification_time' => 1349413325,
'data' => array(
'poster_id' => 2,
@ -311,7 +311,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'item_id' => 1,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'notification_read' => 0,
'notification_time' => 1349413321,
'data' => array(),
),
@ -320,7 +320,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'item_id' => 2,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'notification_read' => 0,
'notification_time' => 1349413322,
'data' => array(),
),
@ -329,7 +329,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'item_id' => 3,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'notification_read' => 0,
'notification_time' => 1234,
'data' => array(),
),
@ -338,7 +338,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'item_id' => 4,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'notification_read' => 0,
'notification_time' => 1349413324,
'data' => array(
'poster_id' => 2,
@ -354,7 +354,7 @@ class phpbb_notification_test extends phpbb_database_test_case
'item_id' => 5,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'notification_read' => 0,
'notification_time' => 1349413325,
'data' => array(
'poster_id' => 2,