[ticket/11103] Use the full class name as the item_type/method

This is going to require you recreate the db tables.

PHPBB3-11103
This commit is contained in:
Nathan Guse 2012-10-20 20:54:18 -05:00
parent 6861af22ee
commit 94d682f774
39 changed files with 412 additions and 543 deletions

View file

@ -1298,12 +1298,12 @@ function get_schema_struct()
$schema_data['phpbb_notifications'] = array( $schema_data['phpbb_notifications'] = array(
'COLUMNS' => array( 'COLUMNS' => array(
'notification_id' => array('UINT', NULL, 'auto_increment'), 'notification_id' => array('UINT', NULL, 'auto_increment'),
'item_type' => array('VCHAR:25', ''), 'item_type' => array('VCHAR:255', ''),
'item_id' => array('UINT', 0), 'item_id' => array('UINT', 0),
'item_parent_id' => array('UINT', 0), 'item_parent_id' => array('UINT', 0),
'user_id' => array('UINT', 0), 'user_id' => array('UINT', 0),
'unread' => array('BOOL', 1), 'unread' => array('BOOL', 1),
'is_enabled' => array('BOOL', 0), 'is_enabled' => array('BOOL', 1),
'time' => array('TIMESTAMP', 1), 'time' => array('TIMESTAMP', 1),
'data' => array('TEXT_UNI', ''), 'data' => array('TEXT_UNI', ''),
), ),
@ -1777,10 +1777,10 @@ function get_schema_struct()
$schema_data['phpbb_user_notifications'] = array( $schema_data['phpbb_user_notifications'] = array(
'COLUMNS' => array( 'COLUMNS' => array(
'item_type' => array('VCHAR:25', ''), 'item_type' => array('VCHAR:255', ''),
'item_id' => array('UINT', 0), 'item_id' => array('UINT', 0),
'user_id' => array('UINT', 0), 'user_id' => array('UINT', 0),
'method' => array('VCHAR:25', ''), 'method' => array('VCHAR:255', ''),
), ),
'PRIMARY_KEY' => array( 'PRIMARY_KEY' => array(
'item_type', 'item_type',

View file

@ -1330,7 +1330,14 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
// Mark all forums read (index page) // Mark all forums read (index page)
// Mark all topic notifications read for this user // Mark all topic notifications read for this user
$phpbb_notifications->mark_notifications_read(array('topic', 'quote', 'bookmark', 'post', 'approve_topic', 'approve_post'), false, $user->data['user_id'], $post_time); $phpbb_notifications->mark_notifications_read(array(
'phpbb_notification_type_topic',
'phpbb_notification_type_quote',
'phpbb_notification_type_bookmark',
'phpbb_notification_type_post',
'phpbb_notification_type_approve_topic',
'phpbb_notification_type_approve_post',
), false, $user->data['user_id'], $post_time);
if ($config['load_db_lastread'] && $user->data['is_registered']) if ($config['load_db_lastread'] && $user->data['is_registered'])
{ {
@ -1386,7 +1393,10 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
$forum_id = array($forum_id); $forum_id = array($forum_id);
} }
$phpbb_notifications->mark_notifications_read_by_parent(array('topic', 'approve_topic'), $forum_id, $user->data['user_id'], $post_time); $phpbb_notifications->mark_notifications_read_by_parent(array(
'phpbb_notification_type_topic',
'phpbb_notification_type_approve_topic',
), $forum_id, $user->data['user_id'], $post_time);
// Mark all post/quote notifications read for this user in this forum // Mark all post/quote notifications read for this user in this forum
$topic_ids = array(); $topic_ids = array();
@ -1400,7 +1410,12 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
$phpbb_notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post', 'approve_post'), $topic_ids, $user->data['user_id'], $post_time); $phpbb_notifications->mark_notifications_read_by_parent(array(
'phpbb_notification_type_quote',
'phpbb_notification_type_bookmark',
'phpbb_notification_type_post',
'phpbb_notification_type_approve_post',
), $topic_ids, $user->data['user_id'], $post_time);
// Add 0 to forums array to mark global announcements correctly // Add 0 to forums array to mark global announcements correctly
// $forum_id[] = 0; // $forum_id[] = 0;
@ -1500,8 +1515,16 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $
} }
// Mark post notifications read for this user in this topic // Mark post notifications read for this user in this topic
$phpbb_notifications->mark_notifications_read(array('topic', 'approve_topic'), $topic_id, $user->data['user_id'], $post_time); $phpbb_notifications->mark_notifications_read(array(
$phpbb_notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post', 'approve_post'), $topic_id, $user->data['user_id'], $post_time); 'phpbb_notification_type_topic',
'phpbb_notification_type_approve_topic',
), $topic_id, $user->data['user_id'], $post_time);
$phpbb_notifications->mark_notifications_read_by_parent(array(
'phpbb_notification_type_quote',
'phpbb_notification_type_bookmark',
'phpbb_notification_type_post',
'phpbb_notification_type_approve_post',
), $topic_id, $user->data['user_id'], $post_time);
if ($config['load_db_lastread'] && $user->data['is_registered']) if ($config['load_db_lastread'] && $user->data['is_registered'])
{ {

View file

@ -716,7 +716,11 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s
set_config_count('num_topics', $approved_topics * (-1), true); set_config_count('num_topics', $approved_topics * (-1), true);
} }
$phpbb_notifications->delete_notifications(array('topic', 'approve_topic', 'topic_in_queue'), $topic_ids); $phpbb_notifications->delete_notifications(array(
'phpbb_notification_type_topic',
'phpbb_notification_type_approve_topic',
'phpbb_notification_type_topic_in_queue',
), $topic_ids);
return $return; return $return;
} }
@ -896,7 +900,13 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync =
delete_topics('topic_id', $remove_topics, $auto_sync, $post_count_sync, false); delete_topics('topic_id', $remove_topics, $auto_sync, $post_count_sync, false);
} }
$phpbb_notifications->delete_notifications(array('quote', 'bookmark', 'post', 'approve_post', 'post_in_queue'), $post_ids); $phpbb_notifications->delete_notifications(array(
'phpbb_notification_type_quote',
'phpbb_notification_type_bookmark',
'phpbb_notification_type_post',
'phpbb_notification_type_approve_post',
'phpbb_notification_type_post_in_queue',
), $post_ids);
return sizeof($post_ids); return sizeof($post_ids);
} }

View file

@ -2234,19 +2234,31 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
switch ($mode) switch ($mode)
{ {
case 'post': case 'post':
$phpbb_notifications->add_notifications(array('quote', 'topic'), $notification_data); $phpbb_notifications->add_notifications(array(
'phpbb_notification_type_quote',
'phpbb_notification_type_topic',
), $notification_data);
break; break;
case 'reply': case 'reply':
case 'quote': case 'quote':
$phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), $notification_data); $phpbb_notifications->add_notifications(array(
'phpbb_notification_type_quote',
'phpbb_notification_type_bookmark',
'phpbb_notification_type_post',
), $notification_data);
break; break;
case 'edit_topic': case 'edit_topic':
case 'edit_first_post': case 'edit_first_post':
case 'edit': case 'edit':
case 'edit_last_post': case 'edit_last_post':
$phpbb_notifications->update_notifications(array('quote', 'bookmark', 'topic', 'post'), $notification_data); $phpbb_notifications->update_notifications(array(
'phpbb_notification_type_quote',
'phpbb_notification_type_bookmark',
'phpbb_notification_type_topic',
'phpbb_notification_type_post',
), $notification_data);
break; break;
} }
} }
@ -2255,20 +2267,24 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
switch ($mode) switch ($mode)
{ {
case 'post': case 'post':
$phpbb_notifications->add_notifications(array('topic_in_queue'), $notification_data); $phpbb_notifications->add_notifications('phpbb_notification_type_topic_in_queue', $notification_data);
break; break;
case 'reply': case 'reply':
case 'quote': case 'quote':
$phpbb_notifications->add_notifications(array('post_in_queue'), $notification_data); $phpbb_notifications->add_notifications('phpbb_notification_type_post_in_queue', $notification_data);
break; break;
case 'edit_topic': case 'edit_topic':
case 'edit_first_post': case 'edit_first_post':
case 'edit': case 'edit':
case 'edit_last_post': case 'edit_last_post':
$phpbb_notifications->delete_notifications('topic', $data['topic_id']); $phpbb_notifications->delete_notifications('phpbb_notification_type_topic', $data['topic_id']);
$phpbb_notifications->delete_notifications(array('quote', 'bookmark', 'post'), $data['post_id']); $phpbb_notifications->delete_notifications(array(
'phpbb_notification_type_quote',
'phpbb_notification_type_bookmark',
'phpbb_notification_type_post',
), $data['post_id']);
break; break;
} }
} }

View file

@ -878,7 +878,7 @@ function update_unread_status($unread, $msg_id, $user_id, $folder_id)
global $db, $user, $phpbb_notifications; global $db, $user, $phpbb_notifications;
$phpbb_notifications->mark_notifications_read('pm', $msg_id, $user_id); $phpbb_notifications->mark_notifications_read('phpbb_notification_type_pm', $msg_id, $user_id);
$sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . " $sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . "
SET pm_unread = 0 SET pm_unread = 0
@ -1096,7 +1096,7 @@ function delete_pm($user_id, $msg_ids, $folder_id)
$user->data['user_unread_privmsg'] -= $num_unread; $user->data['user_unread_privmsg'] -= $num_unread;
} }
$phpbb_notifications->delete_notifications('pm', array_keys($delete_rows)); $phpbb_notifications->delete_notifications('phpbb_notification_type_pm', array_keys($delete_rows));
// Now we have to check which messages we can delete completely // Now we have to check which messages we can delete completely
$sql = 'SELECT msg_id $sql = 'SELECT msg_id
@ -1260,7 +1260,7 @@ function phpbb_delete_user_pms($user_id)
AND ' . $db->sql_in_set('msg_id', $delivered_msg); AND ' . $db->sql_in_set('msg_id', $delivered_msg);
$db->sql_query($sql); $db->sql_query($sql);
$phpbb_notifications->delete_notifications('pm', $delivered_msg); $phpbb_notifications->delete_notifications('phpbb_notification_type_pm', $delivered_msg);
} }
if (!empty($undelivered_msg)) if (!empty($undelivered_msg))
@ -1273,7 +1273,7 @@ function phpbb_delete_user_pms($user_id)
WHERE ' . $db->sql_in_set('msg_id', $undelivered_msg); WHERE ' . $db->sql_in_set('msg_id', $undelivered_msg);
$db->sql_query($sql); $db->sql_query($sql);
$phpbb_notifications->delete_notifications('pm', $undelivered_msg); $phpbb_notifications->delete_notifications('phpbb_notification_type_pm', $undelivered_msg);
} }
} }
@ -1317,7 +1317,7 @@ function phpbb_delete_user_pms($user_id)
WHERE ' . $db->sql_in_set('msg_id', $delete_ids); WHERE ' . $db->sql_in_set('msg_id', $delete_ids);
$db->sql_query($sql); $db->sql_query($sql);
$phpbb_notifications->delete_notifications('pm', $delete_ids); $phpbb_notifications->delete_notifications('phpbb_notification_type_pm', $delete_ids);
} }
} }
@ -1862,11 +1862,11 @@ function submit_pm($mode, $subject, &$data, $put_in_outbox = true)
if ($mode == 'edit') if ($mode == 'edit')
{ {
$phpbb_notifications->update_notifications('pm', $pm_data); $phpbb_notifications->update_notifications('phpbb_notification_type_pm', $pm_data);
} }
else else
{ {
$phpbb_notifications->add_notifications('pm', $pm_data); $phpbb_notifications->add_notifications('phpbb_notification_type_pm', $pm_data);
} }
return $data['msg_id']; return $data['msg_id'];

View file

@ -90,7 +90,7 @@ class mcp_pm_reports
trigger_error('NO_REPORT'); trigger_error('NO_REPORT');
} }
$phpbb_notifications->mark_notifications_read_by_parent('report_pm', $report_id, $user->data['user_id']); $phpbb_notifications->mark_notifications_read_by_parent('phpbb_notification_type_report_pm', $report_id, $user->data['user_id']);
$pm_id = $report['pm_id']; $pm_id = $report['pm_id'];
$report_id = $report['report_id']; $report_id = $report['report_id'];

View file

@ -86,7 +86,7 @@ class mcp_queue
{ {
$post_id = (int) $topic_info[$topic_id]['topic_first_post_id']; $post_id = (int) $topic_info[$topic_id]['topic_first_post_id'];
$phpbb_notifications->mark_notifications_read('topic_in_queue', $topic_id, $user->data['user_id']); $phpbb_notifications->mark_notifications_read('phpbb_notification_type_topic_in_queue', $topic_id, $user->data['user_id']);
} }
else else
{ {
@ -94,7 +94,7 @@ class mcp_queue
} }
} }
$phpbb_notifications->mark_notifications_read('post_in_queue', $post_id, $user->data['user_id']); $phpbb_notifications->mark_notifications_read('phpbb_notification_type_post_in_queue', $post_id, $user->data['user_id']);
$post_info = get_post_data(array($post_id), 'm_approve', true); $post_info = get_post_data(array($post_id), 'm_approve', true);
@ -610,24 +610,28 @@ function approve_post($post_id_list, $id, $mode)
{ {
if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id'])
{ {
$phpbb_notifications->delete_notifications(array('topic_in_queue'), $post_data['topic_id']); $phpbb_notifications->delete_notifications('phpbb_notification_type_topic_in_queue', $post_data['topic_id']);
$phpbb_notifications->add_notifications('topic', $post_data); $phpbb_notifications->add_notifications('phpbb_notification_type_topic', $post_data);
if ($notify_poster) if ($notify_poster)
{ {
$phpbb_notifications->add_notifications('approve_topic', $post_data); $phpbb_notifications->add_notifications('phpbb_notification_type_approve_topic', $post_data);
} }
} }
else else
{ {
$phpbb_notifications->delete_notifications(array('post_in_queue'), $post_id); $phpbb_notifications->delete_notifications('phpbb_notification_type_post_in_queue', $post_id);
$phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), $post_data); $phpbb_notifications->add_notifications(array(
'phpbb_notification_type_quote',
'phpbb_notification_type_bookmark',
'phpbb_notification_type_post',
), $post_data);
if ($notify_poster) if ($notify_poster)
{ {
$phpbb_notifications->add_notifications('approve_post', $post_data); $phpbb_notifications->add_notifications('phpbb_notification_type_approve_post', $post_data);
} }
} }
} }
@ -855,11 +859,11 @@ function disapprove_post($post_id_list, $id, $mode)
{ {
if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id'])
{ {
$phpbb_notifications->delete_notifications(array('topic_in_queue'), $post_data['topic_id']); $phpbb_notifications->delete_notifications('phpbb_notification_type_topic_in_queue', $post_data['topic_id']);
} }
else else
{ {
$phpbb_notifications->delete_notifications(array('post_in_queue'), $post_id); $phpbb_notifications->delete_notifications('phpbb_notification_type_post_in_queue', $post_id);
} }
} }
@ -905,14 +909,14 @@ function disapprove_post($post_id_list, $id, $mode)
{ {
if ($notify_poster) if ($notify_poster)
{ {
$phpbb_notifications->add_notifications('disapprove_topic', $post_data); $phpbb_notifications->add_notifications('phpbb_notification_type_disapprove_topic', $post_data);
} }
} }
else else
{ {
if ($notify_poster) if ($notify_poster)
{ {
$phpbb_notifications->add_notifications('disapprove_post', $post_data); $phpbb_notifications->add_notifications('phpbb_notification_type_disapprove_post', $post_data);
} }
} }
} }

View file

@ -88,7 +88,7 @@ class mcp_reports
trigger_error('NO_REPORT'); trigger_error('NO_REPORT');
} }
$phpbb_notifications->mark_notifications_read('report_post', $post_id, $user->data['user_id']); $phpbb_notifications->mark_notifications_read('phpbb_notification_type_report_post', $post_id, $user->data['user_id']);
if (!$report_id && $report['report_closed']) if (!$report_id && $report['report_closed'])
{ {
@ -647,20 +647,20 @@ function close_report($report_id_list, $mode, $action, $pm = false)
if ($pm) if ($pm)
{ {
$phpbb_notifications->add_notifications('report_pm_closed', array_merge($post_info[$post_id], array( $phpbb_notifications->add_notifications('phpbb_notification_type_report_pm_closed', array_merge($post_info[$post_id], array(
'reporter' => $reporter['user_id'], 'reporter' => $reporter['user_id'],
'closer_id' => $user->data['user_id'], 'closer_id' => $user->data['user_id'],
'from_user_id' => $post_info[$post_id]['author_id'], 'from_user_id' => $post_info[$post_id]['author_id'],
))); )));
$phpbb_notifications->delete_notifications('report_pm', $post_id); $phpbb_notifications->delete_notifications('phpbb_notification_type_report_pm', $post_id);
} }
else else
{ {
$phpbb_notifications->add_notifications('report_post_closed', array_merge($post_info[$post_id], array( $phpbb_notifications->add_notifications('phpbb_notification_type_report_post_closed', array_merge($post_info[$post_id], array(
'reporter' => $reporter['user_id'], 'reporter' => $reporter['user_id'],
'closer_id' => $user->data['user_id'], 'closer_id' => $user->data['user_id'],
))); )));
$phpbb_notifications->delete_notifications('report_post', $post_id); $phpbb_notifications->delete_notifications('phpbb_notification_type_report_post', $post_id);
} }
} }
} }

View file

@ -138,32 +138,16 @@ class phpbb_notification_manager
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
} }
$rowset = array(); if (!$options['count_total'] || $total_count)
// Get the main notifications
$sql = 'SELECT *
FROM ' . NOTIFICATIONS_TABLE . '
WHERE user_id = ' . (int) $options['user_id'] .
(($options['notification_id']) ? ((is_array($options['notification_id'])) ? ' AND ' . $this->db->sql_in_set('notification_id', $options['notification_id']) : ' AND notification_id = ' . (int) $options['notification_id']) : '') . '
AND is_enabled = 1
ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']);
$result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']);
while ($row = $this->db->sql_fetchrow($result))
{ {
$rowset[$row['notification_id']] = $row; $rowset = array();
}
$this->db->sql_freeresult($result);
// Get all unread notifications // Get the main notifications
if ($unread_count && $options['all_unread'] && !empty($rowset))
{
$sql = 'SELECT * $sql = 'SELECT *
FROM ' . NOTIFICATIONS_TABLE . ' FROM ' . NOTIFICATIONS_TABLE . '
WHERE user_id = ' . (int) $options['user_id'] . ' WHERE user_id = ' . (int) $options['user_id'] .
AND unread = 1 (($options['notification_id']) ? ((is_array($options['notification_id'])) ? ' AND ' . $this->db->sql_in_set('notification_id', $options['notification_id']) : ' AND notification_id = ' . (int) $options['notification_id']) : '') . '
AND ' . $this->db->sql_in_set('notification_id', array_keys($rowset), true) . ' AND is_enabled = 1
AND is_is_enabled = 1
ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']); ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']);
$result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']); $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']);
@ -172,37 +156,52 @@ class phpbb_notification_manager
$rowset[$row['notification_id']] = $row; $rowset[$row['notification_id']] = $row;
} }
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
}
foreach ($rowset as $row) // Get all unread notifications
{ if ($unread_count && $options['all_unread'] && !empty($rowset))
$item_type_class_name = $this->get_item_type_class_name($row['item_type'], true);
$notification = $this->get_item_type_class($item_type_class_name, $row);
// Array of user_ids to query all at once
$user_ids = array_merge($user_ids, $notification->users_to_query());
// Some notification types also require querying additional tables themselves
if (!isset($load_special[$row['item_type']]))
{ {
$load_special[$row['item_type']] = array(); $sql = 'SELECT *
FROM ' . NOTIFICATIONS_TABLE . '
WHERE user_id = ' . (int) $options['user_id'] . '
AND unread = 1
AND ' . $this->db->sql_in_set('notification_id', array_keys($rowset), true) . '
AND is_enabled = 1
ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']);
$result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']);
while ($row = $this->db->sql_fetchrow($result))
{
$rowset[$row['notification_id']] = $row;
}
$this->db->sql_freeresult($result);
} }
$load_special[$row['item_type']] = array_merge($load_special[$row['item_type']], $notification->get_load_special());
$notifications[$row['notification_id']] = $notification; foreach ($rowset as $row)
} {
$notification = $this->get_item_type_class($row['item_type'], $row);
$this->load_users($user_ids); // Array of user_ids to query all at once
$user_ids = array_merge($user_ids, $notification->users_to_query());
// Allow each type to load its own special items // Some notification types also require querying additional tables themselves
foreach ($load_special as $item_type => $data) if (!isset($load_special[$row['item_type']]))
{ {
$item_type_class_name = $this->get_item_type_class_name($item_type, true); $load_special[$row['item_type']] = array();
}
$load_special[$row['item_type']] = array_merge($load_special[$row['item_type']], $notification->get_load_special());
$item_class = $this->get_item_type_class($item_type_class_name); $notifications[$row['notification_id']] = $notification;
}
$item_class->load_special($data, $notifications); $this->load_users($user_ids);
// Allow each type to load its own special items
foreach ($load_special as $item_type => $data)
{
$item_class = $this->get_item_type_class($item_type);
$item_class->load_special($data, $notifications);
}
} }
return array( return array(
@ -234,11 +233,6 @@ class phpbb_notification_manager
$time = ($time) ?: time(); $time = ($time) ?: time();
if ($item_type !== false)
{
$this->get_item_type_class_name($item_type);
}
$sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . "
SET unread = 0 SET unread = 0
WHERE time <= " . $time . WHERE time <= " . $time .
@ -270,8 +264,6 @@ class phpbb_notification_manager
$time = ($time) ?: time(); $time = ($time) ?: time();
$item_type_class_name = $this->get_item_type_class_name($item_type);
$sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . "
SET unread = 0 SET unread = 0
WHERE item_type = '" . $this->db->sql_escape($item_type) . "' WHERE item_type = '" . $this->db->sql_escape($item_type) . "'
@ -326,12 +318,10 @@ class phpbb_notification_manager
return $notified_users; return $notified_users;
} }
$item_type_class_name = $this->get_item_type_class_name($item_type); $item_id = $item_type::get_item_id($data);
$item_id = $item_type_class_name::get_item_id($data);
// find out which users want to receive this type of notification // find out which users want to receive this type of notification
$notify_users = $this->get_item_type_class($item_type_class_name)->find_users_for_notification($data, $options); $notify_users = $this->get_item_type_class($item_type)->find_users_for_notification($data, $options);
$this->add_notifications_for_users($item_type, $data, $notify_users); $this->add_notifications_for_users($item_type, $data, $notify_users);
@ -357,9 +347,7 @@ class phpbb_notification_manager
return; return;
} }
$item_type_class_name = $this->get_item_type_class_name($item_type); $item_id = $item_type::get_item_id($data);
$item_id = $item_type_class_name::get_item_id($data);
$user_ids = array(); $user_ids = array();
$notification_objects = $notification_methods = array(); $notification_objects = $notification_methods = array();
@ -388,14 +376,14 @@ class phpbb_notification_manager
} }
// Allow notifications to perform actions before creating the insert array (such as run a query to cache some data needed for all notifications) // Allow notifications to perform actions before creating the insert array (such as run a query to cache some data needed for all notifications)
$notification = $this->get_item_type_class($item_type_class_name); $notification = $this->get_item_type_class($item_type);
$pre_create_data = $notification->pre_create_insert_array($data, $notify_users); $pre_create_data = $notification->pre_create_insert_array($data, $notify_users);
unset($notification); unset($notification);
// Go through each user so we can insert a row in the DB and then notify them by their desired means // Go through each user so we can insert a row in the DB and then notify them by their desired means
foreach ($notify_users as $user => $methods) foreach ($notify_users as $user => $methods)
{ {
$notification = $this->get_item_type_class($item_type_class_name); $notification = $this->get_item_type_class($item_type);
$notification->user_id = (int) $user; $notification->user_id = (int) $user;
@ -412,8 +400,7 @@ class phpbb_notification_manager
{ {
if (!isset($notification_methods[$method])) if (!isset($notification_methods[$method]))
{ {
$method_class_name = 'phpbb_notification_method_' . $method; $notification_methods[$method] = $this->get_method_class($method);
$notification_methods[$method] = $this->get_method_class($method_class_name);
} }
$notification_methods[$method]->add_to_queue($notification); $notification_methods[$method]->add_to_queue($notification);
@ -452,21 +439,19 @@ class phpbb_notification_manager
return; return;
} }
$item_type_class_name = $this->get_item_type_class_name($item_type); $notification = $this->get_item_type_class($item_type);
// Allow the notifications class to over-ride the update_notifications functionality // Allow the notifications class to over-ride the update_notifications functionality
if (method_exists($item_type_class_name, 'update_notifications')) if (method_exists($notification, 'update_notifications'))
{ {
// Return False to over-ride the rest of the update // Return False to over-ride the rest of the update
if ($this->get_item_type_class($item_type_class_name)->update_notifications($data) === false) if ($notification->update_notifications($data) === false)
{ {
return; return;
} }
} }
$item_id = $item_type_class_name::get_item_id($data); $item_id = $item_type::get_item_id($data);
$notification = $this->get_item_type_class($item_type_class_name);
$update_array = $notification->create_update_array($data); $update_array = $notification->create_update_array($data);
$sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . '
@ -495,8 +480,6 @@ class phpbb_notification_manager
return; return;
} }
$this->get_item_type_class_name($item_type);
$sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . "
WHERE item_type = '" . $this->db->sql_escape($item_type) . "' WHERE item_type = '" . $this->db->sql_escape($item_type) . "'
AND " . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id); AND " . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id);
@ -512,17 +495,15 @@ class phpbb_notification_manager
{ {
$subscription_types = array(); $subscription_types = array();
foreach ($this->get_subscription_files('notification/type/') as $class_name => $file) foreach ($this->get_subscription_files('notification/type/') as $class_name)
{ {
$class_name = $this->get_item_type_class_name($class_name);
$class = $this->get_item_type_class($class_name); $class = $this->get_item_type_class($class_name);
if ($class instanceof phpbb_notification_type_interface && $class->is_available() && method_exists($class_name, 'get_item_type')) if ($class instanceof phpbb_notification_type_interface && $class->is_available())
{ {
$options = array_merge(array( $options = array_merge(array(
'id' => $class_name::get_item_type(), 'id' => $class_name,
'lang' => 'NOTIFICATION_TYPE_' . strtoupper($class_name::get_item_type()), 'lang' => 'NOTIFICATION_TYPE_' . strtoupper($class_name),
'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS', 'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS',
), (($class_name::$notification_option !== false) ? $class_name::$notification_option : array())); ), (($class_name::$notification_option !== false) ? $class_name::$notification_option : array()));
@ -550,15 +531,13 @@ class phpbb_notification_manager
{ {
$subscription_methods = array(); $subscription_methods = array();
foreach ($this->get_subscription_files('notification/method/') as $method_name => $file) foreach ($this->get_subscription_files('notification/method/') as $class_name)
{ {
$class_name = 'phpbb_notification_method_' . $method_name;
$method = $this->get_method_class($class_name); $method = $this->get_method_class($class_name);
if ($method instanceof phpbb_notification_method_interface && $method->is_available()) if ($method instanceof phpbb_notification_method_interface && $method->is_available())
{ {
$subscription_methods[] = $method_name; $subscription_methods[] = $class_name;
} }
} }
@ -615,8 +594,6 @@ class phpbb_notification_manager
*/ */
public function add_subscription($item_type, $item_id = 0, $method = '', $user_id = false) public function add_subscription($item_type, $item_id = 0, $method = '', $user_id = false)
{ {
$this->get_item_type_class_name($item_type);
$user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id;
$sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' .
@ -639,8 +616,6 @@ class phpbb_notification_manager
*/ */
public function delete_subscription($item_type, $item_id = 0, $method = '', $user_id = false) public function delete_subscription($item_type, $item_id = 0, $method = '', $user_id = false)
{ {
$this->get_item_type_class_name($item_type);
$user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id;
$sql = 'DELETE FROM ' . USER_NOTIFICATIONS_TABLE . " $sql = 'DELETE FROM ' . USER_NOTIFICATIONS_TABLE . "
@ -692,37 +667,11 @@ class phpbb_notification_manager
return (isset($this->users[$user_id])) ? $this->users[$user_id] : $this->users[ANONYMOUS]; return (isset($this->users[$user_id])) ? $this->users[$user_id] : $this->users[ANONYMOUS];
} }
/**
* Helper to get the notifications item type class name and clean it if unsafe
*/
private function get_item_type_class_name(&$item_type, $safe = false)
{
if (!$safe)
{
$item_type = preg_replace('#[^a-z_-]#', '', $item_type);
}
if (strpos($item_type, 'ext_') === 0)
{
$item_type_ary = explode('-', substr($item_type, 4), 2);
return 'phpbb_ext_' . $item_type_ary[0] . '_notification_type_' . $item_type_ary[1];
}
return 'phpbb_notification_type_' . $item_type;
}
/** /**
* Helper to get the notifications item type class and set it up * Helper to get the notifications item type class and set it up
*/ */
public function get_item_type_class($item_type, $data = array()) public function get_item_type_class($item_type, $data = array())
{ {
if (!strpos($item_type, 'notification_type_'))
{
$item_class = $this->get_item_type_class_name($item_type);
$item_type = $item_class;
}
$item = new $item_type($this, $this->db, $this->cache, $this->template, $this->extension_manager, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext); $item = new $item_type($this, $this->db, $this->cache, $this->template, $this->extension_manager, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext);
$item->set_initial_data($data); $item->set_initial_data($data);
@ -747,31 +696,16 @@ class phpbb_notification_manager
$subscription_files = array(); $subscription_files = array();
$files = $finder $classes = $finder
->core_path('includes/' . $path) ->core_path('includes/' . $path)
->extension_directory($path) ->extension_directory($path)
->get_files(); ->get_classes();
foreach ($files as $file)
{
$name = substr($file, strrpos($file, '/'));
$name = substr($name, 1, (strpos($name, '.' . $this->php_ext) - 1));
if ($name == 'interface' || $name == 'base') unset($classes[array_search('phpbb_notification_type_interface', $classes)]);
{ unset($classes[array_search('phpbb_notification_type_base', $classes)]);
continue; unset($classes[array_search('phpbb_notification_method_interface', $classes)]);
} unset($classes[array_search('phpbb_notification_method_base', $classes)]);
if (!strpos($file, 'includes/')) // is an extension return $classes;
{
$ext_name = substr($file, (strpos($file, 'ext/') + 4));
$ext_name = substr($ext_name, 0, strpos($ext_name, '/'));
$name = 'ext_' . $ext_name . '-' . $name;
}
$subscription_files[$name] = $file;
}
return $subscription_files;
} }
} }

View file

@ -42,15 +42,6 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post
'group' => 'NOTIFICATION_GROUP_POSTING', 'group' => 'NOTIFICATION_GROUP_POSTING',
); );
/**
* Get the type of notification this is
* phpbb_notification_type_
*/
public static function get_item_type()
{
return 'approve_post';
}
/** /**
* Is available * Is available
*/ */

View file

@ -42,15 +42,6 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi
'group' => 'NOTIFICATION_GROUP_POSTING', 'group' => 'NOTIFICATION_GROUP_POSTING',
); );
/**
* Get the type of notification this is
* phpbb_notification_type_
*/
public static function get_item_type()
{
return 'approve_topic';
}
/** /**
* Is available * Is available
*/ */

View file

@ -116,7 +116,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
public function __toString() public function __toString()
{ {
return (!empty($this->data)) ? var_export($this->data, true) : static::get_item_type(); return (!empty($this->data)) ? var_export($this->data, true) : get_class($this);
} }
/** /**
@ -156,7 +156,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
// Defaults // Defaults
$this->data = array_merge(array( $this->data = array_merge(array(
'item_id' => static::get_item_id($type_data), 'item_id' => static::get_item_id($type_data),
'item_type' => $this->get_item_type(), 'item_type' => get_class($this),
'item_parent_id' => static::get_item_parent_id($type_data), 'item_parent_id' => static::get_item_parent_id($type_data),
'time' => time(), 'time' => time(),
@ -324,7 +324,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i
$sql = 'SELECT * $sql = 'SELECT *
FROM ' . USER_NOTIFICATIONS_TABLE . " FROM ' . USER_NOTIFICATIONS_TABLE . "
WHERE item_type = '" . static::get_item_type() . "' WHERE item_type = '" . get_class($this) . "'
AND item_id = " . (int) $item_id; AND item_id = " . (int) $item_id;
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result)) while ($row = $this->db->sql_fetchrow($result))

View file

@ -31,13 +31,15 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post
protected $language_key = 'NOTIFICATION_BOOKMARK'; protected $language_key = 'NOTIFICATION_BOOKMARK';
/** /**
* Get the type of notification this is * Notification option data (for outputting to the user)
* phpbb_notification_type_ *
* @var bool|array False if the service should use it's default data
* Array of data (including keys 'id', 'lang', and 'group')
*/ */
public static function get_item_type() public static $notification_option = array(
{ 'lang' => 'NOTIFICATION_TYPE_BOOKMARK',
return 'bookmark'; 'group' => 'NOTIFICATION_GROUP_POSTING',
} );
/** /**
* Find the users who want to receive notifications * Find the users who want to receive notifications
@ -81,7 +83,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post
$sql = 'SELECT * $sql = 'SELECT *
FROM ' . USER_NOTIFICATIONS_TABLE . " FROM ' . USER_NOTIFICATIONS_TABLE . "
WHERE item_type = '" . self::get_item_type() . "' WHERE item_type = '" . get_class($this) . "'
AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']);
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result)) while ($row = $this->db->sql_fetchrow($result))
@ -104,7 +106,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post
$update_notifications = array(); $update_notifications = array();
$sql = 'SELECT * $sql = 'SELECT *
FROM ' . NOTIFICATIONS_TABLE . " FROM ' . NOTIFICATIONS_TABLE . "
WHERE item_type = '" . self::get_item_type() . "' WHERE item_type = '" . get_class($this) . "'
AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND item_parent_id = " . (int) self::get_item_parent_id($post) . '
AND unread = 1 AND unread = 1
AND is_enabled = 1'; AND is_enabled = 1';
@ -114,7 +116,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post
// Do not create a new notification // Do not create a new notification
unset($notify_users[$row['user_id']]); unset($notify_users[$row['user_id']]);
$notification = $this->notification_manager->get_item_type_class(self::get_item_type(), $row); $notification = $this->notification_manager->get_item_type_class(get_class($this), $row);
$sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . '
SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . '
WHERE notification_id = ' . $row['notification_id']; WHERE notification_id = ' . $row['notification_id'];

View file

@ -42,15 +42,6 @@ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_ap
'group' => 'NOTIFICATION_GROUP_POSTING', 'group' => 'NOTIFICATION_GROUP_POSTING',
); );
/**
* Get the type of notification this is
* phpbb_notification_type_
*/
public static function get_item_type()
{
return 'disapprove_post';
}
/** /**
* Get the HTML formatted title of this notification * Get the HTML formatted title of this notification
* *

View file

@ -42,15 +42,6 @@ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_a
'group' => 'NOTIFICATION_GROUP_POSTING', 'group' => 'NOTIFICATION_GROUP_POSTING',
); );
/**
* Get the type of notification this is
* phpbb_notification_type_
*/
public static function get_item_type()
{
return 'disapprove_topic';
}
/** /**
* Get the HTML formatted title of this notification * Get the HTML formatted title of this notification
* *

View file

@ -28,12 +28,6 @@ interface phpbb_notification_type_interface
*/ */
public function set_initial_data($data); public function set_initial_data($data);
/**
* Get the type of notification this is
* phpbb_notification_type_
*/
public static function get_item_type();
/** /**
* Get the id of the item * Get the id of the item
* *

View file

@ -24,13 +24,14 @@ if (!defined('IN_PHPBB'))
class phpbb_notification_type_pm extends phpbb_notification_type_base class phpbb_notification_type_pm extends phpbb_notification_type_base
{ {
/** /**
* Get the type of notification this is * Notification option data (for outputting to the user)
* phpbb_notification_type_ *
* @var bool|array False if the service should use it's default data
* Array of data (including keys 'id', 'lang', and 'group')
*/ */
public static function get_item_type() public static $notification_option = array(
{ 'lang' => 'NOTIFICATION_TYPE_PM',
return 'pm'; );
}
/** /**
* Get the id of the * Get the id of the
@ -77,7 +78,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base
$sql = 'SELECT * $sql = 'SELECT *
FROM ' . USER_NOTIFICATIONS_TABLE . " FROM ' . USER_NOTIFICATIONS_TABLE . "
WHERE item_type = '" . self::get_item_type() . "' WHERE item_type = '" . get_class($this) . "'
AND " . $this->db->sql_in_set('user_id', array_keys($pm['recipients'])) . ' AND " . $this->db->sql_in_set('user_id', array_keys($pm['recipients'])) . '
AND user_id <> ' . $pm['from_user_id']; AND user_id <> ' . $pm['from_user_id'];
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql);

View file

@ -37,18 +37,10 @@ class phpbb_notification_type_post extends phpbb_notification_type_base
* Array of data (including keys 'id', 'lang', and 'group') * Array of data (including keys 'id', 'lang', and 'group')
*/ */
public static $notification_option = array( public static $notification_option = array(
'lang' => 'NOTIFICATION_TYPE_POST',
'group' => 'NOTIFICATION_GROUP_POSTING', 'group' => 'NOTIFICATION_GROUP_POSTING',
); );
/**
* Get the type of notification this is
* phpbb_notification_type_
*/
public static function get_item_type()
{
return 'post';
}
/** /**
* Get the id of the item * Get the id of the item
* *
@ -112,7 +104,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base
$sql = 'SELECT * $sql = 'SELECT *
FROM ' . USER_NOTIFICATIONS_TABLE . " FROM ' . USER_NOTIFICATIONS_TABLE . "
WHERE item_type = '" . self::get_item_type() . "' WHERE item_type = '" . get_class($this) . "'
AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']);
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result)) while ($row = $this->db->sql_fetchrow($result))
@ -135,7 +127,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base
$update_notifications = array(); $update_notifications = array();
$sql = 'SELECT * $sql = 'SELECT *
FROM ' . NOTIFICATIONS_TABLE . " FROM ' . NOTIFICATIONS_TABLE . "
WHERE item_type = '" . self::get_item_type() . "' WHERE item_type = '" . get_class($this) . "'
AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND item_parent_id = " . (int) self::get_item_parent_id($post) . '
AND unread = 1 AND unread = 1
AND is_enabled = 1'; AND is_enabled = 1';
@ -145,7 +137,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base
// Do not create a new notification // Do not create a new notification
unset($notify_users[$row['user_id']]); unset($notify_users[$row['user_id']]);
$notification = $this->notification_manager->get_item_type_class(self::get_item_type(), $row); $notification = $this->notification_manager->get_item_type_class(get_class($this), $row);
$sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . '
SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . '
WHERE notification_id = ' . $row['notification_id']; WHERE notification_id = ' . $row['notification_id'];

View file

@ -49,15 +49,6 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post
*/ */
protected $permission = 'm_approve'; protected $permission = 'm_approve';
/**
* Get the type of notification this is
* phpbb_notification_type_
*/
public static function get_item_type()
{
return 'post_in_queue';
}
/** /**
* Is available * Is available
*/ */

View file

@ -38,13 +38,15 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post
protected $language_key = 'NOTIFICATION_QUOTE'; protected $language_key = 'NOTIFICATION_QUOTE';
/** /**
* Get the type of notification this is * Notification option data (for outputting to the user)
* phpbb_notification_type_ *
* @var bool|array False if the service should use it's default data
* Array of data (including keys 'id', 'lang', and 'group')
*/ */
public static function get_item_type() public static $notification_option = array(
{ 'lang' => 'NOTIFICATION_TYPE_QUOTE',
return 'quote'; 'group' => 'NOTIFICATION_GROUP_POSTING',
} );
/** /**
* Find the users who want to receive notifications * Find the users who want to receive notifications
@ -100,7 +102,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post
$sql = 'SELECT * $sql = 'SELECT *
FROM ' . USER_NOTIFICATIONS_TABLE . " FROM ' . USER_NOTIFICATIONS_TABLE . "
WHERE item_type = '" . self::get_item_type() . "' WHERE item_type = '" . get_class($this) . "'
AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']);
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result)) while ($row = $this->db->sql_fetchrow($result))
@ -123,7 +125,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post
$update_notifications = array(); $update_notifications = array();
$sql = 'SELECT * $sql = 'SELECT *
FROM ' . NOTIFICATIONS_TABLE . " FROM ' . NOTIFICATIONS_TABLE . "
WHERE item_type = '" . self::get_item_type() . "' WHERE item_type = '" . get_class($this) . "'
AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND item_parent_id = " . (int) self::get_item_parent_id($post) . '
AND unread = 1 AND unread = 1
AND is_enabled = 1'; AND is_enabled = 1';
@ -133,7 +135,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post
// Do not create a new notification // Do not create a new notification
unset($notify_users[$row['user_id']]); unset($notify_users[$row['user_id']]);
$notification = $this->notification_manager->get_item_type_class(self::get_item_type(), $row); $notification = $this->notification_manager->get_item_type_class(get_class($this), $row);
$sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . '
SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . '
WHERE notification_id = ' . $row['notification_id']; WHERE notification_id = ' . $row['notification_id'];
@ -154,7 +156,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post
$old_notifications = array(); $old_notifications = array();
$sql = 'SELECT user_id $sql = 'SELECT user_id
FROM ' . NOTIFICATIONS_TABLE . " FROM ' . NOTIFICATIONS_TABLE . "
WHERE item_type = '" . self::get_item_type() . "' WHERE item_type = '" . get_class($this) . "'
AND item_id = " . self::get_item_id($post) . ' AND item_id = " . self::get_item_id($post) . '
AND is_enabled = 1'; AND is_enabled = 1';
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql);
@ -178,13 +180,13 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post
} }
// Add the necessary notifications // Add the necessary notifications
$this->notification_manager->add_notifications_for_users(self::get_item_type(), $post, $add_notifications); $this->notification_manager->add_notifications_for_users(get_class($this), $post, $add_notifications);
// Remove the necessary notifications // Remove the necessary notifications
if (!empty($remove_notifications)) if (!empty($remove_notifications))
{ {
$sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . "
WHERE item_type = '" . self::get_item_type() . "' WHERE item_type = '" . get_class($this) . "'
AND item_id = " . self::get_item_id($post) . ' AND item_id = " . self::get_item_id($post) . '
AND ' . $this->db->sql_in_set('user_id', $remove_notifications); AND ' . $this->db->sql_in_set('user_id', $remove_notifications);
$this->db->sql_query($sql); $this->db->sql_query($sql);

View file

@ -49,15 +49,6 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm
'group' => 'NOTIFICATION_GROUP_MODERATION', 'group' => 'NOTIFICATION_GROUP_MODERATION',
); );
/**
* Get the type of notification this is
* phpbb_notification_type_
*/
public static function get_item_type()
{
return 'report_pm';
}
/** /**
* Get the id of the parent * Get the id of the parent
* *

View file

@ -42,15 +42,6 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p
return false; return false;
} }
/**
* Get the type of notification this is
* phpbb_notification_type_
*/
public static function get_item_type()
{
return 'report_pm_closed';
}
/** /**
* Find the users who want to receive notifications * Find the users who want to receive notifications
* *

View file

@ -49,15 +49,6 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i
'group' => 'NOTIFICATION_GROUP_MODERATION', 'group' => 'NOTIFICATION_GROUP_MODERATION',
); );
/**
* Get the type of notification this is
* phpbb_notification_type_
*/
public static function get_item_type()
{
return 'report_post';
}
/** /**
* Find the users who want to receive notifications * Find the users who want to receive notifications
* *

View file

@ -42,15 +42,6 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type
return false; return false;
} }
/**
* Get the type of notification this is
* phpbb_notification_type_
*/
public static function get_item_type()
{
return 'report_post_closed';
}
/** /**
* Find the users who want to receive notifications * Find the users who want to receive notifications
* *

View file

@ -37,18 +37,10 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base
* Array of data (including keys 'id', 'lang', and 'group') * Array of data (including keys 'id', 'lang', and 'group')
*/ */
public static $notification_option = array( public static $notification_option = array(
'lang' => 'NOTIFICATION_TYPE_TOPIC',
'group' => 'NOTIFICATION_GROUP_POSTING', 'group' => 'NOTIFICATION_GROUP_POSTING',
); );
/**
* Get the type of notification this is
* phpbb_notification_type_
*/
public static function get_item_type()
{
return 'topic';
}
/** /**
* Get the id of the item * Get the id of the item
* *
@ -116,7 +108,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base
$sql = 'SELECT * $sql = 'SELECT *
FROM ' . USER_NOTIFICATIONS_TABLE . " FROM ' . USER_NOTIFICATIONS_TABLE . "
WHERE item_type = '" . self::get_item_type() . "' WHERE item_type = '" . get_class($this) . "'
AND " . $this->db->sql_in_set('user_id', $auth_read[$topic['forum_id']]['f_read']); AND " . $this->db->sql_in_set('user_id', $auth_read[$topic['forum_id']]['f_read']);
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result)) while ($row = $this->db->sql_fetchrow($result))

View file

@ -52,15 +52,6 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top
return (!empty($m_approve)); return (!empty($m_approve));
} }
/**
* Get the type of notification this is
* phpbb_notification_type_
*/
public static function get_item_type()
{
return 'topic_in_queue';
}
/** /**
* Find the users who want to receive notifications * Find the users who want to receive notifications
* *

View file

@ -192,7 +192,7 @@ class ucp_notifications
$template->assign_block_vars($block . '.notification_methods', array( $template->assign_block_vars($block . '.notification_methods', array(
'METHOD' => $method, 'METHOD' => $method,
'NAME' => $user->lang('NOTIFICATION_METHOD_' . strtoupper($method)), 'NAME' => $user->lang(strtoupper($method)),
'SUBSCRIBED' => (isset($subscriptions[$type]) && in_array($method, $subscriptions[$type])) ? true : false, 'SUBSCRIBED' => (isset($subscriptions[$type]) && in_array($method, $subscriptions[$type])) ? true : false,
)); ));
@ -218,7 +218,7 @@ class ucp_notifications
$template->assign_block_vars($block, array( $template->assign_block_vars($block, array(
'METHOD' => $method, 'METHOD' => $method,
'NAME' => $user->lang('NOTIFICATION_METHOD_' . strtoupper($method)), 'NAME' => $user->lang(strtoupper($method)),
)); ));
} }
} }

View file

@ -1128,12 +1128,12 @@ function database_update_info()
NOTIFICATIONS_TABLE => array( NOTIFICATIONS_TABLE => array(
'COLUMNS' => array( 'COLUMNS' => array(
'notification_id' => array('UINT', NULL, 'auto_increment'), 'notification_id' => array('UINT', NULL, 'auto_increment'),
'item_type' => array('VCHAR:25', ''), 'item_type' => array('VCHAR:255', ''),
'item_id' => array('UINT', 0), 'item_id' => array('UINT', 0),
'item_parent_id' => array('UINT', 0), 'item_parent_id' => array('UINT', 0),
'user_id' => array('UINT', 0), 'user_id' => array('UINT', 0),
'unread' => array('BOOL', 1), 'unread' => array('BOOL', 1),
'is_enabled' => array('BOOL', 0), 'is_enabled' => array('BOOL', 1),
'time' => array('TIMESTAMP', 1), 'time' => array('TIMESTAMP', 1),
'data' => array('TEXT_UNI', ''), 'data' => array('TEXT_UNI', ''),
), ),
@ -1150,10 +1150,10 @@ function database_update_info()
), ),
USER_NOTIFICATIONS_TABLE => array( USER_NOTIFICATIONS_TABLE => array(
'COLUMNS' => array( 'COLUMNS' => array(
'item_type' => array('VCHAR:25', ''), 'item_type' => array('VCHAR:255', ''),
'item_id' => array('UINT', 0), 'item_id' => array('UINT', 0),
'user_id' => array('UINT', 0), 'user_id' => array('UINT', 0),
'method' => array('VCHAR:25', ''), 'method' => array('VCHAR:255', ''),
), ),
'PRIMARY_KEY' => array( 'PRIMARY_KEY' => array(
'item_type', 'item_type',

View file

@ -621,12 +621,12 @@ END;;
# Table: 'phpbb_notifications' # Table: 'phpbb_notifications'
CREATE TABLE phpbb_notifications ( CREATE TABLE phpbb_notifications (
notification_id INTEGER NOT NULL, notification_id INTEGER NOT NULL,
item_type VARCHAR(25) CHARACTER SET NONE DEFAULT '' NOT NULL, item_type VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL,
item_id INTEGER DEFAULT 0 NOT NULL, item_id INTEGER DEFAULT 0 NOT NULL,
item_parent_id INTEGER DEFAULT 0 NOT NULL, item_parent_id INTEGER DEFAULT 0 NOT NULL,
user_id INTEGER DEFAULT 0 NOT NULL, user_id INTEGER DEFAULT 0 NOT NULL,
unread INTEGER DEFAULT 1 NOT NULL, unread INTEGER DEFAULT 1 NOT NULL,
is_disabled INTEGER DEFAULT 0 NOT NULL, is_enabled INTEGER DEFAULT 1 NOT NULL,
time INTEGER DEFAULT 1 NOT NULL, time INTEGER DEFAULT 1 NOT NULL,
data BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL data BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL
);; );;
@ -639,7 +639,7 @@ CREATE INDEX phpbb_notifications_item_pid ON phpbb_notifications(item_parent_id)
CREATE INDEX phpbb_notifications_user_id ON phpbb_notifications(user_id);; CREATE INDEX phpbb_notifications_user_id ON phpbb_notifications(user_id);;
CREATE INDEX phpbb_notifications_time ON phpbb_notifications(time);; CREATE INDEX phpbb_notifications_time ON phpbb_notifications(time);;
CREATE INDEX phpbb_notifications_unread ON phpbb_notifications(unread);; CREATE INDEX phpbb_notifications_unread ON phpbb_notifications(unread);;
CREATE INDEX phpbb_notifications_is_disabled ON phpbb_notifications(is_disabled);; CREATE INDEX phpbb_notifications_is_enabled ON phpbb_notifications(is_enabled);;
CREATE GENERATOR phpbb_notifications_gen;; CREATE GENERATOR phpbb_notifications_gen;;
SET GENERATOR phpbb_notifications_gen TO 0;; SET GENERATOR phpbb_notifications_gen TO 0;;
@ -1237,10 +1237,10 @@ CREATE INDEX phpbb_topics_watch_notify_stat ON phpbb_topics_watch(notify_status)
# Table: 'phpbb_user_notifications' # Table: 'phpbb_user_notifications'
CREATE TABLE phpbb_user_notifications ( CREATE TABLE phpbb_user_notifications (
item_type VARCHAR(25) CHARACTER SET NONE DEFAULT '' NOT NULL, item_type VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL,
item_id INTEGER DEFAULT 0 NOT NULL, item_id INTEGER DEFAULT 0 NOT NULL,
user_id INTEGER DEFAULT 0 NOT NULL, user_id INTEGER DEFAULT 0 NOT NULL,
method VARCHAR(25) CHARACTER SET NONE DEFAULT '' NOT NULL method VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL
);; );;
ALTER TABLE phpbb_user_notifications ADD PRIMARY KEY (item_type, item_id, user_id, method);; ALTER TABLE phpbb_user_notifications ADD PRIMARY KEY (item_type, item_id, user_id, method);;

View file

@ -756,12 +756,12 @@ GO
*/ */
CREATE TABLE [phpbb_notifications] ( CREATE TABLE [phpbb_notifications] (
[notification_id] [int] IDENTITY (1, 1) NOT NULL , [notification_id] [int] IDENTITY (1, 1) NOT NULL ,
[item_type] [varchar] (25) DEFAULT ('') NOT NULL , [item_type] [varchar] (255) DEFAULT ('') NOT NULL ,
[item_id] [int] DEFAULT (0) NOT NULL , [item_id] [int] DEFAULT (0) NOT NULL ,
[item_parent_id] [int] DEFAULT (0) NOT NULL , [item_parent_id] [int] DEFAULT (0) NOT NULL ,
[user_id] [int] DEFAULT (0) NOT NULL , [user_id] [int] DEFAULT (0) NOT NULL ,
[unread] [int] DEFAULT (1) NOT NULL , [unread] [int] DEFAULT (1) NOT NULL ,
[is_disabled] [int] DEFAULT (0) NOT NULL , [is_enabled] [int] DEFAULT (1) NOT NULL ,
[time] [int] DEFAULT (1) NOT NULL , [time] [int] DEFAULT (1) NOT NULL ,
[data] [varchar] (4000) DEFAULT ('') NOT NULL [data] [varchar] (4000) DEFAULT ('') NOT NULL
) ON [PRIMARY] ) ON [PRIMARY]
@ -792,7 +792,7 @@ GO
CREATE INDEX [unread] ON [phpbb_notifications]([unread]) ON [PRIMARY] CREATE INDEX [unread] ON [phpbb_notifications]([unread]) ON [PRIMARY]
GO GO
CREATE INDEX [is_disabled] ON [phpbb_notifications]([is_disabled]) ON [PRIMARY] CREATE INDEX [is_enabled] ON [phpbb_notifications]([is_enabled]) ON [PRIMARY]
GO GO
@ -1523,10 +1523,10 @@ GO
Table: 'phpbb_user_notifications' Table: 'phpbb_user_notifications'
*/ */
CREATE TABLE [phpbb_user_notifications] ( CREATE TABLE [phpbb_user_notifications] (
[item_type] [varchar] (25) DEFAULT ('') NOT NULL , [item_type] [varchar] (255) DEFAULT ('') NOT NULL ,
[item_id] [int] DEFAULT (0) NOT NULL , [item_id] [int] DEFAULT (0) NOT NULL ,
[user_id] [int] DEFAULT (0) NOT NULL , [user_id] [int] DEFAULT (0) NOT NULL ,
[method] [varchar] (25) DEFAULT ('') NOT NULL [method] [varchar] (255) DEFAULT ('') NOT NULL
) ON [PRIMARY] ) ON [PRIMARY]
GO GO

View file

@ -433,12 +433,12 @@ CREATE TABLE phpbb_modules (
# Table: 'phpbb_notifications' # Table: 'phpbb_notifications'
CREATE TABLE phpbb_notifications ( CREATE TABLE phpbb_notifications (
notification_id mediumint(8) UNSIGNED NOT NULL auto_increment, notification_id mediumint(8) UNSIGNED NOT NULL auto_increment,
item_type varbinary(25) DEFAULT '' NOT NULL, item_type varbinary(255) DEFAULT '' NOT NULL,
item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
item_parent_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, user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
unread tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, unread tinyint(1) UNSIGNED DEFAULT '1' NOT NULL,
is_disabled tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, is_enabled tinyint(1) UNSIGNED DEFAULT '1' NOT NULL,
time int(11) UNSIGNED DEFAULT '1' NOT NULL, time int(11) UNSIGNED DEFAULT '1' NOT NULL,
data blob NOT NULL, data blob NOT NULL,
PRIMARY KEY (notification_id), PRIMARY KEY (notification_id),
@ -448,7 +448,7 @@ CREATE TABLE phpbb_notifications (
KEY user_id (user_id), KEY user_id (user_id),
KEY time (time), KEY time (time),
KEY unread (unread), KEY unread (unread),
KEY is_disabled (is_disabled) KEY is_enabled (is_enabled)
); );
@ -873,10 +873,10 @@ CREATE TABLE phpbb_topics_watch (
# Table: 'phpbb_user_notifications' # Table: 'phpbb_user_notifications'
CREATE TABLE phpbb_user_notifications ( CREATE TABLE phpbb_user_notifications (
item_type varbinary(25) DEFAULT '' NOT NULL, item_type varbinary(255) DEFAULT '' NOT NULL,
item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
method varbinary(25) DEFAULT '' NOT NULL, method varbinary(255) DEFAULT '' NOT NULL,
PRIMARY KEY (item_type, item_id, user_id, method), PRIMARY KEY (item_type, item_id, user_id, method),
KEY it (item_type), KEY it (item_type),
KEY uid (user_id) KEY uid (user_id)

View file

@ -433,12 +433,12 @@ CREATE TABLE phpbb_modules (
# Table: 'phpbb_notifications' # Table: 'phpbb_notifications'
CREATE TABLE phpbb_notifications ( CREATE TABLE phpbb_notifications (
notification_id mediumint(8) UNSIGNED NOT NULL auto_increment, notification_id mediumint(8) UNSIGNED NOT NULL auto_increment,
item_type varchar(25) DEFAULT '' NOT NULL, item_type varchar(255) DEFAULT '' NOT NULL,
item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
item_parent_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, user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
unread tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, unread tinyint(1) UNSIGNED DEFAULT '1' NOT NULL,
is_disabled tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, is_enabled tinyint(1) UNSIGNED DEFAULT '1' NOT NULL,
time int(11) UNSIGNED DEFAULT '1' NOT NULL, time int(11) UNSIGNED DEFAULT '1' NOT NULL,
data text NOT NULL, data text NOT NULL,
PRIMARY KEY (notification_id), PRIMARY KEY (notification_id),
@ -448,7 +448,7 @@ CREATE TABLE phpbb_notifications (
KEY user_id (user_id), KEY user_id (user_id),
KEY time (time), KEY time (time),
KEY unread (unread), KEY unread (unread),
KEY is_disabled (is_disabled) KEY is_enabled (is_enabled)
) CHARACTER SET `utf8` COLLATE `utf8_bin`; ) CHARACTER SET `utf8` COLLATE `utf8_bin`;
@ -873,10 +873,10 @@ CREATE TABLE phpbb_topics_watch (
# Table: 'phpbb_user_notifications' # Table: 'phpbb_user_notifications'
CREATE TABLE phpbb_user_notifications ( CREATE TABLE phpbb_user_notifications (
item_type varchar(25) DEFAULT '' NOT NULL, item_type varchar(255) DEFAULT '' NOT NULL,
item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL,
method varchar(25) DEFAULT '' NOT NULL, method varchar(255) DEFAULT '' NOT NULL,
PRIMARY KEY (item_type, item_id, user_id, method), PRIMARY KEY (item_type, item_id, user_id, method),
KEY it (item_type), KEY it (item_type),
KEY uid (user_id) KEY uid (user_id)

View file

@ -845,12 +845,12 @@ END;
*/ */
CREATE TABLE phpbb_notifications ( CREATE TABLE phpbb_notifications (
notification_id number(8) NOT NULL, notification_id number(8) NOT NULL,
item_type varchar2(25) DEFAULT '' , item_type varchar2(255) DEFAULT '' ,
item_id number(8) DEFAULT '0' NOT NULL, item_id number(8) DEFAULT '0' NOT NULL,
item_parent_id number(8) DEFAULT '0' NOT NULL, item_parent_id number(8) DEFAULT '0' NOT NULL,
user_id number(8) DEFAULT '0' NOT NULL, user_id number(8) DEFAULT '0' NOT NULL,
unread number(1) DEFAULT '1' NOT NULL, unread number(1) DEFAULT '1' NOT NULL,
is_disabled number(1) DEFAULT '0' NOT NULL, is_enabled number(1) DEFAULT '1' NOT NULL,
time number(11) DEFAULT '1' NOT NULL, time number(11) DEFAULT '1' NOT NULL,
data clob DEFAULT '' , data clob DEFAULT '' ,
CONSTRAINT pk_phpbb_notifications PRIMARY KEY (notification_id) CONSTRAINT pk_phpbb_notifications PRIMARY KEY (notification_id)
@ -869,7 +869,7 @@ CREATE INDEX phpbb_notifications_time ON phpbb_notifications (time)
/ /
CREATE INDEX phpbb_notifications_unread ON phpbb_notifications (unread) CREATE INDEX phpbb_notifications_unread ON phpbb_notifications (unread)
/ /
CREATE INDEX phpbb_notifications_is_disabled ON phpbb_notifications (is_disabled) CREATE INDEX phpbb_notifications_is_enabled ON phpbb_notifications (is_enabled)
/ /
CREATE SEQUENCE phpbb_notifications_seq CREATE SEQUENCE phpbb_notifications_seq
@ -1641,10 +1641,10 @@ CREATE INDEX phpbb_topics_watch_notify_stat ON phpbb_topics_watch (notify_status
Table: 'phpbb_user_notifications' Table: 'phpbb_user_notifications'
*/ */
CREATE TABLE phpbb_user_notifications ( CREATE TABLE phpbb_user_notifications (
item_type varchar2(25) DEFAULT '' , item_type varchar2(255) DEFAULT '' ,
item_id number(8) DEFAULT '0' NOT NULL, item_id number(8) DEFAULT '0' NOT NULL,
user_id number(8) DEFAULT '0' NOT NULL, user_id number(8) DEFAULT '0' NOT NULL,
method varchar2(25) DEFAULT '' , method varchar2(255) DEFAULT '' ,
CONSTRAINT pk_phpbb_user_notifications PRIMARY KEY (item_type, item_id, user_id, method) CONSTRAINT pk_phpbb_user_notifications PRIMARY KEY (item_type, item_id, user_id, method)
) )
/ /

View file

@ -603,12 +603,12 @@ CREATE SEQUENCE phpbb_notifications_seq;
CREATE TABLE phpbb_notifications ( CREATE TABLE phpbb_notifications (
notification_id INT4 DEFAULT nextval('phpbb_notifications_seq'), notification_id INT4 DEFAULT nextval('phpbb_notifications_seq'),
item_type varchar(25) DEFAULT '' NOT NULL, item_type varchar(255) DEFAULT '' NOT NULL,
item_id INT4 DEFAULT '0' NOT NULL CHECK (item_id >= 0), item_id INT4 DEFAULT '0' NOT NULL CHECK (item_id >= 0),
item_parent_id INT4 DEFAULT '0' NOT NULL CHECK (item_parent_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), user_id INT4 DEFAULT '0' NOT NULL CHECK (user_id >= 0),
unread INT2 DEFAULT '1' NOT NULL CHECK (unread >= 0), unread INT2 DEFAULT '1' NOT NULL CHECK (unread >= 0),
is_disabled INT2 DEFAULT '0' NOT NULL CHECK (is_disabled >= 0), is_enabled INT2 DEFAULT '1' NOT NULL CHECK (is_enabled >= 0),
time INT4 DEFAULT '1' NOT NULL CHECK (time >= 0), time INT4 DEFAULT '1' NOT NULL CHECK (time >= 0),
data varchar(4000) DEFAULT '' NOT NULL, data varchar(4000) DEFAULT '' NOT NULL,
PRIMARY KEY (notification_id) PRIMARY KEY (notification_id)
@ -620,7 +620,7 @@ CREATE INDEX phpbb_notifications_item_pid ON phpbb_notifications (item_parent_id
CREATE INDEX phpbb_notifications_user_id ON phpbb_notifications (user_id); CREATE INDEX phpbb_notifications_user_id ON phpbb_notifications (user_id);
CREATE INDEX phpbb_notifications_time ON phpbb_notifications (time); CREATE INDEX phpbb_notifications_time ON phpbb_notifications (time);
CREATE INDEX phpbb_notifications_unread ON phpbb_notifications (unread); CREATE INDEX phpbb_notifications_unread ON phpbb_notifications (unread);
CREATE INDEX phpbb_notifications_is_disabled ON phpbb_notifications (is_disabled); CREATE INDEX phpbb_notifications_is_enabled ON phpbb_notifications (is_enabled);
/* /*
Table: 'phpbb_poll_options' Table: 'phpbb_poll_options'
@ -1123,10 +1123,10 @@ CREATE INDEX phpbb_topics_watch_notify_stat ON phpbb_topics_watch (notify_status
Table: 'phpbb_user_notifications' Table: 'phpbb_user_notifications'
*/ */
CREATE TABLE phpbb_user_notifications ( CREATE TABLE phpbb_user_notifications (
item_type varchar(25) DEFAULT '' NOT NULL, item_type varchar(255) DEFAULT '' NOT NULL,
item_id INT4 DEFAULT '0' NOT NULL CHECK (item_id >= 0), item_id INT4 DEFAULT '0' NOT NULL CHECK (item_id >= 0),
user_id INT4 DEFAULT '0' NOT NULL CHECK (user_id >= 0), user_id INT4 DEFAULT '0' NOT NULL CHECK (user_id >= 0),
method varchar(25) DEFAULT '' NOT NULL, method varchar(255) DEFAULT '' NOT NULL,
PRIMARY KEY (item_type, item_id, user_id, method) PRIMARY KEY (item_type, item_id, user_id, method)
); );

View file

@ -420,12 +420,12 @@ CREATE INDEX phpbb_modules_class_left_id ON phpbb_modules (module_class, left_id
# Table: 'phpbb_notifications' # Table: 'phpbb_notifications'
CREATE TABLE phpbb_notifications ( CREATE TABLE phpbb_notifications (
notification_id INTEGER PRIMARY KEY NOT NULL , notification_id INTEGER PRIMARY KEY NOT NULL ,
item_type varchar(25) NOT NULL DEFAULT '', item_type varchar(255) NOT NULL DEFAULT '',
item_id INTEGER UNSIGNED NOT NULL DEFAULT '0', item_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
item_parent_id INTEGER UNSIGNED NOT NULL DEFAULT '0', item_parent_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
user_id INTEGER UNSIGNED NOT NULL DEFAULT '0', user_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
unread INTEGER UNSIGNED NOT NULL DEFAULT '1', unread INTEGER UNSIGNED NOT NULL DEFAULT '1',
is_disabled INTEGER UNSIGNED NOT NULL DEFAULT '0', is_enabled INTEGER UNSIGNED NOT NULL DEFAULT '1',
time INTEGER UNSIGNED NOT NULL DEFAULT '1', time INTEGER UNSIGNED NOT NULL DEFAULT '1',
data text(65535) NOT NULL DEFAULT '' data text(65535) NOT NULL DEFAULT ''
); );
@ -436,7 +436,7 @@ CREATE INDEX phpbb_notifications_item_pid ON phpbb_notifications (item_parent_id
CREATE INDEX phpbb_notifications_user_id ON phpbb_notifications (user_id); CREATE INDEX phpbb_notifications_user_id ON phpbb_notifications (user_id);
CREATE INDEX phpbb_notifications_time ON phpbb_notifications (time); CREATE INDEX phpbb_notifications_time ON phpbb_notifications (time);
CREATE INDEX phpbb_notifications_unread ON phpbb_notifications (unread); CREATE INDEX phpbb_notifications_unread ON phpbb_notifications (unread);
CREATE INDEX phpbb_notifications_is_disabled ON phpbb_notifications (is_disabled); CREATE INDEX phpbb_notifications_is_enabled ON phpbb_notifications (is_enabled);
# Table: 'phpbb_poll_options' # Table: 'phpbb_poll_options'
CREATE TABLE phpbb_poll_options ( CREATE TABLE phpbb_poll_options (
@ -846,10 +846,10 @@ CREATE INDEX phpbb_topics_watch_notify_stat ON phpbb_topics_watch (notify_status
# Table: 'phpbb_user_notifications' # Table: 'phpbb_user_notifications'
CREATE TABLE phpbb_user_notifications ( CREATE TABLE phpbb_user_notifications (
item_type varchar(25) NOT NULL DEFAULT '', item_type varchar(255) NOT NULL DEFAULT '',
item_id INTEGER UNSIGNED NOT NULL DEFAULT '0', item_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
user_id INTEGER UNSIGNED NOT NULL DEFAULT '0', user_id INTEGER UNSIGNED NOT NULL DEFAULT '0',
method varchar(25) NOT NULL DEFAULT '', method varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (item_type, item_id, user_id, method) PRIMARY KEY (item_type, item_id, user_id, method)
); );

View file

@ -295,8 +295,6 @@ $lang = array_merge($lang, array(
'NOTIFICATION_GROUP_MISCELLANEOUS' => 'Miscellaneous Notifications', 'NOTIFICATION_GROUP_MISCELLANEOUS' => 'Miscellaneous Notifications',
'NOTIFICATION_GROUP_MODERATION' => 'Moderation Notifications', 'NOTIFICATION_GROUP_MODERATION' => 'Moderation Notifications',
'NOTIFICATION_GROUP_POSTING' => 'Posting Notifications', 'NOTIFICATION_GROUP_POSTING' => 'Posting Notifications',
'NOTIFICATION_METHOD_EMAIL' => 'Email',
'NOTIFICATION_METHOD_JABBER' => 'Jabber',
'NOTIFICATION_TYPE' => 'Notification type', 'NOTIFICATION_TYPE' => 'Notification type',
'NOTIFICATION_TYPE_BOOKMARK' => 'Someone replies to a topic you have bookmarked', 'NOTIFICATION_TYPE_BOOKMARK' => 'Someone replies to a topic you have bookmarked',
'NOTIFICATION_TYPE_IN_MODERATION_QUEUE' => 'A post or topic needs approval', 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE' => 'A post or topic needs approval',
@ -376,6 +374,8 @@ $lang = array_merge($lang, array(
'PASSWORD_UPDATED' => 'A new password was sent to your registered email address.', 'PASSWORD_UPDATED' => 'A new password was sent to your registered email address.',
'PERMISSIONS_RESTORED' => 'Successfully restored original permissions.', 'PERMISSIONS_RESTORED' => 'Successfully restored original permissions.',
'PERMISSIONS_TRANSFERRED' => 'Successfully transferred permissions from <strong>%s</strong>, you are now able to browse the board with this users permissions.<br />Please note that admin permissions were not transferred. You are able to revert to your permission set at any time.', 'PERMISSIONS_TRANSFERRED' => 'Successfully transferred permissions from <strong>%s</strong>, you are now able to browse the board with this users permissions.<br />Please note that admin permissions were not transferred. You are able to revert to your permission set at any time.',
'PHPBB_NOTIFICATION_METHOD_EMAIL' => 'Email',
'PHPBB_NOTIFICATION_METHOD_JABBER' => 'Jabber',
'PM_DISABLED' => 'Private messaging has been disabled on this board.', 'PM_DISABLED' => 'Private messaging has been disabled on this board.',
'PM_FROM' => 'From', 'PM_FROM' => 'From',
'PM_FROM_REMOVED_AUTHOR' => 'This message was sent by a user no longer registered.', 'PM_FROM_REMOVED_AUTHOR' => 'This message was sent by a user no longer registered.',

View file

@ -185,7 +185,7 @@ if ($submit && $reason_id)
$lang_return = $user->lang['RETURN_TOPIC']; $lang_return = $user->lang['RETURN_TOPIC'];
$lang_success = $user->lang['POST_REPORTED_SUCCESS']; $lang_success = $user->lang['POST_REPORTED_SUCCESS'];
$phpbb_notifications->add_notifications('report_post', array_merge($report_data, $row, $forum_data, array( $phpbb_notifications->add_notifications('phpbb_notification_type_report_post', array_merge($report_data, $row, $forum_data, array(
'report_text' => $report_text, 'report_text' => $report_text,
))); )));
} }
@ -215,7 +215,7 @@ if ($submit && $reason_id)
$lang_return = $user->lang['RETURN_PM']; $lang_return = $user->lang['RETURN_PM'];
$lang_success = $user->lang['PM_REPORTED_SUCCESS']; $lang_success = $user->lang['PM_REPORTED_SUCCESS'];
$phpbb_notifications->add_notifications('report_pm', array_merge($report_data, $row, array( $phpbb_notifications->add_notifications('phpbb_notification_type_report_pm', array_merge($report_data, $row, array(
'report_text' => $report_text, 'report_text' => $report_text,
'from_user_id' => $report_data['author_id'], 'from_user_id' => $report_data['author_id'],
'report_id' => $report_id, 'report_id' => $report_id,

View file

@ -17,13 +17,6 @@ if (!defined('IN_PHPBB'))
class phpbb_ext_test_notification_type_test extends phpbb_notification_type_base class phpbb_ext_test_notification_type_test extends phpbb_notification_type_base
{ {
public $email_template = 'topic_notify';
public static function get_item_type()
{
return 'ext_test-test';
}
public static function get_item_id($post) public static function get_item_id($post)
{ {
return (int) $post['post_id']; return (int) $post['post_id'];
@ -39,11 +32,25 @@ class phpbb_ext_test_notification_type_test extends phpbb_notification_type_base
return $this->_find_users_for_notification(0, $options); return $this->_find_users_for_notification(0, $options);
} }
public function create_insert_array($post) public function create_insert_array($post, $pre_create_data = array())
{ {
$this->time = $post['post_time']; $this->time = $post['post_time'];
return parent::create_insert_array($post); return parent::create_insert_array($post, $pre_create_data);
}
public function create_update_array($type_data)
{
$data = $this->create_insert_array($type_data);
// Unset data unique to each row
unset(
$data['notification_id'],
$data['unread'],
$data['user_id']
);
return $data;
} }
public function get_title() public function get_title()
@ -61,6 +68,11 @@ class phpbb_ext_test_notification_type_test extends phpbb_notification_type_base
return ''; return '';
} }
public function get_email_template()
{
return false;
}
public function get_email_template_variables() public function get_email_template_variables()
{ {
return array(); return array();

View file

@ -95,13 +95,20 @@ class phpbb_notification_test extends phpbb_database_test_case
public function test_get_subscription_types() public function test_get_subscription_types()
{ {
$this->assertArrayHasKey('ext_test-test', $this->notifications->get_subscription_types()); $subscription_types = $this->notifications->get_subscription_types();
$this->assertArrayHasKey('moderation_queue', $this->notifications->get_subscription_types());
$this->assertArrayHasKey('bookmark', $this->notifications->get_subscription_types()); $this->assertArrayHasKey('NOTIFICATION_GROUP_MISCELLANEOUS', $subscription_types);
$this->assertArrayHasKey('pm', $this->notifications->get_subscription_types()); $this->assertArrayHasKey('NOTIFICATION_GROUP_POSTING', $subscription_types);
$this->assertArrayHasKey('post', $this->notifications->get_subscription_types());
$this->assertArrayHasKey('quote', $this->notifications->get_subscription_types()); $this->assertArrayHasKey('phpbb_notification_type_bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']);
$this->assertArrayHasKey('topic', $this->notifications->get_subscription_types()); $this->assertArrayHasKey('phpbb_notification_type_post', $subscription_types['NOTIFICATION_GROUP_POSTING']);
$this->assertArrayHasKey('phpbb_notification_type_quote', $subscription_types['NOTIFICATION_GROUP_POSTING']);
$this->assertArrayHasKey('phpbb_notification_type_topic', $subscription_types['NOTIFICATION_GROUP_POSTING']);
$this->assertArrayHasKey('moderation_queue', $subscription_types['NOTIFICATION_GROUP_POSTING']);
$this->assertArrayHasKey('phpbb_notification_type_pm', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']);
$this->assertArrayHasKey('phpbb_ext_test_notification_type_test', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']);
//get_subscription_types //get_subscription_types
//get_subscription_methods //get_subscription_methods
@ -109,23 +116,23 @@ class phpbb_notification_test extends phpbb_database_test_case
public function test_subscriptions() public function test_subscriptions()
{ {
$this->notifications->add_subscription('post', 0, ''); $this->notifications->add_subscription('phpbb_notification_type_post', 0, '');
$this->notifications->add_subscription('post', 0, '', 1); $this->notifications->add_subscription('phpbb_notification_type_post', 0, '', 1);
$this->notifications->add_subscription('quote', 0, '', 1); $this->notifications->add_subscription('phpbb_notification_type_quote', 0, '', 1);
$this->notifications->add_subscription('post', 0, '', 2); $this->notifications->add_subscription('phpbb_notification_type_post', 0, '', 2);
$this->notifications->add_subscription('post', 0, 'email', 2); $this->notifications->add_subscription('phpbb_notification_type_post', 0, 'email', 2);
$this->notifications->add_subscription('post', 0, 'jabber', 2); $this->notifications->add_subscription('phpbb_notification_type_post', 0, 'jabber', 2);
$this->notifications->add_subscription('post', 1, '', 2); $this->notifications->add_subscription('phpbb_notification_type_post', 1, '', 2);
$this->notifications->add_subscription('post', 1, 'email', 2); $this->notifications->add_subscription('phpbb_notification_type_post', 1, 'email', 2);
$this->notifications->add_subscription('post', 1, 'jabber', 2); $this->notifications->add_subscription('phpbb_notification_type_post', 1, 'jabber', 2);
$this->notifications->add_subscription('post', 2, '', 2); $this->notifications->add_subscription('phpbb_notification_type_post', 2, '', 2);
$this->notifications->add_subscription('post', 2, 'email', 2); $this->notifications->add_subscription('phpbb_notification_type_post', 2, 'email', 2);
$this->notifications->add_subscription('post', 2, 'jabber', 2); $this->notifications->add_subscription('phpbb_notification_type_post', 2, 'jabber', 2);
$this->assertEquals(array( $this->assertEquals(array(
array( array(
'item_type' => 'post', 'item_type' => 'phpbb_notification_type_post',
'item_id' => 0, 'item_id' => 0,
'user_id' => 0, 'user_id' => 0,
'method' => '', 'method' => '',
@ -134,13 +141,13 @@ class phpbb_notification_test extends phpbb_database_test_case
$this->assertEquals(array( $this->assertEquals(array(
array( array(
'item_type' => 'post', 'item_type' => 'phpbb_notification_type_post',
'item_id' => 0, 'item_id' => 0,
'user_id' => 1, 'user_id' => 1,
'method' => '', 'method' => '',
), ),
array( array(
'item_type' => 'quote', 'item_type' => 'phpbb_notification_type_quote',
'item_id' => 0, 'item_id' => 0,
'user_id' => 1, 'user_id' => 1,
'method' => '', 'method' => '',
@ -149,55 +156,55 @@ class phpbb_notification_test extends phpbb_database_test_case
$this->assertEquals(array( $this->assertEquals(array(
array( array(
'item_type' => 'post', 'item_type' => 'phpbb_notification_type_post',
'item_id' => 0, 'item_id' => 0,
'user_id' => 2, 'user_id' => 2,
'method' => '', 'method' => '',
), ),
array( array(
'item_type' => 'post', 'item_type' => 'phpbb_notification_type_post',
'item_id' => 0, 'item_id' => 0,
'user_id' => 2, 'user_id' => 2,
'method' => 'email', 'method' => 'email',
), ),
array( array(
'item_type' => 'post', 'item_type' => 'phpbb_notification_type_post',
'item_id' => 0, 'item_id' => 0,
'user_id' => 2, 'user_id' => 2,
'method' => 'jabber', 'method' => 'jabber',
), ),
array( array(
'item_type' => 'post', 'item_type' => 'phpbb_notification_type_post',
'item_id' => 1, 'item_id' => 1,
'user_id' => 2, 'user_id' => 2,
'method' => '', 'method' => '',
), ),
array( array(
'item_type' => 'post', 'item_type' => 'phpbb_notification_type_post',
'item_id' => 1, 'item_id' => 1,
'user_id' => 2, 'user_id' => 2,
'method' => 'email', 'method' => 'email',
), ),
array( array(
'item_type' => 'post', 'item_type' => 'phpbb_notification_type_post',
'item_id' => 1, 'item_id' => 1,
'user_id' => 2, 'user_id' => 2,
'method' => 'jabber', 'method' => 'jabber',
), ),
array( array(
'item_type' => 'post', 'item_type' => 'phpbb_notification_type_post',
'item_id' => 2, 'item_id' => 2,
'user_id' => 2, 'user_id' => 2,
'method' => '', 'method' => '',
), ),
array( array(
'item_type' => 'post', 'item_type' => 'phpbb_notification_type_post',
'item_id' => 2, 'item_id' => 2,
'user_id' => 2, 'user_id' => 2,
'method' => 'email', 'method' => 'email',
), ),
array( array(
'item_type' => 'post', 'item_type' => 'phpbb_notification_type_post',
'item_id' => 2, 'item_id' => 2,
'user_id' => 2, 'user_id' => 2,
'method' => 'jabber', 'method' => 'jabber',
@ -205,50 +212,50 @@ class phpbb_notification_test extends phpbb_database_test_case
), $this->notifications->get_subscriptions(2)); ), $this->notifications->get_subscriptions(2));
$this->assertEquals(array( $this->assertEquals(array(
'post' => array( 'phpbb_notification_type_post' => array(
'', '',
'email', 'email',
'jabber', 'jabber',
), ),
), $this->notifications->get_subscriptions(2, true)); ), $this->notifications->get_subscriptions(2, true));
$this->notifications->delete_subscription('post', 0, '', 2); $this->notifications->delete_subscription('phpbb_notification_type_post', 0, '', 2);
$this->notifications->delete_subscription('post', 1, 'email', 2); $this->notifications->delete_subscription('phpbb_notification_type_post', 1, 'email', 2);
$this->notifications->delete_subscription('post', 2, 'jabber', 2); $this->notifications->delete_subscription('phpbb_notification_type_post', 2, 'jabber', 2);
$this->assertEquals(array( $this->assertEquals(array(
array( array(
'item_type' => 'post', 'item_type' => 'phpbb_notification_type_post',
'item_id' => 0, 'item_id' => 0,
'user_id' => 2, 'user_id' => 2,
'method' => 'email', 'method' => 'email',
), ),
array( array(
'item_type' => 'post', 'item_type' => 'phpbb_notification_type_post',
'item_id' => 0, 'item_id' => 0,
'user_id' => 2, 'user_id' => 2,
'method' => 'jabber', 'method' => 'jabber',
), ),
array( array(
'item_type' => 'post', 'item_type' => 'phpbb_notification_type_post',
'item_id' => 1, 'item_id' => 1,
'user_id' => 2, 'user_id' => 2,
'method' => '', 'method' => '',
), ),
array( array(
'item_type' => 'post', 'item_type' => 'phpbb_notification_type_post',
'item_id' => 1, 'item_id' => 1,
'user_id' => 2, 'user_id' => 2,
'method' => 'jabber', 'method' => 'jabber',
), ),
array( array(
'item_type' => 'post', 'item_type' => 'phpbb_notification_type_post',
'item_id' => 2, 'item_id' => 2,
'user_id' => 2, 'user_id' => 2,
'method' => '', 'method' => '',
), ),
array( array(
'item_type' => 'post', 'item_type' => 'phpbb_notification_type_post',
'item_id' => 2, 'item_id' => 2,
'user_id' => 2, 'user_id' => 2,
'method' => 'email', 'method' => 'email',
@ -260,7 +267,7 @@ class phpbb_notification_test extends phpbb_database_test_case
{ {
global $db; global $db;
$this->notifications->add_subscription('ext_test-test'); $this->notifications->add_subscription('phpbb_ext_test_notification_type_test');
// Used to test post notifications later // Used to test post notifications later
$db->sql_query('INSERT INTO ' . TOPICS_WATCH_TABLE . ' ' . $db->sql_build_array('INSERT', array( $db->sql_query('INSERT INTO ' . TOPICS_WATCH_TABLE . ' ' . $db->sql_build_array('INSERT', array(
@ -277,25 +284,25 @@ class phpbb_notification_test extends phpbb_database_test_case
'count_unread' => true, 'count_unread' => true,
))); )));
$this->notifications->add_notifications('ext_test-test', array( $this->notifications->add_notifications('phpbb_ext_test_notification_type_test', array(
'post_id' => '1', 'post_id' => '1',
'topic_id' => '1', 'topic_id' => '1',
'post_time' => 1349413321, 'post_time' => 1349413321,
)); ));
$this->notifications->add_notifications('ext_test-test', array( $this->notifications->add_notifications('phpbb_ext_test_notification_type_test', array(
'post_id' => '2', 'post_id' => '2',
'topic_id' => '2', 'topic_id' => '2',
'post_time' => 1349413322, 'post_time' => 1349413322,
)); ));
$this->notifications->add_notifications('ext_test-test', array( $this->notifications->add_notifications('phpbb_ext_test_notification_type_test', array(
'post_id' => '3', 'post_id' => '3',
'topic_id' => '2', 'topic_id' => '2',
'post_time' => 1349413323, 'post_time' => 1349413323,
)); ));
$this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'ext_test-test'), array( $this->notifications->add_notifications(array('phpbb_notification_type_quote', 'phpbb_notification_type_bookmark', 'phpbb_notification_type_post', 'phpbb_ext_test_notification_type_test'), array(
'post_id' => '4', 'post_id' => '4',
'topic_id' => '2', 'topic_id' => '2',
'post_time' => 1349413324, 'post_time' => 1349413324,
@ -310,9 +317,9 @@ class phpbb_notification_test extends phpbb_database_test_case
'topic_id' => 2, 'topic_id' => 2,
'user_id' => 0, 'user_id' => 0,
))); )));
$this->notifications->add_subscription('bookmark'); $this->notifications->add_subscription('phpbb_notification_type_bookmark');
$this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'ext_test-test'), array( $this->notifications->add_notifications(array('phpbb_notification_type_quote', 'phpbb_notification_type_bookmark', 'phpbb_notification_type_post', 'phpbb_ext_test_notification_type_test'), array(
'post_id' => '5', 'post_id' => '5',
'topic_id' => '2', 'topic_id' => '2',
'post_time' => 1349413325, 'post_time' => 1349413325,
@ -323,9 +330,9 @@ class phpbb_notification_test extends phpbb_database_test_case
'forum_name' => 'Your first forum', 'forum_name' => 'Your first forum',
)); ));
$this->notifications->delete_subscription('ext_test-test'); $this->notifications->delete_subscription('phpbb_ext_test_notification_type_test');
$this->notifications->add_notifications('ext_test-test', array( $this->notifications->add_notifications('phpbb_ext_test_notification_type_test', array(
'post_id' => '6', 'post_id' => '6',
'topic_id' => '2', 'topic_id' => '2',
'post_time' => 1349413326, 'post_time' => 1349413326,
@ -336,8 +343,51 @@ class phpbb_notification_test extends phpbb_database_test_case
)); ));
$expected = array( $expected = array(
1 => array(
'item_type' => 'phpbb_ext_test_notification_type_test',
'item_id' => 1,
'item_parent_id' => 1,
'user_id' => 0,
'unread' => 1,
'time' => 1349413321,
'data' => array(),
),
2 => array(
'item_type' => 'phpbb_ext_test_notification_type_test',
'item_id' => 2,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'time' => 1349413322,
'data' => array(),
),
3 => array(
'item_type' => 'phpbb_ext_test_notification_type_test',
'item_id' => 3,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'time' => 1349413323,
'data' => array(),
),
4 => array(
'item_type' => 'phpbb_notification_type_post',
'item_id' => 4,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'time' => 1349413324,
'data' => array(
'poster_id' => 2,
'topic_title' => 'test-title',
'post_subject' => 'Re: test-title',
'post_username' => '',
'forum_id' => 2,
'forum_name' => 'Your first forum',
),
),
5 => array( 5 => array(
'item_type' => 'bookmark', 'item_type' => 'phpbb_notification_type_bookmark',
'item_id' => 5, 'item_id' => 5,
'item_parent_id' => 2, 'item_parent_id' => 2,
'user_id' => 0, 'user_id' => 0,
@ -352,88 +402,41 @@ class phpbb_notification_test extends phpbb_database_test_case
'forum_name' => 'Your first forum', 'forum_name' => 'Your first forum',
), ),
), ),
4 => array(
'item_type' => 'post',
'item_id' => 4,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'time' => 1349413324,
'data' => array(
'poster_id' => 2,
'topic_title' => 'test-title',
'post_subject' => 'Re: test-title',
'post_username' => '',
'forum_id' => 2,
'forum_name' => 'Your first forum',
),
),
3 => array(
'item_type' => 'ext_test-test',
'item_id' => 3,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'time' => 1349413323,
'data' => array(),
),
2 => array(
'item_type' => 'ext_test-test',
'item_id' => 2,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'time' => 1349413322,
'data' => array(),
),
1 => array(
'item_type' => 'ext_test-test',
'item_id' => 1,
'item_parent_id' => 1,
'user_id' => 0,
'unread' => 1,
'time' => 1349413321,
'data' => array(),
),
); );
$this->assertEquals(sizeof($expected), $notifications['unread_count']); $this->assertEquals(sizeof($expected), $notifications['unread_count']);
$notifications = $notifications['notifications']; $notifications = $notifications['notifications'];
$i = 0;
foreach ($expected as $notification_id => $notification_data) foreach ($expected as $notification_id => $notification_data)
{ {
//echo $notifications[$i]; //echo $notifications[$notification_id];
$this->assertEquals($notification_id, $notifications[$i]->notification_id, 'notification_id'); $this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id');
foreach ($notification_data as $key => $value) foreach ($notification_data as $key => $value)
{ {
$this->assertEquals($value, $notifications[$i]->$key, $key . ' ' . $notification_id); $this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id);
} }
$i++;
} }
// Now test updating ------------------------------- // Now test updating -------------------------------
$this->notifications->update_notifications('ext_test-test', array( $this->notifications->update_notifications('phpbb_ext_test_notification_type_test', array(
'post_id' => '1', 'post_id' => '1',
'topic_id' => '2', // change parent_id 'topic_id' => '2', // change parent_id
'post_time' => 1349413321, 'post_time' => 1349413321,
)); ));
$this->notifications->update_notifications('ext_test-test', array( $this->notifications->update_notifications('phpbb_ext_test_notification_type_test', array(
'post_id' => '3', 'post_id' => '3',
'topic_id' => '2', 'topic_id' => '2',
'post_time' => 1234, // change post_time 'post_time' => 1234, // change time
)); ));
$this->notifications->update_notifications(array('quote', 'bookmark', 'post', 'ext_test-test'), array( $this->notifications->update_notifications(array('phpbb_notification_type_quote', 'phpbb_notification_type_bookmark', 'phpbb_notification_type_post', 'phpbb_ext_test_notification_type_test'), array(
'post_id' => '5', 'post_id' => '5',
'topic_id' => '2', 'topic_id' => '2',
'post_time' => 12345, // change post_time
'poster_id' => 2, 'poster_id' => 2,
'topic_title' => 'test-title2', // change topic_title 'topic_title' => 'test-title2', // change topic_title
'post_subject' => 'Re: test-title2', // change post_subject 'post_subject' => 'Re: test-title2', // change post_subject
@ -446,8 +449,35 @@ class phpbb_notification_test extends phpbb_database_test_case
)); ));
$expected = array( $expected = array(
1 => array(
'item_type' => 'phpbb_ext_test_notification_type_test',
'item_id' => 1,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'time' => 1349413321,
'data' => array(),
),
2 => array(
'item_type' => 'phpbb_ext_test_notification_type_test',
'item_id' => 2,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'time' => 1349413322,
'data' => array(),
),
3 => array(
'item_type' => 'phpbb_ext_test_notification_type_test',
'item_id' => 3,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'time' => 1234,
'data' => array(),
),
4 => array( 4 => array(
'item_type' => 'post', 'item_type' => 'phpbb_notification_type_post',
'item_id' => 4, 'item_id' => 4,
'item_parent_id' => 2, 'item_parent_id' => 2,
'user_id' => 0, 'user_id' => 0,
@ -462,31 +492,13 @@ class phpbb_notification_test extends phpbb_database_test_case
'forum_name' => 'Your first forum', 'forum_name' => 'Your first forum',
), ),
), ),
2 => array(
'item_type' => 'ext_test-test',
'item_id' => 2,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'time' => 1349413322,
'data' => array(),
),
1 => array(
'item_type' => 'ext_test-test',
'item_id' => 1,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'time' => 1349413321,
'data' => array(),
),
5 => array( 5 => array(
'item_type' => 'bookmark', 'item_type' => 'phpbb_notification_type_bookmark',
'item_id' => 5, 'item_id' => 5,
'item_parent_id' => 2, 'item_parent_id' => 2,
'user_id' => 0, 'user_id' => 0,
'unread' => 1, 'unread' => 1,
'time' => 12345, 'time' => 1349413325,
'data' => array( 'data' => array(
'poster_id' => 2, 'poster_id' => 2,
'topic_title' => 'test-title2', 'topic_title' => 'test-title2',
@ -496,56 +508,21 @@ class phpbb_notification_test extends phpbb_database_test_case
'forum_name' => 'Your second forum', 'forum_name' => 'Your second forum',
), ),
), ),
3 => array(
'item_type' => 'ext_test-test',
'item_id' => 3,
'item_parent_id' => 2,
'user_id' => 0,
'unread' => 1,
'time' => 1234,
'data' => array(),
),
); );
$this->assertEquals(sizeof($expected), $notifications['unread_count']); $this->assertEquals(sizeof($expected), $notifications['unread_count']);
$notifications = $notifications['notifications']; $notifications = $notifications['notifications'];
$i = 0;
foreach ($expected as $notification_id => $notification_data) foreach ($expected as $notification_id => $notification_data)
{ {
//echo $notifications[$i]; //echo $notifications[$notification_id];
$this->assertEquals($notification_id, $notifications[$i]->notification_id, 'notification_id'); $this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id');
foreach ($notification_data as $key => $value) foreach ($notification_data as $key => $value)
{ {
$this->assertEquals($value, $notifications[$i]->$key, $key . ' ' . $notification_id); $this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id);
}
$i++;
}
}
private function dump($array, $pre = '')
{
echo ($pre == '') ? "\n------------------------------------------------\n" : '';
foreach ($array as $key => $value)
{
echo $pre . $key . ' => ';
if (is_array($value))
{
echo "\n";
$this->dump($value, $pre . "\t");
}
else
{
echo (string) $value;
echo "\n";
} }
} }
} }