From b887fcc3d180860e3b7fdcb2a70e2cd8a519bea2 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Sep 2012 10:49:58 -0500 Subject: [ticket/11103] The start of an all-encompassing notifications system This system will take input from various systems to store notifications and send notifications to users all in one nice extendable system. This system should act something like the notifications system on other social networking sites (in that, there is a single location where a user can see all of their notifications for various events). PHPBB3-11103 --- phpBB/includes/constants.php | 1 + phpBB/includes/notifications/method/base.php | 51 ++++++ phpBB/includes/notifications/method/email.php | 28 +++ phpBB/includes/notifications/method/interface.php | 24 +++ phpBB/includes/notifications/service.php | 197 ++++++++++++++++++++++ phpBB/includes/notifications/type/base.php | 128 ++++++++++++++ phpBB/includes/notifications/type/interface.php | 31 ++++ phpBB/includes/notifications/type/post.php | 65 +++++++ 8 files changed, 525 insertions(+) create mode 100644 phpBB/includes/notifications/method/base.php create mode 100644 phpBB/includes/notifications/method/email.php create mode 100644 phpBB/includes/notifications/method/interface.php create mode 100644 phpBB/includes/notifications/service.php create mode 100644 phpBB/includes/notifications/type/base.php create mode 100644 phpBB/includes/notifications/type/interface.php create mode 100644 phpBB/includes/notifications/type/post.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index 68af41ab20..de289c73dc 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -239,6 +239,7 @@ define('LOG_TABLE', $table_prefix . 'log'); define('LOGIN_ATTEMPT_TABLE', $table_prefix . 'login_attempts'); define('MODERATOR_CACHE_TABLE', $table_prefix . 'moderator_cache'); define('MODULES_TABLE', $table_prefix . 'modules'); +define('NOTIFICATIONS_TABLE', $table_prefix . 'notifications'); define('POLL_OPTIONS_TABLE', $table_prefix . 'poll_options'); define('POLL_VOTES_TABLE', $table_prefix . 'poll_votes'); define('POSTS_TABLE', $table_prefix . 'posts'); diff --git a/phpBB/includes/notifications/method/base.php b/phpBB/includes/notifications/method/base.php new file mode 100644 index 0000000000..a70f37db95 --- /dev/null +++ b/phpBB/includes/notifications/method/base.php @@ -0,0 +1,51 @@ +phpbb_container = $phpbb_container; + + // Some common things we're going to use + $this->db = $phpbb_container->get('dbal.conn'); + $this->user = $phpbb_container->get('user'); + } +} diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php new file mode 100644 index 0000000000..b06e2c018e --- /dev/null +++ b/phpBB/includes/notifications/method/email.php @@ -0,0 +1,28 @@ +phpbb_container = $phpbb_container; + + // Some common things we're going to use + $this->db = $phpbb_container->get('dbal.conn'); + } + + private function get_type_class_name(&$type, $safe = false) + { + if (!$safe) + { + $type = preg_replace('#[^a-z]#', '', $type); + } + + return 'phpbb_notifications_type_' . $type; + } + + /** + * Load the user's notifications + * + * @param array $options Optional options to control what notifications are loaded + * user_id User id to load notifications for (Default: $user->data['user_id']) + * limit Number of notifications to load (Default: 5) + * start Notifications offset (Default: 0) + */ + public function load_notifications($options = array()) + { + $user = $this->phpbb_container->get('user'); + + // Merge default options + $options = array_merge(array( + 'user_id' => $user->data['user_id'], + 'limit' => 5, + 'start' => 0, + ), $options); + + $notifications = $user_ids = array(); + + $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . ' + WHERE user_id = ' . (int) $options['user_id']; + $result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']); + + while ($row = $this->db->sql_fetchrow($result)) + { + $type_class_name = $this->get_type_class_name($row['type'], true); + + $notification = new $type_class_name($this->phpbb_container, $row); + $notification->users($this->users); + + $user_ids = array_merge($user_ids, $notification->users_to_query()); + + $notifications[] = $notification(); + } + $this->db->sql_freeresult($result); + + // Load the users + $user_ids = array_unique($user_ids); + + // @todo do not load users we already have in $this->users + + if (sizeof($user_ids)) + { + // @todo do not select everything + $sql = 'SELECT * FROM ' . USERS_TABLE . ' + WHERE ' . $this->db->sql_in_set('user_id', $user_ids); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->users[$row['user_id']] = $row; + } + $this->db->sql_freeresult($result); + } + + return $notifications; + } + + public function add_notifications($type, $data) + { + $type_class_name = $this->get_type_class_name($type); + + $notification_objects = array(); // 'user_id' => object + $methods = $new_rows = array(); + + // find out which users want to receive this type of notification + $sql = 'SELECT user_id FROM ' . USERS_TABLE . ' + WHERE ' . $this->db->sql_in_set('user_id', array(2)); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $row['method'] = ''; + + $notification = new $type_class_name($this->phpbb_container); + + $notification->user_id = $row['user_id']; + + $new_rows[] = $notification->create_insert_array($data); + + // setup the notification methods and add the notification to the queue + if ($row['method']) + { + if (!isset($methods[$row['method']])) + { + $method_class_name = 'phpbb_notifications_method_' . $row['method']; + $methods[$row['method']] = new $$method_class_name(); + } + + $methods[$row['method']]->add_to_queue($notification); + } + } + + // insert into the db + $this->db->sql_multi_insert(NOTIFICATIONS_TABLE, $new_rows); + + // run the queue for each method to send notifications + foreach ($methods as $method) + { + $method->run_queue(); + } + } + + public function update_notifications($type, $type_id, $data) + { + $type_class_name = $this->get_type_class_name($type); + + $object = new $$type_class($this->phpbb_container); + $update = $object->update($data); + + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $update) . " + WHERE type = '" . $this->db->sql_escape($type) . "' + AND type_id = " . (int) $type_id; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $object = new $type_class_name($this->phpbb_container, $row); + $object->update($data); + + $update_rows[] = $object->getForUpdate(); + } + } +} diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php new file mode 100644 index 0000000000..959516fd19 --- /dev/null +++ b/phpBB/includes/notifications/type/base.php @@ -0,0 +1,128 @@ +phpbb_container = $phpbb_container; + + // Some common things we're going to use + $this->db = $phpbb_container->get('dbal.conn'); + $this->phpbb_root_path = $phpbb_container->getParameter('core.root_path'); + $this->php_ext = $phpbb_container->getParameter('core.php_ext'); + + // The row from the database (unless this is a new notification we're going to add) + $this->data = $data; + $this->data['data'] = (isset($this->data['data'])) ? unserialize($this->data['data']) : array(); + } + + public function __get($name) + { + return $this->data[$name]; + } + + public function __set($name, $value) + { + $this->data[$name] = $value; + } + + public function get_data($name) + { + return $this->data['data'][$name]; + } + + public function set_data($name, $value) + { + $this->data['data'][$name] = $value; + } + + public function users(&$users) + { + $this->users = $users; + } + + /** + * Output the notification to the template + * + * @param array $options Array of options + * template_block Template block name to output to (Default: notifications) + */ + public function display($options = array()) + { + $template = $this->phpbb_container->get('template'); + $user = $this->phpbb_container->get('user'); + + // Merge default options + $options = array_merge(array( + 'template_block' => 'notifications', + ), $options); + + $template->assign_block_vars($options['template_block'], array( + 'TITLE' => $this->get_title(), + 'URL' => $this->get_url(), + 'TIME' => $user->format_date($this->time), + + 'ID' => $this->notification_id, + 'UNREAD' => $this->unread, + )); + } + + public function create_insert_array($data) + { + // Defaults + $data = array_merge(array( + 'item_type' => $this->get_type(), + 'time' => time(), + 'unread' => true, + + 'data' => array(), + ), $this->data); + + $data['data'] = serialize($data['data']); + + return $data; + } +} diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php new file mode 100644 index 0000000000..ace5ca67da --- /dev/null +++ b/phpBB/includes/notifications/type/interface.php @@ -0,0 +1,31 @@ +data['post_username'] . ' posted in the topic ' . censor_text($this->data['topic_title']); + } + + public function get_url() + { + return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}"); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['poster_id']); + } + + public function create_insert_array($post) + { + $this->item_id = $post['post_id']; + + $this->set_data('poster_id', $post['poster_id']); + + $this->set_data('topic_title', $post['topic_title']); + + $this->set_data('post_username', $post['post_username']); + + return parent::create_insert_array($post); + } +} -- cgit v1.2.1 From 44f07df96fbf933bc20166a516bf0eecee00df4c Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Sep 2012 11:40:02 -0500 Subject: [ticket/11103] Working on the add/update notifications functions Some cleanup and additional commenting as well PHPBB3-11103 --- phpBB/includes/notifications/method/base.php | 18 +---- phpBB/includes/notifications/service.php | 100 +++++++++++++++--------- phpBB/includes/notifications/type/base.php | 66 ++++++++++++++-- phpBB/includes/notifications/type/interface.php | 2 +- phpBB/includes/notifications/type/post.php | 20 +++++ 5 files changed, 146 insertions(+), 60 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/method/base.php b/phpBB/includes/notifications/method/base.php index a70f37db95..1c223df045 100644 --- a/phpBB/includes/notifications/method/base.php +++ b/phpBB/includes/notifications/method/base.php @@ -7,6 +7,8 @@ * */ +use Symfony\Component\DependencyInjection\ContainerBuilder; + /** * @ignore */ @@ -25,21 +27,7 @@ abstract class phpbb_notifications_method_base implements phpbb_notifications_me protected $db; protected $user; - /** - * notification_id - * item_type - * item_id - * - * by_user_id (one who caused the notification) - * user_id - * time - * unread - * - * data (special serialized field that each notification type can use to store stuff) - */ - protected $data = array(); - - public function __construct(Symfony\Component\DependencyInjection\ContainerBuilder $phpbb_container, $data = array()) + public function __construct(ContainerBuilder $phpbb_container, $data = array()) { // phpBB Container $this->phpbb_container = $phpbb_container; diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 8f5d559867..fd2c51a330 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -7,6 +7,8 @@ * */ +use Symfony\Component\DependencyInjection\ContainerBuilder; + /** * @ignore */ @@ -50,7 +52,7 @@ class phpbb_notifications_service * sms? */ - public function __construct(Symfony\Component\DependencyInjection\ContainerBuilder $phpbb_container) + public function __construct(ContainerBuilder $phpbb_container) { $this->phpbb_container = $phpbb_container; @@ -58,23 +60,13 @@ class phpbb_notifications_service $this->db = $phpbb_container->get('dbal.conn'); } - private function get_type_class_name(&$type, $safe = false) - { - if (!$safe) - { - $type = preg_replace('#[^a-z]#', '', $type); - } - - return 'phpbb_notifications_type_' . $type; - } - /** * Load the user's notifications * * @param array $options Optional options to control what notifications are loaded - * user_id User id to load notifications for (Default: $user->data['user_id']) - * limit Number of notifications to load (Default: 5) - * start Notifications offset (Default: 0) + * user_id User id to load notifications for (Default: $user->data['user_id']) + * limit Number of notifications to load (Default: 5) + * start Notifications offset (Default: 0) */ public function load_notifications($options = array()) { @@ -128,38 +120,58 @@ class phpbb_notifications_service return $notifications; } + /** + * Add a notification + * + * @param string $type Type identifier + * @param int $type_id Identifier within the type + * @param array $data Data specific for this type that will be inserted + */ public function add_notifications($type, $data) { $type_class_name = $this->get_type_class_name($type); - $notification_objects = array(); // 'user_id' => object - $methods = $new_rows = array(); + $notify_users = array(); + $notification_objects = $notification_methods = array(); + $new_rows = array(); // find out which users want to receive this type of notification $sql = 'SELECT user_id FROM ' . USERS_TABLE . ' WHERE ' . $this->db->sql_in_set('user_id', array(2)); $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) { - $row['method'] = ''; + if (!isset($notify_users[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = ''; + } + $this->db->sql_freeresult($result); + // 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) + { $notification = new $type_class_name($this->phpbb_container); - $notification->user_id = $row['user_id']; + $notification->user_id = (int) $user; $new_rows[] = $notification->create_insert_array($data); - // setup the notification methods and add the notification to the queue - if ($row['method']) + foreach ($methods as $method) { - if (!isset($methods[$row['method']])) + // setup the notification methods and add the notification to the queue + if ($row['method']) { - $method_class_name = 'phpbb_notifications_method_' . $row['method']; - $methods[$row['method']] = new $$method_class_name(); - } + if (!isset($notification_methods[$row['method']])) + { + $method_class_name = 'phpbb_notifications_method_' . $row['method']; + $notification_methods[$row['method']] = new $method_class_name(); + } - $methods[$row['method']]->add_to_queue($notification); + $notification_methods[$row['method']]->add_to_queue($notification); + } } } @@ -167,31 +179,43 @@ class phpbb_notifications_service $this->db->sql_multi_insert(NOTIFICATIONS_TABLE, $new_rows); // run the queue for each method to send notifications - foreach ($methods as $method) + foreach ($notification_methods as $method) { $method->run_queue(); } } + /** + * Update a notification + * + * @param string $type Type identifier + * @param int $type_id Identifier within the type + * @param array $data Data specific for this type that will be updated + */ public function update_notifications($type, $type_id, $data) { $type_class_name = $this->get_type_class_name($type); - $object = new $$type_class($this->phpbb_container); - $update = $object->update($data); + $notification = new $type_class_name($this->phpbb_container); + $update_array = $notification->create_update_array($data); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $update) . " - WHERE type = '" . $this->db->sql_escape($type) . "' - AND type_id = " . (int) $type_id; - $result = $this->db->sql_query($sql); + SET ' . $this->db->sql_build_array('UPDATE', $update_array) . " + WHERE item_type = '" . $this->db->sql_escape($type) . "' + AND item_id = " . (int) $type_id; + $this->db->sql_query($sql); + } - while ($row = $this->db->sql_fetchrow($result)) + /** + * Helper to get the notifications type class name and clean it if unsafe + */ + private function get_type_class_name(&$type, $safe = false) + { + if (!$safe) { - $object = new $type_class_name($this->phpbb_container, $row); - $object->update($data); - - $update_rows[] = $object->getForUpdate(); + $type = preg_replace('#[^a-z]#', '', $type); } + + return 'phpbb_notifications_type_' . $type; } } diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 959516fd19..2b194557e3 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -7,6 +7,8 @@ * */ +use Symfony\Component\DependencyInjection\ContainerBuilder; + /** * @ignore */ @@ -26,7 +28,12 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type protected $phpbb_root_path; protected $php_ext; - protected $users; + /** + * Array of user data containing information needed to output the notifications to the template + * + * @var array + */ + protected $users = array(); /** * Indentification data @@ -40,11 +47,11 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type * data (special serialized field that each notification type can use to store stuff) * * @var array $data Notification row from the database - * This must be private, all interaction should use __get(), __set() + * This must be private, all interaction should use __get(), __set(), get_data(), set_data() */ private $data = array(); - public function __construct(Symfony\Component\DependencyInjection\ContainerBuilder $phpbb_container, $data = array()) + public function __construct(ContainerBuilder $phpbb_container, $data = array()) { // phpBB Container $this->phpbb_container = $phpbb_container; @@ -69,16 +76,33 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type $this->data[$name] = $value; } - public function get_data($name) + /** + * Get special data (only important for the classes that extend this) + * + * @param string $name Name of the variable to get + * + * @return mixed + */ + protected function get_data($name) { return $this->data['data'][$name]; } - public function set_data($name, $value) + /** + * Set special data (only important for the classes that extend this) + * + * @param string $name Name of the variable to set + * @param mixed $value Value to set to the variable + */ + protected function set_data($name, $value) { $this->data['data'][$name] = $value; } + /** + * Function to store the users loaded from the database (for output to the template) + * (The service handles this) + */ public function users(&$users) { $this->users = $users; @@ -110,7 +134,15 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type )); } - public function create_insert_array($data) + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $special_data Data unique to this notification type + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($special_data) { // Defaults $data = array_merge(array( @@ -125,4 +157,26 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type return $data; } + + /** + * Function for preparing the data for update in an SQL query + * (The service handles insertion) + * + * @param array $special_data Data unique to this notification type + * + * @return array Array of data ready to be updated in the database + */ + public function create_update_array($special_data) + { + $data = $this->create_insert_array($special_data); + + // Unset data unique to each row + unset( + $data['notification_id'], + $data['unread'], + $data['user_id'] + ); + + return $data; + } } diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index ace5ca67da..57de755c82 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -27,5 +27,5 @@ interface phpbb_notifications_type_interface public function get_url(); - public function create_insert_array($data); + public function create_insert_array($special_data); } diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index eb8d92c79c..08da7a77cb 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -30,11 +30,21 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base return 'post'; } + /** + * Get the title of this notification + * + * @return string + */ public function get_title() { return $this->data['post_username'] . ' posted in the topic ' . censor_text($this->data['topic_title']); } + /** + * Get the url to this item + * + * @return string URL + */ public function get_url() { return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}"); @@ -50,6 +60,14 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base return array($this->data['poster_id']); } + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ public function create_insert_array($post) { $this->item_id = $post['post_id']; @@ -60,6 +78,8 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $this->set_data('post_username', $post['post_username']); + $this->time = $post['post_time']; + return parent::create_insert_array($post); } } -- cgit v1.2.1 From e45fb0025ec8c27147caee7e3c14902f2e3f02c5 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Sep 2012 12:05:55 -0500 Subject: [ticket/11103] Output the notifications to the template For now, just dumping the notifications in the header. PHPBB3-11103 --- phpBB/includes/functions.php | 9 ++++++++- phpBB/includes/notifications/service.php | 4 ++-- phpBB/includes/notifications/type/base.php | 15 +++++++++++++-- phpBB/includes/notifications/type/post.php | 13 ++++++++++++- 4 files changed, 35 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 834f57a38b..7632ea1fcb 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4778,7 +4778,7 @@ function phpbb_http_login($param) function page_header($page_title = '', $display_online_list = true, $item_id = 0, $item = 'forum') { global $db, $config, $template, $SID, $_SID, $_EXTRA_URL, $user, $auth, $phpEx, $phpbb_root_path; - global $phpbb_dispatcher; + global $phpbb_dispatcher, $phpbb_container; if (defined('HEADER_INC')) { @@ -5092,6 +5092,13 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'A_COOKIE_SETTINGS' => addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')), )); + // Output the notifications + $phpbb_notifications = $phpbb_container->get('notifications'); + foreach ($phpbb_notifications->load_notifications() as $notification) + { + $notification->display(); + } + // application/xhtml+xml not used because of IE header('Content-type: text/html; charset=UTF-8'); diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index fd2c51a330..8db414cb16 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -87,14 +87,14 @@ class phpbb_notifications_service while ($row = $this->db->sql_fetchrow($result)) { - $type_class_name = $this->get_type_class_name($row['type'], true); + $type_class_name = $this->get_type_class_name($row['item_type'], true); $notification = new $type_class_name($this->phpbb_container, $row); $notification->users($this->users); $user_ids = array_merge($user_ids, $notification->users_to_query()); - $notifications[] = $notification(); + $notifications[] = $notification; } $this->db->sql_freeresult($result); diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 2b194557e3..1b01e1d46c 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -85,7 +85,7 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type */ protected function get_data($name) { - return $this->data['data'][$name]; + return (isset($this->data['data'][$name])) ? $this->data['data'][$name] : null; } /** @@ -105,7 +105,18 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type */ public function users(&$users) { - $this->users = $users; + $this->users = &$users; + } + + /** + * Get a user row from our users cache + * + * @param int $user_id + * @return array + */ + protected function get_user($user_id) + { + return $this->users[$user_id]; } /** diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 08da7a77cb..4b343650a1 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -37,7 +37,18 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base */ public function get_title() { - return $this->data['post_username'] . ' posted in the topic ' . censor_text($this->data['topic_title']); + if ($this->get_data('post_username')) + { + $username = $this->get_data('post_username'); + } + else + { + $user_data = $this->get_user($this->get_data('poster_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + } + + return $username . ' posted in the topic ' . censor_text($this->get_data('topic_title')); } /** -- cgit v1.2.1 From 32a966b21da7051def3bd2ae608f3f2457d22476 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Sep 2012 12:28:58 -0500 Subject: [ticket/11103] Private Message type notification Also cleanup PHPBB3-11103 --- phpBB/includes/notifications/service.php | 68 ++++++++++++----- phpBB/includes/notifications/type/base.php | 2 +- phpBB/includes/notifications/type/interface.php | 4 +- phpBB/includes/notifications/type/pm.php | 97 +++++++++++++++++++++++++ phpBB/includes/notifications/type/post.php | 12 ++- 5 files changed, 162 insertions(+), 21 deletions(-) create mode 100644 phpBB/includes/notifications/type/pm.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 8db414cb16..059c2b420d 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -87,9 +87,9 @@ class phpbb_notifications_service while ($row = $this->db->sql_fetchrow($result)) { - $type_class_name = $this->get_type_class_name($row['item_type'], true); + $item_type_class_name = $this->get_item_type_class_name($row['item_type'], true); - $notification = new $type_class_name($this->phpbb_container, $row); + $notification = new $item_type_class_name($this->phpbb_container, $row); $notification->users($this->users); $user_ids = array_merge($user_ids, $notification->users_to_query()); @@ -123,13 +123,18 @@ class phpbb_notifications_service /** * Add a notification * - * @param string $type Type identifier - * @param int $type_id Identifier within the type + * @param string $item_type Type identifier + * @param int $item_id Identifier within the type * @param array $data Data specific for this type that will be inserted */ - public function add_notifications($type, $data) + public function add_notifications($item_type, $data) { - $type_class_name = $this->get_type_class_name($type); + $item_type_class_name = $this->get_item_type_class_name($item_type); + + $item_id = $item_type_class_name::get_item_id($data); + + // Update any existing notifications for this item + $this->update_notifications($item_type, $item_id, $data); $notify_users = array(); $notification_objects = $notification_methods = array(); @@ -150,10 +155,22 @@ class phpbb_notifications_service } $this->db->sql_freeresult($result); + // Make sure not to send new notifications to users who've already been notified about this item + // This may happen when an item was added, but now new users are able to see the item + $sql = 'SELECT user_id FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + unset($notify_users[$row['user_id']]); + } + $this->db->sql_freeresult($result); + // 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) { - $notification = new $type_class_name($this->phpbb_container); + $notification = new $item_type_class_name($this->phpbb_container); $notification->user_id = (int) $user; @@ -188,34 +205,49 @@ class phpbb_notifications_service /** * Update a notification * - * @param string $type Type identifier - * @param int $type_id Identifier within the type + * @param string $item_type Type identifier + * @param int $item_id Identifier within the type * @param array $data Data specific for this type that will be updated */ - public function update_notifications($type, $type_id, $data) + public function update_notifications($item_type, $item_id, $data) { - $type_class_name = $this->get_type_class_name($type); + $item_type_class_name = $this->get_item_type_class_name($item_type); - $notification = new $type_class_name($this->phpbb_container); + $notification = new $item_type_class_name($this->phpbb_container); $update_array = $notification->create_update_array($data); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $update_array) . " - WHERE item_type = '" . $this->db->sql_escape($type) . "' - AND item_id = " . (int) $type_id; + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id; + $this->db->sql_query($sql); + } + + /** + * Delete a notification + * + * @param string $item_type Type identifier + * @param int $item_id Identifier within the type + * @param array $data Data specific for this type that will be updated + */ + public function delete_notifications($item_type, $item_id) + { + $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id; $this->db->sql_query($sql); } /** - * Helper to get the notifications type class name and clean it if unsafe + * Helper to get the notifications item type class name and clean it if unsafe */ - private function get_type_class_name(&$type, $safe = false) + private function get_item_type_class_name(&$item_type, $safe = false) { if (!$safe) { - $type = preg_replace('#[^a-z]#', '', $type); + $item_type = preg_replace('#[^a-z]#', '', $item_type); } - return 'phpbb_notifications_type_' . $type; + return 'phpbb_notifications_type_' . $item_type; } } diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 1b01e1d46c..89143873a8 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -157,7 +157,7 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type { // Defaults $data = array_merge(array( - 'item_type' => $this->get_type(), + 'item_type' => $this->get_item_type(), 'time' => time(), 'unread' => true, diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index 57de755c82..b1ee9ae0b6 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -21,7 +21,9 @@ if (!defined('IN_PHPBB')) */ interface phpbb_notifications_type_interface { - public function get_type(); + public static function get_item_type(); + + public static function get_item_id($post); public function get_title(); diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php new file mode 100644 index 0000000000..f86050486e --- /dev/null +++ b/phpBB/includes/notifications/type/pm.php @@ -0,0 +1,97 @@ +get_user($this->get_data('author_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + + return $username . ' sent you a private message titled: ' . $this->get_data('message_subject'); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=pm&mode=view&p={$this->item_id}"); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['author_id']); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $this->item_id = $post['msg_id']; + + $this->set_data('author_id', $post['author_id']); + + $this->set_data('message_subject', $post['message_subject']); + + $this->time = $post['message_time']; + + return parent::create_insert_array($post); + } +} diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 4b343650a1..9bd343d288 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -25,11 +25,21 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base * Get the type of notification this is * phpbb_notifications_type_ */ - public function get_type() + public static function get_item_type() { return 'post'; } + /** + * Get the id of the + * + * @param array $post The data from the post + */ + public static function get_item_id($post) + { + return $post['post_id']; + } + /** * Get the title of this notification * -- cgit v1.2.1 From b59463552644ca4afd9e8ca7edd761ae382fc8ed Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Sep 2012 13:09:34 -0500 Subject: [ticket/11103] Add tables to the database updater and installer PHPBB3-11103 --- phpBB/includes/notifications/method/base.php | 32 +++++++++++++++++++ phpBB/includes/notifications/method/interface.php | 1 + phpBB/includes/notifications/service.php | 38 +++++++++++------------ 3 files changed, 52 insertions(+), 19 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/method/base.php b/phpBB/includes/notifications/method/base.php index 1c223df045..dbf851a059 100644 --- a/phpBB/includes/notifications/method/base.php +++ b/phpBB/includes/notifications/method/base.php @@ -27,6 +27,13 @@ abstract class phpbb_notifications_method_base implements phpbb_notifications_me protected $db; protected $user; + /** + * Queue of messages to be sent + * + * @var array + */ + protected $queue = array(); + public function __construct(ContainerBuilder $phpbb_container, $data = array()) { // phpBB Container @@ -36,4 +43,29 @@ abstract class phpbb_notifications_method_base implements phpbb_notifications_me $this->db = $phpbb_container->get('dbal.conn'); $this->user = $phpbb_container->get('user'); } + + /** + * Add a notification to the queue + * + * @param phpbb_notifications_type_interface $notification + */ + public function add_to_queue(phpbb_notifications_type_interface $notification) + { + $this->queue[] = $notification; + } + + /** + * Basic run queue function. + * Child methods should override this function if there are more efficient methods to mass-notification + */ + public function run_queue() + { + foreach ($this->queue as $notification) + { + $this->notify($notification); + } + + // Empty queue + $this->queue = array(); + } } diff --git a/phpBB/includes/notifications/method/interface.php b/phpBB/includes/notifications/method/interface.php index 2d8a8b605e..f18d005b8b 100644 --- a/phpBB/includes/notifications/method/interface.php +++ b/phpBB/includes/notifications/method/interface.php @@ -21,4 +21,5 @@ if (!defined('IN_PHPBB')) */ interface phpbb_notifications_method_interface { + public function notify($notification); } diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 059c2b420d..32211b26cf 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -33,25 +33,6 @@ class phpbb_notifications_service */ protected $users; - /** - * Desired notifications - * unique by (type, type_id, user_id, method) - * if multiple methods are desired, multiple rows will exist. - * - * method of "none" will over-ride any other options - * - * type - * type_id - * user_id - * method - * none (will never receive notifications) - * standard (listed in notifications window - * popup? - * email - * jabber - * sms? - */ - public function __construct(ContainerBuilder $phpbb_container) { $this->phpbb_container = $phpbb_container; @@ -140,6 +121,25 @@ class phpbb_notifications_service $notification_objects = $notification_methods = array(); $new_rows = array(); + /** + * Desired notifications + * unique by (type, type_id, user_id, method) + * if multiple methods are desired, multiple rows will exist. + * + * method of "none" will over-ride any other options + * + * item_type + * item_id + * user_id + * method + * none (will never receive notifications) + * standard (listed in notifications window + * popup? + * email + * jabber + * sms? + */ + // find out which users want to receive this type of notification $sql = 'SELECT user_id FROM ' . USERS_TABLE . ' WHERE ' . $this->db->sql_in_set('user_id', array(2)); -- cgit v1.2.1 From 7b0b6fc63c2593cafaa84cc38a9b3029af1ed369 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Sep 2012 13:40:05 -0500 Subject: [ticket/11103] Forgot a constant PHPBB3-11103 --- phpBB/includes/constants.php | 1 + phpBB/includes/notifications/method/email.php | 10 +++++++++- phpBB/includes/notifications/type/pm.php | 2 ++ phpBB/includes/notifications/type/post.php | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index de289c73dc..7a3c73e987 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -273,6 +273,7 @@ define('TOPICS_POSTED_TABLE', $table_prefix . 'topics_posted'); define('TOPICS_TRACK_TABLE', $table_prefix . 'topics_track'); define('TOPICS_WATCH_TABLE', $table_prefix . 'topics_watch'); define('USER_GROUP_TABLE', $table_prefix . 'user_group'); +define('USER_NOTIFICATIONS_TABLE', $table_prefix . 'user_notifications'); define('USERS_TABLE', $table_prefix . 'users'); define('WARNINGS_TABLE', $table_prefix . 'warnings'); define('WORDS_TABLE', $table_prefix . 'words'); diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index b06e2c018e..0c3cb4bd85 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -17,11 +17,19 @@ if (!defined('IN_PHPBB')) /** * Email notification method class +* This class handles sending emails for notifications +* * @package notifications */ class phpbb_notifications_method_email extends phpbb_notifications_method_base { - function notify() + public static function is_available() + { + // Email is always available + return true; + } + + public function notify() { // email the user } diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index f86050486e..191c0b7e7f 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -17,6 +17,8 @@ if (!defined('IN_PHPBB')) /** * Private message notifications class +* This class handles notifications for private messages +* * @package notifications */ class phpbb_notifications_type_pm extends phpbb_notifications_type_base diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 9bd343d288..addaa30ea6 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -17,6 +17,8 @@ if (!defined('IN_PHPBB')) /** * Post notifications class +* This class handles notifications for replies to a topic +* * @package notifications */ class phpbb_notifications_type_post extends phpbb_notifications_type_base -- cgit v1.2.1 From 7fee0cfdf60c9aeebcd498d2f41696bb7fed2dd0 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Sep 2012 15:48:46 -0500 Subject: [ticket/11103] Work on the pm type and email method PHPBB3-11103 --- phpBB/includes/functions_privmsgs.php | 13 +++++ phpBB/includes/notifications/method/base.php | 11 +++- phpBB/includes/notifications/method/email.php | 61 ++++++++++++++++++++++ phpBB/includes/notifications/service.php | 14 +---- phpBB/includes/notifications/type/base.php | 13 ++--- phpBB/includes/notifications/type/interface.php | 6 ++- phpBB/includes/notifications/type/pm.php | 69 ++++++++++++++++++++++--- 7 files changed, 159 insertions(+), 28 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 9e055a319f..99ad2ad791 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -1855,6 +1855,19 @@ function submit_pm($mode, $subject, &$data, $put_in_outbox = true) */ function pm_notification($mode, $author, $recipients, $subject, $message, $msg_id) { + global $phpbb_container; + + $phpbb_notifications = $phpbb_container->get('notifications'); + + $phpbb_notifications->add_notifications('pm', array( + 'author_id' => $author, + 'recipients' => $recipients, + 'message_subject' => $subject, + 'msg_id' => $msg_id, + )); + + return; + global $db, $user, $config, $phpbb_root_path, $phpEx, $auth; $subject = censor_text($subject); diff --git a/phpBB/includes/notifications/method/base.php b/phpBB/includes/notifications/method/base.php index dbf851a059..98c06509c6 100644 --- a/phpBB/includes/notifications/method/base.php +++ b/phpBB/includes/notifications/method/base.php @@ -26,6 +26,8 @@ abstract class phpbb_notifications_method_base implements phpbb_notifications_me protected $phpbb_container; protected $db; protected $user; + protected $phpbb_root_path; + protected $php_ext; /** * Queue of messages to be sent @@ -42,6 +44,9 @@ abstract class phpbb_notifications_method_base implements phpbb_notifications_me // Some common things we're going to use $this->db = $phpbb_container->get('dbal.conn'); $this->user = $phpbb_container->get('user'); + + $this->phpbb_root_path = $phpbb_container->getParameter('core.root_path'); + $this->php_ext = $phpbb_container->getParameter('core.php_ext'); } /** @@ -65,7 +70,11 @@ abstract class phpbb_notifications_method_base implements phpbb_notifications_me $this->notify($notification); } - // Empty queue + $this->empty_queue(); + } + + protected function empty_queue() + { $this->queue = array(); } } diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index 0c3cb4bd85..725ede7913 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -33,4 +33,65 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base { // email the user } + + public function run_queue() + { + if (!sizeof($this->queue)) + { + return; + } + + // Load all users we want to notify (we need their email address) + $user_ids = $users = array(); + foreach ($this->queue as $notification) + { + $user_ids[] = $notification->user_id; + } + + $sql = 'SELECT * FROM ' . USERS_TABLE . ' + WHERE ' . $this->db->sql_in_set('user_id', $user_ids); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $users[$row['user_id']] = $row; + } + $this->db->sql_freeresult($result); + + // Load the messenger + if (!class_exists('messenger')) + { + include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext); + } + $messenger = new messenger(); + $board_url = generate_board_url(); + + // Time to go through the queue and send emails + foreach ($this->queue as $notification) + { + $notification->users($users); + + $user = $notification->get_user(); + + $messenger->template('privmsg_notify', $user['user_lang']); + + $messenger->to($user['user_email'], $user['username']); + + $messenger->assign_vars(array( + 'SUBJECT' => htmlspecialchars_decode($notification->get_title()), + 'AUTHOR_NAME' => '', + 'USERNAME' => htmlspecialchars_decode($user['username']), + + 'U_INBOX' => $board_url . "/ucp.{$this->php_ext}?i=pm&folder=inbox", + 'U_VIEW_MESSAGE' => $board_url . "/ucp.{$this->php_ext}?i=pm&mode=view&p={$notification->get_item_id()}", + )); + + $messenger->send($addr['method']); + } + + // Save the queue in the messenger class (has to be called or these emails could be lost?) + $messenger->save_queue(); + + // We're done, empty the queue + $this->empty_queue(); + } } diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 32211b26cf..ba57fe9f72 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -141,19 +141,7 @@ class phpbb_notifications_service */ // find out which users want to receive this type of notification - $sql = 'SELECT user_id FROM ' . USERS_TABLE . ' - WHERE ' . $this->db->sql_in_set('user_id', array(2)); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (!isset($notify_users[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = ''; - } - $this->db->sql_freeresult($result); + $notify_users = $item_type_class_name::find_users_for_notification($data); // Make sure not to send new notifications to users who've already been notified about this item // This may happen when an item was added, but now new users are able to see the item diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 89143873a8..f031abae77 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -58,6 +58,7 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type // Some common things we're going to use $this->db = $phpbb_container->get('dbal.conn'); + $this->phpbb_root_path = $phpbb_container->getParameter('core.root_path'); $this->php_ext = $phpbb_container->getParameter('core.php_ext'); @@ -114,7 +115,7 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type * @param int $user_id * @return array */ - protected function get_user($user_id) + public function get_user($user_id) { return $this->users[$user_id]; } @@ -149,11 +150,11 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type * Function for preparing the data for insertion in an SQL query * (The service handles insertion) * - * @param array $special_data Data unique to this notification type + * @param array $type_data Data unique to this notification type * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($special_data) + public function create_insert_array($type_data) { // Defaults $data = array_merge(array( @@ -173,13 +174,13 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type * Function for preparing the data for update in an SQL query * (The service handles insertion) * - * @param array $special_data Data unique to this notification type + * @param array $type_data Data unique to this notification type * * @return array Array of data ready to be updated in the database */ - public function create_update_array($special_data) + public function create_update_array($type_data) { - $data = $this->create_insert_array($special_data); + $data = $this->create_insert_array($type_data); // Unset data unique to each row unset( diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index b1ee9ae0b6..b710a75606 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -23,11 +23,13 @@ interface phpbb_notifications_type_interface { public static function get_item_type(); - public static function get_item_id($post); + public static function get_item_id($type_data); public function get_title(); public function get_url(); - public function create_insert_array($special_data); + public function create_insert_array($type_data); + + public function find_users_for_notification($type_data); } diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 191c0b7e7f..7685a49614 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -84,16 +84,73 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($pm) { - $this->item_id = $post['msg_id']; + $this->item_id = $pm['msg_id']; - $this->set_data('author_id', $post['author_id']); + $this->set_data('author_id', $pm['author_id']); - $this->set_data('message_subject', $post['message_subject']); + $this->set_data('message_subject', $pm['message_subject']); - $this->time = $post['message_time']; + return parent::create_insert_array($pm); + } + + /** + * Find the users who want to receive notifications + * + * @param array $pm Data from + * @return array + */ + public function find_users_for_notification($pm) + { + $user = $this->phpbb_container->get('user'); + + // Exclude guests, current user and banned users from notifications + unset($pm['recipients'][ANONYMOUS], $pm['recipients'][$user->data['user_id']]); + + if (!sizeof($pm['recipients'])) + { + return; + } + + if (!function_exists('phpbb_get_banned_user_ids')) + { + include($phpbb_root_path . 'includes/functions_user.' . $phpEx); + } + $banned_users = phpbb_get_banned_user_ids(array_keys($pm['recipients'])); + $pm['recipients'] = array_diff(array_keys($pm['recipients']), $banned_users); + + if (!sizeof($pm['recipients'])) + { + return; + } + + $sql = 'SELECT user_id, user_notify_pm, user_notify_type + FROM ' . USERS_TABLE . ' + WHERE ' . $db->sql_in_set('user_id', $pm['recipients']); + $result = $db->sql_query($sql); + + $pm['recipients'] = array(); + + while ($row = $db->sql_fetchrow($result)) + { + if ($row['user_notify_pm']) + { + $pm['recipients'][$row['user_id']] = array(); + + if ($row['user_notify_type'] == NOTIFY_EMAIL || $row['user_notify_type'] == NOTIFY_BOTH) + { + $pm['recipients'][$row['user_id']][] = 'email'; + } + + if ($row['user_notify_type'] == NOTIFY_IM || $row['user_notify_type'] == NOTIFY_BOTH) + { + $pm['recipients'][$row['user_id']][] = 'jabber'; + } + } + } + $db->sql_freeresult($result); - return parent::create_insert_array($post); + return $pm['recipients']; } } -- cgit v1.2.1 From a4eb8bf47a77cb2637bfad5db20ab9f0dc236059 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Sep 2012 15:49:22 -0500 Subject: [ticket/11103] Jabber notification method base PHPBB3-11103 --- phpBB/includes/notifications/method/jabber.php | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 phpBB/includes/notifications/method/jabber.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/method/jabber.php b/phpBB/includes/notifications/method/jabber.php new file mode 100644 index 0000000000..15614db96c --- /dev/null +++ b/phpBB/includes/notifications/method/jabber.php @@ -0,0 +1,36 @@ + Date: Sat, 8 Sep 2012 16:02:32 -0500 Subject: [ticket/11103] Fixing some db columns that were of the incorrect type PHPBB3-11103 --- phpBB/includes/notifications/service.php | 7 ++++++- phpBB/includes/notifications/type/interface.php | 2 +- phpBB/includes/notifications/type/pm.php | 11 +++++++---- phpBB/includes/notifications/type/post.php | 2 ++ 4 files changed, 16 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index ba57fe9f72..a689e1c68a 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -141,7 +141,7 @@ class phpbb_notifications_service */ // find out which users want to receive this type of notification - $notify_users = $item_type_class_name::find_users_for_notification($data); + $notify_users = $item_type_class_name::find_users_for_notification($this->phpbb_container, $data); // Make sure not to send new notifications to users who've already been notified about this item // This may happen when an item was added, but now new users are able to see the item @@ -155,6 +155,11 @@ class phpbb_notifications_service } $this->db->sql_freeresult($result); + if (!sizeof($notify_users)) + { + return; + } + // 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) { diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index b710a75606..ccd963ba06 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -31,5 +31,5 @@ interface phpbb_notifications_type_interface public function create_insert_array($type_data); - public function find_users_for_notification($type_data); + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $type_data); } diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 7685a49614..2b2a835470 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -7,6 +7,8 @@ * */ +use Symfony\Component\DependencyInjection\ContainerBuilder; + /** * @ignore */ @@ -101,12 +103,13 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base * @param array $pm Data from * @return array */ - public function find_users_for_notification($pm) + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $pm) { - $user = $this->phpbb_container->get('user'); + $db = $phpbb_container->get('dbal.conn'); + $user = $phpbb_container->get('user'); // Exclude guests, current user and banned users from notifications - unset($pm['recipients'][ANONYMOUS], $pm['recipients'][$user->data['user_id']]); + unset($pm['recipients'][ANONYMOUS]);//, $pm['recipients'][$user->data['user_id']]); if (!sizeof($pm['recipients'])) { @@ -115,7 +118,7 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base if (!function_exists('phpbb_get_banned_user_ids')) { - include($phpbb_root_path . 'includes/functions_user.' . $phpEx); + include($phpbb_container->getParameter('core.root_path') . 'includes/functions_user.' . $phpbb_container->getParameter('core.php_ext')); } $banned_users = phpbb_get_banned_user_ids(array_keys($pm['recipients'])); $pm['recipients'] = array_diff(array_keys($pm['recipients']), $banned_users); diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index addaa30ea6..920a53bcf2 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -7,6 +7,8 @@ * */ +use Symfony\Component\DependencyInjection\ContainerBuilder; + /** * @ignore */ -- cgit v1.2.1 From 86b801df7304d43f117bea762710149c25385260 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Sep 2012 16:12:20 -0500 Subject: [ticket/11103] Some fixes for the email method PHPBB3-11103 --- phpBB/includes/functions_privmsgs.php | 25 +++++++++++-------------- phpBB/includes/notifications/method/email.php | 8 ++++---- phpBB/includes/notifications/service.php | 11 +++++------ phpBB/includes/notifications/type/base.php | 2 -- 4 files changed, 20 insertions(+), 26 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 99ad2ad791..8002765ee2 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -1543,6 +1543,7 @@ function get_folder_status($folder_id, $folder) function submit_pm($mode, $subject, &$data, $put_in_outbox = true) { global $db, $auth, $config, $phpEx, $template, $user, $phpbb_root_path; + global $phpbb_container; // We do not handle erasing pms here if ($mode == 'delete') @@ -1844,7 +1845,16 @@ function submit_pm($mode, $subject, &$data, $put_in_outbox = true) // Send Notifications if ($mode != 'edit') { - pm_notification($mode, $data['from_username'], $recipients, $subject, $data['message'], $data['msg_id']); + $phpbb_notifications = $phpbb_container->get('notifications'); + + $phpbb_notifications->add_notifications('pm', array( + 'author_id' => $data['from_user_id'], + 'recipients' => $recipients, + 'message_subject' => $subject, + 'msg_id' => $data['msg_id'], + )); + + //pm_notification($mode, $data['from_username'], $recipients, $subject, $data['message'], $data['msg_id']); } return $data['msg_id']; @@ -1855,19 +1865,6 @@ function submit_pm($mode, $subject, &$data, $put_in_outbox = true) */ function pm_notification($mode, $author, $recipients, $subject, $message, $msg_id) { - global $phpbb_container; - - $phpbb_notifications = $phpbb_container->get('notifications'); - - $phpbb_notifications->add_notifications('pm', array( - 'author_id' => $author, - 'recipients' => $recipients, - 'message_subject' => $subject, - 'msg_id' => $msg_id, - )); - - return; - global $db, $user, $config, $phpbb_root_path, $phpEx, $auth; $subject = censor_text($subject); diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index 725ede7913..0120485cff 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -29,7 +29,7 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base return true; } - public function notify() + public function notify($notification) { // email the user } @@ -70,7 +70,7 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base { $notification->users($users); - $user = $notification->get_user(); + $user = $notification->get_user($notification->user_id); $messenger->template('privmsg_notify', $user['user_lang']); @@ -82,10 +82,10 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base 'USERNAME' => htmlspecialchars_decode($user['username']), 'U_INBOX' => $board_url . "/ucp.{$this->php_ext}?i=pm&folder=inbox", - 'U_VIEW_MESSAGE' => $board_url . "/ucp.{$this->php_ext}?i=pm&mode=view&p={$notification->get_item_id()}", + 'U_VIEW_MESSAGE' => $board_url . "/ucp.{$this->php_ext}?i=pm&mode=view&p={$notification->item_id}", )); - $messenger->send($addr['method']); + $messenger->send('email'); } // Save the queue in the messenger class (has to be called or these emails could be lost?) diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index a689e1c68a..74e2e29e1a 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -172,15 +172,14 @@ class phpbb_notifications_service foreach ($methods as $method) { // setup the notification methods and add the notification to the queue - if ($row['method']) + if ($method) { - if (!isset($notification_methods[$row['method']])) + if (!isset($notification_methods[$method])) { - $method_class_name = 'phpbb_notifications_method_' . $row['method']; - $notification_methods[$row['method']] = new $method_class_name(); + $method_class_name = 'phpbb_notifications_method_' . $method; + $notification_methods[$method] = new $method_class_name($this->phpbb_container); } - - $notification_methods[$row['method']]->add_to_queue($notification); + $notification_methods[$method]->add_to_queue($notification); } } } diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index f031abae77..32d8f58ff3 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -37,7 +37,6 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type /** * Indentification data - * notification_id * item_type * item_id * user_id @@ -141,7 +140,6 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type 'URL' => $this->get_url(), 'TIME' => $user->format_date($this->time), - 'ID' => $this->notification_id, 'UNREAD' => $this->unread, )); } -- cgit v1.2.1 From 16a0757f2a21ad2ca36a9463c822539c9ea14d30 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 8 Sep 2012 17:28:13 -0500 Subject: [ticket/11103] Order notifications properly PHPBB3-11103 --- phpBB/includes/notifications/service.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 74e2e29e1a..4794472883 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -46,6 +46,8 @@ class phpbb_notifications_service * * @param array $options Optional options to control what notifications are loaded * user_id User id to load notifications for (Default: $user->data['user_id']) + * order_by Order by (Default: time) + * order_dir Order direction (Default: DESC) * limit Number of notifications to load (Default: 5) * start Notifications offset (Default: 0) */ @@ -58,12 +60,15 @@ class phpbb_notifications_service 'user_id' => $user->data['user_id'], 'limit' => 5, 'start' => 0, + 'order_by' => 'time', + 'order_dir' => 'DESC', ), $options); $notifications = $user_ids = array(); $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . ' - WHERE user_id = ' . (int) $options['user_id']; + WHERE user_id = ' . (int) $options['user_id'] . ' + 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)) -- cgit v1.2.1 From 6983f380c55779054b545e4760bf250e8ecace2e Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 8 Sep 2012 17:48:13 -0500 Subject: [ticket/11103] Full url function PHPBB3-11103 --- phpBB/includes/notifications/method/email.php | 11 ++++++----- phpBB/includes/notifications/type/interface.php | 2 ++ phpBB/includes/notifications/type/pm.php | 12 +++++++++++- 3 files changed, 19 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index 0120485cff..b1979296b9 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -23,6 +23,10 @@ if (!defined('IN_PHPBB')) */ class phpbb_notifications_method_email extends phpbb_notifications_method_base { + /** + * Is this method available for the user? + * This is checked on the notifications options + */ public static function is_available() { // Email is always available @@ -77,12 +81,9 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base $messenger->to($user['user_email'], $user['username']); $messenger->assign_vars(array( - 'SUBJECT' => htmlspecialchars_decode($notification->get_title()), - 'AUTHOR_NAME' => '', - 'USERNAME' => htmlspecialchars_decode($user['username']), + 'SUBJECT' => htmlspecialchars_decode($notification->get_title()), - 'U_INBOX' => $board_url . "/ucp.{$this->php_ext}?i=pm&folder=inbox", - 'U_VIEW_MESSAGE' => $board_url . "/ucp.{$this->php_ext}?i=pm&mode=view&p={$notification->item_id}", + 'U_VIEW_MESSAGE' => $notification->get_full_url(), )); $messenger->send('email'); diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index ccd963ba06..03e24358a9 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -29,6 +29,8 @@ interface phpbb_notifications_type_interface public function get_url(); + public function get_full_url(); + public function create_insert_array($type_data); public static function find_users_for_notification(ContainerBuilder $phpbb_container, $type_data); diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 2b2a835470..50c67de21a 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -65,7 +65,17 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base */ public function get_url() { - return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=pm&mode=view&p={$this->item_id}"); + return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=pm&mode=view&p={$this->item_id}"); + } + + /** + * Get the full url to this item + * + * @return string URL + */ + public function get_full_url() + { + return generate_board_url() . "/ucp.{$this->php_ext}?i=pm&mode=view&p={$this->item_id}"; } /** -- cgit v1.2.1 From 98a03090a05b1d7651c05ad23802973cf20dcf6b Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 8 Sep 2012 21:05:49 -0500 Subject: [ticket/11103] Move banned user checking to email method This will make sure banned users are never sent notification emails PHPBB3-11103 --- phpBB/includes/notifications/method/email.php | 12 ++++++++++++ phpBB/includes/notifications/type/pm.php | 16 ++-------------- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index b1979296b9..2b80b5bf3a 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -52,6 +52,13 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base $user_ids[] = $notification->user_id; } + // We do not send emails to banned users + if (!function_exists('phpbb_get_banned_user_ids')) + { + include($phpbb_container->getParameter('core.root_path') . 'includes/functions_user.' . $phpbb_container->getParameter('core.php_ext')); + } + $banned_users = phpbb_get_banned_user_ids($user_ids); + $sql = 'SELECT * FROM ' . USERS_TABLE . ' WHERE ' . $this->db->sql_in_set('user_id', $user_ids); $result = $this->db->sql_query($sql); @@ -72,6 +79,11 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base // Time to go through the queue and send emails foreach ($this->queue as $notification) { + if (in_array($notification->user_id, $banned_users)) + { + continue; + } + $notification->users($users); $user = $notification->get_user($notification->user_id); diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 50c67de21a..92026c08d7 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -118,20 +118,8 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base $db = $phpbb_container->get('dbal.conn'); $user = $phpbb_container->get('user'); - // Exclude guests, current user and banned users from notifications - unset($pm['recipients'][ANONYMOUS]);//, $pm['recipients'][$user->data['user_id']]); - - if (!sizeof($pm['recipients'])) - { - return; - } - - if (!function_exists('phpbb_get_banned_user_ids')) - { - include($phpbb_container->getParameter('core.root_path') . 'includes/functions_user.' . $phpbb_container->getParameter('core.php_ext')); - } - $banned_users = phpbb_get_banned_user_ids(array_keys($pm['recipients'])); - $pm['recipients'] = array_diff(array_keys($pm['recipients']), $banned_users); + // Exclude guests and current user from notifications + unset($pm['recipients'][ANONYMOUS], $pm['recipients'][$user->data['user_id']]); if (!sizeof($pm['recipients'])) { -- cgit v1.2.1 From 4b4ea7c5cde7c9f3684ca325c110f81eda593d67 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Sep 2012 10:19:46 -0500 Subject: [ticket/11103] The service now handles all user loading itself Delete pm notifications when pms are deleted PHPBB3-11103 --- phpBB/includes/functions_privmsgs.php | 106 ++++-------------------- phpBB/includes/notifications/method/base.php | 25 +++++- phpBB/includes/notifications/method/email.php | 14 +--- phpBB/includes/notifications/service.php | 101 ++++++++++++---------- phpBB/includes/notifications/type/base.php | 24 +----- phpBB/includes/notifications/type/interface.php | 4 +- phpBB/includes/notifications/type/pm.php | 98 +++++++++++----------- 7 files changed, 152 insertions(+), 220 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 8002765ee2..88c5bd8e2a 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -982,6 +982,7 @@ function handle_mark_actions($user_id, $mark_action) function delete_pm($user_id, $msg_ids, $folder_id) { global $db, $user, $phpbb_root_path, $phpEx; + global $phpbb_container; $user_id = (int) $user_id; $folder_id = (int) $folder_id; @@ -1093,6 +1094,10 @@ function delete_pm($user_id, $msg_ids, $folder_id) $user->data['user_unread_privmsg'] -= $num_unread; } + // Delete Notifications + $phpbb_notifications = $phpbb_container->get('notifications'); + $phpbb_notifications->delete_notifications('pm', array_keys($delete_rows)); + // Now we have to check which messages we can delete completely $sql = 'SELECT msg_id FROM ' . PRIVMSGS_TO_TABLE . ' @@ -1843,104 +1848,23 @@ function submit_pm($mode, $subject, &$data, $put_in_outbox = true) $db->sql_transaction('commit'); // Send Notifications - if ($mode != 'edit') - { - $phpbb_notifications = $phpbb_container->get('notifications'); - - $phpbb_notifications->add_notifications('pm', array( - 'author_id' => $data['from_user_id'], - 'recipients' => $recipients, - 'message_subject' => $subject, - 'msg_id' => $data['msg_id'], - )); - - //pm_notification($mode, $data['from_username'], $recipients, $subject, $data['message'], $data['msg_id']); - } - - return $data['msg_id']; -} - -/** -* PM Notification -*/ -function pm_notification($mode, $author, $recipients, $subject, $message, $msg_id) -{ - global $db, $user, $config, $phpbb_root_path, $phpEx, $auth; - - $subject = censor_text($subject); - - // Exclude guests, current user and banned users from notifications - unset($recipients[ANONYMOUS], $recipients[$user->data['user_id']]); - - if (!sizeof($recipients)) - { - return; - } - - if (!function_exists('phpbb_get_banned_user_ids')) - { - include($phpbb_root_path . 'includes/functions_user.' . $phpEx); - } - $banned_users = phpbb_get_banned_user_ids(array_keys($recipients)); - $recipients = array_diff(array_keys($recipients), $banned_users); + $phpbb_notifications = $phpbb_container->get('notifications'); - if (!sizeof($recipients)) - { - return; - } - - $sql = 'SELECT user_id, username, user_email, user_lang, user_notify_pm, user_notify_type, user_jabber - FROM ' . USERS_TABLE . ' - WHERE ' . $db->sql_in_set('user_id', $recipients); - $result = $db->sql_query($sql); - - $msg_list_ary = array(); - while ($row = $db->sql_fetchrow($result)) - { - if ($row['user_notify_pm'] == 1 && trim($row['user_email'])) - { - $msg_list_ary[] = array( - 'method' => $row['user_notify_type'], - 'email' => $row['user_email'], - 'jabber' => $row['user_jabber'], - 'name' => $row['username'], - 'lang' => $row['user_lang'] - ); - } - } - $db->sql_freeresult($result); + $pm_data = array_merge($data, array( + 'message_subject' => $subject, + 'recipients' => $recipients, + )); - if (!sizeof($msg_list_ary)) + if ($mode == 'edit') { - return; + $phpbb_notifications->update_notifications('pm', $pm_data); } - - include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); - $messenger = new messenger(); - - foreach ($msg_list_ary as $pos => $addr) + else { - $messenger->template('privmsg_notify', $addr['lang']); - - $messenger->to($addr['email'], $addr['name']); - $messenger->im($addr['jabber'], $addr['name']); - - $messenger->assign_vars(array( - 'SUBJECT' => htmlspecialchars_decode($subject), - 'AUTHOR_NAME' => htmlspecialchars_decode($author), - 'USERNAME' => htmlspecialchars_decode($addr['name']), - - 'U_INBOX' => generate_board_url() . "/ucp.$phpEx?i=pm&folder=inbox", - 'U_VIEW_MESSAGE' => generate_board_url() . "/ucp.$phpEx?i=pm&mode=view&p=$msg_id", - )); - - $messenger->send($addr['method']); + $phpbb_notifications->add_notifications('pm', $pm_data); } - unset($msg_list_ary); - $messenger->save_queue(); - - unset($messenger); + return $data['msg_id']; } /** diff --git a/phpBB/includes/notifications/method/base.php b/phpBB/includes/notifications/method/base.php index 98c06509c6..3ed9d3f33c 100644 --- a/phpBB/includes/notifications/method/base.php +++ b/phpBB/includes/notifications/method/base.php @@ -24,11 +24,31 @@ if (!defined('IN_PHPBB')) abstract class phpbb_notifications_method_base implements phpbb_notifications_method_interface { protected $phpbb_container; + protected $service; protected $db; protected $user; protected $phpbb_root_path; protected $php_ext; + /** + * Desired notifications + * unique by (type, type_id, user_id, method) + * if multiple methods are desired, multiple rows will exist. + * + * method of "none" will over-ride any other options + * + * item_type + * item_id + * user_id + * method + * none (will never receive notifications) + * standard (listed in notifications window + * popup? + * email + * jabber + * sms? + */ + /** * Queue of messages to be sent * @@ -36,11 +56,14 @@ abstract class phpbb_notifications_method_base implements phpbb_notifications_me */ protected $queue = array(); - public function __construct(ContainerBuilder $phpbb_container, $data = array()) + public function __construct(ContainerBuilder $phpbb_container) { // phpBB Container $this->phpbb_container = $phpbb_container; + // Service + $this->service = $phpbb_container->get('notifications'); + // Some common things we're going to use $this->db = $phpbb_container->get('dbal.conn'); $this->user = $phpbb_container->get('user'); diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index 2b80b5bf3a..50df9a6c56 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -59,14 +59,8 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base } $banned_users = phpbb_get_banned_user_ids($user_ids); - $sql = 'SELECT * FROM ' . USERS_TABLE . ' - WHERE ' . $this->db->sql_in_set('user_id', $user_ids); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $users[$row['user_id']] = $row; - } - $this->db->sql_freeresult($result); + // Load all the users we need + $this->service->load_users($user_ids); // Load the messenger if (!class_exists('messenger')) @@ -84,9 +78,7 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base continue; } - $notification->users($users); - - $user = $notification->get_user($notification->user_id); + $user = $this->service->get_user($notification->user_id); $messenger->template('privmsg_notify', $user['user_lang']); diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 4794472883..50ceb1584a 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -31,7 +31,7 @@ class phpbb_notifications_service * * @var array Array of user data that we've loaded from the DB */ - protected $users; + protected $users = array(); public function __construct(ContainerBuilder $phpbb_container) { @@ -76,7 +76,6 @@ class phpbb_notifications_service $item_type_class_name = $this->get_item_type_class_name($row['item_type'], true); $notification = new $item_type_class_name($this->phpbb_container, $row); - $notification->users($this->users); $user_ids = array_merge($user_ids, $notification->users_to_query()); @@ -84,24 +83,7 @@ class phpbb_notifications_service } $this->db->sql_freeresult($result); - // Load the users - $user_ids = array_unique($user_ids); - - // @todo do not load users we already have in $this->users - - if (sizeof($user_ids)) - { - // @todo do not select everything - $sql = 'SELECT * FROM ' . USERS_TABLE . ' - WHERE ' . $this->db->sql_in_set('user_id', $user_ids); - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $this->users[$row['user_id']] = $row; - } - $this->db->sql_freeresult($result); - } + $this->load_users($user_ids); return $notifications; } @@ -122,32 +104,16 @@ class phpbb_notifications_service // Update any existing notifications for this item $this->update_notifications($item_type, $item_id, $data); - $notify_users = array(); + $notify_users = $user_ids = array(); $notification_objects = $notification_methods = array(); $new_rows = array(); - /** - * Desired notifications - * unique by (type, type_id, user_id, method) - * if multiple methods are desired, multiple rows will exist. - * - * method of "none" will over-ride any other options - * - * item_type - * item_id - * user_id - * method - * none (will never receive notifications) - * standard (listed in notifications window - * popup? - * email - * jabber - * sms? - */ - // find out which users want to receive this type of notification $notify_users = $item_type_class_name::find_users_for_notification($this->phpbb_container, $data); + // Never send notifications to the anonymous user or the current user! + $notify_users = array_diff($notify_users, array(ANONYMOUS, $this->phpbb_container->get('user')->data['user_id'])); + // Make sure not to send new notifications to users who've already been notified about this item // This may happen when an item was added, but now new users are able to see the item $sql = 'SELECT user_id FROM ' . NOTIFICATIONS_TABLE . " @@ -172,8 +138,12 @@ class phpbb_notifications_service $notification->user_id = (int) $user; + // Store the creation array in our new rows that will be inserted later $new_rows[] = $notification->create_insert_array($data); + // Users are needed to send notifications + $user_ids = array_merge($user_ids, $notification->users_to_query()); + foreach ($methods as $method) { // setup the notification methods and add the notification to the queue @@ -184,6 +154,7 @@ class phpbb_notifications_service $method_class_name = 'phpbb_notifications_method_' . $method; $notification_methods[$method] = new $method_class_name($this->phpbb_container); } + $notification_methods[$method]->add_to_queue($notification); } } @@ -192,6 +163,9 @@ class phpbb_notifications_service // insert into the db $this->db->sql_multi_insert(NOTIFICATIONS_TABLE, $new_rows); + // We need to load all of the users to send notifications + $this->load_users($user_ids); + // run the queue for each method to send notifications foreach ($notification_methods as $method) { @@ -203,13 +177,14 @@ class phpbb_notifications_service * Update a notification * * @param string $item_type Type identifier - * @param int $item_id Identifier within the type * @param array $data Data specific for this type that will be updated */ - public function update_notifications($item_type, $item_id, $data) + public function update_notifications($item_type, $data) { $item_type_class_name = $this->get_item_type_class_name($item_type); + $item_id = $item_type_class_name::get_item_id($data); + $notification = new $item_type_class_name($this->phpbb_container); $update_array = $notification->create_update_array($data); @@ -224,17 +199,55 @@ class phpbb_notifications_service * Delete a notification * * @param string $item_type Type identifier - * @param int $item_id Identifier within the type + * @param int|array $item_id Identifier within the type (or array of ids) * @param array $data Data specific for this type that will be updated */ public function delete_notifications($item_type, $item_id) { $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' - AND item_id = " . (int) $item_id; + AND " . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id); $this->db->sql_query($sql); } + /** + * Load user helper + * + * @param array $user_ids + */ + public function load_users($user_ids) + { + // Load the users + $user_ids = array_unique($user_ids); + + // Do not load users we already have in $this->users + $user_ids = array_diff($user_ids, array_keys($this->users)); + + if (sizeof($user_ids)) + { + $sql = 'SELECT * FROM ' . USERS_TABLE . ' + WHERE ' . $this->db->sql_in_set('user_id', $user_ids); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->users[$row['user_id']] = $row; + } + $this->db->sql_freeresult($result); + } + } + + /** + * Get a user row from our users cache + * + * @param int $user_id + * @return array + */ + public function get_user($user_id) + { + return $this->users[$user_id]; + } + /** * Helper to get the notifications item type class name and clean it if unsafe */ diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 32d8f58ff3..b0b8801a7e 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -24,6 +24,7 @@ if (!defined('IN_PHPBB')) abstract class phpbb_notifications_type_base implements phpbb_notifications_type_interface { protected $phpbb_container; + protected $service; protected $db; protected $phpbb_root_path; protected $php_ext; @@ -55,6 +56,9 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type // phpBB Container $this->phpbb_container = $phpbb_container; + // Service + $this->service = $phpbb_container->get('notifications'); + // Some common things we're going to use $this->db = $phpbb_container->get('dbal.conn'); @@ -99,26 +103,6 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type $this->data['data'][$name] = $value; } - /** - * Function to store the users loaded from the database (for output to the template) - * (The service handles this) - */ - public function users(&$users) - { - $this->users = &$users; - } - - /** - * Get a user row from our users cache - * - * @param int $user_id - * @return array - */ - public function get_user($user_id) - { - return $this->users[$user_id]; - } - /** * Output the notification to the template * diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index 03e24358a9..85fe41f6ef 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -25,6 +25,8 @@ interface phpbb_notifications_type_interface public static function get_item_id($type_data); + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $type_data); + public function get_title(); public function get_url(); @@ -32,6 +34,4 @@ interface phpbb_notifications_type_interface public function get_full_url(); public function create_insert_array($type_data); - - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $type_data); } diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 92026c08d7..8b8f41d1c2 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -44,6 +44,50 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base return $pm['msg_id']; } + /** + * Find the users who want to receive notifications + * + * @param array $pm Data from + * @return array + */ + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $pm) + { + $service = $phpbb_container->get('notifications'); + $db = $phpbb_container->get('dbal.conn'); + $user = $phpbb_container->get('user'); + + if (!sizeof($pm['recipients'])) + { + return array(); + } + + $service->load_users(array_keys($pm['recipients'])); + + $notify_users = array(); + + foreach (array_keys($pm['recipients']) as $user_id) + { + $recipient = $service->get_user($user_id); + + if ($recipient['user_notify_pm']) + { + $notify_users[$recipient['user_id']] = array(); + + if ($recipient['user_notify_type'] == NOTIFY_EMAIL || $recipient['user_notify_type'] == NOTIFY_BOTH) + { + $notify_users[$recipient['user_id']][] = 'email'; + } + + if ($recipient['user_notify_type'] == NOTIFY_IM || $recipient['user_notify_type'] == NOTIFY_BOTH) + { + $notify_users[$recipient['user_id']][] = 'jabber'; + } + } + } + + return $notify_users; + } + /** * Get the title of this notification * @@ -51,7 +95,7 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base */ public function get_title() { - $user_data = $this->get_user($this->get_data('author_id')); + $user_data = $this->service->get_user($this->get_data('from_user_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); @@ -85,7 +129,7 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base */ public function users_to_query() { - return array($this->data['author_id']); + return array($this->data['from_user_id']); } /** @@ -100,58 +144,10 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base { $this->item_id = $pm['msg_id']; - $this->set_data('author_id', $pm['author_id']); + $this->set_data('from_user_id', $pm['from_user_id']); $this->set_data('message_subject', $pm['message_subject']); return parent::create_insert_array($pm); } - - /** - * Find the users who want to receive notifications - * - * @param array $pm Data from - * @return array - */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $pm) - { - $db = $phpbb_container->get('dbal.conn'); - $user = $phpbb_container->get('user'); - - // Exclude guests and current user from notifications - unset($pm['recipients'][ANONYMOUS], $pm['recipients'][$user->data['user_id']]); - - if (!sizeof($pm['recipients'])) - { - return; - } - - $sql = 'SELECT user_id, user_notify_pm, user_notify_type - FROM ' . USERS_TABLE . ' - WHERE ' . $db->sql_in_set('user_id', $pm['recipients']); - $result = $db->sql_query($sql); - - $pm['recipients'] = array(); - - while ($row = $db->sql_fetchrow($result)) - { - if ($row['user_notify_pm']) - { - $pm['recipients'][$row['user_id']] = array(); - - if ($row['user_notify_type'] == NOTIFY_EMAIL || $row['user_notify_type'] == NOTIFY_BOTH) - { - $pm['recipients'][$row['user_id']][] = 'email'; - } - - if ($row['user_notify_type'] == NOTIFY_IM || $row['user_notify_type'] == NOTIFY_BOTH) - { - $pm['recipients'][$row['user_id']][] = 'jabber'; - } - } - } - $db->sql_freeresult($result); - - return $pm['recipients']; - } } -- cgit v1.2.1 From ff45c9aa7c077fc0a03c64764917d1efcccf48f4 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Sep 2012 10:36:22 -0500 Subject: [ticket/11103] General notification email template. PHPBB3-11103 --- phpBB/includes/notifications/method/base.php | 13 +------------ phpBB/includes/notifications/method/email.php | 15 +++++++-------- phpBB/includes/notifications/method/interface.php | 2 +- phpBB/includes/notifications/service.php | 2 +- phpBB/includes/notifications/type/base.php | 22 +++++++++++++++++++++- phpBB/includes/notifications/type/interface.php | 4 ++++ phpBB/includes/notifications/type/pm.php | 16 ++++++++++++++-- 7 files changed, 49 insertions(+), 25 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/method/base.php b/phpBB/includes/notifications/method/base.php index 3ed9d3f33c..b860fcffda 100644 --- a/phpBB/includes/notifications/method/base.php +++ b/phpBB/includes/notifications/method/base.php @@ -83,19 +83,8 @@ abstract class phpbb_notifications_method_base implements phpbb_notifications_me } /** - * Basic run queue function. - * Child methods should override this function if there are more efficient methods to mass-notification + * Empty the queue */ - public function run_queue() - { - foreach ($this->queue as $notification) - { - $this->notify($notification); - } - - $this->empty_queue(); - } - protected function empty_queue() { $this->queue = array(); diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index 50df9a6c56..69546be73f 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -33,12 +33,7 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base return true; } - public function notify($notification) - { - // email the user - } - - public function run_queue() + public function notify() { if (!sizeof($this->queue)) { @@ -80,14 +75,18 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base $user = $this->service->get_user($notification->user_id); - $messenger->template('privmsg_notify', $user['user_lang']); + $messenger->template('notification', $user['user_lang']); $messenger->to($user['user_email'], $user['username']); $messenger->assign_vars(array( - 'SUBJECT' => htmlspecialchars_decode($notification->get_title()), + 'USERNAME' => $user['username'], + + 'MESSAGE' => htmlspecialchars_decode($notification->get_title()), 'U_VIEW_MESSAGE' => $notification->get_full_url(), + + 'U_UNSUBSCRIBE' => $notification->get_unsubscribe_url(), )); $messenger->send('email'); diff --git a/phpBB/includes/notifications/method/interface.php b/phpBB/includes/notifications/method/interface.php index f18d005b8b..7d7f3abcd0 100644 --- a/phpBB/includes/notifications/method/interface.php +++ b/phpBB/includes/notifications/method/interface.php @@ -21,5 +21,5 @@ if (!defined('IN_PHPBB')) */ interface phpbb_notifications_method_interface { - public function notify($notification); + public function notify(); } diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 50ceb1584a..463798fa07 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -169,7 +169,7 @@ class phpbb_notifications_service // run the queue for each method to send notifications foreach ($notification_methods as $method) { - $method->run_queue(); + $method->notify(); } } diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index b0b8801a7e..91cc9f175a 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -120,7 +120,7 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type ), $options); $template->assign_block_vars($options['template_block'], array( - 'TITLE' => $this->get_title(), + 'TITLE' => $this->get_formatted_title(), 'URL' => $this->get_url(), 'TIME' => $user->format_date($this->time), @@ -173,4 +173,24 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type return $data; } + + /** + * Get the formatted title of this notification (fall-back) + * + * @return string + */ + public function get_formatted_title() + { + return $this->get_title(); + } + + /** + * URL to unsubscribe to this notification + * + * @param string|bool $method Method name to unsubscribe from (email|jabber|etc), False to unsubscribe from all notifications for this item + */ + public function get_unsubscribe_url($method = false) + { + return false; + } } diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index 85fe41f6ef..c165815835 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -29,9 +29,13 @@ interface phpbb_notifications_type_interface public function get_title(); + public function get_formatted_title(); + public function get_url(); public function get_full_url(); + public function get_unsubscribe_url($method); + public function create_insert_array($type_data); } diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 8b8f41d1c2..702ec39c16 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -89,11 +89,11 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base } /** - * Get the title of this notification + * Get the HTML formatted title of this notification * * @return string */ - public function get_title() + public function get_formatted_title() { $user_data = $this->service->get_user($this->get_data('from_user_id')); @@ -102,6 +102,18 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base return $username . ' sent you a private message titled: ' . $this->get_data('message_subject'); } + /** + * Get the plain text title of this notification + * + * @return string + */ + public function get_title() + { + $user_data = $this->service->get_user($this->get_data('from_user_id')); + + return $user_data['username'] . ' sent you a private message titled: ' . $this->get_data('message_subject'); + } + /** * Get the url to this item * -- cgit v1.2.1 From 74e2a8f893a2e7a69ba129a74dd0b3c31e742e79 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Sep 2012 13:29:47 -0500 Subject: [ticket/11103] Post notifications PHPBB3-11103 --- phpBB/includes/functions_posting.php | 252 +++-------------------------- phpBB/includes/mcp/mcp_queue.php | 6 +- phpBB/includes/notifications/type/base.php | 32 ++++ phpBB/includes/notifications/type/pm.php | 2 + phpBB/includes/notifications/type/post.php | 71 +++++++- 5 files changed, 122 insertions(+), 241 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index c50395a5df..6c5c4535a3 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -61,7 +61,7 @@ function generate_smilies($mode, $forum_id) 'body' => 'posting_smilies.html') ); - generate_pagination(append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=smilies&f=' . $forum_id), $smiley_count, $config['smilies_per_page'], $start); + generate_pagination(append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=smilies&f=' . $forum_id), $smiley_count, $config['smilies_per_page'], $start); } $display_link = false; @@ -1173,237 +1173,6 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id return true; } -/** -* User Notification -*/ -function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id, $topic_id, $post_id) -{ - global $db, $user, $config, $phpbb_root_path, $phpEx, $auth; - - $topic_notification = ($mode == 'reply' || $mode == 'quote') ? true : false; - $forum_notification = ($mode == 'post') ? true : false; - - if (!$topic_notification && !$forum_notification) - { - trigger_error('NO_MODE'); - } - - if (($topic_notification && !$config['allow_topic_notify']) || ($forum_notification && !$config['allow_forum_notify'])) - { - return; - } - - $topic_title = ($topic_notification) ? $topic_title : $subject; - $topic_title = censor_text($topic_title); - - // Exclude guests, current user and banned users from notifications - if (!function_exists('phpbb_get_banned_user_ids')) - { - include($phpbb_root_path . 'includes/functions_user.' . $phpEx); - } - $sql_ignore_users = phpbb_get_banned_user_ids(); - $sql_ignore_users[ANONYMOUS] = ANONYMOUS; - $sql_ignore_users[$user->data['user_id']] = $user->data['user_id']; - - $notify_rows = array(); - - // -- get forum_userids || topic_userids - $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, u.user_notify_type, u.user_jabber - FROM ' . (($topic_notification) ? TOPICS_WATCH_TABLE : FORUMS_WATCH_TABLE) . ' w, ' . USERS_TABLE . ' u - WHERE w.' . (($topic_notification) ? 'topic_id' : 'forum_id') . ' = ' . (($topic_notification) ? $topic_id : $forum_id) . ' - AND ' . $db->sql_in_set('w.user_id', $sql_ignore_users, true) . ' - AND w.notify_status = ' . NOTIFY_YES . ' - AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') - AND u.user_id = w.user_id'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $notify_user_id = (int) $row['user_id']; - $notify_rows[$notify_user_id] = array( - 'user_id' => $notify_user_id, - 'username' => $row['username'], - 'user_email' => $row['user_email'], - 'user_jabber' => $row['user_jabber'], - 'user_lang' => $row['user_lang'], - 'notify_type' => ($topic_notification) ? 'topic' : 'forum', - 'template' => ($topic_notification) ? 'topic_notify' : 'newtopic_notify', - 'method' => $row['user_notify_type'], - 'allowed' => false - ); - - // Add users who have been already notified to ignore list - $sql_ignore_users[$notify_user_id] = $notify_user_id; - } - $db->sql_freeresult($result); - - // forum notification is sent to those not already receiving topic notifications - if ($topic_notification) - { - $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, u.user_notify_type, u.user_jabber - FROM ' . FORUMS_WATCH_TABLE . ' fw, ' . USERS_TABLE . " u - WHERE fw.forum_id = $forum_id - AND " . $db->sql_in_set('fw.user_id', $sql_ignore_users, true) . ' - AND fw.notify_status = ' . NOTIFY_YES . ' - AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') - AND u.user_id = fw.user_id'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $notify_user_id = (int) $row['user_id']; - $notify_rows[$notify_user_id] = array( - 'user_id' => $notify_user_id, - 'username' => $row['username'], - 'user_email' => $row['user_email'], - 'user_jabber' => $row['user_jabber'], - 'user_lang' => $row['user_lang'], - 'notify_type' => 'forum', - 'template' => 'forum_notify', - 'method' => $row['user_notify_type'], - 'allowed' => false - ); - } - $db->sql_freeresult($result); - } - - if (!sizeof($notify_rows)) - { - return; - } - - // Make sure users are allowed to read the forum - foreach ($auth->acl_get_list(array_keys($notify_rows), 'f_read', $forum_id) as $forum_id => $forum_ary) - { - foreach ($forum_ary as $auth_option => $user_ary) - { - foreach ($user_ary as $user_id) - { - $notify_rows[$user_id]['allowed'] = true; - } - } - } - - // Now, we have to do a little step before really sending, we need to distinguish our users a little bit. ;) - $msg_users = $delete_ids = $update_notification = array(); - foreach ($notify_rows as $user_id => $row) - { - if (!$row['allowed'] || !trim($row['user_email'])) - { - $delete_ids[$row['notify_type']][] = $row['user_id']; - } - else - { - $msg_users[] = $row; - $update_notification[$row['notify_type']][] = $row['user_id']; - - /* - * We also update the forums watch table for this user when we are - * sending out a topic notification to prevent sending out another - * notification in case this user is also subscribed to the forum - * this topic was posted in. - * Since an UPDATE query is used, this has no effect on users only - * subscribed to the topic (i.e. no row is created) and should not - * be a performance issue. - */ - if ($row['notify_type'] === 'topic') - { - $update_notification['forum'][] = $row['user_id']; - } - } - } - unset($notify_rows); - - // Now, we are able to really send out notifications - if (sizeof($msg_users)) - { - include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); - $messenger = new messenger(); - - $msg_list_ary = array(); - foreach ($msg_users as $row) - { - $pos = (!isset($msg_list_ary[$row['template']])) ? 0 : sizeof($msg_list_ary[$row['template']]); - - $msg_list_ary[$row['template']][$pos]['method'] = $row['method']; - $msg_list_ary[$row['template']][$pos]['email'] = $row['user_email']; - $msg_list_ary[$row['template']][$pos]['jabber'] = $row['user_jabber']; - $msg_list_ary[$row['template']][$pos]['name'] = $row['username']; - $msg_list_ary[$row['template']][$pos]['lang'] = $row['user_lang']; - $msg_list_ary[$row['template']][$pos]['user_id']= $row['user_id']; - } - unset($msg_users); - - foreach ($msg_list_ary as $email_template => $email_list) - { - foreach ($email_list as $addr) - { - $messenger->template($email_template, $addr['lang']); - - $messenger->to($addr['email'], $addr['name']); - $messenger->im($addr['jabber'], $addr['name']); - - $messenger->assign_vars(array( - 'USERNAME' => htmlspecialchars_decode($addr['name']), - 'TOPIC_TITLE' => htmlspecialchars_decode($topic_title), - 'FORUM_NAME' => htmlspecialchars_decode($forum_name), - - 'U_FORUM' => generate_board_url() . "/viewforum.$phpEx?f=$forum_id", - 'U_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id", - 'U_NEWEST_POST' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id&p=$post_id&e=$post_id", - 'U_STOP_WATCHING_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?uid={$addr['user_id']}&f=$forum_id&t=$topic_id&unwatch=topic", - 'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.$phpEx?uid={$addr['user_id']}&f=$forum_id&unwatch=forum", - )); - - $messenger->send($addr['method']); - } - } - unset($msg_list_ary); - - $messenger->save_queue(); - } - - // Handle the DB updates - $db->sql_transaction('begin'); - - if (!empty($update_notification['topic'])) - { - $sql = 'UPDATE ' . TOPICS_WATCH_TABLE . ' - SET notify_status = ' . NOTIFY_NO . " - WHERE topic_id = $topic_id - AND " . $db->sql_in_set('user_id', $update_notification['topic']); - $db->sql_query($sql); - } - - if (!empty($update_notification['forum'])) - { - $sql = 'UPDATE ' . FORUMS_WATCH_TABLE . ' - SET notify_status = ' . NOTIFY_NO . " - WHERE forum_id = $forum_id - AND " . $db->sql_in_set('user_id', $update_notification['forum']); - $db->sql_query($sql); - } - - // Now delete the user_ids not authorised to receive notifications on this topic/forum - if (!empty($delete_ids['topic'])) - { - $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . " - WHERE topic_id = $topic_id - AND " . $db->sql_in_set('user_id', $delete_ids['topic']); - $db->sql_query($sql); - } - - if (!empty($delete_ids['forum'])) - { - $sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . " - WHERE forum_id = $forum_id - AND " . $db->sql_in_set('user_id', $delete_ids['forum']); - $db->sql_query($sql); - } - - $db->sql_transaction('commit'); -} - // // Post handling functions // @@ -1640,6 +1409,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true, $update_search_index = true) { global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path; + global $phpbb_container; // We do not handle erasing posts here if ($mode == 'delete') @@ -2452,7 +2222,23 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Send Notifications if (($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_approval) { - user_notification($mode, $subject, $data['topic_title'], $data['forum_name'], $data['forum_id'], $data['topic_id'], $data['post_id']); + $notifications = $phpbb_container->get('notifications'); + + switch ($mode) + { + case 'reply' : + case 'quote' : + $notifications->add_notifications('post', array_merge($data, array( + 'post_username' => $username, + ))); + break; + + case 'post' : + $notifications->add_notifications('topic', array_merge($data, array( + 'post_username' => $username, + ))); + break; + } } $params = $add_anchor = ''; diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index b44685b8a3..d5c431e478 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -421,7 +421,7 @@ class mcp_queue $base_url = $this->u_action . "&f=$forum_id&st=$sort_days&sk=$sort_key&sd=$sort_dir"; phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start); - + // Now display the page $template->assign_vars(array( 'L_DISPLAY_ITEMS' => ($mode == 'unapproved_posts') ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_TOPICS'], @@ -639,12 +639,12 @@ 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']) { // Forum Notifications - user_notification('post', $post_data['topic_title'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id); + $notifications->add_notifications('topic', $post_data); } else { // Topic Notifications - user_notification('reply', $post_data['post_subject'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id); + $notifications->add_notifications('post', $post_data); } } diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 91cc9f175a..df273f9e81 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -174,6 +174,38 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type return $data; } + /** + * Find the users who want to receive notifications (helper) + * + * @param ContainerBuilder $phpbb_container + * @param array $item_id The item_id to search for + * + * @return array + */ + protected static function _find_users_for_notification(ContainerBuilder $phpbb_container, $item_id) + { + $db = $phpbb_container->get('dbal.conn'); + + $rowset = array(); + + $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . static::get_item_type() . "' + AND item_id = " . (int) $item_id; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (!isset($rowset[$row['user_id']])) + { + $rowset[$row['user_id']] = array(); + } + + $rowset[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + return $rowset; + } + /** * Get the formatted title of this notification (fall-back) * diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 702ec39c16..e060b5d658 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -47,7 +47,9 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base /** * Find the users who want to receive notifications * + * @param ContainerBuilder $phpbb_container * @param array $pm Data from + * * @return array */ public static function find_users_for_notification(ContainerBuilder $phpbb_container, $pm) diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 920a53bcf2..96faa0131c 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -45,11 +45,45 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base } /** - * Get the title of this notification + * Find the users who want to receive notifications + * + * @param ContainerBuilder $phpbb_container + * @param array $post Data from + * + * @return array + */ + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post) + { + $users = parent::_find_users_for_notification($phpbb_container, $post['topic_id']); + + if (!sizeof($users)) + { + return array(); + } + + $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = array(); + + foreach ($auth_read[$post['forum_id']]['f_read'] as $user_id) + { + $notify_users[$user_id] = $users[$user_id]; + } + + return $notify_users; + } + + /** + * Get the HTML formatted title of this notification * * @return string */ - public function get_title() + public function get_formatted_title() { if ($this->get_data('post_username')) { @@ -57,7 +91,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base } else { - $user_data = $this->get_user($this->get_data('poster_id')); + $user_data = $this->service->get_user($this->get_data('poster_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } @@ -65,6 +99,25 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base return $username . ' posted in the topic ' . censor_text($this->get_data('topic_title')); } + /** + * Get the title of this notification + * + * @return string + */ + public function get_title() + { + if ($this->get_data('post_username')) + { + $username = $this->get_data('post_username'); + } + else + { + $username = $user_data['username']; + } + + return $username . ' posted in the topic ' . censor_text($this->get_data('topic_title')); + } + /** * Get the url to this item * @@ -75,6 +128,16 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}"); } + /** + * Get the full url to this item + * + * @return string URL + */ + public function get_full_url() + { + return generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}"; + } + /** * Users needed to query before this notification can be displayed * @@ -103,8 +166,6 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $this->set_data('post_username', $post['post_username']); - $this->time = $post['post_time']; - return parent::create_insert_array($post); } } -- cgit v1.2.1 From 3624d2c50ac1acca767c5642767102b97fd6b832 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Sep 2012 14:20:14 -0500 Subject: [ticket/11103] Use the language system, topic notifications PHPBB3-11103 --- phpBB/includes/notifications/method/email.php | 8 +- phpBB/includes/notifications/type/pm.php | 4 +- phpBB/includes/notifications/type/post.php | 8 +- phpBB/includes/notifications/type/topic.php | 185 ++++++++++++++++++++++++++ 4 files changed, 197 insertions(+), 8 deletions(-) create mode 100644 phpBB/includes/notifications/type/topic.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index 69546be73f..d6468c9dc3 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -50,7 +50,7 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base // We do not send emails to banned users if (!function_exists('phpbb_get_banned_user_ids')) { - include($phpbb_container->getParameter('core.root_path') . 'includes/functions_user.' . $phpbb_container->getParameter('core.php_ext')); + include($this->phpbb_container->getParameter('core.root_path') . 'includes/functions_user.' . $this->phpbb_container->getParameter('core.php_ext')); } $banned_users = phpbb_get_banned_user_ids($user_ids); @@ -68,13 +68,13 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base // Time to go through the queue and send emails foreach ($this->queue as $notification) { - if (in_array($notification->user_id, $banned_users)) + $user = $this->service->get_user($notification->user_id); + + if ($user['user_type'] == USER_IGNORE || in_array($notification->user_id, $banned_users)) { continue; } - $user = $this->service->get_user($notification->user_id); - $messenger->template('notification', $user['user_lang']); $messenger->to($user['user_email'], $user['username']); diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index e060b5d658..3368b171df 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -101,7 +101,7 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); - return $username . ' sent you a private message titled: ' . $this->get_data('message_subject'); + return $this->phpbb_container->get('user')->lang('NOTIFICATION_PM', $username, $this->get_data('message_subject')); } /** @@ -113,7 +113,7 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base { $user_data = $this->service->get_user($this->get_data('from_user_id')); - return $user_data['username'] . ' sent you a private message titled: ' . $this->get_data('message_subject'); + return $this->phpbb_container->get('user')->lang('NOTIFICATION_PM', $user_data['username'], $this->get_data('message_subject')); } /** diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 96faa0131c..04e269737e 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -96,7 +96,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } - return $username . ' posted in the topic ' . censor_text($this->get_data('topic_title')); + return $this->phpbb_container->get('user')->lang('NOTIFICATION_POST', $username, censor_text($this->get_data('topic_title'))); } /** @@ -112,10 +112,12 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base } else { + $user_data = $this->service->get_user($this->get_data('poster_id')); + $username = $user_data['username']; } - return $username . ' posted in the topic ' . censor_text($this->get_data('topic_title')); + return $this->phpbb_container->get('user')->lang('NOTIFICATION_POST', $username, censor_text($this->get_data('topic_title'))); } /** @@ -166,6 +168,8 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $this->set_data('post_username', $post['post_username']); + $this->set_data('forum_name', $post['forum_name']); + return parent::create_insert_array($post); } } diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php new file mode 100644 index 0000000000..f58419a633 --- /dev/null +++ b/phpBB/includes/notifications/type/topic.php @@ -0,0 +1,185 @@ +get('auth')->acl_get_list(array_keys($users), 'f_read', $topic['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = array(); + + foreach ($auth_read[$topic['forum_id']]['f_read'] as $user_id) + { + $notify_users[$user_id] = $users[$user_id]; + } + + return $notify_users; + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_formatted_title() + { + if ($this->get_data('post_username')) + { + $username = $this->get_data('post_username'); + } + else + { + $user_data = $this->service->get_user($this->get_data('poster_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + } + + return $this->phpbb_container->get('user')->lang( + 'NOTIFICATION_TOPIC', + $username, + censor_text($this->get_data('topic_title')), + $this->get_data('forum_name') + ); + } + + /** + * Get the title of this notification + * + * @return string + */ + public function get_title() + { + if ($this->get_data('post_username')) + { + $username = $this->get_data('post_username'); + } + else + { + $user_data = $this->service->get_user($this->get_data('poster_id')); + + $username = $user_data['username']; + } + + return $this->phpbb_container->get('user')->lang( + 'NOTIFICATION_TOPIC', + $username, + censor_text($this->get_data('topic_title')), + $this->get_data('forum_name') + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "t{$this->item_id}"); + } + + /** + * Get the full url to this item + * + * @return string URL + */ + public function get_full_url() + { + return generate_board_url() . "/viewtopic.{$this->php_ext}?t{$this->item_id}"; + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['poster_id']); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $this->item_id = $post['post_id']; + + $this->set_data('poster_id', $post['poster_id']); + + $this->set_data('topic_title', $post['topic_title']); + + $this->set_data('post_username', $post['post_username']); + + $this->set_data('forum_name', $post['forum_name']); + + return parent::create_insert_array($post); + } +} -- cgit v1.2.1 From e09f25d59707fc842b073fa2909cefc3d16ecbf3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Sep 2012 14:55:40 -0500 Subject: [ticket/11103] Update notifications on post/topic edit PHPBB3-11103 --- phpBB/includes/functions_posting.php | 19 ++++++++++++++++--- phpBB/includes/notifications/service.php | 6 +++--- phpBB/includes/notifications/type/post.php | 14 +++++++++++--- phpBB/includes/notifications/type/topic.php | 8 ++++---- 4 files changed, 34 insertions(+), 13 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 6c5c4535a3..64840bfa51 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2220,12 +2220,18 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } // Send Notifications - if (($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_approval) + if ($post_approval) { $notifications = $phpbb_container->get('notifications'); switch ($mode) { + case 'post' : + $notifications->add_notifications('topic', array_merge($data, array( + 'post_username' => $username, + ))); + break; + case 'reply' : case 'quote' : $notifications->add_notifications('post', array_merge($data, array( @@ -2233,8 +2239,15 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u ))); break; - case 'post' : - $notifications->add_notifications('topic', array_merge($data, array( + case 'edit_topic' : + case 'edit_first_post' : + case 'edit' : + case 'edit_last_post' : + $notifications->update_notifications('topic', array_merge($data, array( + 'post_username' => $username, + 'topic_title' => $subject, + ))); + $notifications->update_notifications('post', array_merge($data, array( 'post_username' => $username, ))); break; diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 463798fa07..112cbae3fd 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -58,10 +58,10 @@ class phpbb_notifications_service // Merge default options $options = array_merge(array( 'user_id' => $user->data['user_id'], - 'limit' => 5, - 'start' => 0, 'order_by' => 'time', 'order_dir' => 'DESC', + 'limit' => 5, + 'start' => 0, ), $options); $notifications = $user_ids = array(); @@ -147,7 +147,7 @@ class phpbb_notifications_service foreach ($methods as $method) { // setup the notification methods and add the notification to the queue - if ($method) + if ($method) // blank means we just insert it as a notification, but do not notify them by any other means { if (!isset($notification_methods[$method])) { diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 04e269737e..efada4220e 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -96,7 +96,11 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } - return $this->phpbb_container->get('user')->lang('NOTIFICATION_POST', $username, censor_text($this->get_data('topic_title'))); + return $this->phpbb_container->get('user')->lang( + 'NOTIFICATION_POST', + $username, + censor_text($this->get_data('topic_title')) + ); } /** @@ -117,7 +121,11 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $username = $user_data['username']; } - return $this->phpbb_container->get('user')->lang('NOTIFICATION_POST', $username, censor_text($this->get_data('topic_title'))); + return $this->phpbb_container->get('user')->lang( + 'NOTIFICATION_POST', + $username, + censor_text($this->get_data('topic_title')) + ); } /** @@ -166,7 +174,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $this->set_data('topic_title', $post['topic_title']); - $this->set_data('post_username', $post['post_username']); + $this->set_data('post_username', (($post['post_username'] != $this->phpbb_container->get('user')->data['username']) ? $post['post_username'] : '')); $this->set_data('forum_name', $post['forum_name']); diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php index f58419a633..ee8c21fd9c 100644 --- a/phpBB/includes/notifications/type/topic.php +++ b/phpBB/includes/notifications/type/topic.php @@ -137,7 +137,7 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base */ public function get_url() { - return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "t{$this->item_id}"); + return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "t={$this->item_id}"); } /** @@ -147,7 +147,7 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base */ public function get_full_url() { - return generate_board_url() . "/viewtopic.{$this->php_ext}?t{$this->item_id}"; + return generate_board_url() . "/viewtopic.{$this->php_ext}?t={$this->item_id}"; } /** @@ -170,13 +170,13 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base */ public function create_insert_array($post) { - $this->item_id = $post['post_id']; + $this->item_id = $post['topic_id']; $this->set_data('poster_id', $post['poster_id']); $this->set_data('topic_title', $post['topic_title']); - $this->set_data('post_username', $post['post_username']); + $this->set_data('post_username', (($post['post_username'] != $this->phpbb_container->get('user')->data['username']) ? $post['post_username'] : '')); $this->set_data('forum_name', $post['forum_name']); -- cgit v1.2.1 From 5502f3c4aa30ce72131f2a55bcfa3db7a4059427 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Sep 2012 17:20:39 -0500 Subject: [ticket/11103] Restyle the notification list Very rough (lots of inline CSS, very ugly) PHPBB3-11103 --- phpBB/includes/functions.php | 2 +- phpBB/includes/functions_display.php | 7 +++-- phpBB/includes/mcp/mcp_queue.php | 4 ++- phpBB/includes/notifications/service.php | 14 +++++++++ phpBB/includes/notifications/type/base.php | 44 ++++++++++++++++++----------- phpBB/includes/notifications/type/pm.php | 8 ++++++ phpBB/includes/notifications/type/post.php | 8 ++++++ phpBB/includes/notifications/type/topic.php | 8 ++++++ 8 files changed, 73 insertions(+), 22 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 7632ea1fcb..e5c7839894 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5096,7 +5096,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 $phpbb_notifications = $phpbb_container->get('notifications'); foreach ($phpbb_notifications->load_notifications() as $notification) { - $notification->display(); + $template->assign_block_vars('notifications', $notification->prepare_for_display()); } // application/xhtml+xml not used because of IE diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 8328b9ee7a..84cb47867e 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1319,10 +1319,11 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank * @param string $avatar_height Height of users avatar * @param string $alt Optional language string for alt tag within image, can be a language key or text * @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP +* @param string $custom_css Custom CSS class to apply to the image * * @return string Avatar image */ -function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false) +function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false, $custom_css = '') { global $user, $config, $phpbb_root_path, $phpEx; global $phpbb_dispatcher; @@ -1343,7 +1344,7 @@ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $ * @var string overwrite_avatar If set, this string will be the avatar * @since 3.1-A1 */ - $vars = array('avatar', 'avatar_type', 'avatar_width', 'avatar_height', 'alt', 'ignore_config', 'overwrite_avatar'); + $vars = array('avatar', 'avatar_type', 'avatar_width', 'avatar_height', 'alt', 'ignore_config', 'overwrite_avatar', 'custom_css'); extract($phpbb_dispatcher->trigger_event('core.user_get_avatar', compact($vars))); if ($overwrite_avatar) @@ -1385,7 +1386,7 @@ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $ } $avatar_img .= $avatar; - return '' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . ''; + return '' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . ''; } /** diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index d5c431e478..1d9a2dfedc 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -451,7 +451,7 @@ function approve_post($post_id_list, $id, $mode) { global $db, $template, $user, $config; global $phpEx, $phpbb_root_path; - global $request; + global $request, $phpbb_container; if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) { @@ -634,6 +634,8 @@ function approve_post($post_id_list, $id, $mode) // Send out normal user notifications $email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']); + $notifications = $phpbb_container->get('notifications'); + foreach ($post_info as $post_id => $post_data) { if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 112cbae3fd..5dcfeb127b 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -210,6 +210,20 @@ class phpbb_notifications_service $this->db->sql_query($sql); } + public function add_subscription($item_type, $item_id, $method = '') + { + $this->get_item_type_class_name($item_type); + + $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . + $this->db->sql_build_array('INSERT', array( + 'item_type' => $item_type, + 'item_id' => (int) $item_id, + 'user_id' => $this->phpbb_container->get('user')->data['user_id'], + 'method' => $method, + )); + $this->db->sql_query($sql); + } + /** * Load user helper * diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index df273f9e81..e60b20c449 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -104,28 +104,23 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type } /** - * Output the notification to the template - * - * @param array $options Array of options - * template_block Template block name to output to (Default: notifications) + * Prepare to output the notification to the template */ - public function display($options = array()) + public function prepare_for_display() { - $template = $this->phpbb_container->get('template'); $user = $this->phpbb_container->get('user'); - // Merge default options - $options = array_merge(array( - 'template_block' => 'notifications', - ), $options); + return array( + 'AVATAR' => $this->get_avatar(), + + 'FORMATTED_TITLE' => $this->get_formatted_title(), + 'TITLE' => $this->get_title(), - $template->assign_block_vars($options['template_block'], array( - 'TITLE' => $this->get_formatted_title(), - 'URL' => $this->get_url(), - 'TIME' => $user->format_date($this->time), + 'URL' => $this->get_url(), + 'TIME' => $user->format_date($this->time), - 'UNREAD' => $this->unread, - )); + 'UNREAD' => $this->unread, + ); } /** @@ -206,6 +201,13 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type return $rowset; } + protected function _get_avatar($user_id) + { + $user = $this->service->get_user($user_id); + + return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height'], $user['username'], false, 'notifications-avatar'); + } + /** * Get the formatted title of this notification (fall-back) * @@ -217,7 +219,7 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type } /** - * URL to unsubscribe to this notification + * URL to unsubscribe to this notification (fall-back) * * @param string|bool $method Method name to unsubscribe from (email|jabber|etc), False to unsubscribe from all notifications for this item */ @@ -225,4 +227,12 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type { return false; } + + /** + * Get the user's avatar (fall-back) + */ + public function get_avatar() + { + return ''; + } } diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 3368b171df..c78efcdd55 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -90,6 +90,14 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base return $notify_users; } + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('from_user_id')); + } + /** * Get the HTML formatted title of this notification * diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index efada4220e..f374114890 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -78,6 +78,14 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base return $notify_users; } + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('poster_id')); + } + /** * Get the HTML formatted title of this notification * diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php index ee8c21fd9c..51a95d5e19 100644 --- a/phpBB/includes/notifications/type/topic.php +++ b/phpBB/includes/notifications/type/topic.php @@ -78,6 +78,14 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base return $notify_users; } + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('poster_id')); + } + /** * Get the HTML formatted title of this notification * -- cgit v1.2.1 From 2c31e82b60aebd650d288079b6dcd420e414e266 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Sep 2012 17:23:32 -0500 Subject: [ticket/11103] Coding guidelines (SQL Queries) PHPBB3-11103 --- phpBB/includes/notifications/service.php | 9 ++++++--- phpBB/includes/notifications/type/base.php | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 5dcfeb127b..e697374b0a 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -66,7 +66,8 @@ class phpbb_notifications_service $notifications = $user_ids = array(); - $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . ' + $sql = 'SELECT * + FROM ' . NOTIFICATIONS_TABLE . ' WHERE user_id = ' . (int) $options['user_id'] . ' 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']); @@ -116,7 +117,8 @@ class phpbb_notifications_service // Make sure not to send new notifications to users who've already been notified about this item // This may happen when an item was added, but now new users are able to see the item - $sql = 'SELECT user_id FROM ' . NOTIFICATIONS_TABLE . " + $sql = 'SELECT user_id + FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id; $result = $this->db->sql_query($sql); @@ -239,7 +241,8 @@ class phpbb_notifications_service if (sizeof($user_ids)) { - $sql = 'SELECT * FROM ' . USERS_TABLE . ' + $sql = 'SELECT * + FROM ' . USERS_TABLE . ' WHERE ' . $this->db->sql_in_set('user_id', $user_ids); $result = $this->db->sql_query($sql); diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index e60b20c449..859ffb5116 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -183,7 +183,8 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type $rowset = array(); - $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . static::get_item_type() . "' AND item_id = " . (int) $item_id; $result = $db->sql_query($sql); -- cgit v1.2.1 From 12e46e48c80191d0e4ee134257375ea40c13da60 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Sep 2012 17:43:10 -0500 Subject: [ticket/11103] Remove notifications to posts/topics when they are deleted PHPBB3-11103 --- phpBB/includes/functions_admin.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 5e2ee8c8f6..6845ae14e3 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -619,6 +619,7 @@ function move_posts($post_ids, $topic_id, $auto_sync = true) function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_sync = true, $call_delete_posts = true) { global $db, $config; + global $phpbb_container; $approved_topics = 0; $forum_ids = $topic_ids = array(); @@ -715,6 +716,10 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s set_config_count('num_topics', $approved_topics * (-1), true); } + // Delete notifications + $notifications = $phpbb_container->get('notifications'); + $notifications->delete_notifications('topic', $topic_ids); + return $return; } @@ -724,6 +729,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = true, $post_count_sync = true, $call_delete_topics = true) { global $db, $config, $phpbb_root_path, $phpEx, $auth, $user; + global $phpbb_container; if ($where_type === 'range') { @@ -892,6 +898,10 @@ 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 notifications + $notifications = $phpbb_container->get('notifications'); + $notifications->delete_notifications('post', $post_ids); + return sizeof($post_ids); } -- cgit v1.2.1 From 9b1de1e487e162f55085ce72e660c5b348615649 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 12 Sep 2012 21:05:11 -0500 Subject: [ticket/11103] Add topic ID to view post URL PHPBB3-11103 --- phpBB/includes/notifications/type/post.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index f374114890..3568b9d478 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -143,7 +143,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base */ public function get_url() { - return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}"); + return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "t={$this->get_data('topic_id')}&p={$this->item_id}#p{$this->item_id}"); } /** @@ -153,7 +153,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base */ public function get_full_url() { - return generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}"; + return generate_board_url() . "/viewtopic.{$this->php_ext}?t={$this->get_data('topic_id')}&p={$this->item_id}#p{$this->item_id}"; } /** @@ -178,6 +178,8 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base { $this->item_id = $post['post_id']; + $this->set_data('topic_id', $post['topic_id']); + $this->set_data('poster_id', $post['poster_id']); $this->set_data('topic_title', $post['topic_title']); -- cgit v1.2.1 From e14595621259edb093a8bb984a95747ede2041ff Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 12 Sep 2012 21:23:24 -0500 Subject: [ticket/11103] Use the Topic/Forum Subscriptions system Using the Topic/Forum Subscription system that already exists is going to save many hours of work. If it is desired, it can always be easily converted over to the new USER_NOTIFICATIONS_TABLE later (for the same amount of work). PHPBB3-11103 --- phpBB/includes/notifications/type/post.php | 16 ++++++++++++++-- phpBB/includes/notifications/type/topic.php | 16 ++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 3568b9d478..b951b79fa6 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -54,9 +54,21 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base */ public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post) { - $users = parent::_find_users_for_notification($phpbb_container, $post['topic_id']); + // Let's continue to use the phpBB subscriptions system, at least for now. + // It may not be the nicest thing, but it is already working and it would be significant work to replace it + //$users = parent::_find_users_for_notification($phpbb_container, $post['topic_id']); - if (!sizeof($users)) + $db = $phpbb_container->get('dbal.conn'); + + $sql = 'SELECT user_id + FROM ' . TOPICS_WATCH_TABLE . ' + WHERE topic_id = ' . (int) $post['topic_id'] . ' + AND notify_status = ' . NOTIFY_YES; + $result = $db->sql_query($sql); + $users = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + + if (empty($users)) { return array(); } diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php index 51a95d5e19..58a3740e3a 100644 --- a/phpBB/includes/notifications/type/topic.php +++ b/phpBB/includes/notifications/type/topic.php @@ -54,9 +54,21 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base */ public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic) { - $users = parent::_find_users_for_notification($phpbb_container, $topic['forum_id']); + // Let's continue to use the phpBB subscriptions system, at least for now. + // It may not be the nicest thing, but it is already working and it would be significant work to replace it + //$users = parent::_find_users_for_notification($phpbb_container, $topic['forum_id']); - if (!sizeof($users)) + $db = $phpbb_container->get('dbal.conn'); + + $sql = 'SELECT user_id + FROM ' . FORUMS_WATCH_TABLE . ' + WHERE forum_id = ' . (int) $topic['forum_id'] . ' + AND notify_status = ' . NOTIFY_YES; + $result = $db->sql_query($sql); + $users = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); + + if (empty($users)) { return array(); } -- cgit v1.2.1 From 3d1549d43f42631c7be8d90a1f215db239baac92 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 12 Sep 2012 22:29:48 -0500 Subject: [ticket/11103] Add ability for notification types to load special data For consistency, links to posts do not include topic_id. As is done in viewtopic, do not include the topic_id when linking to a post PHPBB3-11103 --- phpBB/includes/notifications/service.php | 17 ++++++ phpBB/includes/notifications/type/base.php | 70 +++++++++++++++++++++++++ phpBB/includes/notifications/type/interface.php | 8 +++ phpBB/includes/notifications/type/post.php | 13 +++-- 4 files changed, 105 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index e697374b0a..b6255309c7 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -65,6 +65,7 @@ class phpbb_notifications_service ), $options); $notifications = $user_ids = array(); + $load_special = array(); $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . ' @@ -78,14 +79,30 @@ class phpbb_notifications_service $notification = new $item_type_class_name($this->phpbb_container, $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(); + } + $load_special[$row['item_type']] = array_merge($load_special[$row['item_type']], $notification->get_load_special()); + $notifications[] = $notification; } $this->db->sql_freeresult($result); $this->load_users($user_ids); + // Allow each type to load it's own special items + foreach ($load_special as $item_type => $data) + { + $item_type_class_name = $this->get_item_type_class_name($item_type, true); + + $item_type_class_name::load_special($this->phpbb_container, $data, $notifications); + } + return $notifications; } diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 859ffb5116..47db2c4aa7 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -123,6 +123,55 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type ); } + /** + * Mark this item read + * + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + public function mark_read($return = true) + { + return $this->mark(false, $return); + } + + /** + * Mark this item unread + * + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + public function mark_unread($return = true) + { + return $this->mark(true, $return); + } + + /** + * Mark this item read/unread + * + * @param bool $unread Unread (True/False) (Default: False) + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + protected function mark($unread = true, $return = false) + { + $where = array( + 'item_type = ' . $this->db->sql_escape($this->item_type), + 'item_id = ' . (int) $this->item_id, + 'user_id = ' . (int) $this->user_id, + ); + $where = implode(' AND ' . $where); + + if ($return) + { + return $where; + } + + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + SET unread = ' . (bool) $unread . ' + WHERE ' . $where; + $this->db->sql_query($sql); + } + /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) @@ -206,6 +255,11 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type { $user = $this->service->get_user($user_id); + if (!function_exists('get_user_avatar')) + { + include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); + } + return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height'], $user['username'], false, 'notifications-avatar'); } @@ -236,4 +290,20 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type { return ''; } + + /** + * Get the special items to load (fall-back) + */ + public function get_load_special() + { + return array(); + } + + /** + * Load the special items (fall-back) + */ + public static function load_special(ContainerBuilder $phpbb_container, $data, $notifications) + { + return; + } } diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index c165815835..c1c0eb0b0c 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -37,5 +37,13 @@ interface phpbb_notifications_type_interface public function get_unsubscribe_url($method); + public function mark_read($return); + + public function mark_unread($return); + public function create_insert_array($type_data); + + public function get_load_special(); + + public static function load_special(ContainerBuilder $phpbb_container, $data, $notifications); } diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index b951b79fa6..23358599a1 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -60,12 +60,19 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $db = $phpbb_container->get('dbal.conn'); + /* todo + * find what type of notification they'd like to receive + * make sure not to send duplicate notifications + */ $sql = 'SELECT user_id FROM ' . TOPICS_WATCH_TABLE . ' WHERE topic_id = ' . (int) $post['topic_id'] . ' AND notify_status = ' . NOTIFY_YES; $result = $db->sql_query($sql); - $users = $db->sql_fetchrowset($result); + while ($row = $db->sql_fetchrow($result)) + { + $users[$row['user_id']] = array(''); + } $db->sql_freeresult($result); if (empty($users)) @@ -155,7 +162,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base */ public function get_url() { - return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "t={$this->get_data('topic_id')}&p={$this->item_id}#p{$this->item_id}"); + return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}"); } /** @@ -165,7 +172,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base */ public function get_full_url() { - return generate_board_url() . "/viewtopic.{$this->php_ext}?t={$this->get_data('topic_id')}&p={$this->item_id}#p{$this->item_id}"; + return generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}"; } /** -- cgit v1.2.1 From 48cb98045ecd93f05b51aa528cc5248493b47c98 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 12 Sep 2012 22:38:23 -0500 Subject: [ticket/11103] Correctly find users for notification for new topics Append the forum_id to the URL to view the new topic in the notification PHPBB3-11103 --- phpBB/includes/notifications/type/post.php | 2 ++ phpBB/includes/notifications/type/topic.php | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 23358599a1..4fd4128168 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -60,6 +60,8 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $db = $phpbb_container->get('dbal.conn'); + $users = array(); + /* todo * find what type of notification they'd like to receive * make sure not to send duplicate notifications diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php index 58a3740e3a..209d23b823 100644 --- a/phpBB/includes/notifications/type/topic.php +++ b/phpBB/includes/notifications/type/topic.php @@ -60,12 +60,21 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base $db = $phpbb_container->get('dbal.conn'); + $users = array(); + + /* todo + * find what type of notification they'd like to receive + * make sure not to send duplicate notifications + */ $sql = 'SELECT user_id FROM ' . FORUMS_WATCH_TABLE . ' WHERE forum_id = ' . (int) $topic['forum_id'] . ' AND notify_status = ' . NOTIFY_YES; $result = $db->sql_query($sql); - $users = $db->sql_fetchrowset($result); + while ($row = $db->sql_fetchrow($result)) + { + $users[$row['user_id']] = array(''); + } $db->sql_freeresult($result); if (empty($users)) @@ -157,7 +166,7 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base */ public function get_url() { - return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "t={$this->item_id}"); + return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "f={$this->get_data('forum_id')}&t={$this->item_id}"); } /** @@ -167,7 +176,7 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base */ public function get_full_url() { - return generate_board_url() . "/viewtopic.{$this->php_ext}?t={$this->item_id}"; + return generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_id}"; } /** @@ -200,6 +209,8 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base $this->set_data('forum_name', $post['forum_name']); + $this->set_data('forum_id', $post['forum_id']); + return parent::create_insert_array($post); } } -- cgit v1.2.1 From 97fde62b1470f04da17335674bceab3360542e3e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 12 Sep 2012 23:03:26 -0500 Subject: [ticket/11103] Jabber notification method PHPBB3-11103 --- phpBB/includes/notifications/method/email.php | 11 +++++-- phpBB/includes/notifications/method/interface.php | 2 ++ phpBB/includes/notifications/method/jabber.php | 38 +++++++++++++++++++---- 3 files changed, 43 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index d6468c9dc3..1bcea13d92 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -23,11 +23,18 @@ if (!defined('IN_PHPBB')) */ class phpbb_notifications_method_email extends phpbb_notifications_method_base { + /** + * Notify method (since jabber gets sent through the same messenger, we let the jabber class inherit from this to reduce code duplication) + * + * @var mixed + */ + protected $notify_method = NOTIFY_EMAIL; + /** * Is this method available for the user? * This is checked on the notifications options */ - public static function is_available() + public function is_available() { // Email is always available return true; @@ -89,7 +96,7 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base 'U_UNSUBSCRIBE' => $notification->get_unsubscribe_url(), )); - $messenger->send('email'); + $messenger->send($this->notify_method); } // Save the queue in the messenger class (has to be called or these emails could be lost?) diff --git a/phpBB/includes/notifications/method/interface.php b/phpBB/includes/notifications/method/interface.php index 7d7f3abcd0..820cf4fc12 100644 --- a/phpBB/includes/notifications/method/interface.php +++ b/phpBB/includes/notifications/method/interface.php @@ -21,5 +21,7 @@ if (!defined('IN_PHPBB')) */ interface phpbb_notifications_method_interface { + public function is_available(); + public function notify(); } diff --git a/phpBB/includes/notifications/method/jabber.php b/phpBB/includes/notifications/method/jabber.php index 15614db96c..738400a50e 100644 --- a/phpBB/includes/notifications/method/jabber.php +++ b/phpBB/includes/notifications/method/jabber.php @@ -17,20 +17,46 @@ if (!defined('IN_PHPBB')) /** * Jabber notification method class -* This class handles sending Jabber notifications for notifications +* This class handles sending Jabber messages for notifications * * @package notifications */ -class phpbb_notifications_method_jabber extends phpbb_notifications_method_base +class phpbb_notifications_method_jabber extends phpbb_notifications_method_email { - public static function is_available() + /** + * Notify method (since jabber gets sent through the same messenger, we let the jabber class inherit from this to reduce code duplication) + * + * @var mixed + */ + protected $notify_method = NOTIFY_IM; + + /** + * Is this method available for the user? + * This is checked on the notifications options + */ + public function is_available() + { + return ($this->global_available() && $this->phpbb_container->get('user')->data['jabber']); + } + + /** + * Is this method available at all? + * This is checked before notifications are sent + */ + public function global_available() { - // Is jabber enabled & can this user receive jabber messages? - return false; // for now + $config = $this->phpbb_container->get('config'); + + return ($config['jab_enable'] && @extension_loaded('xml')); } public function notify() { - // message the user + if (!$this->global_available()) + { + return; + } + + return parent::notify(); } } -- cgit v1.2.1 From 207bbdf48cb05abfb611f238e4ba07131131c74d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 12 Sep 2012 23:55:29 -0500 Subject: [ticket/11103] Quote notifications PHPBB3-11103 --- phpBB/includes/functions_posting.php | 9 ++ phpBB/includes/notifications/service.php | 2 +- phpBB/includes/notifications/type/quote.php | 149 ++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 phpBB/includes/notifications/type/quote.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 64840bfa51..ff0a59a4e3 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2230,6 +2230,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $notifications->add_notifications('topic', array_merge($data, array( 'post_username' => $username, ))); + $notifications->add_notifications('quote', array_merge($data, array( + 'post_username' => $username, + ))); break; case 'reply' : @@ -2237,6 +2240,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $notifications->add_notifications('post', array_merge($data, array( 'post_username' => $username, ))); + $notifications->add_notifications('quote', array_merge($data, array( + 'post_username' => $username, + ))); break; case 'edit_topic' : @@ -2250,6 +2256,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $notifications->update_notifications('post', array_merge($data, array( 'post_username' => $username, ))); + $notifications->add_notifications('quote', array_merge($data, array( + 'post_username' => $username, + ))); break; } } diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index b6255309c7..0f7752446a 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -130,7 +130,7 @@ class phpbb_notifications_service $notify_users = $item_type_class_name::find_users_for_notification($this->phpbb_container, $data); // Never send notifications to the anonymous user or the current user! - $notify_users = array_diff($notify_users, array(ANONYMOUS, $this->phpbb_container->get('user')->data['user_id'])); + unset($notify_users[ANONYMOUS], $notify_users[$this->phpbb_container->get('user')->data['user_id']]); // Make sure not to send new notifications to users who've already been notified about this item // This may happen when an item was added, but now new users are able to see the item diff --git a/phpBB/includes/notifications/type/quote.php b/phpBB/includes/notifications/type/quote.php new file mode 100644 index 0000000000..8f93c67de1 --- /dev/null +++ b/phpBB/includes/notifications/type/quote.php @@ -0,0 +1,149 @@ +get('dbal.conn'); + + $usernames = false; + preg_match_all(self::$regular_expression_match, $post['message'], $usernames); + + if (empty($usernames[1])) + { + return array(); + } + + $usernames[1] = array_unique($usernames[1]); + + $usernames = array_map('utf8_clean_string', $usernames[1]); + + $users = array(); + + /* todo + * find what type of notification they'd like to receive + */ + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . ' + WHERE ' . $db->sql_in_set('username_clean', $usernames); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $users[$row['user_id']] = array(''); + } + $db->sql_freeresult($result); + + if (empty($users)) + { + return array(); + } + + $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = array(); + + foreach ($auth_read[$post['forum_id']]['f_read'] as $user_id) + { + $notify_users[$user_id] = $users[$user_id]; + } + + return $notify_users; + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_formatted_title() + { + if ($this->get_data('post_username')) + { + $username = $this->get_data('post_username'); + } + else + { + $user_data = $this->service->get_user($this->get_data('poster_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + } + + return $this->phpbb_container->get('user')->lang( + 'NOTIFICATION_QUOTE', + $username, + censor_text($this->get_data('topic_title')) + ); + } + + /** + * Get the title of this notification + * + * @return string + */ + public function get_title() + { + if ($this->get_data('post_username')) + { + $username = $this->get_data('post_username'); + } + else + { + $user_data = $this->service->get_user($this->get_data('poster_id')); + + $username = $user_data['username']; + } + + return $this->phpbb_container->get('user')->lang( + 'NOTIFICATION_QUOTE', + $username, + censor_text($this->get_data('topic_title')) + ); + } +} -- cgit v1.2.1 From 44aa773ce07d81d4585f3a24a728f9b445c4c098 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 14 Sep 2012 14:55:14 -0500 Subject: [ticket/11103] Allow notification types to override update functionality This is needed for quote editing because we need to check if the users are still all quoted or notify new quotes appropriately. PHPBB3-11103 --- phpBB/includes/functions_posting.php | 2 +- phpBB/includes/notifications/service.php | 39 ++++++++++++++++---- phpBB/includes/notifications/type/pm.php | 2 +- phpBB/includes/notifications/type/post.php | 2 +- phpBB/includes/notifications/type/quote.php | 55 +++++++++++++++++++++++++++++ phpBB/includes/notifications/type/topic.php | 2 +- 6 files changed, 92 insertions(+), 10 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index ff0a59a4e3..26d9b81896 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2256,7 +2256,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $notifications->update_notifications('post', array_merge($data, array( 'post_username' => $username, ))); - $notifications->add_notifications('quote', array_merge($data, array( + $notifications->update_notifications('quote', array_merge($data, array( 'post_username' => $username, ))); break; diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 0f7752446a..10af5b349b 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -110,7 +110,6 @@ class phpbb_notifications_service * Add a notification * * @param string $item_type Type identifier - * @param int $item_id Identifier within the type * @param array $data Data specific for this type that will be inserted */ public function add_notifications($item_type, $data) @@ -120,20 +119,38 @@ class phpbb_notifications_service $item_id = $item_type_class_name::get_item_id($data); // Update any existing notifications for this item - $this->update_notifications($item_type, $item_id, $data); - - $notify_users = $user_ids = array(); - $notification_objects = $notification_methods = array(); - $new_rows = array(); + $this->update_notifications($item_type, $data); // find out which users want to receive this type of notification $notify_users = $item_type_class_name::find_users_for_notification($this->phpbb_container, $data); + $this->add_notifications_for_users($item_type, $data, $notify_users); + } + + /** + * Add a notification for specific users + * + * @param string $item_type Type identifier + * @param array $data Data specific for this type that will be inserted + * @param array $notify_users User list to notify + */ + public function add_notifications_for_users($item_type, $data, $notify_users) + { + $item_type_class_name = $this->get_item_type_class_name($item_type); + + $item_id = $item_type_class_name::get_item_id($data); + + $user_ids = array(); + $notification_objects = $notification_methods = array(); + $new_rows = array(); + // Never send notifications to the anonymous user or the current user! unset($notify_users[ANONYMOUS], $notify_users[$this->phpbb_container->get('user')->data['user_id']]); // Make sure not to send new notifications to users who've already been notified about this item // This may happen when an item was added, but now new users are able to see the item + // todo Users should not receive notifications from multiple events from the same item (ex: for a topic reply with a quote including your username) + // Probably should be handled within each type? $sql = 'SELECT user_id FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' @@ -202,6 +219,16 @@ class phpbb_notifications_service { $item_type_class_name = $this->get_item_type_class_name($item_type); + // Allow the notifications class to over-ride the update_notifications functionality + if (method_exists($item_type_class_name, 'update_notifications')) + { + // Return False to over-ride the rest of the update + if ($item_type_class_name::update_notifications($this->phpbb_container, $data) === false) + { + return; + } + } + $item_id = $item_type_class_name::get_item_id($data); $notification = new $item_type_class_name($this->phpbb_container); diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index c78efcdd55..8ea1045641 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -41,7 +41,7 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base */ public static function get_item_id($pm) { - return $pm['msg_id']; + return (int) $pm['msg_id']; } /** diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 4fd4128168..d5759111cf 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -41,7 +41,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base */ public static function get_item_id($post) { - return $post['post_id']; + return (int) $post['post_id']; } /** diff --git a/phpBB/includes/notifications/type/quote.php b/phpBB/includes/notifications/type/quote.php index 8f93c67de1..e17769acea 100644 --- a/phpBB/includes/notifications/type/quote.php +++ b/phpBB/includes/notifications/type/quote.php @@ -146,4 +146,59 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post censor_text($this->get_data('topic_title')) ); } + + /** + * Update a notification + * + * @param ContainerBuilder $phpbb_container + * @param array $data Data specific for this type that will be updated + */ + public static function update_notifications(ContainerBuilder $phpbb_container, $post) + { + $service = $phpbb_container->get('notifications'); + $db = $phpbb_container->get('dbal.conn'); + + $old_notifications = array(); + $sql = 'SELECT user_id + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND item_id = " . self::get_item_id($post); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $old_notifications[] = $row['user_id']; + } + $db->sql_freeresult($result); + + // Find the new users to notify + $notifications = self::find_users_for_notification($phpbb_container, $post); + + // Find the notifications we must delete + $remove_notifications = array_diff($old_notifications, array_keys($notifications)); + + // Find the notifications we must add + $add_notifications = array(); + foreach (array_diff(array_keys($notifications), $old_notifications) as $user_id) + { + $add_notifications[$user_id] = $notifications[$user_id]; + } + + var_dump($old_notifications, $notifications, $remove_notifications, $add_notifications); + + // Add the necessary notifications + $service->add_notifications_for_users(self::get_item_type(), $post, $add_notifications); + + // Remove the necessary notifications + if (!empty($remove_notifications)) + { + $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND item_id = " . self::get_item_id($post) . ' + AND ' . $db->sql_in_set('user_id', $remove_notifications); + $db->sql_query($sql); + } + + // return true to continue with the update code in the notifications service (this will update the rest of the notifications) + return true; + } } diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php index 209d23b823..cb7bfdbb8f 100644 --- a/phpBB/includes/notifications/type/topic.php +++ b/phpBB/includes/notifications/type/topic.php @@ -41,7 +41,7 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base */ public static function get_item_id($post) { - return $post['topic_id']; + return (int) $post['topic_id']; } /** -- cgit v1.2.1 From fb0ed78c8fffe95d40e47c8dd27d44973eba88ae Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 14 Sep 2012 15:59:13 -0500 Subject: [ticket/11103] Store the item's parent id for marking things read Mark topics/posts read from the markread() function. Identify unread items by a grey background in the header (for now) PHPBB3-11103 --- phpBB/includes/functions.php | 18 +++- phpBB/includes/notifications/service.php | 51 +++++++++- phpBB/includes/notifications/type/base.php | 150 ++++++++++++++++------------ phpBB/includes/notifications/type/pm.php | 13 ++- phpBB/includes/notifications/type/post.php | 16 ++- phpBB/includes/notifications/type/quote.php | 2 - phpBB/includes/notifications/type/topic.php | 20 ++-- 7 files changed, 183 insertions(+), 87 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index e5c7839894..3d3dd1f5bc 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1285,15 +1285,20 @@ function phpbb_timezone_select($user, $default = '', $truncate = false) function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $user_id = 0) { global $db, $user, $config; - global $request; + global $request, $phpbb_container; if ($mode == 'all') { if ($forum_id === false || !sizeof($forum_id)) { + // Mark all forums read (index page) + + // Mark all topic notifications read for this user + $notifications = $phpbb_container->get('notifications'); + $notifications->mark_notifications_read('topic', false, $user->data['user_id'], $post_time); + if ($config['load_db_lastread'] && $user->data['is_registered']) { - // Mark all forums read (index page) $db->sql_query('DELETE FROM ' . TOPICS_TRACK_TABLE . " WHERE user_id = {$user->data['user_id']}"); $db->sql_query('DELETE FROM ' . FORUMS_TRACK_TABLE . " WHERE user_id = {$user->data['user_id']}"); $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_lastmark = ' . time() . " WHERE user_id = {$user->data['user_id']}"); @@ -1330,6 +1335,10 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ $forum_id = array($forum_id); } + // Mark topic notifications read for this user in this forum + $notifications = $phpbb_container->get('notifications'); + $notifications->mark_notifications_read_by_parent('topic', $forum_id, $user->data['user_id'], $post_time); + // Add 0 to forums array to mark global announcements correctly // $forum_id[] = 0; @@ -1424,6 +1433,11 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ return; } + // Mark post notifications read for this user in this topic + $notifications = $phpbb_container->get('notifications'); + $notifications->mark_notifications_read_by_parent('post', $topic_id, $user->data['user_id'], $post_time); + $notifications->mark_notifications_read_by_parent('quote', $topic_id, $user->data['user_id'], $post_time); + if ($config['load_db_lastread'] && $user->data['is_registered']) { $sql = 'UPDATE ' . TOPICS_TRACK_TABLE . ' diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 10af5b349b..8be8ae2a95 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -106,6 +106,52 @@ class phpbb_notifications_service return $notifications; } + /** + * Mark notifications read + * + * @param string $item_type item type + * @param bool|int|array $item_id Item id or array of item ids. False to mark read for all item ids + * @param bool|int|array $user_id User id or array of user ids. False to mark read for all user ids + * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False) + */ + public function mark_notifications_read($item_type, $item_id, $user_id, $time = false) + { + $time = ($time) ?: time(); + + $this->get_item_type_class_name($item_type); + + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + SET unread = 0 + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND time <= " . $time . + (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : '') . + (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); + $this->db->sql_query($sql); + } + + /** + * Mark notifications read from a parent identifier + * + * @param string $item_type item type + * @param bool|int|array $item_parent_id Item parent id or array of item parent ids. False to mark read for all item parent ids + * @param bool|int|array $user_id User id or array of user ids. False to mark read for all user ids + * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False) + */ + public function mark_notifications_read_by_parent($item_type, $item_parent_id, $user_id, $time = false) + { + $time = ($time) ?: time(); + + $item_type_class_name = $this->get_item_type_class_name($item_type); + + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + SET unread = 0 + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND time <= " . $time . + (($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id) : 'item_parent_id = ' . (int) $item_parent_id) : '') . + (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); + $this->db->sql_query($sql); + } + /** * Add a notification * @@ -118,9 +164,6 @@ class phpbb_notifications_service $item_id = $item_type_class_name::get_item_id($data); - // Update any existing notifications for this item - $this->update_notifications($item_type, $data); - // find out which users want to receive this type of notification $notify_users = $item_type_class_name::find_users_for_notification($this->phpbb_container, $data); @@ -250,6 +293,8 @@ class phpbb_notifications_service */ public function delete_notifications($item_type, $item_id) { + $this->get_item_type_class_name($item_type); + $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " 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); diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 47db2c4aa7..daca3b43cb 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -40,6 +40,7 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type * Indentification data * item_type * item_id + * item_parent_id // Parent item id (ex: for topic => forum_id, for post => topic_id, etc) * user_id * unread * @@ -145,33 +146,6 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type return $this->mark(true, $return); } - /** - * Mark this item read/unread - * - * @param bool $unread Unread (True/False) (Default: False) - * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) - * @return string - */ - protected function mark($unread = true, $return = false) - { - $where = array( - 'item_type = ' . $this->db->sql_escape($this->item_type), - 'item_id = ' . (int) $this->item_id, - 'user_id = ' . (int) $this->user_id, - ); - $where = implode(' AND ' . $where); - - if ($return) - { - return $where; - } - - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' - SET unread = ' . (bool) $unread . ' - WHERE ' . $where; - $this->db->sql_query($sql); - } - /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) @@ -184,11 +158,14 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type { // Defaults $data = array_merge(array( - 'item_type' => $this->get_item_type(), - 'time' => time(), - 'unread' => true, + 'item_id' => static::get_item_id($type_data), + 'item_type' => $this->get_item_type(), + 'item_parent_id' => static::get_item_parent_id($type_data), - 'data' => array(), + 'time' => time(), + 'unread' => true, + + 'data' => array(), ), $this->data); $data['data'] = serialize($data['data']); @@ -218,6 +195,58 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type return $data; } + /** + * -------------- Fall back functions ------------------- + */ + + /** + * Get the formatted title of this notification (fall-back) + * + * @return string + */ + public function get_formatted_title() + { + return $this->get_title(); + } + + /** + * URL to unsubscribe to this notification (fall-back) + * + * @param string|bool $method Method name to unsubscribe from (email|jabber|etc), False to unsubscribe from all notifications for this item + */ + public function get_unsubscribe_url($method = false) + { + return false; + } + + /** + * Get the user's avatar (fall-back) + */ + public function get_avatar() + { + return ''; + } + + /** + * Get the special items to load (fall-back) + */ + public function get_load_special() + { + return array(); + } + + /** + * Load the special items (fall-back) + */ + public static function load_special(ContainerBuilder $phpbb_container, $data, $notifications) + { + return; + } + + /** + * -------------- Helper functions ------------------- + */ + /** * Find the users who want to receive notifications (helper) * @@ -251,6 +280,12 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type return $rowset; } + /** + * Get avatar helper + * + * @param int $user_id + * @return string + */ protected function _get_avatar($user_id) { $user = $this->service->get_user($user_id); @@ -264,46 +299,29 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type } /** - * Get the formatted title of this notification (fall-back) + * Mark this item read/unread helper * + * @param bool $unread Unread (True/False) (Default: False) + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) * @return string */ - public function get_formatted_title() - { - return $this->get_title(); - } - - /** - * URL to unsubscribe to this notification (fall-back) - * - * @param string|bool $method Method name to unsubscribe from (email|jabber|etc), False to unsubscribe from all notifications for this item - */ - public function get_unsubscribe_url($method = false) - { - return false; - } - - /** - * Get the user's avatar (fall-back) - */ - public function get_avatar() + protected function mark($unread = true, $return = false) { - return ''; - } + $where = array( + 'item_type = ' . $this->db->sql_escape($this->item_type), + 'item_id = ' . (int) $this->item_id, + 'user_id = ' . (int) $this->user_id, + ); + $where = implode(' AND ' . $where); - /** - * Get the special items to load (fall-back) - */ - public function get_load_special() - { - return array(); - } + if ($return) + { + return $where; + } - /** - * Load the special items (fall-back) - */ - public static function load_special(ContainerBuilder $phpbb_container, $data, $notifications) - { - return; + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + SET unread = ' . (bool) $unread . ' + WHERE ' . $where; + $this->db->sql_query($sql); } } diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 8ea1045641..89f338f3f9 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -44,6 +44,17 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base return (int) $pm['msg_id']; } + /** + * Get the id of the parent + * + * @param array $pm The data from the pm + */ + public static function get_item_parent_id($pm) + { + // No parent + return 0; + } + /** * Find the users who want to receive notifications * @@ -164,8 +175,6 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base */ public function create_insert_array($pm) { - $this->item_id = $pm['msg_id']; - $this->set_data('from_user_id', $pm['from_user_id']); $this->set_data('message_subject', $pm['message_subject']); diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index d5759111cf..324a40888d 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -35,7 +35,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base } /** - * Get the id of the + * Get the id of the item * * @param array $post The data from the post */ @@ -44,6 +44,16 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base return (int) $post['post_id']; } + /** + * Get the id of the parent + * + * @param array $post The data from the post + */ + public static function get_item_parent_id($post) + { + return (int) $post['topic_id']; + } + /** * Find the users who want to receive notifications * @@ -197,10 +207,6 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base */ public function create_insert_array($post) { - $this->item_id = $post['post_id']; - - $this->set_data('topic_id', $post['topic_id']); - $this->set_data('poster_id', $post['poster_id']); $this->set_data('topic_title', $post['topic_title']); diff --git a/phpBB/includes/notifications/type/quote.php b/phpBB/includes/notifications/type/quote.php index e17769acea..11186f3685 100644 --- a/phpBB/includes/notifications/type/quote.php +++ b/phpBB/includes/notifications/type/quote.php @@ -183,8 +183,6 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post $add_notifications[$user_id] = $notifications[$user_id]; } - var_dump($old_notifications, $notifications, $remove_notifications, $add_notifications); - // Add the necessary notifications $service->add_notifications_for_users(self::get_item_type(), $post, $add_notifications); diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php index cb7bfdbb8f..0fce65a0cf 100644 --- a/phpBB/includes/notifications/type/topic.php +++ b/phpBB/includes/notifications/type/topic.php @@ -35,7 +35,7 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base } /** - * Get the id of the + * Get the id of the item * * @param array $post The data from the post */ @@ -44,6 +44,16 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base return (int) $post['topic_id']; } + /** + * Get the id of the parent + * + * @param array $post The data from the post + */ + public static function get_item_parent_id($post) + { + return (int) $post['forum_id']; + } + /** * Find the users who want to receive notifications * @@ -166,7 +176,7 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base */ public function get_url() { - return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "f={$this->get_data('forum_id')}&t={$this->item_id}"); + return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "f={$this->item_parent_id}&t={$this->item_id}"); } /** @@ -176,7 +186,7 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base */ public function get_full_url() { - return generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_id}"; + return generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}"; } /** @@ -199,8 +209,6 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base */ public function create_insert_array($post) { - $this->item_id = $post['topic_id']; - $this->set_data('poster_id', $post['poster_id']); $this->set_data('topic_title', $post['topic_title']); @@ -209,8 +217,6 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base $this->set_data('forum_name', $post['forum_name']); - $this->set_data('forum_id', $post['forum_id']); - return parent::create_insert_array($post); } } -- cgit v1.2.1 From f083c6d7765b63ad0179bc82a3d9f0abbf08637c Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 14 Sep 2012 16:15:15 -0500 Subject: [ticket/11103] Mark all post/quote notifications read when marking topics Mark forum read marks all topics read, so do so properly for notifications PHPBB3-11103 --- phpBB/includes/functions.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 3d3dd1f5bc..b996fef292 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1339,6 +1339,21 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ $notifications = $phpbb_container->get('notifications'); $notifications->mark_notifications_read_by_parent('topic', $forum_id, $user->data['user_id'], $post_time); + // Mark all post/quote notifications read for this user in this forum + $topic_ids = array(); + $sql = 'SELECT topic_id + FROM ' . TOPICS_TABLE . ' + WHERE ' . $db->sql_in_set('forum_id', $forum_id); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $topic_ids[] = $row['topic_id']; + } + $db->sql_freeresult($result); + + $notifications->mark_notifications_read_by_parent('post', $topic_ids, $user->data['user_id'], $post_time); + $notifications->mark_notifications_read_by_parent('quote', $topic_ids, $user->data['user_id'], $post_time); + // Add 0 to forums array to mark global announcements correctly // $forum_id[] = 0; -- cgit v1.2.1 From 40bc3b1f19af09f974e2c5bd6c113b78bcfe4f0b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 14 Sep 2012 16:20:15 -0500 Subject: [ticket/11103] Mark Private Messages as read PHPBB3-11103 --- phpBB/includes/functions_privmsgs.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 88c5bd8e2a..dbf5df787f 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -876,7 +876,11 @@ function update_unread_status($unread, $msg_id, $user_id, $folder_id) return; } - global $db, $user; + global $db, $user, $phpbb_container; + + // Mark the PM as read + $notifications = $phpbb_container->get('notifications'); + $notifications->mark_notifications_read('pm', $msg_id, $user_id); $sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . " SET pm_unread = 0 -- cgit v1.2.1 From 1ab0c469e253df0e01f358a4a86e1b6df290d740 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 14 Sep 2012 16:24:50 -0500 Subject: [ticket/11103] Delete notifications for PMs deleted by phpbb_delete_user_pms PHPBB3-11103 --- phpBB/includes/functions_privmsgs.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index dbf5df787f..133b6fc9bc 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -1146,6 +1146,7 @@ function delete_pm($user_id, $msg_ids, $folder_id) function phpbb_delete_user_pms($user_id) { global $db, $user, $phpbb_root_path, $phpEx; + global $phpbb_container; $user_id = (int) $user_id; @@ -1262,6 +1263,10 @@ function phpbb_delete_user_pms($user_id) WHERE folder_id = ' . PRIVMSGS_NO_BOX . ' AND ' . $db->sql_in_set('msg_id', $delivered_msg); $db->sql_query($sql); + + // Delete Notifications + $phpbb_notifications = $phpbb_container->get('notifications'); + $phpbb_notifications->delete_notifications('pm', $delivered_msg); } if (!empty($undelivered_msg)) @@ -1273,6 +1278,10 @@ function phpbb_delete_user_pms($user_id) $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' WHERE ' . $db->sql_in_set('msg_id', $undelivered_msg); $db->sql_query($sql); + + // Delete Notifications + $phpbb_notifications = $phpbb_container->get('notifications'); + $phpbb_notifications->delete_notifications('pm', $undelivered_msg); } } @@ -1315,6 +1324,10 @@ function phpbb_delete_user_pms($user_id) $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' WHERE ' . $db->sql_in_set('msg_id', $delete_ids); $db->sql_query($sql); + + // Delete Notifications + $phpbb_notifications = $phpbb_container->get('notifications'); + $phpbb_notifications->delete_notifications('pm', $delete_ids); } } -- cgit v1.2.1 From ed1ec8e720a7ec3c1270cd631cc37e531f315f26 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 14 Sep 2012 16:54:20 -0500 Subject: [ticket/11103] Add/Update/Mark Read functions accept an array for the type This saves a lot of code in some areas (where the same data is sent, just for different types) Notifications for bookmarks PHPBB3-11103 --- phpBB/includes/functions.php | 6 +- phpBB/includes/functions_posting.php | 16 ++--- phpBB/includes/mcp/mcp_queue.php | 2 +- phpBB/includes/notifications/service.php | 60 +++++++++++++++-- phpBB/includes/notifications/type/bookmark.php | 92 ++++++++++++++++++++++++++ phpBB/includes/notifications/type/post.php | 11 ++- phpBB/includes/notifications/type/quote.php | 66 ++++-------------- 7 files changed, 177 insertions(+), 76 deletions(-) create mode 100644 phpBB/includes/notifications/type/bookmark.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b996fef292..aec7759f19 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1351,8 +1351,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ } $db->sql_freeresult($result); - $notifications->mark_notifications_read_by_parent('post', $topic_ids, $user->data['user_id'], $post_time); - $notifications->mark_notifications_read_by_parent('quote', $topic_ids, $user->data['user_id'], $post_time); + $notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post'), $topic_ids, $user->data['user_id'], $post_time); // Add 0 to forums array to mark global announcements correctly // $forum_id[] = 0; @@ -1450,8 +1449,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ // Mark post notifications read for this user in this topic $notifications = $phpbb_container->get('notifications'); - $notifications->mark_notifications_read_by_parent('post', $topic_id, $user->data['user_id'], $post_time); - $notifications->mark_notifications_read_by_parent('quote', $topic_id, $user->data['user_id'], $post_time); + $notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post'), $topic_id, $user->data['user_id'], $post_time); if ($config['load_db_lastread'] && $user->data['is_registered']) { diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 26d9b81896..56f84562f7 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2227,20 +2227,14 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u switch ($mode) { case 'post' : - $notifications->add_notifications('topic', array_merge($data, array( - 'post_username' => $username, - ))); - $notifications->add_notifications('quote', array_merge($data, array( + $notifications->add_notifications(array('topic', 'quote'), array_merge($data, array( 'post_username' => $username, ))); break; case 'reply' : case 'quote' : - $notifications->add_notifications('post', array_merge($data, array( - 'post_username' => $username, - ))); - $notifications->add_notifications('quote', array_merge($data, array( + $notifications->add_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( 'post_username' => $username, ))); break; @@ -2253,10 +2247,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'post_username' => $username, 'topic_title' => $subject, ))); - $notifications->update_notifications('post', array_merge($data, array( - 'post_username' => $username, - ))); - $notifications->update_notifications('quote', array_merge($data, array( + + $notifications->update_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( 'post_username' => $username, ))); break; diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 1d9a2dfedc..48557192d2 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -646,7 +646,7 @@ function approve_post($post_id_list, $id, $mode) else { // Topic Notifications - $notifications->add_notifications('post', $post_data); + $notifications->add_notifications(array('quote', 'bookmark', 'post'), $post_data); } } diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 8be8ae2a95..4933cf0f9a 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -109,13 +109,23 @@ class phpbb_notifications_service /** * Mark notifications read * - * @param string $item_type item type + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) * @param bool|int|array $item_id Item id or array of item ids. False to mark read for all item ids * @param bool|int|array $user_id User id or array of user ids. False to mark read for all user ids * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False) */ public function mark_notifications_read($item_type, $item_id, $user_id, $time = false) { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->mark_notifications_read($type, $item_id, $user_id, $time); + } + + return; + } + $time = ($time) ?: time(); $this->get_item_type_class_name($item_type); @@ -132,13 +142,23 @@ class phpbb_notifications_service /** * Mark notifications read from a parent identifier * - * @param string $item_type item type + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) * @param bool|int|array $item_parent_id Item parent id or array of item parent ids. False to mark read for all item parent ids * @param bool|int|array $user_id User id or array of user ids. False to mark read for all user ids * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False) */ public function mark_notifications_read_by_parent($item_type, $item_parent_id, $user_id, $time = false) { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->mark_notifications_read($type, $item_id, $user_id, $time); + } + + return; + } + $time = ($time) ?: time(); $item_type_class_name = $this->get_item_type_class_name($item_type); @@ -155,11 +175,21 @@ class phpbb_notifications_service /** * Add a notification * - * @param string $item_type Type identifier + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) * @param array $data Data specific for this type that will be inserted */ public function add_notifications($item_type, $data) { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->add_notifications($type, $data); + } + + return; + } + $item_type_class_name = $this->get_item_type_class_name($item_type); $item_id = $item_type_class_name::get_item_id($data); @@ -173,12 +203,22 @@ class phpbb_notifications_service /** * Add a notification for specific users * - * @param string $item_type Type identifier + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) * @param array $data Data specific for this type that will be inserted * @param array $notify_users User list to notify */ public function add_notifications_for_users($item_type, $data, $notify_users) { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->add_notifications($type, $data); + } + + return; + } + $item_type_class_name = $this->get_item_type_class_name($item_type); $item_id = $item_type_class_name::get_item_id($data); @@ -255,11 +295,21 @@ class phpbb_notifications_service /** * Update a notification * - * @param string $item_type Type identifier + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) * @param array $data Data specific for this type that will be updated */ public function update_notifications($item_type, $data) { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->add_notifications($type, $data); + } + + return; + } + $item_type_class_name = $this->get_item_type_class_name($item_type); // Allow the notifications class to over-ride the update_notifications functionality diff --git a/phpBB/includes/notifications/type/bookmark.php b/phpBB/includes/notifications/type/bookmark.php new file mode 100644 index 0000000000..7896703f00 --- /dev/null +++ b/phpBB/includes/notifications/type/bookmark.php @@ -0,0 +1,92 @@ +get('dbal.conn'); + + $users = array(); + + /* todo + * find what type of notification they'd like to receive + */ + $sql = 'SELECT user_id + FROM ' . BOOKMARKS_TABLE . ' + WHERE ' . $db->sql_in_set('topic_id', $post['topic_id']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $users[$row['user_id']] = array(''); + } + $db->sql_freeresult($result); + + if (empty($users)) + { + return array(); + } + + $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = array(); + + foreach ($auth_read[$post['forum_id']]['f_read'] as $user_id) + { + $notify_users[$user_id] = $users[$user_id]; + } + + return $notify_users; + } +} diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 324a40888d..cc72ab8b1f 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -25,6 +25,13 @@ if (!defined('IN_PHPBB')) */ class phpbb_notifications_type_post extends phpbb_notifications_type_base { + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_POST'; + /** * Get the type of notification this is * phpbb_notifications_type_ @@ -136,7 +143,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base } return $this->phpbb_container->get('user')->lang( - 'NOTIFICATION_POST', + $this->language_key, $username, censor_text($this->get_data('topic_title')) ); @@ -161,7 +168,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base } return $this->phpbb_container->get('user')->lang( - 'NOTIFICATION_POST', + $this->language_key, $username, censor_text($this->get_data('topic_title')) ); diff --git a/phpBB/includes/notifications/type/quote.php b/phpBB/includes/notifications/type/quote.php index 11186f3685..86d157631d 100644 --- a/phpBB/includes/notifications/type/quote.php +++ b/phpBB/includes/notifications/type/quote.php @@ -18,15 +18,27 @@ if (!defined('IN_PHPBB')) } /** -* Post tagging notifications class -* This class handles notifications for tagging users in a post (ex: @EXreaction) +* Post quoting notifications class +* This class handles notifications for quoting users in a post * * @package notifications */ class phpbb_notifications_type_quote extends phpbb_notifications_type_post { + /** + * regular expression to match to find usernames + * + * @var string + */ protected static $regular_expression_match = '#\[quote="(.+?)":#'; + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_QUOTE'; + /** * Get the type of notification this is * phpbb_notifications_type_ @@ -97,56 +109,6 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post return $notify_users; } - /** - * Get the HTML formatted title of this notification - * - * @return string - */ - public function get_formatted_title() - { - if ($this->get_data('post_username')) - { - $username = $this->get_data('post_username'); - } - else - { - $user_data = $this->service->get_user($this->get_data('poster_id')); - - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); - } - - return $this->phpbb_container->get('user')->lang( - 'NOTIFICATION_QUOTE', - $username, - censor_text($this->get_data('topic_title')) - ); - } - - /** - * Get the title of this notification - * - * @return string - */ - public function get_title() - { - if ($this->get_data('post_username')) - { - $username = $this->get_data('post_username'); - } - else - { - $user_data = $this->service->get_user($this->get_data('poster_id')); - - $username = $user_data['username']; - } - - return $this->phpbb_container->get('user')->lang( - 'NOTIFICATION_QUOTE', - $username, - censor_text($this->get_data('topic_title')) - ); - } - /** * Update a notification * -- cgit v1.2.1 From 8e977544fb6763412e45f84791de8c3eccf321c9 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 14 Sep 2012 17:01:08 -0500 Subject: [ticket/11103] Normalization of $phpbb_notifications variable name Use $phpbb_notifications instead of $notifications everywhere for consistency and conflict prevention. PHPBB3-11103 --- phpBB/includes/functions.php | 14 +++++++------- phpBB/includes/functions_admin.php | 8 ++++---- phpBB/includes/functions_posting.php | 10 +++++----- phpBB/includes/functions_privmsgs.php | 4 ++-- phpBB/includes/mcp/mcp_queue.php | 6 +++--- 5 files changed, 21 insertions(+), 21 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index aec7759f19..b7243227bd 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1294,8 +1294,8 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ // Mark all forums read (index page) // Mark all topic notifications read for this user - $notifications = $phpbb_container->get('notifications'); - $notifications->mark_notifications_read('topic', false, $user->data['user_id'], $post_time); + $phpbb_notifications = $phpbb_container->get('notifications'); + $phpbb_notifications->mark_notifications_read('topic', false, $user->data['user_id'], $post_time); if ($config['load_db_lastread'] && $user->data['is_registered']) { @@ -1336,8 +1336,8 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ } // Mark topic notifications read for this user in this forum - $notifications = $phpbb_container->get('notifications'); - $notifications->mark_notifications_read_by_parent('topic', $forum_id, $user->data['user_id'], $post_time); + $phpbb_notifications = $phpbb_container->get('notifications'); + $phpbb_notifications->mark_notifications_read_by_parent('topic', $forum_id, $user->data['user_id'], $post_time); // Mark all post/quote notifications read for this user in this forum $topic_ids = array(); @@ -1351,7 +1351,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ } $db->sql_freeresult($result); - $notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post'), $topic_ids, $user->data['user_id'], $post_time); + $phpbb_notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post'), $topic_ids, $user->data['user_id'], $post_time); // Add 0 to forums array to mark global announcements correctly // $forum_id[] = 0; @@ -1448,8 +1448,8 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ } // Mark post notifications read for this user in this topic - $notifications = $phpbb_container->get('notifications'); - $notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post'), $topic_id, $user->data['user_id'], $post_time); + $phpbb_notifications = $phpbb_container->get('notifications'); + $phpbb_notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post'), $topic_id, $user->data['user_id'], $post_time); if ($config['load_db_lastread'] && $user->data['is_registered']) { diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 6845ae14e3..1cbd44e97e 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -717,8 +717,8 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s } // Delete notifications - $notifications = $phpbb_container->get('notifications'); - $notifications->delete_notifications('topic', $topic_ids); + $phpbb_notifications = $phpbb_container->get('notifications'); + $phpbb_notifications->delete_notifications('topic', $topic_ids); return $return; } @@ -899,8 +899,8 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = } // Delete notifications - $notifications = $phpbb_container->get('notifications'); - $notifications->delete_notifications('post', $post_ids); + $phpbb_notifications = $phpbb_container->get('notifications'); + $phpbb_notifications->delete_notifications('post', $post_ids); return sizeof($post_ids); } diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 56f84562f7..e48a2b6bec 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2222,19 +2222,19 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Send Notifications if ($post_approval) { - $notifications = $phpbb_container->get('notifications'); + $phpbb_notifications = $phpbb_container->get('notifications'); switch ($mode) { case 'post' : - $notifications->add_notifications(array('topic', 'quote'), array_merge($data, array( + $phpbb_notifications->add_notifications(array('topic', 'quote'), array_merge($data, array( 'post_username' => $username, ))); break; case 'reply' : case 'quote' : - $notifications->add_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( + $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( 'post_username' => $username, ))); break; @@ -2243,12 +2243,12 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u case 'edit_first_post' : case 'edit' : case 'edit_last_post' : - $notifications->update_notifications('topic', array_merge($data, array( + $phpbb_notifications->update_notifications('topic', array_merge($data, array( 'post_username' => $username, 'topic_title' => $subject, ))); - $notifications->update_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( + $phpbb_notifications->update_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( 'post_username' => $username, ))); break; diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 133b6fc9bc..8545cc7ef5 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -879,8 +879,8 @@ function update_unread_status($unread, $msg_id, $user_id, $folder_id) global $db, $user, $phpbb_container; // Mark the PM as read - $notifications = $phpbb_container->get('notifications'); - $notifications->mark_notifications_read('pm', $msg_id, $user_id); + $phpbb_notifications = $phpbb_container->get('notifications'); + $phpbb_notifications->mark_notifications_read('pm', $msg_id, $user_id); $sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . " SET pm_unread = 0 diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 48557192d2..1373829ecf 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -634,19 +634,19 @@ function approve_post($post_id_list, $id, $mode) // Send out normal user notifications $email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']); - $notifications = $phpbb_container->get('notifications'); + $phpbb_notifications = $phpbb_container->get('notifications'); foreach ($post_info as $post_id => $post_data) { if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) { // Forum Notifications - $notifications->add_notifications('topic', $post_data); + $phpbb_notifications->add_notifications('topic', $post_data); } else { // Topic Notifications - $notifications->add_notifications(array('quote', 'bookmark', 'post'), $post_data); + $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), $post_data); } } -- cgit v1.2.1 From 959c81d00e830e89fa9d583ee93bf8f166013fe0 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 14 Sep 2012 18:05:13 -0500 Subject: [ticket/11103] Use appropriate email templates to send notifications Fixing a number of bugs PHPBB3-11103 --- phpBB/includes/functions_posting.php | 2 ++ phpBB/includes/notifications/method/email.php | 14 +++++------- phpBB/includes/notifications/service.php | 2 +- phpBB/includes/notifications/type/base.php | 4 +++- phpBB/includes/notifications/type/bookmark.php | 7 ++++++ phpBB/includes/notifications/type/interface.php | 4 ++-- phpBB/includes/notifications/type/pm.php | 28 +++++++++++++++++------ phpBB/includes/notifications/type/post.php | 30 +++++++++++++++++++------ phpBB/includes/notifications/type/quote.php | 23 +++++++++++++++++++ phpBB/includes/notifications/type/topic.php | 27 ++++++++++++++++------ 10 files changed, 107 insertions(+), 34 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index e48a2b6bec..fc2c5a47b6 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2229,6 +2229,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u case 'post' : $phpbb_notifications->add_notifications(array('topic', 'quote'), array_merge($data, array( 'post_username' => $username, + 'poster_id' => (int) $user->data['user_id'], ))); break; @@ -2236,6 +2237,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u case 'quote' : $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( 'post_username' => $username, + 'poster_id' => (int) $user->data['user_id'], ))); break; diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index 1bcea13d92..a1ca955ee1 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -82,19 +82,15 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base continue; } - $messenger->template('notification', $user['user_lang']); + $messenger->template($notification->email_template, $user['user_lang']); $messenger->to($user['user_email'], $user['username']); - $messenger->assign_vars(array( - 'USERNAME' => $user['username'], + $messenger->assign_vars(array_merge(array( + 'USERNAME' => $user['username'], - 'MESSAGE' => htmlspecialchars_decode($notification->get_title()), - - 'U_VIEW_MESSAGE' => $notification->get_full_url(), - - 'U_UNSUBSCRIBE' => $notification->get_unsubscribe_url(), - )); + 'U_NOTIFICATION_SETTINGS' => generate_board_url() . '/ucp.' . $this->php_ext . '?i=notifications', // todo Update URL + ), $notification->get_email_template_variables())); $messenger->send($this->notify_method); } diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 4933cf0f9a..d2ff20333e 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -153,7 +153,7 @@ class phpbb_notifications_service { foreach ($item_type as $type) { - $this->mark_notifications_read($type, $item_id, $user_id, $time); + $this->mark_notifications_read_by_parent($type, $item_parent_id, $user_id, $time); } return; diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index daca3b43cb..4958e27919 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -157,7 +157,7 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type public function create_insert_array($type_data) { // Defaults - $data = array_merge(array( + $this->data = array_merge(array( 'item_id' => static::get_item_id($type_data), 'item_type' => $this->get_item_type(), 'item_parent_id' => static::get_item_parent_id($type_data), @@ -168,6 +168,8 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type 'data' => array(), ), $this->data); + $data = $this->data; + $data['data'] = serialize($data['data']); return $data; diff --git a/phpBB/includes/notifications/type/bookmark.php b/phpBB/includes/notifications/type/bookmark.php index 7896703f00..86a99e4ff5 100644 --- a/phpBB/includes/notifications/type/bookmark.php +++ b/phpBB/includes/notifications/type/bookmark.php @@ -25,6 +25,13 @@ if (!defined('IN_PHPBB')) */ class phpbb_notifications_type_bookmark extends phpbb_notifications_type_post { + /** + * Email template to use to send notifications + * + * @var string + */ + public $email_template = 'notifications/bookmark'; + /** * Language key used to output the text * diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index c1c0eb0b0c..a8c6e4869b 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -31,9 +31,9 @@ interface phpbb_notifications_type_interface public function get_formatted_title(); - public function get_url(); + public function get_email_template_variables(); - public function get_full_url(); + public function get_url(); public function get_unsubscribe_url($method); diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 89f338f3f9..816383949b 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -25,6 +25,13 @@ if (!defined('IN_PHPBB')) */ class phpbb_notifications_type_pm extends phpbb_notifications_type_base { + /** + * Email template to use to send notifications + * + * @var string + */ + public $email_template = 'privmsg_notify'; + /** * Get the type of notification this is * phpbb_notifications_type_ @@ -136,23 +143,30 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base } /** - * Get the url to this item + * Get email template variables * - * @return string URL + * @return array */ - public function get_url() + public function get_email_template_variables() { - return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=pm&mode=view&p={$this->item_id}"); + $user_data = $this->service->get_user($this->get_data('from_user_id')); + + return array( + 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), + 'SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('message_subject'))), + + 'U_VIEW_MESSAGE' => generate_board_url() . '/ucp.' . $this->php_ext . "?i=pm&mode=view&p={$this->item_id}", + ); } /** - * Get the full url to this item + * Get the url to this item * * @return string URL */ - public function get_full_url() + public function get_url() { - return generate_board_url() . "/ucp.{$this->php_ext}?i=pm&mode=view&p={$this->item_id}"; + return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=pm&mode=view&p={$this->item_id}"); } /** diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index cc72ab8b1f..13742ee78b 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -25,6 +25,13 @@ if (!defined('IN_PHPBB')) */ class phpbb_notifications_type_post extends phpbb_notifications_type_base { + /** + * Email template to use to send notifications + * + * @var string + */ + public $email_template = 'topic_notify'; + /** * Language key used to output the text * @@ -175,23 +182,30 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base } /** - * Get the url to this item + * Get email template variables * - * @return string URL + * @return array */ - public function get_url() + public function get_email_template_variables() { - return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}"); + return array( + 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), + + 'U_NEWEST_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&view=unread#unread", + 'U_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + 'U_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}", + 'U_STOP_WATCHING_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?uid={$this->user_id}&f={$this->get_data('forum_id')}&t={$this->item_parent_id}&unwatch=topic", + ); } /** - * Get the full url to this item + * Get the url to this item * * @return string URL */ - public function get_full_url() + public function get_url() { - return generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}"; + return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}"); } /** @@ -220,6 +234,8 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $this->set_data('post_username', (($post['post_username'] != $this->phpbb_container->get('user')->data['username']) ? $post['post_username'] : '')); + $this->set_data('forum_id', $post['forum_id']); + $this->set_data('forum_name', $post['forum_name']); return parent::create_insert_array($post); diff --git a/phpBB/includes/notifications/type/quote.php b/phpBB/includes/notifications/type/quote.php index 86d157631d..48d63003dd 100644 --- a/phpBB/includes/notifications/type/quote.php +++ b/phpBB/includes/notifications/type/quote.php @@ -25,6 +25,13 @@ if (!defined('IN_PHPBB')) */ class phpbb_notifications_type_quote extends phpbb_notifications_type_post { + /** + * Email template to use to send notifications + * + * @var string + */ + public $email_template = 'notifications/quote'; + /** * regular expression to match to find usernames * @@ -161,4 +168,20 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post // return true to continue with the update code in the notifications service (this will update the rest of the notifications) return true; } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + $user_data = $this->service->get_user($this->get_data('poster_id')); + + return array_merge(parent::get_email_template_variables(), array( + 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), + + 'U_QUOTED_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", + )); + } } diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php index 0fce65a0cf..e31c8d792b 100644 --- a/phpBB/includes/notifications/type/topic.php +++ b/phpBB/includes/notifications/type/topic.php @@ -25,6 +25,13 @@ if (!defined('IN_PHPBB')) */ class phpbb_notifications_type_topic extends phpbb_notifications_type_base { + /** + * Email template to use to send notifications + * + * @var string + */ + public $email_template = 'newtopic_notify'; + /** * Get the type of notification this is * phpbb_notifications_type_ @@ -170,23 +177,29 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base } /** - * Get the url to this item + * Get email template variables * - * @return string URL + * @return array */ - public function get_url() + public function get_email_template_variables() { - return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "f={$this->item_parent_id}&t={$this->item_id}"); + return array( + 'FORUM_NAME' => htmlspecialchars_decode($this->get_data('forum_name')), + 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), + + 'U_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->item_parent_id}", + 'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?uid={$this->user_id}&f={$this->item_parent_id}&unwatch=forum", + ); } /** - * Get the full url to this item + * Get the url to this item * * @return string URL */ - public function get_full_url() + public function get_url() { - return generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}"; + return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "f={$this->item_parent_id}&t={$this->item_id}"); } /** -- cgit v1.2.1 From 7589a3093d95048f5a8cfdc6259501f43fd3fe10 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 14 Sep 2012 18:30:12 -0500 Subject: [ticket/11103] Display all unread notifications by default Add unread count to the page title PHPBB3-11103 --- phpBB/includes/functions.php | 16 +++++++----- phpBB/includes/notifications/service.php | 44 ++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 9 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b7243227bd..e26db56442 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4994,6 +4994,14 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 $timezone_name = $user->lang['timezones'][$timezone_name]; } + // Output the notifications + $phpbb_notifications = $phpbb_container->get('notifications'); + $notifications = $phpbb_notifications->load_notifications(); + foreach ($notifications['notifications'] as $notification) + { + $template->assign_block_vars('notifications', $notification->prepare_for_display()); + } + // The following assigns all _common_ variables that may be used at any point in a template. $template->assign_vars(array( 'SITENAME' => $config['sitename'], @@ -5008,6 +5016,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'RECORD_USERS' => $l_online_record, 'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text, 'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread, + 'NUM_UNREAD_NOTIFICATIONS' => $notifications['unread_count'], 'S_USER_NEW_PRIVMSG' => $user->data['user_new_privmsg'], 'S_USER_UNREAD_PRIVMSG' => $user->data['user_unread_privmsg'], @@ -5119,13 +5128,6 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'A_COOKIE_SETTINGS' => addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')), )); - // Output the notifications - $phpbb_notifications = $phpbb_container->get('notifications'); - foreach ($phpbb_notifications->load_notifications() as $notification) - { - $template->assign_block_vars('notifications', $notification->prepare_for_display()); - } - // application/xhtml+xml not used because of IE header('Content-type: text/html; charset=UTF-8'); diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index d2ff20333e..9f3fe8326f 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -50,6 +50,7 @@ class phpbb_notifications_service * order_dir Order direction (Default: DESC) * limit Number of notifications to load (Default: 5) * start Notifications offset (Default: 0) + * all_unread Load all unread messages? (Default: true) */ public function load_notifications($options = array()) { @@ -62,11 +63,24 @@ class phpbb_notifications_service 'order_dir' => 'DESC', 'limit' => 5, 'start' => 0, + 'all_unread' => true, ), $options); $notifications = $user_ids = array(); $load_special = array(); + // Get the total number of unread notifications + $sql = 'SELECT COUNT(*) AS count + FROM ' . NOTIFICATIONS_TABLE . ' + WHERE user_id = ' . (int) $options['user_id'] . ' + AND unread = 1'; + $result = $this->db->sql_query($sql); + $count = $this->db->sql_fetchfield('count', $result); + $this->db->sql_freeresult($result); + + $rowset = array(); + + // Get the main notifications $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . ' WHERE user_id = ' . (int) $options['user_id'] . ' @@ -74,6 +88,30 @@ class phpbb_notifications_service $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); + + // Get all unread notifications + if ($options['all_unread']) + { + $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) . ' + 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); + } + + foreach ($rowset as $row) { $item_type_class_name = $this->get_item_type_class_name($row['item_type'], true); @@ -91,7 +129,6 @@ class phpbb_notifications_service $notifications[] = $notification; } - $this->db->sql_freeresult($result); $this->load_users($user_ids); @@ -103,7 +140,10 @@ class phpbb_notifications_service $item_type_class_name::load_special($this->phpbb_container, $data, $notifications); } - return $notifications; + return array( + 'notifications' => $notifications, + 'unread_count' => $count, + ); } /** -- cgit v1.2.1 From a1e2fb93add6cf6ff0c83879b347d1780411a335 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Sep 2012 11:59:30 -0500 Subject: [ticket/11103] Bots/Anonymous never receive notifications Do not waste queries trying to load notifications for these users PHPBB3-11103 --- phpBB/includes/notifications/service.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 9f3fe8326f..7fdba5e48a 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -66,6 +66,12 @@ class phpbb_notifications_service 'all_unread' => true, ), $options); + // Anonymous users and bots never receive notifications + if ($options['user_id'] == $user->data['user_id'] && ($user->data['user_id'] == ANONYMOUS || $user->data['user_type'] == USER_IGNORE)) + { + return; + } + $notifications = $user_ids = array(); $load_special = array(); @@ -94,7 +100,7 @@ class phpbb_notifications_service $this->db->sql_freeresult($result); // Get all unread notifications - if ($options['all_unread']) + if ($options['all_unread'] && !empty($rowset)) { $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . ' -- cgit v1.2.1 From 9c54465a1331216be1e3369346921dee9148e590 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Sep 2012 12:00:03 -0500 Subject: [ticket/11103] Starting approve_post type notification PHPBB3-11103 --- phpBB/includes/mcp/mcp_queue.php | 33 ++---- phpBB/includes/notifications/type/approve_post.php | 114 +++++++++++++++++++++ 2 files changed, 122 insertions(+), 25 deletions(-) create mode 100644 phpBB/includes/notifications/type/approve_post.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 1373829ecf..df99e34576 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -597,45 +597,28 @@ function approve_post($post_id_list, $id, $mode) sync('forum', 'forum_id', array_keys($forum_id_list), true, true); unset($topic_id_list, $forum_id_list); - $messenger = new messenger(); + $phpbb_notifications = $phpbb_container->get('notifications'); // Notify Poster? if ($notify_poster) { + // Forum Notifications foreach ($post_info as $post_id => $post_data) { - if ($post_data['poster_id'] == ANONYMOUS) + if ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) { - continue; + $phpbb_notifications->add_notifications('approve_topic', $post_data); + } + else + { + $phpbb_notifications->add_notifications('approve_post', $post_data); } - - $email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_approved' : 'post_approved'; - - $messenger->template($email_template, $post_data['user_lang']); - - $messenger->to($post_data['user_email'], $post_data['username']); - $messenger->im($post_data['user_jabber'], $post_data['username']); - - $messenger->assign_vars(array( - 'USERNAME' => htmlspecialchars_decode($post_data['username']), - 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_data['post_subject'])), - 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_data['topic_title'])), - - 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&e=0", - 'U_VIEW_POST' => generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&p=$post_id&e=$post_id") - ); - - $messenger->send($post_data['user_notify_type']); } } - $messenger->save_queue(); - // Send out normal user notifications $email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']); - $phpbb_notifications = $phpbb_container->get('notifications'); - foreach ($post_info as $post_id => $post_data) { if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) diff --git a/phpBB/includes/notifications/type/approve_post.php b/phpBB/includes/notifications/type/approve_post.php new file mode 100644 index 0000000000..9724916a0e --- /dev/null +++ b/phpBB/includes/notifications/type/approve_post.php @@ -0,0 +1,114 @@ +get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = array(); + + foreach ($auth_read[$post['forum_id']]['f_read'] as $user_id) + { + $notify_users[$user_id] = $users[$user_id]; + } + + return $notify_users; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + return array( + 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), + + 'U_VIEW_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", + 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + ); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $this->set_data('post_subject', $post['post_subject']); + + return parent::create_insert_array($post); + } +} -- cgit v1.2.1 From 05b573ebf76c737f89deaefd22ce963aa910e5d1 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Sep 2012 13:51:02 -0500 Subject: [ticket/11103] Topic and post dis/approval notifications Remove the formatted title function, plaintext is not needed since email templates are used Fix a number of bugs. PHPBB3-11103 --- phpBB/includes/functions.php | 9 +- phpBB/includes/functions_posting.php | 2 + phpBB/includes/mcp/mcp_queue.php | 82 +++++++-------- phpBB/includes/notifications/service.php | 11 +- phpBB/includes/notifications/type/approve_post.php | 4 +- .../includes/notifications/type/approve_topic.php | 113 +++++++++++++++++++++ phpBB/includes/notifications/type/base.php | 13 +-- phpBB/includes/notifications/type/bookmark.php | 3 + .../notifications/type/disapprove_post.php | 105 +++++++++++++++++++ .../notifications/type/disapprove_topic.php | 104 +++++++++++++++++++ phpBB/includes/notifications/type/interface.php | 2 - phpBB/includes/notifications/type/pm.php | 14 +-- phpBB/includes/notifications/type/post.php | 32 ++---- phpBB/includes/notifications/type/quote.php | 5 +- phpBB/includes/notifications/type/topic.php | 42 +++----- 15 files changed, 404 insertions(+), 137 deletions(-) create mode 100644 phpBB/includes/notifications/type/approve_topic.php create mode 100644 phpBB/includes/notifications/type/disapprove_post.php create mode 100644 phpBB/includes/notifications/type/disapprove_topic.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index cb8dddd5f8..e9d673455c 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1295,7 +1295,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ // Mark all topic notifications read for this user $phpbb_notifications = $phpbb_container->get('notifications'); - $phpbb_notifications->mark_notifications_read('topic', false, $user->data['user_id'], $post_time); + $phpbb_notifications->mark_notifications_read(array('topic', 'quote', 'bookmark', 'post', 'approve_topic', 'approve_post'), false, $user->data['user_id'], $post_time); if ($config['load_db_lastread'] && $user->data['is_registered']) { @@ -1337,7 +1337,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ // Mark topic notifications read for this user in this forum $phpbb_notifications = $phpbb_container->get('notifications'); - $phpbb_notifications->mark_notifications_read_by_parent('topic', $forum_id, $user->data['user_id'], $post_time); + $phpbb_notifications->mark_notifications_read_by_parent(array('topic', 'approve_topic'), $forum_id, $user->data['user_id'], $post_time); // Mark all post/quote notifications read for this user in this forum $topic_ids = array(); @@ -1351,7 +1351,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ } $db->sql_freeresult($result); - $phpbb_notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post'), $topic_ids, $user->data['user_id'], $post_time); + $phpbb_notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post', 'approve_post'), $topic_ids, $user->data['user_id'], $post_time); // Add 0 to forums array to mark global announcements correctly // $forum_id[] = 0; @@ -1449,7 +1449,8 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ // Mark post notifications read for this user in this topic $phpbb_notifications = $phpbb_container->get('notifications'); - $phpbb_notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post'), $topic_id, $user->data['user_id'], $post_time); + $phpbb_notifications->mark_notifications_read(array('topic', 'approve_topic'), $topic_id, $user->data['user_id'], $post_time); + $phpbb_notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post', 'approve_post'), $topic_id, $user->data['user_id'], $post_time); if ($config['load_db_lastread'] && $user->data['is_registered']) { diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index fc2c5a47b6..6089ef0014 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2238,6 +2238,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( 'post_username' => $username, 'poster_id' => (int) $user->data['user_id'], + 'post_text' => $data['message'], ))); break; @@ -2252,6 +2253,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $phpbb_notifications->update_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( 'post_username' => $username, + 'post_text' => $data['message'], ))); break; } diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index df99e34576..bd2092e4bb 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -597,39 +597,34 @@ function approve_post($post_id_list, $id, $mode) sync('forum', 'forum_id', array_keys($forum_id_list), true, true); unset($topic_id_list, $forum_id_list); - $phpbb_notifications = $phpbb_container->get('notifications'); - - // Notify Poster? - if ($notify_poster) - { - // Forum Notifications - foreach ($post_info as $post_id => $post_data) - { - if ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) - { - $phpbb_notifications->add_notifications('approve_topic', $post_data); - } - else - { - $phpbb_notifications->add_notifications('approve_post', $post_data); - } - } - } - // Send out normal user notifications $email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']); + // Handle notifications + $phpbb_notifications = $phpbb_container->get('notifications'); foreach ($post_info as $post_id => $post_data) { if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) { // Forum Notifications $phpbb_notifications->add_notifications('topic', $post_data); + + // Notify poster? + if ($notify_poster) + { + $phpbb_notifications->add_notifications('approve_topic', $post_data); + } } else { // Topic Notifications $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), $post_data); + + // Notify poster? + if ($notify_poster) + { + $phpbb_notifications->add_notifications('approve_post', $post_data); + } } } @@ -719,7 +714,7 @@ function disapprove_post($post_id_list, $id, $mode) { global $db, $template, $user, $config; global $phpEx, $phpbb_root_path; - global $request; + global $request, $phpbb_container; if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) { @@ -852,20 +847,16 @@ function disapprove_post($post_id_list, $id, $mode) } } - $messenger = new messenger(); - // Notify Poster? if ($notify_poster) { $lang_reasons = array(); + // Handle notifications + $phpbb_notifications = $phpbb_container->get('notifications'); foreach ($post_info as $post_id => $post_data) { - if ($post_data['poster_id'] == ANONYMOUS) - { - continue; - } - + $post_data['disapprove_reason'] = ''; if (isset($disapprove_reason_lang)) { // Okay we need to get the reason from the posters language @@ -891,33 +882,32 @@ function disapprove_post($post_id_list, $id, $mode) } } - $email_disapprove_reason = $lang_reasons[$post_data['user_lang']]; - $email_disapprove_reason .= ($reason) ? "\n\n" . $reason : ''; + $post_data['disapprove_reason'] = $lang_reasons[$post_data['user_lang']]; + $post_data['disapprove_reason'] .= ($reason) ? "\n\n" . $reason : ''; } - $email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_disapproved' : 'post_disapproved'; - - $messenger->template($email_template, $post_data['user_lang']); - - $messenger->to($post_data['user_email'], $post_data['username']); - $messenger->im($post_data['user_jabber'], $post_data['username']); - - $messenger->assign_vars(array( - 'USERNAME' => htmlspecialchars_decode($post_data['username']), - 'REASON' => htmlspecialchars_decode($email_disapprove_reason), - 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_data['post_subject'])), - 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_data['topic_title']))) - ); - - $messenger->send($post_data['user_notify_type']); + if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) + { + // Notify poster? + if ($notify_poster) + { + $phpbb_notifications->add_notifications('disapprove_topic', $post_data); + } + } + else + { + // Notify poster? + if ($notify_poster) + { + $phpbb_notifications->add_notifications('disapprove_post', $post_data); + } + } } unset($lang_reasons); } unset($post_info, $disapprove_reason, $email_disapprove_reason, $disapprove_reason_lang); - $messenger->save_queue(); - if ($num_disapproved_topics) { $success_msg = ($num_disapproved_topics == 1) ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS'; diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 7fdba5e48a..6e7b160e0f 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -69,7 +69,10 @@ class phpbb_notifications_service // Anonymous users and bots never receive notifications if ($options['user_id'] == $user->data['user_id'] && ($user->data['user_id'] == ANONYMOUS || $user->data['user_type'] == USER_IGNORE)) { - return; + return array( + 'notifications' => array(), + 'unread_count' => 0, + ); } $notifications = $user_ids = array(); @@ -273,8 +276,8 @@ class phpbb_notifications_service $notification_objects = $notification_methods = array(); $new_rows = array(); - // Never send notifications to the anonymous user or the current user! - unset($notify_users[ANONYMOUS], $notify_users[$this->phpbb_container->get('user')->data['user_id']]); + // Never send notifications to the anonymous user! + unset($notify_users[ANONYMOUS]); // Make sure not to send new notifications to users who've already been notified about this item // This may happen when an item was added, but now new users are able to see the item @@ -457,7 +460,7 @@ class phpbb_notifications_service { if (!$safe) { - $item_type = preg_replace('#[^a-z]#', '', $item_type); + $item_type = preg_replace('#[^a-z_]#', '', $item_type); } return 'phpbb_notifications_type_' . $item_type; diff --git a/phpBB/includes/notifications/type/approve_post.php b/phpBB/includes/notifications/type/approve_post.php index 9724916a0e..4a310db389 100644 --- a/phpBB/includes/notifications/type/approve_post.php +++ b/phpBB/includes/notifications/type/approve_post.php @@ -37,7 +37,7 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos * * @var string */ - protected $language_key = 'NOTIFICATION_POST'; + protected $language_key = 'NOTIFICATION_POST_APPROVED'; /** * Get the type of notification this is @@ -109,6 +109,8 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos { $this->set_data('post_subject', $post['post_subject']); + $this->time = time(); + return parent::create_insert_array($post); } } diff --git a/phpBB/includes/notifications/type/approve_topic.php b/phpBB/includes/notifications/type/approve_topic.php new file mode 100644 index 0000000000..426c4e374a --- /dev/null +++ b/phpBB/includes/notifications/type/approve_topic.php @@ -0,0 +1,113 @@ +get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = array(); + + foreach ($auth_read[$post['forum_id']]['f_read'] as $user_id) + { + $notify_users[$user_id] = $users[$user_id]; + } + + return $notify_users; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + return array( + 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), + + 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}", + ); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $this->time = time(); + + return parent::create_insert_array($post); + } +} diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 4958e27919..fb75e19cad 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -114,8 +114,7 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type return array( 'AVATAR' => $this->get_avatar(), - 'FORMATTED_TITLE' => $this->get_formatted_title(), - 'TITLE' => $this->get_title(), + 'FORMATTED_TITLE' => $this->get_title(), 'URL' => $this->get_url(), 'TIME' => $user->format_date($this->time), @@ -201,16 +200,6 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type * -------------- Fall back functions ------------------- */ - /** - * Get the formatted title of this notification (fall-back) - * - * @return string - */ - public function get_formatted_title() - { - return $this->get_title(); - } - /** * URL to unsubscribe to this notification (fall-back) * diff --git a/phpBB/includes/notifications/type/bookmark.php b/phpBB/includes/notifications/type/bookmark.php index 86a99e4ff5..9f2c2e26dc 100644 --- a/phpBB/includes/notifications/type/bookmark.php +++ b/phpBB/includes/notifications/type/bookmark.php @@ -75,6 +75,9 @@ class phpbb_notifications_type_bookmark extends phpbb_notifications_type_post } $db->sql_freeresult($result); + // Never notify the poster + unset($users[$post['poster_id']]); + if (empty($users)) { return array(); diff --git a/phpBB/includes/notifications/type/disapprove_post.php b/phpBB/includes/notifications/type/disapprove_post.php new file mode 100644 index 0000000000..9ef32349b3 --- /dev/null +++ b/phpBB/includes/notifications/type/disapprove_post.php @@ -0,0 +1,105 @@ +phpbb_container->get('user')->lang( + $this->language_key, + censor_text($this->get_data('topic_title')), + $this->get_data('disapprove_reason') + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return ''; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + return array( + 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), + 'REASON' => htmlspecialchars_decode($this->get_data('disapprove_reason')), + ); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $this->set_data('post_subject', $post['post_subject']); + $this->set_data('disapprove_reason', $post['disapprove_reason']); + + $this->time = time(); + + return parent::create_insert_array($post); + } +} diff --git a/phpBB/includes/notifications/type/disapprove_topic.php b/phpBB/includes/notifications/type/disapprove_topic.php new file mode 100644 index 0000000000..eba82d2548 --- /dev/null +++ b/phpBB/includes/notifications/type/disapprove_topic.php @@ -0,0 +1,104 @@ +phpbb_container->get('user')->lang( + $this->language_key, + censor_text($this->get_data('topic_title')), + $this->get_data('disapprove_reason') + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return ''; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + return array( + 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), + + 'REASON' => htmlspecialchars_decode($this->get_data('disapprove_reason')), + ); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $this->set_data('disapprove_reason', $post['disapprove_reason']); + $this->time = time(); + + return parent::create_insert_array($post); + } +} diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index a8c6e4869b..de08576a38 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -29,8 +29,6 @@ interface phpbb_notifications_type_interface public function get_title(); - public function get_formatted_title(); - public function get_email_template_variables(); public function get_url(); diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 816383949b..df7b42564c 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -121,7 +121,7 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base * * @return string */ - public function get_formatted_title() + public function get_title() { $user_data = $this->service->get_user($this->get_data('from_user_id')); @@ -130,18 +130,6 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base return $this->phpbb_container->get('user')->lang('NOTIFICATION_PM', $username, $this->get_data('message_subject')); } - /** - * Get the plain text title of this notification - * - * @return string - */ - public function get_title() - { - $user_data = $this->service->get_user($this->get_data('from_user_id')); - - return $this->phpbb_container->get('user')->lang('NOTIFICATION_PM', $user_data['username'], $this->get_data('message_subject')); - } - /** * Get email template variables * diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 13742ee78b..0ad2c4893f 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -101,6 +101,9 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base } $db->sql_freeresult($result); + // Never notify the poster + unset($users[$post['poster_id']]); + if (empty($users)) { return array(); @@ -136,31 +139,6 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base * * @return string */ - public function get_formatted_title() - { - if ($this->get_data('post_username')) - { - $username = $this->get_data('post_username'); - } - else - { - $user_data = $this->service->get_user($this->get_data('poster_id')); - - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); - } - - return $this->phpbb_container->get('user')->lang( - $this->language_key, - $username, - censor_text($this->get_data('topic_title')) - ); - } - - /** - * Get the title of this notification - * - * @return string - */ public function get_title() { if ($this->get_data('post_username')) @@ -171,7 +149,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base { $user_data = $this->service->get_user($this->get_data('poster_id')); - $username = $user_data['username']; + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } return $this->phpbb_container->get('user')->lang( @@ -238,6 +216,8 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $this->set_data('forum_name', $post['forum_name']); + $this->time = $post['post_time']; + return parent::create_insert_array($post); } } diff --git a/phpBB/includes/notifications/type/quote.php b/phpBB/includes/notifications/type/quote.php index 48d63003dd..647f81041d 100644 --- a/phpBB/includes/notifications/type/quote.php +++ b/phpBB/includes/notifications/type/quote.php @@ -68,7 +68,7 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post $db = $phpbb_container->get('dbal.conn'); $usernames = false; - preg_match_all(self::$regular_expression_match, $post['message'], $usernames); + preg_match_all(self::$regular_expression_match, $post['post_text'], $usernames); if (empty($usernames[1])) { @@ -94,6 +94,9 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post } $db->sql_freeresult($result); + // Never notify the poster + unset($users[$post['poster_id']]); + if (empty($users)) { return array(); diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php index e31c8d792b..cfc629430b 100644 --- a/phpBB/includes/notifications/type/topic.php +++ b/phpBB/includes/notifications/type/topic.php @@ -32,6 +32,13 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base */ public $email_template = 'newtopic_notify'; + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_TOPIC'; + /** * Get the type of notification this is * phpbb_notifications_type_ @@ -94,6 +101,9 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base } $db->sql_freeresult($result); + // Never notify the poster + unset($users[$topic['poster_id']]); + if (empty($users)) { return array(); @@ -129,32 +139,6 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base * * @return string */ - public function get_formatted_title() - { - if ($this->get_data('post_username')) - { - $username = $this->get_data('post_username'); - } - else - { - $user_data = $this->service->get_user($this->get_data('poster_id')); - - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); - } - - return $this->phpbb_container->get('user')->lang( - 'NOTIFICATION_TOPIC', - $username, - censor_text($this->get_data('topic_title')), - $this->get_data('forum_name') - ); - } - - /** - * Get the title of this notification - * - * @return string - */ public function get_title() { if ($this->get_data('post_username')) @@ -165,11 +149,11 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base { $user_data = $this->service->get_user($this->get_data('poster_id')); - $username = $user_data['username']; + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } return $this->phpbb_container->get('user')->lang( - 'NOTIFICATION_TOPIC', + $this->language_key, $username, censor_text($this->get_data('topic_title')), $this->get_data('forum_name') @@ -230,6 +214,8 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base $this->set_data('forum_name', $post['forum_name']); + $this->time = $post['post_time']; + return parent::create_insert_array($post); } } -- cgit v1.2.1 From 7454d5c2d526f237bf24825b80edf6c9f1750fc6 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Sep 2012 14:33:15 -0500 Subject: [ticket/11103] Topic/Post in queue notification Also, bug fixes and cleanup PHPBB3-11103 --- phpBB/includes/functions_posting.php | 31 ++++++- phpBB/includes/mcp/mcp_queue.php | 21 ++++- phpBB/includes/notifications/service.php | 18 +++- phpBB/includes/notifications/type/approve_post.php | 21 +---- .../includes/notifications/type/approve_topic.php | 20 +---- .../notifications/type/disapprove_post.php | 14 ++-- .../notifications/type/disapprove_topic.php | 13 +-- phpBB/includes/notifications/type/post.php | 5 ++ .../includes/notifications/type/post_in_queue.php | 97 ++++++++++++++++++++++ phpBB/includes/notifications/type/quote.php | 2 - phpBB/includes/notifications/type/topic.php | 4 +- .../includes/notifications/type/topic_in_queue.php | 97 ++++++++++++++++++++++ 12 files changed, 288 insertions(+), 55 deletions(-) create mode 100644 phpBB/includes/notifications/type/post_in_queue.php create mode 100644 phpBB/includes/notifications/type/topic_in_queue.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 6089ef0014..4dd840ad53 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2220,10 +2220,9 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } // Send Notifications + $phpbb_notifications = $phpbb_container->get('notifications'); if ($post_approval) { - $phpbb_notifications = $phpbb_container->get('notifications'); - switch ($mode) { case 'post' : @@ -2258,6 +2257,34 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u break; } } + else + { + switch ($mode) + { + case 'post' : + $phpbb_notifications->add_notifications(array('topic_in_queue'), array_merge($data, array( + 'post_username' => $username, + 'poster_id' => (int) $user->data['user_id'], + ))); + break; + + case 'reply' : + case 'quote' : + $phpbb_notifications->add_notifications(array('post_in_queue'), array_merge($data, array( + 'post_username' => $username, + 'poster_id' => (int) $user->data['user_id'], + ))); + break; + + case 'edit_topic' : + case 'edit_first_post' : + case 'edit' : + case 'edit_last_post' : + $phpbb_notifications->delete_notifications('topic', $data['topic_id']); + $phpbb_notifications->delete_notifications(array('quote', 'bookmark', 'post'), $data['post_id']); + break; + } + } $params = $add_anchor = ''; diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index bd2092e4bb..1d2caa38d5 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -606,6 +606,9 @@ 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']) { + // Delete topic in queue notifications + $phpbb_notifications->delete_notifications(array('topic_in_queue'), $post_data['topic_id']); + // Forum Notifications $phpbb_notifications->add_notifications('topic', $post_data); @@ -617,6 +620,9 @@ function approve_post($post_id_list, $id, $mode) } else { + // Delete post in queue notification + $phpbb_notifications->delete_notifications(array('post_in_queue'), $post_id); + // Topic Notifications $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), $post_data); @@ -847,13 +853,26 @@ function disapprove_post($post_id_list, $id, $mode) } } + // Handle notifications (topic/post in queue) + $phpbb_notifications = $phpbb_container->get('notifications'); + foreach ($post_info as $post_id => $post_data) + { + 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']); + } + else + { + $phpbb_notifications->delete_notifications(array('post_in_queue'), $post_id); + } + } + // Notify Poster? if ($notify_poster) { $lang_reasons = array(); // Handle notifications - $phpbb_notifications = $phpbb_container->get('notifications'); foreach ($post_info as $post_id => $post_data) { $post_data['disapprove_reason'] = ''; diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 6e7b160e0f..777fa9a42f 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -262,7 +262,7 @@ class phpbb_notifications_service { foreach ($item_type as $type) { - $this->add_notifications($type, $data); + $this->add_notifications_for_users($type, $data, $notify_users); } return; @@ -353,7 +353,7 @@ class phpbb_notifications_service { foreach ($item_type as $type) { - $this->add_notifications($type, $data); + $this->update_notifications($type, $data); } return; @@ -386,12 +386,22 @@ class phpbb_notifications_service /** * Delete a notification * - * @param string $item_type Type identifier + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $item_id is identical for the specified types) * @param int|array $item_id Identifier within the type (or array of ids) * @param array $data Data specific for this type that will be updated */ public function delete_notifications($item_type, $item_id) { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->delete_notifications($type, $item_id); + } + + return; + } + $this->get_item_type_class_name($item_type); $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " @@ -400,6 +410,7 @@ class phpbb_notifications_service $this->db->sql_query($sql); } +/* public function add_subscription($item_type, $item_id, $method = '') { $this->get_item_type_class_name($item_type); @@ -413,6 +424,7 @@ class phpbb_notifications_service )); $this->db->sql_query($sql); } +*/ /** * Load user helper diff --git a/phpBB/includes/notifications/type/approve_post.php b/phpBB/includes/notifications/type/approve_post.php index 4a310db389..b5e5cfd337 100644 --- a/phpBB/includes/notifications/type/approve_post.php +++ b/phpBB/includes/notifications/type/approve_post.php @@ -82,21 +82,6 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos return $notify_users; } - /** - * Get email template variables - * - * @return array - */ - public function get_email_template_variables() - { - return array( - 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), - - 'U_VIEW_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", - 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", - ); - } - /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) @@ -109,8 +94,10 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos { $this->set_data('post_subject', $post['post_subject']); - $this->time = time(); + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); - return parent::create_insert_array($post); + return $data; } } diff --git a/phpBB/includes/notifications/type/approve_topic.php b/phpBB/includes/notifications/type/approve_topic.php index 426c4e374a..3ba871599e 100644 --- a/phpBB/includes/notifications/type/approve_topic.php +++ b/phpBB/includes/notifications/type/approve_topic.php @@ -82,20 +82,6 @@ class phpbb_notifications_type_approve_topic extends phpbb_notifications_type_to return $notify_users; } - /** - * Get email template variables - * - * @return array - */ - public function get_email_template_variables() - { - return array( - 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), - - 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}", - ); - } - /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) @@ -106,8 +92,10 @@ class phpbb_notifications_type_approve_topic extends phpbb_notifications_type_to */ public function create_insert_array($post) { - $this->time = time(); + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); - return parent::create_insert_array($post); + return $data; } } diff --git a/phpBB/includes/notifications/type/disapprove_post.php b/phpBB/includes/notifications/type/disapprove_post.php index 9ef32349b3..e0b7bfb178 100644 --- a/phpBB/includes/notifications/type/disapprove_post.php +++ b/phpBB/includes/notifications/type/disapprove_post.php @@ -79,10 +79,9 @@ class phpbb_notifications_type_disapprove_post extends phpbb_notifications_type_ */ public function get_email_template_variables() { - return array( - 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), - 'REASON' => htmlspecialchars_decode($this->get_data('disapprove_reason')), - ); + return array_merge(parent::get_email_template_variables(), array( + 'REASON' => htmlspecialchars_decode($this->get_data('disapprove_reason')), + )); } /** @@ -95,11 +94,12 @@ class phpbb_notifications_type_disapprove_post extends phpbb_notifications_type_ */ public function create_insert_array($post) { - $this->set_data('post_subject', $post['post_subject']); $this->set_data('disapprove_reason', $post['disapprove_reason']); - $this->time = time(); + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); - return parent::create_insert_array($post); + return $data; } } diff --git a/phpBB/includes/notifications/type/disapprove_topic.php b/phpBB/includes/notifications/type/disapprove_topic.php index eba82d2548..7ad4c4edb8 100644 --- a/phpBB/includes/notifications/type/disapprove_topic.php +++ b/phpBB/includes/notifications/type/disapprove_topic.php @@ -79,11 +79,9 @@ class phpbb_notifications_type_disapprove_topic extends phpbb_notifications_type */ public function get_email_template_variables() { - return array( - 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), - + return array_merge(parent::get_email_template_variables(), array( 'REASON' => htmlspecialchars_decode($this->get_data('disapprove_reason')), - ); + )); } /** @@ -97,8 +95,11 @@ class phpbb_notifications_type_disapprove_topic extends phpbb_notifications_type public function create_insert_array($post) { $this->set_data('disapprove_reason', $post['disapprove_reason']); - $this->time = time(); - return parent::create_insert_array($post); + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); + + return $data; } } diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 0ad2c4893f..8e801a2595 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -167,10 +167,13 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base public function get_email_template_variables() { return array( + 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), + 'U_VIEW_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", 'U_NEWEST_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&view=unread#unread", 'U_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", 'U_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}", 'U_STOP_WATCHING_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?uid={$this->user_id}&f={$this->get_data('forum_id')}&t={$this->item_parent_id}&unwatch=topic", ); @@ -210,6 +213,8 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $this->set_data('topic_title', $post['topic_title']); + $this->set_data('post_subject', $post['post_subject']); + $this->set_data('post_username', (($post['post_username'] != $this->phpbb_container->get('user')->data['username']) ? $post['post_username'] : '')); $this->set_data('forum_id', $post['forum_id']); diff --git a/phpBB/includes/notifications/type/post_in_queue.php b/phpBB/includes/notifications/type/post_in_queue.php new file mode 100644 index 0000000000..cd3a452856 --- /dev/null +++ b/phpBB/includes/notifications/type/post_in_queue.php @@ -0,0 +1,97 @@ +get('auth')->acl_get_list(false, 'm_approve', $post['forum_id']); + + if (empty($auth_approve)) + { + return array(); + } + + $notify_users = array(); + + foreach ($auth_approve[$post['forum_id']]['m_approve'] as $user_id) + { + $notify_users[$user_id] = array(''); + } + + return $notify_users; + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); + + return $data; + } +} diff --git a/phpBB/includes/notifications/type/quote.php b/phpBB/includes/notifications/type/quote.php index 647f81041d..d116a40e4d 100644 --- a/phpBB/includes/notifications/type/quote.php +++ b/phpBB/includes/notifications/type/quote.php @@ -183,8 +183,6 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post return array_merge(parent::get_email_template_variables(), array( 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), - - 'U_QUOTED_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", )); } } diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php index cfc629430b..cf56451214 100644 --- a/phpBB/includes/notifications/type/topic.php +++ b/phpBB/includes/notifications/type/topic.php @@ -72,7 +72,7 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base * Find the users who want to receive notifications * * @param ContainerBuilder $phpbb_container - * @param array $post Data from + * @param array $topic Data from the topic * * @return array */ @@ -171,6 +171,8 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base 'FORUM_NAME' => htmlspecialchars_decode($this->get_data('forum_name')), 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), + 'U_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}", + 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}", 'U_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->item_parent_id}", 'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?uid={$this->user_id}&f={$this->item_parent_id}&unwatch=forum", ); diff --git a/phpBB/includes/notifications/type/topic_in_queue.php b/phpBB/includes/notifications/type/topic_in_queue.php new file mode 100644 index 0000000000..583ab5d8b3 --- /dev/null +++ b/phpBB/includes/notifications/type/topic_in_queue.php @@ -0,0 +1,97 @@ +get('auth')->acl_get_list(false, 'm_approve', $topic['forum_id']); + + if (empty($auth_approve)) + { + return array(); + } + + $notify_users = array(); + + foreach ($auth_approve[$topic['forum_id']]['m_approve'] as $user_id) + { + $notify_users[$user_id] = array(''); + } + + return $notify_users; + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $topic Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($topic) + { + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); + + return $data; + } +} -- cgit v1.2.1 From b081729f25dab258ac4259907ba1af1a16ee8138 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Sep 2012 14:47:58 -0500 Subject: [ticket/11103] Revert the changes to functions_display.php The css we need to apply to avatars can be applied through css rules. We don't need to be able to specify a class for the img. PHPBB3-11103 --- phpBB/includes/functions_display.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 84cb47867e..8328b9ee7a 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1319,11 +1319,10 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank * @param string $avatar_height Height of users avatar * @param string $alt Optional language string for alt tag within image, can be a language key or text * @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP -* @param string $custom_css Custom CSS class to apply to the image * * @return string Avatar image */ -function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false, $custom_css = '') +function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false) { global $user, $config, $phpbb_root_path, $phpEx; global $phpbb_dispatcher; @@ -1344,7 +1343,7 @@ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $ * @var string overwrite_avatar If set, this string will be the avatar * @since 3.1-A1 */ - $vars = array('avatar', 'avatar_type', 'avatar_width', 'avatar_height', 'alt', 'ignore_config', 'overwrite_avatar', 'custom_css'); + $vars = array('avatar', 'avatar_type', 'avatar_width', 'avatar_height', 'alt', 'ignore_config', 'overwrite_avatar'); extract($phpbb_dispatcher->trigger_event('core.user_get_avatar', compact($vars))); if ($overwrite_avatar) @@ -1386,7 +1385,7 @@ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $ } $avatar_img .= $avatar; - return '' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . ''; + return '' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . ''; } /** -- cgit v1.2.1 From a4ec7e2aea8a47fff9d7effa76a3d07a2dd6a305 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Sep 2012 14:50:05 -0500 Subject: [ticket/11103] Delete some notifications when deleting posts/topics PHPBB3-11103 --- phpBB/includes/functions_admin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 1cbd44e97e..55e539cb37 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -718,7 +718,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s // Delete notifications $phpbb_notifications = $phpbb_container->get('notifications'); - $phpbb_notifications->delete_notifications('topic', $topic_ids); + $phpbb_notifications->delete_notifications(array('topic', 'approve_topic', 'topic_in_queue')), $topic_ids); return $return; } @@ -900,7 +900,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = // Delete notifications $phpbb_notifications = $phpbb_container->get('notifications'); - $phpbb_notifications->delete_notifications('post', $post_ids); + $phpbb_notifications->delete_notifications(array('quote', 'bookmark', 'post', 'approve_post', 'post_in_queue'), $post_ids); return sizeof($post_ids); } -- cgit v1.2.1 From 661dd09d6f44b46e5a30b37bb3425058f055ea01 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 16 Sep 2012 23:03:00 -0500 Subject: [ticket/11103] Bug fix PHPBB3-11103 --- phpBB/includes/functions_admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 55e539cb37..27128aafac 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -718,7 +718,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s // Delete notifications $phpbb_notifications = $phpbb_container->get('notifications'); - $phpbb_notifications->delete_notifications(array('topic', 'approve_topic', 'topic_in_queue')), $topic_ids); + $phpbb_notifications->delete_notifications(array('topic', 'approve_topic', 'topic_in_queue'), $topic_ids); return $return; } -- cgit v1.2.1 From 98731b127748af4673fdee92db2e139e84fd4d4b Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 20 Sep 2012 10:36:11 -0500 Subject: [ticket/11103] Prettify the output for prosilver. Create a way to mark items read from the output list. PHPBB3-11103 --- phpBB/includes/functions.php | 5 +- phpBB/includes/notifications/service.php | 73 +++++++++++++++++++++--------- phpBB/includes/notifications/type/base.php | 2 + 3 files changed, 57 insertions(+), 23 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index e9d673455c..92cea20d10 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4997,7 +4997,10 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 // Output the notifications $phpbb_notifications = $phpbb_container->get('notifications'); - $notifications = $phpbb_notifications->load_notifications(); + $notifications = $phpbb_notifications->load_notifications(array( + 'all_unread' => true, + 'limit' => 5, + )); foreach ($notifications['notifications'] as $notification) { $template->assign_block_vars('notifications', $notification->prepare_for_display()); diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 777fa9a42f..b1ee420c2e 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -45,12 +45,14 @@ class phpbb_notifications_service * Load the user's notifications * * @param array $options Optional options to control what notifications are loaded - * user_id User id to load notifications for (Default: $user->data['user_id']) - * order_by Order by (Default: time) - * order_dir Order direction (Default: DESC) - * limit Number of notifications to load (Default: 5) - * start Notifications offset (Default: 0) - * all_unread Load all unread messages? (Default: true) + * notification_id Notification id to load (or array of notification ids) + * user_id User id to load notifications for (Default: $user->data['user_id']) + * order_by Order by (Default: time) + * order_dir Order direction (Default: DESC) + * limit Number of notifications to load (Default: 5) + * start Notifications offset (Default: 0) + * all_unread Load all unread messages? If set to true, count_unread is set to true (Default: false) + * count_unread Count all unread messages? (Default: false) */ public function load_notifications($options = array()) { @@ -58,14 +60,19 @@ class phpbb_notifications_service // Merge default options $options = array_merge(array( - 'user_id' => $user->data['user_id'], - 'order_by' => 'time', - 'order_dir' => 'DESC', - 'limit' => 5, - 'start' => 0, - 'all_unread' => true, + 'notification_id' => false, + 'user_id' => $user->data['user_id'], + 'order_by' => 'time', + 'order_dir' => 'DESC', + 'limit' => 0, + 'start' => 0, + 'all_unread' => false, + 'count_unread' => false, ), $options); + // If all_unread, count_unread mus be true + $options['count_unread'] = ($options['all_unread']) ? true : $options['count_unread']; + // Anonymous users and bots never receive notifications if ($options['user_id'] == $user->data['user_id'] && ($user->data['user_id'] == ANONYMOUS || $user->data['user_type'] == USER_IGNORE)) { @@ -77,22 +84,27 @@ class phpbb_notifications_service $notifications = $user_ids = array(); $load_special = array(); + $count = 0; - // Get the total number of unread notifications - $sql = 'SELECT COUNT(*) AS count - FROM ' . NOTIFICATIONS_TABLE . ' - WHERE user_id = ' . (int) $options['user_id'] . ' - AND unread = 1'; - $result = $this->db->sql_query($sql); - $count = $this->db->sql_fetchfield('count', $result); - $this->db->sql_freeresult($result); + if ($options['count_unread']) + { + // Get the total number of unread notifications + $sql = 'SELECT COUNT(*) AS count + FROM ' . NOTIFICATIONS_TABLE . ' + WHERE user_id = ' . (int) $options['user_id'] . ' + AND unread = 1'; + $result = $this->db->sql_query($sql); + $count = (int) $this->db->sql_fetchfield('count', $result); + $this->db->sql_freeresult($result); + } $rowset = array(); // Get the main notifications $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . ' - WHERE user_id = ' . (int) $options['user_id'] . ' + 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']) : '') . ' 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']); @@ -103,7 +115,7 @@ class phpbb_notifications_service $this->db->sql_freeresult($result); // Get all unread notifications - if ($options['all_unread'] && !empty($rowset)) + if ($count && $options['all_unread'] && !empty($rowset)) { $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . ' @@ -221,6 +233,23 @@ class phpbb_notifications_service $this->db->sql_query($sql); } + /** + * Mark notifications read + * + * @param int|array $notification_id Notification id or array of notification ids. + * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False) + */ + public function mark_notifications_read_by_id($notification_id, $time = false) + { + $time = ($time) ?: time(); + + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + SET unread = 0 + WHERE time <= " . $time . ' + AND ' . ((is_array($notification_id)) ? $this->db->sql_in_set('notification_id', $notification_id) : 'notification_id = ' . (int) $notification_id); + $this->db->sql_query($sql); + } + /** * Add a notification * diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index fb75e19cad..710f1f7c6e 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -120,6 +120,8 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type 'TIME' => $user->format_date($this->time), 'UNREAD' => $this->unread, + + 'U_MARK_READ' => append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification[]=' . $this->notification_id), ); } -- cgit v1.2.1 From 3897a442f7fe0107cf71adc02af999b496bfebaf Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 20 Sep 2012 10:40:18 -0500 Subject: [ticket/11103] Bug fixing PHPBB3-11103 --- phpBB/includes/functions_posting.php | 4 ++++ phpBB/includes/notifications/type/post.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 4dd840ad53..4ae5989fed 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2229,6 +2229,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $phpbb_notifications->add_notifications(array('topic', 'quote'), array_merge($data, array( 'post_username' => $username, 'poster_id' => (int) $user->data['user_id'], + 'post_time' => $current_time, ))); break; @@ -2238,6 +2239,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'post_username' => $username, 'poster_id' => (int) $user->data['user_id'], 'post_text' => $data['message'], + 'post_time' => $current_time, ))); break; @@ -2265,6 +2267,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $phpbb_notifications->add_notifications(array('topic_in_queue'), array_merge($data, array( 'post_username' => $username, 'poster_id' => (int) $user->data['user_id'], + 'post_time' => $current_time, ))); break; @@ -2273,6 +2276,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u $phpbb_notifications->add_notifications(array('post_in_queue'), array_merge($data, array( 'post_username' => $username, 'poster_id' => (int) $user->data['user_id'], + 'post_time' => $current_time, ))); break; diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 8e801a2595..17a7a6863a 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -215,7 +215,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $this->set_data('post_subject', $post['post_subject']); - $this->set_data('post_username', (($post['post_username'] != $this->phpbb_container->get('user')->data['username']) ? $post['post_username'] : '')); + $this->set_data('post_username', (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : '')); $this->set_data('forum_id', $post['forum_id']); -- cgit v1.2.1 From aa3f6f4002094d29952d0383107af687bf7dcb15 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 25 Sep 2012 10:10:10 -0500 Subject: [ticket/11103] Fixing some bugs with the post/topic notifications PHPBB3-11103 --- phpBB/includes/functions_posting.php | 43 +++++++++-------------------- phpBB/includes/notifications/type/quote.php | 8 +++++- phpBB/includes/notifications/type/topic.php | 2 +- 3 files changed, 21 insertions(+), 32 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 4ae5989fed..41bdd9f598 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2221,41 +2221,32 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Send Notifications $phpbb_notifications = $phpbb_container->get('notifications'); + $notification_data = array_merge($data, array( + 'topic_title' => (isset($data['topic_title'])) ? $data['topic_title'] : $subject, + 'post_username' => $username, + 'poster_id' => $poster_id, + 'post_text' => $data['message'], + 'post_time' => $current_time, + 'post_subject' => $subject, + )); if ($post_approval) { switch ($mode) { case 'post' : - $phpbb_notifications->add_notifications(array('topic', 'quote'), array_merge($data, array( - 'post_username' => $username, - 'poster_id' => (int) $user->data['user_id'], - 'post_time' => $current_time, - ))); + $phpbb_notifications->add_notifications(array('topic', 'quote'), $notification_data); break; case 'reply' : case 'quote' : - $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( - 'post_username' => $username, - 'poster_id' => (int) $user->data['user_id'], - 'post_text' => $data['message'], - 'post_time' => $current_time, - ))); + $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), $notification_data); break; case 'edit_topic' : case 'edit_first_post' : case 'edit' : case 'edit_last_post' : - $phpbb_notifications->update_notifications('topic', array_merge($data, array( - 'post_username' => $username, - 'topic_title' => $subject, - ))); - - $phpbb_notifications->update_notifications(array('quote', 'bookmark', 'post'), array_merge($data, array( - 'post_username' => $username, - 'post_text' => $data['message'], - ))); + $phpbb_notifications->update_notifications(array('quote', 'bookmark', 'topic', 'post'), $notification_data); break; } } @@ -2264,20 +2255,12 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u switch ($mode) { case 'post' : - $phpbb_notifications->add_notifications(array('topic_in_queue'), array_merge($data, array( - 'post_username' => $username, - 'poster_id' => (int) $user->data['user_id'], - 'post_time' => $current_time, - ))); + $phpbb_notifications->add_notifications(array('topic_in_queue'), $notification_data); break; case 'reply' : case 'quote' : - $phpbb_notifications->add_notifications(array('post_in_queue'), array_merge($data, array( - 'post_username' => $username, - 'poster_id' => (int) $user->data['user_id'], - 'post_time' => $current_time, - ))); + $phpbb_notifications->add_notifications(array('post_in_queue'), $notification_data); break; case 'edit_topic' : diff --git a/phpBB/includes/notifications/type/quote.php b/phpBB/includes/notifications/type/quote.php index d116a40e4d..2079617510 100644 --- a/phpBB/includes/notifications/type/quote.php +++ b/phpBB/includes/notifications/type/quote.php @@ -37,7 +37,7 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post * * @var string */ - protected static $regular_expression_match = '#\[quote="(.+?)":#'; + protected static $regular_expression_match = '#\[quote="(.+?)"#'; /** * Language key used to output the text @@ -155,6 +155,12 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post $add_notifications[$user_id] = $notifications[$user_id]; } + // todo Adding notifications while editing a post can be funky. + // If the user has read the topic/post already, and the user is newly quoted it an edit, + // The notification will be stuck as unread until another post is made and the user visits + // the topic again because the posts will not be marked as read since the topic is already + // marked as read + // Add the necessary notifications $service->add_notifications_for_users(self::get_item_type(), $post, $add_notifications); diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php index cf56451214..733b2108cc 100644 --- a/phpBB/includes/notifications/type/topic.php +++ b/phpBB/includes/notifications/type/topic.php @@ -212,7 +212,7 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base $this->set_data('topic_title', $post['topic_title']); - $this->set_data('post_username', (($post['post_username'] != $this->phpbb_container->get('user')->data['username']) ? $post['post_username'] : '')); + $this->set_data('post_username', (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : '')); $this->set_data('forum_name', $post['forum_name']); -- cgit v1.2.1 From 3242ce0d3aa395b2c603e9172dfb17bcc5f081de Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 25 Sep 2012 10:35:50 -0500 Subject: [ticket/11103] Add/delete subscription functions for the service PHPBB3-11103 --- phpBB/includes/notifications/service.php | 38 ++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index b1ee420c2e..feeafe09a5 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -439,21 +439,51 @@ class phpbb_notifications_service $this->db->sql_query($sql); } -/* - public function add_subscription($item_type, $item_id, $method = '') + /** + * Add a subscription + * + * @param string $item_type Type identifier of the subscription + * @param int $item_id The id of the item + * @param string $method The method of the notification e.g. '', 'email', or 'jabber' + * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) + */ + public function add_subscription($item_type, $item_id, $method = '', $user_id = false) { $this->get_item_type_class_name($item_type); + $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; + $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( 'item_type' => $item_type, 'item_id' => (int) $item_id, - 'user_id' => $this->phpbb_container->get('user')->data['user_id'], + 'user_id' => (int) $user_id, 'method' => $method, )); $this->db->sql_query($sql); } -*/ + + /** + * Delete a subscription + * + * @param string $item_type Type identifier of the subscription + * @param int $item_id The id of the item + * @param string $method The method of the notification e.g. '', 'email', or 'jabber' + * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) + */ + public function delete_subscription($item_type, $item_id, $method = '', $user_id = false) + { + $this->get_item_type_class_name($item_type); + + $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; + + $sql = 'DELETE FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id . ' + AND user_id = ' .(int) $user_id . " + AND method = '" . $this->db->sql_escape($method) . "'"; + $this->db->sql_query($sql); + } /** * Load user helper -- cgit v1.2.1 From 28c8c0ce463290b1b4085daafccc24f4297c0d23 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 26 Sep 2012 21:48:59 -0500 Subject: [ticket/11103] Get subscription types/methods functions in the service PHPBB3-11103 --- phpBB/includes/notifications/service.php | 69 ++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index feeafe09a5..a174193491 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -439,6 +439,43 @@ class phpbb_notifications_service $this->db->sql_query($sql); } + /** + * Get all of the subscription types + * + * @return array Array of item types + */ + public function get_subscription_types() + { + $subscription_types = array(); + + foreach ($this->get_subscription_files('notifications/type/') as $class => $file) + { + $class = $this->get_item_type_class_name($class); + + if (!class_exists($class)) + { + include($file); + } + + if (method_exists($class, 'get_item_type')) + { + $subscription_types[] = $class::get_item_type(); + } + } + + return $subscription_types; + } + + /** + * Get all of the subscription methods + * + * @return array Array of methods + */ + public function get_subscription_methods() + { + return array_keys($this->get_subscription_files('notifications/method/')); + } + /** * Add a subscription * @@ -536,4 +573,36 @@ class phpbb_notifications_service return 'phpbb_notifications_type_' . $item_type; } + + /** + * Helper to get subscription related files with the finder + */ + private function get_subscription_files($path) + { + $ext_manager = $this->phpbb_container->get('ext.manager'); + $php_ext = $this->phpbb_container->getParameter('core.php_ext'); + + $finder = $ext_manager->get_finder(); + + $subscription_files = array(); + + $files = $finder + ->core_path('includes/' . $path) + ->extension_directory($path) + ->get_files(); + foreach ($files as $file) + { + $class = substr($file, strrpos($file, '/')); + $class = substr($class, 1, (strpos($class, '.' . $php_ext) - 1)); + + if ($class == 'interface' || $class == 'base') + { + continue; + } + + $subscription_files[$class] = $file; + } + + return $subscription_files; + } } -- cgit v1.2.1 From b052741fcb0b3cab4317a759ec935518bef7c73b Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 26 Sep 2012 21:50:21 -0500 Subject: [ticket/11103] UCP base files for notification options PHPBB3-11103 --- phpBB/includes/ucp/info/ucp_notifications.php | 34 +++++++++++++++++++++++++++ phpBB/includes/ucp/ucp_notifications.php | 26 ++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 phpBB/includes/ucp/info/ucp_notifications.php create mode 100644 phpBB/includes/ucp/ucp_notifications.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/info/ucp_notifications.php b/phpBB/includes/ucp/info/ucp_notifications.php new file mode 100644 index 0000000000..f1e6bf65b8 --- /dev/null +++ b/phpBB/includes/ucp/info/ucp_notifications.php @@ -0,0 +1,34 @@ + 'ucp_notifications', + 'title' => 'UCP_NOTIFICATIONS', + 'version' => '1.0.0', + 'modes' => array( + 'notification_options' => array('title' => 'UCP_NOTIFICATION_OPTIONS', 'auth' => '', 'cat' => array('UCP_MAIN')), + ), + ); + } + + function install() + { + } + + function uninstall() + { + } +} diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php new file mode 100644 index 0000000000..92a899af7d --- /dev/null +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -0,0 +1,26 @@ + Date: Wed, 26 Sep 2012 22:39:12 -0500 Subject: [ticket/11103] More work on the UCP Notifications page PHPBB3-11103 --- phpBB/includes/notifications/service.php | 21 ++++++- phpBB/includes/ucp/ucp_notifications.php | 95 +++++++++++++++++++++++++++++++- 2 files changed, 113 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index a174193491..3160864f37 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -473,7 +473,26 @@ class phpbb_notifications_service */ public function get_subscription_methods() { - return array_keys($this->get_subscription_files('notifications/method/')); + $subscription_methods = array(); + + foreach ($this->get_subscription_files('notifications/method/') as $method_name => $file) + { + $class_name = 'phpbb_notifications_method_' . $method_name; + + if (!class_exists($class_name)) + { + include($file); + } + + $method = new $class_name($this->phpbb_container); + + if ($method->is_available()) + { + $subscription_methods[] = $method_name; + } + } + + return $subscription_methods; } /** diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index 92a899af7d..0a01cd1cde 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -17,10 +17,101 @@ if (!defined('IN_PHPBB')) class ucp_notifications { - var $u_action; + public $u_action; - function main($id, $mode) + public function main($id, $mode) { + global $phpbb_container; + $phpbb_notifications = $phpbb_container->get('notifications'); + $template = $phpbb_container->get('template'); + $user = $phpbb_container->get('user'); + $request = $phpbb_container->get('request'); + + if ($request->is_set_post('submit')) + { + $notification_methods = $phpbb_notifications->get_subscription_methods(); + foreach($phpbb_notifications->get_subscription_types() as $type) + { + if ($request->is_set_post($type . '_notification')) + { + // add + } + else + { + // remove + } + + foreach($notification_methods as $method) + { + if ($request->is_set_post($type . '_' . $method)) + { + // add + } + else + { + // remove + } + } + } + } + + // todo include language files for extensions? + + $this->output_notification_methods('notification_methods', $phpbb_notifications, $template, $user); + + $this->output_notification_types('notification_types', $phpbb_notifications, $template, $user); + + $this->tpl_name = 'ucp_notifications'; + $this->page_title = 'UCP_NOTIFICATIONS'; + } + + /** + * Output all the notification types to the template + * + * @param string $block + * @param phpbb_notifications_service $phpbb_notifications + * @param phpbb_template $template + * @param phpbb_user $user + */ + public function output_notification_types($block = 'notification_types', phpbb_notifications_service $phpbb_notifications, phpbb_template $template, phpbb_user $user) + { + foreach($phpbb_notifications->get_subscription_types() as $type) + { + $template->assign_block_vars($block, array( + 'TYPE' => $type, + + 'NAME' => $user->lang('NOTIFICATION_TYPE_' . strtoupper($type)), + )); + + $this->output_notification_methods($block . '.notification_methods', $phpbb_notifications, $template, $user); + } + } + + /** + * Output all the notification methods to the template + * + * @param string $block + * @param phpbb_notifications_service $phpbb_notifications + * @param phpbb_template $template + * @param phpbb_user $user + */ + public function output_notification_methods($block = 'notification_methods', phpbb_notifications_service $phpbb_notifications, phpbb_template $template, phpbb_user $user) + { + static $notification_methods = false; + + if ($notification_methods === false) + { + $notification_methods = $phpbb_notifications->get_subscription_methods(); + } + + foreach($notification_methods as $method) + { + $template->assign_block_vars($block, array( + 'METHOD' => $method, + + 'NAME' => $user->lang('NOTIFICATION_METHOD_' . strtoupper($method)), + )); + } } } -- cgit v1.2.1 From ae91a0a846828b44a53c2a7cd724e0ba062b0f3e Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 27 Sep 2012 10:37:37 -0500 Subject: [ticket/11103] Allow grouping of multiple types in ucp notification options Ability to hide notification types from UCP Notification options (if users do not have permission to use the notification type, or for whatever reason they should not see it) PHPBB3-11103 --- phpBB/includes/notifications/service.php | 15 ++++++-- phpBB/includes/notifications/type/approve_post.php | 11 ++++++ .../includes/notifications/type/approve_topic.php | 11 ++++++ phpBB/includes/notifications/type/base.php | 16 ++++++++ .../notifications/type/disapprove_post.php | 11 ++++++ .../notifications/type/disapprove_topic.php | 11 ++++++ phpBB/includes/notifications/type/interface.php | 2 + .../includes/notifications/type/post_in_queue.php | 41 ++++++++++++++++++--- .../includes/notifications/type/topic_in_queue.php | 43 +++++++++++++++++++--- phpBB/includes/ucp/info/ucp_notifications.php | 2 +- phpBB/includes/ucp/ucp_notifications.php | 4 +- 11 files changed, 150 insertions(+), 17 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 3160864f37..174b73f9a5 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -457,9 +457,16 @@ class phpbb_notifications_service include($file); } - if (method_exists($class, 'get_item_type')) + if ($class::is_available($this->phpbb_container) && method_exists($class, 'get_item_type')) { - $subscription_types[] = $class::get_item_type(); + if ($class::$notification_option === false) + { + $subscription_types[$class::get_item_type()] = $class::get_item_type(); + } + else + { + $subscription_types[$class::$notification_option['id']] = $class::$notification_option; + } } } @@ -548,6 +555,8 @@ class phpbb_notifications_service */ public function load_users($user_ids) { + $user_ids[] = ANONYMOUS; + // Load the users $user_ids = array_unique($user_ids); @@ -577,7 +586,7 @@ class phpbb_notifications_service */ public function get_user($user_id) { - return $this->users[$user_id]; + return (isset($this->users[$user_id])) ? $this->users[$user_id] : $this->users[ANONYMOUS]; } /** diff --git a/phpBB/includes/notifications/type/approve_post.php b/phpBB/includes/notifications/type/approve_post.php index b5e5cfd337..a3a52b8780 100644 --- a/phpBB/includes/notifications/type/approve_post.php +++ b/phpBB/includes/notifications/type/approve_post.php @@ -39,6 +39,17 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos */ protected $language_key = 'NOTIFICATION_POST_APPROVED'; + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id' and 'lang') + */ + public static $notification_option = array( + 'id' => 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + ); + /** * Get the type of notification this is * phpbb_notifications_type_ diff --git a/phpBB/includes/notifications/type/approve_topic.php b/phpBB/includes/notifications/type/approve_topic.php index 3ba871599e..ba7227c671 100644 --- a/phpBB/includes/notifications/type/approve_topic.php +++ b/phpBB/includes/notifications/type/approve_topic.php @@ -39,6 +39,17 @@ class phpbb_notifications_type_approve_topic extends phpbb_notifications_type_to */ protected $language_key = 'NOTIFICATION_TOPIC_APPROVED'; + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id' and 'lang') + */ + public static $notification_option = array( + 'id' => 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + ); + /** * Get the type of notification this is * phpbb_notifications_type_ diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 710f1f7c6e..0da4dc8d93 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -36,6 +36,14 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type */ protected $users = array(); + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id' and 'lang') + */ + public static $notification_option = false; + /** * Indentification data * item_type @@ -236,6 +244,14 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type return; } + /** + * Is available (fall-back) + */ + public static function is_available(ContainerBuilder $phpbb_container) + { + return true; + } + /** * -------------- Helper functions ------------------- */ diff --git a/phpBB/includes/notifications/type/disapprove_post.php b/phpBB/includes/notifications/type/disapprove_post.php index e0b7bfb178..6911af5b08 100644 --- a/phpBB/includes/notifications/type/disapprove_post.php +++ b/phpBB/includes/notifications/type/disapprove_post.php @@ -39,6 +39,17 @@ class phpbb_notifications_type_disapprove_post extends phpbb_notifications_type_ */ protected $language_key = 'NOTIFICATION_POST_DISAPPROVED'; + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id' and 'lang') + */ + public static $notification_option = array( + 'id' => 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + ); + /** * Get the type of notification this is * phpbb_notifications_type_ diff --git a/phpBB/includes/notifications/type/disapprove_topic.php b/phpBB/includes/notifications/type/disapprove_topic.php index 7ad4c4edb8..dab5ec1b02 100644 --- a/phpBB/includes/notifications/type/disapprove_topic.php +++ b/phpBB/includes/notifications/type/disapprove_topic.php @@ -39,6 +39,17 @@ class phpbb_notifications_type_disapprove_topic extends phpbb_notifications_type */ protected $language_key = 'NOTIFICATION_TOPIC_DISAPPROVED'; + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id' and 'lang') + */ + public static $notification_option = array( + 'id' => 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + ); + /** * Get the type of notification this is * phpbb_notifications_type_ diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index de08576a38..c85d7441f6 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -25,6 +25,8 @@ interface phpbb_notifications_type_interface public static function get_item_id($type_data); + public static function is_available(ContainerBuilder $phpbb_container); + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $type_data); public function get_title(); diff --git a/phpBB/includes/notifications/type/post_in_queue.php b/phpBB/includes/notifications/type/post_in_queue.php index cd3a452856..0043a38944 100644 --- a/phpBB/includes/notifications/type/post_in_queue.php +++ b/phpBB/includes/notifications/type/post_in_queue.php @@ -39,6 +39,17 @@ class phpbb_notifications_type_post_in_queue extends phpbb_notifications_type_po */ protected $language_key = 'NOTIFICATION_POST_IN_QUEUE'; + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id' and 'lang') + */ + public static $notification_option = array( + 'id' => 'needs_approval', + 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', + ); + /** * Get the type of notification this is * phpbb_notifications_type_ @@ -48,6 +59,16 @@ class phpbb_notifications_type_post_in_queue extends phpbb_notifications_type_po return 'post_in_queue'; } + /** + * Is available + */ + public static function is_available(ContainerBuilder $phpbb_container) + { + $m_approve = $phpbb_container->get('auth')->acl_getf('m_approve', true); + + return (!empty($m_approve)); + } + /** * Find the users who want to receive notifications * @@ -58,9 +79,8 @@ class phpbb_notifications_type_post_in_queue extends phpbb_notifications_type_po */ public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post) { - /* todo - * find what type of notification they'd like to receive - */ + $db = $phpbb_container->get('dbal.conn'); + $auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $post['forum_id']); if (empty($auth_approve)) @@ -70,10 +90,21 @@ class phpbb_notifications_type_post_in_queue extends phpbb_notifications_type_po $notify_users = array(); - foreach ($auth_approve[$post['forum_id']]['m_approve'] as $user_id) + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = 'needs_approval' + AND " . $db->sql_in_set('user_id', $auth_approve[$topic['forum_id']]['m_approve']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) { - $notify_users[$user_id] = array(''); + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; } + $db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/notifications/type/topic_in_queue.php b/phpBB/includes/notifications/type/topic_in_queue.php index 583ab5d8b3..dda647d18e 100644 --- a/phpBB/includes/notifications/type/topic_in_queue.php +++ b/phpBB/includes/notifications/type/topic_in_queue.php @@ -39,6 +39,27 @@ class phpbb_notifications_type_topic_in_queue extends phpbb_notifications_type_t */ protected $language_key = 'NOTIFICATION_TOPIC_IN_QUEUE'; + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id' and 'lang') + */ + public static $notification_option = array( + 'id' => 'needs_approval', + 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', + ); + + /** + * Is available + */ + public static function is_available(ContainerBuilder $phpbb_container) + { + $m_approve = $phpbb_container->get('auth')->acl_getf('m_approve', true); + + return (!empty($m_approve)); + } + /** * Get the type of notification this is * phpbb_notifications_type_ @@ -58,9 +79,8 @@ class phpbb_notifications_type_topic_in_queue extends phpbb_notifications_type_t */ public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic) { - /* todo - * find what type of notification they'd like to receive - */ + $db = $phpbb_container->get('dbal.conn'); + $auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $topic['forum_id']); if (empty($auth_approve)) @@ -70,10 +90,21 @@ class phpbb_notifications_type_topic_in_queue extends phpbb_notifications_type_t $notify_users = array(); - foreach ($auth_approve[$topic['forum_id']]['m_approve'] as $user_id) + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = 'needs_approval' + AND " . $db->sql_in_set('user_id', $auth_approve[$topic['forum_id']]['m_approve']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) { - $notify_users[$user_id] = array(''); + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; } + $db->sql_freeresult($result); return $notify_users; } @@ -88,7 +119,7 @@ class phpbb_notifications_type_topic_in_queue extends phpbb_notifications_type_t */ public function create_insert_array($topic) { - $data = parent::create_insert_array($post); + $data = parent::create_insert_array($topic); $this->time = $data['time'] = time(); diff --git a/phpBB/includes/ucp/info/ucp_notifications.php b/phpBB/includes/ucp/info/ucp_notifications.php index f1e6bf65b8..4bc9ae2cea 100644 --- a/phpBB/includes/ucp/info/ucp_notifications.php +++ b/phpBB/includes/ucp/info/ucp_notifications.php @@ -16,7 +16,7 @@ class ucp_notifications_info { return array( 'filename' => 'ucp_notifications', - 'title' => 'UCP_NOTIFICATIONS', + 'title' => 'UCP_NOTIFICATION_OPTIONS', 'version' => '1.0.0', 'modes' => array( 'notification_options' => array('title' => 'UCP_NOTIFICATION_OPTIONS', 'auth' => '', 'cat' => array('UCP_MAIN')), diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index 0a01cd1cde..86052ada14 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -76,12 +76,12 @@ class ucp_notifications */ public function output_notification_types($block = 'notification_types', phpbb_notifications_service $phpbb_notifications, phpbb_template $template, phpbb_user $user) { - foreach($phpbb_notifications->get_subscription_types() as $type) + foreach($phpbb_notifications->get_subscription_types() as $type => $data) { $template->assign_block_vars($block, array( 'TYPE' => $type, - 'NAME' => $user->lang('NOTIFICATION_TYPE_' . strtoupper($type)), + 'NAME' => (isset($data['lang'])) ? $user->lang($data['lang']) : $user->lang('NOTIFICATION_TYPE_' . strtoupper($type)), )); $this->output_notification_methods($block . '.notification_methods', $phpbb_notifications, $template, $user); -- cgit v1.2.1 From f062087f30fab4ce497333cd88735920efe0737f Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 27 Sep 2012 10:42:50 -0500 Subject: [ticket/11103] Approve/disapprove notification options PHPBB3-11103 --- phpBB/includes/notifications/type/approve_post.php | 21 +++++++++++++++------ phpBB/includes/notifications/type/approve_topic.php | 21 +++++++++++++++------ 2 files changed, 30 insertions(+), 12 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/type/approve_post.php b/phpBB/includes/notifications/type/approve_post.php index a3a52b8780..91fb4106b1 100644 --- a/phpBB/includes/notifications/type/approve_post.php +++ b/phpBB/includes/notifications/type/approve_post.php @@ -69,11 +69,9 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos */ public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post) { - $users = array(); + $db = $phpbb_container->get('dbal.conn'); - /* todo - * find what type of notification they'd like to receive - */ + $users = array(); $users[$post['poster_id']] = array(''); $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); @@ -85,10 +83,21 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos $notify_users = array(); - foreach ($auth_read[$post['forum_id']]['f_read'] as $user_id) + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = 'moderation_queue' + AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) { - $notify_users[$user_id] = $users[$user_id]; + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; } + $db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/notifications/type/approve_topic.php b/phpBB/includes/notifications/type/approve_topic.php index ba7227c671..7da6fde747 100644 --- a/phpBB/includes/notifications/type/approve_topic.php +++ b/phpBB/includes/notifications/type/approve_topic.php @@ -69,11 +69,9 @@ class phpbb_notifications_type_approve_topic extends phpbb_notifications_type_to */ public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post) { - $users = array(); + $db = $phpbb_container->get('dbal.conn'); - /* todo - * find what type of notification they'd like to receive - */ + $users = array(); $users[$post['poster_id']] = array(''); $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); @@ -85,10 +83,21 @@ class phpbb_notifications_type_approve_topic extends phpbb_notifications_type_to $notify_users = array(); - foreach ($auth_read[$post['forum_id']]['f_read'] as $user_id) + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = 'moderation_queue' + AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) { - $notify_users[$user_id] = $users[$user_id]; + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; } + $db->sql_freeresult($result); return $notify_users; } -- cgit v1.2.1 From 48ccc9eb93c8413f05f6a50d40e597f560c671d8 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 27 Sep 2012 18:25:37 -0500 Subject: [ticket/11103] UCP Notification Options can now be set PHPBB3-11103 --- phpBB/includes/functions.php | 1 + phpBB/includes/notifications/service.php | 44 ++++++++++++++++++++++++++++++-- phpBB/includes/ucp/ucp_notifications.php | 43 +++++++++++++++++++++---------- 3 files changed, 73 insertions(+), 15 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 92cea20d10..92d72b6636 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5021,6 +5021,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text, 'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread, 'NUM_UNREAD_NOTIFICATIONS' => $notifications['unread_count'], + 'NOTIFICATIONS_CNT' => $user->lang('NOTIFICATIONS_CNT', $notifications['unread_count']), 'S_USER_NEW_PRIVMSG' => $user->data['user_new_privmsg'], 'S_USER_UNREAD_PRIVMSG' => $user->data['user_unread_privmsg'], diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 174b73f9a5..2c1eb859c7 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -502,6 +502,46 @@ class phpbb_notifications_service return $subscription_methods; } + /** + * Get subscriptions + * + * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) + * @param bool $only_global True to select only global subscription options (item_id = 0) + * + * @return array Subscriptions + */ + public function get_subscriptions($user_id = false, $only_global = false) + { + $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; + + $subscriptions = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . ' + WHERE user_id = ' . (int) $user_id . + (($only_global) ? ' AND item_id = 0' : ''); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + if ($only_global) + { + if (!isset($subscriptions[$row['item_type']])) + { + $subscriptions[$row['item_type']] = array(); + } + + $subscriptions[$row['item_type']][] = $row['method']; + } + else + { + $subscriptions[] = $row; + } + } + $this->db->sql_freeresult($result); + + return $subscriptions; + } + /** * Add a subscription * @@ -510,7 +550,7 @@ class phpbb_notifications_service * @param string $method The method of the notification e.g. '', 'email', or 'jabber' * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) */ - public function add_subscription($item_type, $item_id, $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); @@ -534,7 +574,7 @@ class phpbb_notifications_service * @param string $method The method of the notification e.g. '', 'email', or 'jabber' * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) */ - public function delete_subscription($item_type, $item_id, $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); diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index 86052ada14..ad399ca290 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -28,29 +28,37 @@ class ucp_notifications $user = $phpbb_container->get('user'); $request = $phpbb_container->get('request'); + $subscriptions = $phpbb_notifications->get_subscriptions(false, true); + + // Add/remove subscriptions if ($request->is_set_post('submit')) { $notification_methods = $phpbb_notifications->get_subscription_methods(); - foreach($phpbb_notifications->get_subscription_types() as $type) + + foreach($phpbb_notifications->get_subscription_types() as $type => $data) { - if ($request->is_set_post($type . '_notification')) + if ($request->is_set_post($type . '_notification') && !isset($subscriptions[$type])) { // add + $phpbb_notifications->add_subscription($type); } - else + else if (!$request->is_set_post($type . '_notification') && isset($subscriptions[$type])) { // remove + $phpbb_notifications->delete_subscription($type); } foreach($notification_methods as $method) { - if ($request->is_set_post($type . '_' . $method)) + if ($request->is_set_post($type . '_' . $method) && (!isset($subscriptions[$type]) || !in_array($method, $subscriptions[$type]))) { // add + $phpbb_notifications->add_subscription($type, 0, $method); } - else + else if (!$request->is_set_post($type . '_' . $method) && isset($subscriptions[$type]) && in_array($method, $subscriptions[$type])) { // remove + $phpbb_notifications->delete_subscription($type, 0, $method); } } } @@ -76,15 +84,29 @@ class ucp_notifications */ public function output_notification_types($block = 'notification_types', phpbb_notifications_service $phpbb_notifications, phpbb_template $template, phpbb_user $user) { + $notification_methods = $phpbb_notifications->get_subscription_methods(); + $subscriptions = $phpbb_notifications->get_subscriptions(false, true); + foreach($phpbb_notifications->get_subscription_types() as $type => $data) { $template->assign_block_vars($block, array( 'TYPE' => $type, - 'NAME' => (isset($data['lang'])) ? $user->lang($data['lang']) : $user->lang('NOTIFICATION_TYPE_' . strtoupper($type)), + 'NAME' => (is_array($data) && isset($data['lang'])) ? $user->lang($data['lang']) : $user->lang('NOTIFICATION_TYPE_' . strtoupper($type)), + + 'SUBSCRIBED' => (isset($subscriptions[$type])) ? true : false, )); - $this->output_notification_methods($block . '.notification_methods', $phpbb_notifications, $template, $user); + foreach($notification_methods as $method) + { + $template->assign_block_vars($block . '.notification_methods', array( + 'METHOD' => $method, + + 'NAME' => $user->lang('NOTIFICATION_METHOD_' . strtoupper($method)), + + 'SUBSCRIBED' => (isset($subscriptions[$type]) && in_array($method, $subscriptions[$type])) ? true : false, + )); + } } } @@ -98,12 +120,7 @@ class ucp_notifications */ public function output_notification_methods($block = 'notification_methods', phpbb_notifications_service $phpbb_notifications, phpbb_template $template, phpbb_user $user) { - static $notification_methods = false; - - if ($notification_methods === false) - { - $notification_methods = $phpbb_notifications->get_subscription_methods(); - } + $notification_methods = $phpbb_notifications->get_subscription_methods(); foreach($notification_methods as $method) { -- cgit v1.2.1 From 858201cc1f96a749fbcc875d54d033cbe4aeb8ea Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 27 Sep 2012 18:41:07 -0500 Subject: [ticket/11103] Types now all send notifications as per user setting PHPBB3-11103 --- phpBB/includes/notifications/type/approve_post.php | 2 +- .../includes/notifications/type/approve_topic.php | 2 +- phpBB/includes/notifications/type/bookmark.php | 28 +++++++++++++-------- phpBB/includes/notifications/type/post.php | 25 +++++++++++++------ .../includes/notifications/type/post_in_queue.php | 2 +- phpBB/includes/notifications/type/quote.php | 28 +++++++++++++-------- phpBB/includes/notifications/type/topic.php | 29 +++++++++++++--------- .../includes/notifications/type/topic_in_queue.php | 2 +- 8 files changed, 72 insertions(+), 46 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/type/approve_post.php b/phpBB/includes/notifications/type/approve_post.php index 91fb4106b1..faa88e862c 100644 --- a/phpBB/includes/notifications/type/approve_post.php +++ b/phpBB/includes/notifications/type/approve_post.php @@ -85,7 +85,7 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = 'moderation_queue' + WHERE item_type = '" . self::$notification_option['id'] . "' AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) diff --git a/phpBB/includes/notifications/type/approve_topic.php b/phpBB/includes/notifications/type/approve_topic.php index 7da6fde747..fbe44c8a2c 100644 --- a/phpBB/includes/notifications/type/approve_topic.php +++ b/phpBB/includes/notifications/type/approve_topic.php @@ -85,7 +85,7 @@ class phpbb_notifications_type_approve_topic extends phpbb_notifications_type_to $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = 'moderation_queue' + WHERE item_type = '" . self::$notification_option['id'] . "' AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) diff --git a/phpBB/includes/notifications/type/bookmark.php b/phpBB/includes/notifications/type/bookmark.php index 9f2c2e26dc..0e5358b105 100644 --- a/phpBB/includes/notifications/type/bookmark.php +++ b/phpBB/includes/notifications/type/bookmark.php @@ -62,28 +62,23 @@ class phpbb_notifications_type_bookmark extends phpbb_notifications_type_post $users = array(); - /* todo - * find what type of notification they'd like to receive - */ $sql = 'SELECT user_id FROM ' . BOOKMARKS_TABLE . ' - WHERE ' . $db->sql_in_set('topic_id', $post['topic_id']); + WHERE ' . $db->sql_in_set('topic_id', $post['topic_id']) . ' + AND user_id <> ' . (int) $post['poster_id']; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { - $users[$row['user_id']] = array(''); + $users[] = $row['user_id']; } $db->sql_freeresult($result); - // Never notify the poster - unset($users[$post['poster_id']]); - if (empty($users)) { return array(); } - $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); if (empty($auth_read)) { @@ -92,10 +87,21 @@ class phpbb_notifications_type_bookmark extends phpbb_notifications_type_post $notify_users = array(); - foreach ($auth_read[$post['forum_id']]['f_read'] as $user_id) + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) { - $notify_users[$user_id] = $users[$user_id]; + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; } + $db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index 17a7a6863a..bf41d2b05e 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -93,23 +93,21 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $sql = 'SELECT user_id FROM ' . TOPICS_WATCH_TABLE . ' WHERE topic_id = ' . (int) $post['topic_id'] . ' - AND notify_status = ' . NOTIFY_YES; + AND notify_status = ' . NOTIFY_YES . ' + AND user_id <> ' . (int) $post['poster_id']; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { - $users[$row['user_id']] = array(''); + $users[] = $row['user_id']; } $db->sql_freeresult($result); - // Never notify the poster - unset($users[$post['poster_id']]); - if (empty($users)) { return array(); } - $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); if (empty($auth_read)) { @@ -118,10 +116,21 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $notify_users = array(); - foreach ($auth_read[$post['forum_id']]['f_read'] as $user_id) + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) { - $notify_users[$user_id] = $users[$user_id]; + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; } + $db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/notifications/type/post_in_queue.php b/phpBB/includes/notifications/type/post_in_queue.php index 0043a38944..ca02b8d85a 100644 --- a/phpBB/includes/notifications/type/post_in_queue.php +++ b/phpBB/includes/notifications/type/post_in_queue.php @@ -92,7 +92,7 @@ class phpbb_notifications_type_post_in_queue extends phpbb_notifications_type_po $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = 'needs_approval' + WHERE item_type = '" . self::$notification_option['id'] . "' AND " . $db->sql_in_set('user_id', $auth_approve[$topic['forum_id']]['m_approve']); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) diff --git a/phpBB/includes/notifications/type/quote.php b/phpBB/includes/notifications/type/quote.php index 2079617510..be149673c2 100644 --- a/phpBB/includes/notifications/type/quote.php +++ b/phpBB/includes/notifications/type/quote.php @@ -81,28 +81,23 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post $users = array(); - /* todo - * find what type of notification they'd like to receive - */ $sql = 'SELECT user_id FROM ' . USERS_TABLE . ' - WHERE ' . $db->sql_in_set('username_clean', $usernames); + WHERE ' . $db->sql_in_set('username_clean', $usernames) . ' + AND user_id <> ' . (int) $post['poster_id']; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { - $users[$row['user_id']] = array(''); + $users[] = $row['user_id']; } $db->sql_freeresult($result); - // Never notify the poster - unset($users[$post['poster_id']]); - if (empty($users)) { return array(); } - $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); if (empty($auth_read)) { @@ -111,10 +106,21 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post $notify_users = array(); - foreach ($auth_read[$post['forum_id']]['f_read'] as $user_id) + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) { - $notify_users[$user_id] = $users[$user_id]; + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; } + $db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php index 733b2108cc..32d30bc142 100644 --- a/phpBB/includes/notifications/type/topic.php +++ b/phpBB/includes/notifications/type/topic.php @@ -86,30 +86,24 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base $users = array(); - /* todo - * find what type of notification they'd like to receive - * make sure not to send duplicate notifications - */ $sql = 'SELECT user_id FROM ' . FORUMS_WATCH_TABLE . ' WHERE forum_id = ' . (int) $topic['forum_id'] . ' - AND notify_status = ' . NOTIFY_YES; + AND notify_status = ' . NOTIFY_YES . ' + AND user_id <> ' . (int) $topic['poster_id']; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { - $users[$row['user_id']] = array(''); + $users[] = $row['user_id']; } $db->sql_freeresult($result); - // Never notify the poster - unset($users[$topic['poster_id']]); - if (empty($users)) { return array(); } - $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $topic['forum_id']); + $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $topic['forum_id']); if (empty($auth_read)) { @@ -118,10 +112,21 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base $notify_users = array(); - foreach ($auth_read[$topic['forum_id']]['f_read'] as $user_id) + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND " . $db->sql_in_set('user_id', $auth_read[$topic['forum_id']]['f_read']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) { - $notify_users[$user_id] = $users[$user_id]; + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; } + $db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/notifications/type/topic_in_queue.php b/phpBB/includes/notifications/type/topic_in_queue.php index dda647d18e..559af3e505 100644 --- a/phpBB/includes/notifications/type/topic_in_queue.php +++ b/phpBB/includes/notifications/type/topic_in_queue.php @@ -92,7 +92,7 @@ class phpbb_notifications_type_topic_in_queue extends phpbb_notifications_type_t $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = 'needs_approval' + WHERE item_type = '" . self::$notification_option['id'] . "' AND " . $db->sql_in_set('user_id', $auth_approve[$topic['forum_id']]['m_approve']); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) -- cgit v1.2.1 From cbe0d478f1d984560b588dc0ef0cd4bec233263f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 27 Sep 2012 18:44:31 -0500 Subject: [ticket/11103] Bug (using wrong variable) PHPBB3-11103 --- phpBB/includes/notifications/type/post_in_queue.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/type/post_in_queue.php b/phpBB/includes/notifications/type/post_in_queue.php index ca02b8d85a..5f8f9988c5 100644 --- a/phpBB/includes/notifications/type/post_in_queue.php +++ b/phpBB/includes/notifications/type/post_in_queue.php @@ -93,7 +93,7 @@ class phpbb_notifications_type_post_in_queue extends phpbb_notifications_type_po $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $db->sql_in_set('user_id', $auth_approve[$topic['forum_id']]['m_approve']); + AND " . $db->sql_in_set('user_id', $auth_approve[$post['forum_id']]['m_approve']); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { -- cgit v1.2.1 From c841aa34b64f3c83dfa8c637f2b20ae472c6de4d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 27 Sep 2012 18:48:13 -0500 Subject: [ticket/11103] A couple to-dos PHPBB3-11103 --- phpBB/includes/notifications/method/email.php | 2 +- phpBB/includes/notifications/type/post.php | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index a1ca955ee1..ebfc0c7c71 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -89,7 +89,7 @@ class phpbb_notifications_method_email extends phpbb_notifications_method_base $messenger->assign_vars(array_merge(array( 'USERNAME' => $user['username'], - 'U_NOTIFICATION_SETTINGS' => generate_board_url() . '/ucp.' . $this->php_ext . '?i=notifications', // todo Update URL + 'U_NOTIFICATION_SETTINGS' => generate_board_url() . '/ucp.' . $this->php_ext . '?i=ucp_notifications', ), $notification->get_email_template_variables())); $messenger->send($this->notify_method); diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index bf41d2b05e..e47ddafe1d 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -86,10 +86,6 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $users = array(); - /* todo - * find what type of notification they'd like to receive - * make sure not to send duplicate notifications - */ $sql = 'SELECT user_id FROM ' . TOPICS_WATCH_TABLE . ' WHERE topic_id = ' . (int) $post['topic_id'] . ' -- cgit v1.2.1 From ba7289b9d273df4f3dfb228ab37d324ff17cc9db Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 27 Sep 2012 19:19:38 -0500 Subject: [ticket/11103] Use PM Notification Preferences from Notification Options Remove all PM Notification preferences from UCP Board Preferences PHPBB3-11103 --- phpBB/includes/notifications/type/pm.php | 26 +++++++++++--------------- phpBB/includes/ucp/ucp_prefs.php | 18 ------------------ 2 files changed, 11 insertions(+), 33 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index df7b42564c..75c79e35e6 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -85,25 +85,21 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base $notify_users = array(); - foreach (array_keys($pm['recipients']) as $user_id) + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND " . $db->sql_in_set('user_id', array_keys($pm['recipients'])); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) { - $recipient = $service->get_user($user_id); - - if ($recipient['user_notify_pm']) + if (!isset($rowset[$row['user_id']])) { - $notify_users[$recipient['user_id']] = array(); - - if ($recipient['user_notify_type'] == NOTIFY_EMAIL || $recipient['user_notify_type'] == NOTIFY_BOTH) - { - $notify_users[$recipient['user_id']][] = 'email'; - } - - if ($recipient['user_notify_type'] == NOTIFY_IM || $recipient['user_notify_type'] == NOTIFY_BOTH) - { - $notify_users[$recipient['user_id']][] = 'jabber'; - } + $notify_users[$row['user_id']] = array(); } + + $notify_users[$row['user_id']][] = $row['method']; } + $db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index 2228bc7931..709d2a90b0 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -37,7 +37,6 @@ class ucp_prefs case 'personal': add_form_key('ucp_prefs_personal'); $data = array( - 'notifymethod' => request_var('notifymethod', $user->data['user_notify_type']), 'dateformat' => request_var('dateformat', $user->data['user_dateformat'], true), 'lang' => basename(request_var('lang', $user->data['user_lang'])), 'style' => request_var('style', (int) $user->data['user_style']), @@ -46,17 +45,9 @@ class ucp_prefs 'viewemail' => request_var('viewemail', (bool) $user->data['user_allow_viewemail']), 'massemail' => request_var('massemail', (bool) $user->data['user_allow_massemail']), 'hideonline' => request_var('hideonline', (bool) !$user->data['user_allow_viewonline']), - 'notifypm' => request_var('notifypm', (bool) $user->data['user_notify_pm']), - 'popuppm' => request_var('popuppm', (bool) $user->optionget('popuppm')), 'allowpm' => request_var('allowpm', (bool) $user->data['user_allow_pm']), ); - if ($data['notifymethod'] == NOTIFY_IM && (!$config['jab_enable'] || !$user->data['user_jabber'] || !@extension_loaded('xml'))) - { - // Jabber isnt enabled, or no jabber field filled in. Update the users table to be sure its correct. - $data['notifymethod'] = NOTIFY_BOTH; - } - if ($submit) { if ($config['override_user_style']) @@ -81,15 +72,11 @@ class ucp_prefs if (!sizeof($error)) { - $user->optionset('popuppm', $data['popuppm']); - $sql_ary = array( 'user_allow_pm' => $data['allowpm'], 'user_allow_viewemail' => $data['viewemail'], 'user_allow_massemail' => $data['massemail'], 'user_allow_viewonline' => ($auth->acl_get('u_hideonline')) ? !$data['hideonline'] : $user->data['user_allow_viewonline'], - 'user_notify_type' => $data['notifymethod'], - 'user_notify_pm' => $data['notifypm'], 'user_options' => $user->data['user_options'], 'user_dateformat' => $data['dateformat'], @@ -135,15 +122,10 @@ class ucp_prefs $template->assign_vars(array( 'ERROR' => (sizeof($error)) ? implode('
', $error) : '', - 'S_NOTIFY_EMAIL' => ($data['notifymethod'] == NOTIFY_EMAIL) ? true : false, - 'S_NOTIFY_IM' => ($data['notifymethod'] == NOTIFY_IM) ? true : false, - 'S_NOTIFY_BOTH' => ($data['notifymethod'] == NOTIFY_BOTH) ? true : false, 'S_VIEW_EMAIL' => $data['viewemail'], 'S_MASS_EMAIL' => $data['massemail'], 'S_ALLOW_PM' => $data['allowpm'], 'S_HIDE_ONLINE' => $data['hideonline'], - 'S_NOTIFY_PM' => $data['notifypm'], - 'S_POPUP_PM' => $data['popuppm'], 'DATE_FORMAT' => $data['dateformat'], 'A_DATE_FORMAT' => addslashes($data['dateformat']), -- cgit v1.2.1 From 07616bfa92654473580dc55ccda95139e8595575 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 27 Sep 2012 19:21:57 -0500 Subject: [ticket/11103] UCP Notifications Options Form Key PHPBB3-11103 --- phpBB/includes/ucp/ucp_notifications.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index ad399ca290..950b70a156 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -23,6 +23,8 @@ class ucp_notifications { global $phpbb_container; + add_form_key('ucp_notification_options'); + $phpbb_notifications = $phpbb_container->get('notifications'); $template = $phpbb_container->get('template'); $user = $phpbb_container->get('user'); @@ -33,6 +35,11 @@ class ucp_notifications // Add/remove subscriptions if ($request->is_set_post('submit')) { + if (!check_form_key('ucp_notification_options')) + { + trigger_error('FORM_INVALID'); + } + $notification_methods = $phpbb_notifications->get_subscription_methods(); foreach($phpbb_notifications->get_subscription_types() as $type => $data) -- cgit v1.2.1 From 2a5baad61bace05ee4907f7125555777cf7b1401 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 27 Sep 2012 20:05:06 -0500 Subject: [ticket/11103] Only notify a user once for a single item Note: The user may be notified multiple times IF they use different notification options. e.g They are subscribed to topics they have bookmarked by a notification and subscribed to the topic by an email notification. In this case, they would receive two notifications. This occurs because we do not want to omit any more direct types of notifications (if they want an email, they should _always_ get at least one email). PHPBB3-11103 --- phpBB/includes/functions_posting.php | 2 +- phpBB/includes/notifications/service.php | 18 ++++++++++++++---- phpBB/includes/notifications/type/approve_post.php | 11 ++++++++++- phpBB/includes/notifications/type/approve_topic.php | 11 ++++++++++- phpBB/includes/notifications/type/base.php | 11 ++++++++++- phpBB/includes/notifications/type/bookmark.php | 11 ++++++++++- phpBB/includes/notifications/type/interface.php | 2 +- phpBB/includes/notifications/type/pm.php | 11 ++++++++++- phpBB/includes/notifications/type/post.php | 11 ++++++++++- phpBB/includes/notifications/type/post_in_queue.php | 11 ++++++++++- phpBB/includes/notifications/type/quote.php | 11 ++++++++++- phpBB/includes/notifications/type/topic.php | 11 ++++++++++- phpBB/includes/notifications/type/topic_in_queue.php | 11 ++++++++++- 13 files changed, 116 insertions(+), 16 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 41bdd9f598..6262cee4ad 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2234,7 +2234,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u switch ($mode) { case 'post' : - $phpbb_notifications->add_notifications(array('topic', 'quote'), $notification_data); + $phpbb_notifications->add_notifications(array('quote', 'topic'), $notification_data); break; case 'reply' : diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 2c1eb859c7..35d60a7c51 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -256,16 +256,24 @@ class phpbb_notifications_service * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) * @param array $data Data specific for this type that will be inserted */ - public function add_notifications($item_type, $data) + public function add_notifications($item_type, $data, $options = array()) { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + if (is_array($item_type)) { + $notified_users = array(); + $temp_options = $options; + foreach ($item_type as $type) { - $this->add_notifications($type, $data); + $temp_options['ignore_users'] = $options['ignore_users'] + $notified_users; + $notified_users += $this->add_notifications($type, $data, $temp_options); } - return; + return $notified_users; } $item_type_class_name = $this->get_item_type_class_name($item_type); @@ -273,9 +281,11 @@ class phpbb_notifications_service $item_id = $item_type_class_name::get_item_id($data); // find out which users want to receive this type of notification - $notify_users = $item_type_class_name::find_users_for_notification($this->phpbb_container, $data); + $notify_users = $item_type_class_name::find_users_for_notification($this->phpbb_container, $data, $options); $this->add_notifications_for_users($item_type, $data, $notify_users); + + return $notify_users; } /** diff --git a/phpBB/includes/notifications/type/approve_post.php b/phpBB/includes/notifications/type/approve_post.php index faa88e862c..912b9082a2 100644 --- a/phpBB/includes/notifications/type/approve_post.php +++ b/phpBB/includes/notifications/type/approve_post.php @@ -67,8 +67,12 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post) + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + $db = $phpbb_container->get('dbal.conn'); $users = array(); @@ -90,6 +94,11 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + if (!isset($rowset[$row['user_id']])) { $notify_users[$row['user_id']] = array(); diff --git a/phpBB/includes/notifications/type/approve_topic.php b/phpBB/includes/notifications/type/approve_topic.php index fbe44c8a2c..e0e3a38e46 100644 --- a/phpBB/includes/notifications/type/approve_topic.php +++ b/phpBB/includes/notifications/type/approve_topic.php @@ -67,8 +67,12 @@ class phpbb_notifications_type_approve_topic extends phpbb_notifications_type_to * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post) + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + $db = $phpbb_container->get('dbal.conn'); $users = array(); @@ -90,6 +94,11 @@ class phpbb_notifications_type_approve_topic extends phpbb_notifications_type_to $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + if (!isset($rowset[$row['user_id']])) { $notify_users[$row['user_id']] = array(); diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 0da4dc8d93..01720b4554 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -264,8 +264,12 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type * * @return array */ - protected static function _find_users_for_notification(ContainerBuilder $phpbb_container, $item_id) + protected static function _find_users_for_notification(ContainerBuilder $phpbb_container, $item_id, $options) { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + $db = $phpbb_container->get('dbal.conn'); $rowset = array(); @@ -277,6 +281,11 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + if (!isset($rowset[$row['user_id']])) { $rowset[$row['user_id']] = array(); diff --git a/phpBB/includes/notifications/type/bookmark.php b/phpBB/includes/notifications/type/bookmark.php index 0e5358b105..a452583c77 100644 --- a/phpBB/includes/notifications/type/bookmark.php +++ b/phpBB/includes/notifications/type/bookmark.php @@ -56,8 +56,12 @@ class phpbb_notifications_type_bookmark extends phpbb_notifications_type_post * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post) + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + $db = $phpbb_container->get('dbal.conn'); $users = array(); @@ -94,6 +98,11 @@ class phpbb_notifications_type_bookmark extends phpbb_notifications_type_post $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + if (!isset($rowset[$row['user_id']])) { $notify_users[$row['user_id']] = array(); diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index c85d7441f6..95c307013e 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -27,7 +27,7 @@ interface phpbb_notifications_type_interface public static function is_available(ContainerBuilder $phpbb_container); - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $type_data); + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $type_data, $options); public function get_title(); diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index 75c79e35e6..f0730f285c 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -70,8 +70,12 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $pm) + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $pm, $options = array()) { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + $service = $phpbb_container->get('notifications'); $db = $phpbb_container->get('dbal.conn'); $user = $phpbb_container->get('user'); @@ -92,6 +96,11 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + if (!isset($rowset[$row['user_id']])) { $notify_users[$row['user_id']] = array(); diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index e47ddafe1d..d654a2e3a3 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -76,8 +76,12 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post) + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + // Let's continue to use the phpBB subscriptions system, at least for now. // It may not be the nicest thing, but it is already working and it would be significant work to replace it //$users = parent::_find_users_for_notification($phpbb_container, $post['topic_id']); @@ -119,6 +123,11 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + if (!isset($rowset[$row['user_id']])) { $notify_users[$row['user_id']] = array(); diff --git a/phpBB/includes/notifications/type/post_in_queue.php b/phpBB/includes/notifications/type/post_in_queue.php index 5f8f9988c5..64f68c07e2 100644 --- a/phpBB/includes/notifications/type/post_in_queue.php +++ b/phpBB/includes/notifications/type/post_in_queue.php @@ -77,8 +77,12 @@ class phpbb_notifications_type_post_in_queue extends phpbb_notifications_type_po * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post) + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + $db = $phpbb_container->get('dbal.conn'); $auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $post['forum_id']); @@ -97,6 +101,11 @@ class phpbb_notifications_type_post_in_queue extends phpbb_notifications_type_po $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + if (!isset($rowset[$row['user_id']])) { $notify_users[$row['user_id']] = array(); diff --git a/phpBB/includes/notifications/type/quote.php b/phpBB/includes/notifications/type/quote.php index be149673c2..f162b37126 100644 --- a/phpBB/includes/notifications/type/quote.php +++ b/phpBB/includes/notifications/type/quote.php @@ -63,8 +63,12 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post) + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + $db = $phpbb_container->get('dbal.conn'); $usernames = false; @@ -113,6 +117,11 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + if (!isset($rowset[$row['user_id']])) { $notify_users[$row['user_id']] = array(); diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php index 32d30bc142..ddef0147ba 100644 --- a/phpBB/includes/notifications/type/topic.php +++ b/phpBB/includes/notifications/type/topic.php @@ -76,8 +76,12 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic) + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic, $options = array()) { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + // Let's continue to use the phpBB subscriptions system, at least for now. // It may not be the nicest thing, but it is already working and it would be significant work to replace it //$users = parent::_find_users_for_notification($phpbb_container, $topic['forum_id']); @@ -119,6 +123,11 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + if (!isset($rowset[$row['user_id']])) { $notify_users[$row['user_id']] = array(); diff --git a/phpBB/includes/notifications/type/topic_in_queue.php b/phpBB/includes/notifications/type/topic_in_queue.php index 559af3e505..dc7f7aa105 100644 --- a/phpBB/includes/notifications/type/topic_in_queue.php +++ b/phpBB/includes/notifications/type/topic_in_queue.php @@ -77,8 +77,12 @@ class phpbb_notifications_type_topic_in_queue extends phpbb_notifications_type_t * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic) + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic, $options = array()) { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + $db = $phpbb_container->get('dbal.conn'); $auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $topic['forum_id']); @@ -97,6 +101,11 @@ class phpbb_notifications_type_topic_in_queue extends phpbb_notifications_type_t $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + if (!isset($rowset[$row['user_id']])) { $notify_users[$row['user_id']] = array(); -- cgit v1.2.1 From 25b9ea24bfb75d62b01e2f7aceaaef100830b5a3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 27 Sep 2012 20:11:28 -0500 Subject: [ticket/11103] Note on the add_notifications function about the last change PHPBB3-11103 --- phpBB/includes/notifications/service.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index 35d60a7c51..ebf4cef12d 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -254,6 +254,8 @@ class phpbb_notifications_service * Add a notification * * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) + * Note: If you send an array of types, any user who could receive multiple notifications from this single item will only receive + * a single notification. If they MUST receive multiple notifications, call this function multiple times instead of sending an array * @param array $data Data specific for this type that will be inserted */ public function add_notifications($item_type, $data, $options = array()) -- cgit v1.2.1 From 37e24736058f4e41c67023ce48edeb75e44bbe75 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 4 Oct 2012 13:39:54 -0500 Subject: [ticket/11103] Rename classes phpbb_notifications_service -> phpbb_notification_manager phpbb_notifications_ -> phpbb_notification_ PHPBB3-11103 --- phpBB/includes/notifications/method/base.php | 6 +++--- phpBB/includes/notifications/method/email.php | 2 +- phpBB/includes/notifications/method/interface.php | 2 +- phpBB/includes/notifications/method/jabber.php | 2 +- phpBB/includes/notifications/service.php | 2 +- phpBB/includes/notifications/type/approve_post.php | 4 ++-- phpBB/includes/notifications/type/approve_topic.php | 4 ++-- phpBB/includes/notifications/type/base.php | 2 +- phpBB/includes/notifications/type/bookmark.php | 4 ++-- phpBB/includes/notifications/type/disapprove_post.php | 4 ++-- phpBB/includes/notifications/type/disapprove_topic.php | 4 ++-- phpBB/includes/notifications/type/interface.php | 2 +- phpBB/includes/notifications/type/pm.php | 4 ++-- phpBB/includes/notifications/type/post.php | 4 ++-- phpBB/includes/notifications/type/post_in_queue.php | 4 ++-- phpBB/includes/notifications/type/quote.php | 4 ++-- phpBB/includes/notifications/type/topic.php | 4 ++-- phpBB/includes/notifications/type/topic_in_queue.php | 4 ++-- phpBB/includes/ucp/ucp_notifications.php | 8 ++++---- 19 files changed, 35 insertions(+), 35 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notifications/method/base.php b/phpBB/includes/notifications/method/base.php index b860fcffda..b502d3afd0 100644 --- a/phpBB/includes/notifications/method/base.php +++ b/phpBB/includes/notifications/method/base.php @@ -21,7 +21,7 @@ if (!defined('IN_PHPBB')) * Base notifications method class * @package notifications */ -abstract class phpbb_notifications_method_base implements phpbb_notifications_method_interface +abstract class phpbb_notification_method_base implements phpbb_notification_method_interface { protected $phpbb_container; protected $service; @@ -75,9 +75,9 @@ abstract class phpbb_notifications_method_base implements phpbb_notifications_me /** * Add a notification to the queue * - * @param phpbb_notifications_type_interface $notification + * @param phpbb_notification_type_interface $notification */ - public function add_to_queue(phpbb_notifications_type_interface $notification) + public function add_to_queue(phpbb_notification_type_interface $notification) { $this->queue[] = $notification; } diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php index ebfc0c7c71..1b6b44d137 100644 --- a/phpBB/includes/notifications/method/email.php +++ b/phpBB/includes/notifications/method/email.php @@ -21,7 +21,7 @@ if (!defined('IN_PHPBB')) * * @package notifications */ -class phpbb_notifications_method_email extends phpbb_notifications_method_base +class phpbb_notification_method_email extends phpbb_notification_method_base { /** * Notify method (since jabber gets sent through the same messenger, we let the jabber class inherit from this to reduce code duplication) diff --git a/phpBB/includes/notifications/method/interface.php b/phpBB/includes/notifications/method/interface.php index 820cf4fc12..4b990ec9fa 100644 --- a/phpBB/includes/notifications/method/interface.php +++ b/phpBB/includes/notifications/method/interface.php @@ -19,7 +19,7 @@ if (!defined('IN_PHPBB')) * Base notifications method interface * @package notifications */ -interface phpbb_notifications_method_interface +interface phpbb_notification_method_interface { public function is_available(); diff --git a/phpBB/includes/notifications/method/jabber.php b/phpBB/includes/notifications/method/jabber.php index 738400a50e..9232d8fc45 100644 --- a/phpBB/includes/notifications/method/jabber.php +++ b/phpBB/includes/notifications/method/jabber.php @@ -21,7 +21,7 @@ if (!defined('IN_PHPBB')) * * @package notifications */ -class phpbb_notifications_method_jabber extends phpbb_notifications_method_email +class phpbb_notification_method_jabber extends phpbb_notification_method_email { /** * Notify method (since jabber gets sent through the same messenger, we let the jabber class inherit from this to reduce code duplication) diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php index ebf4cef12d..2bf21cefa5 100644 --- a/phpBB/includes/notifications/service.php +++ b/phpBB/includes/notifications/service.php @@ -21,7 +21,7 @@ if (!defined('IN_PHPBB')) * Notifications service class * @package notifications */ -class phpbb_notifications_service +class phpbb_notification_manager { protected $phpbb_container; protected $db; diff --git a/phpBB/includes/notifications/type/approve_post.php b/phpBB/includes/notifications/type/approve_post.php index 912b9082a2..9a3def6217 100644 --- a/phpBB/includes/notifications/type/approve_post.php +++ b/phpBB/includes/notifications/type/approve_post.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) * * @package notifications */ -class phpbb_notifications_type_approve_post extends phpbb_notifications_type_post +class phpbb_notification_type_approve_post extends phpbb_notification_type_post { /** * Email template to use to send notifications @@ -52,7 +52,7 @@ class phpbb_notifications_type_approve_post extends phpbb_notifications_type_pos /** * Get the type of notification this is - * phpbb_notifications_type_ + * phpbb_notification_type_ */ public static function get_item_type() { diff --git a/phpBB/includes/notifications/type/approve_topic.php b/phpBB/includes/notifications/type/approve_topic.php index e0e3a38e46..00af312018 100644 --- a/phpBB/includes/notifications/type/approve_topic.php +++ b/phpBB/includes/notifications/type/approve_topic.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) * * @package notifications */ -class phpbb_notifications_type_approve_topic extends phpbb_notifications_type_topic +class phpbb_notification_type_approve_topic extends phpbb_notification_type_topic { /** * Email template to use to send notifications @@ -52,7 +52,7 @@ class phpbb_notifications_type_approve_topic extends phpbb_notifications_type_to /** * Get the type of notification this is - * phpbb_notifications_type_ + * phpbb_notification_type_ */ public static function get_item_type() { diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php index 01720b4554..40462bccfb 100644 --- a/phpBB/includes/notifications/type/base.php +++ b/phpBB/includes/notifications/type/base.php @@ -21,7 +21,7 @@ if (!defined('IN_PHPBB')) * Base notifications class * @package notifications */ -abstract class phpbb_notifications_type_base implements phpbb_notifications_type_interface +abstract class phpbb_notification_type_base implements phpbb_notification_type_interface { protected $phpbb_container; protected $service; diff --git a/phpBB/includes/notifications/type/bookmark.php b/phpBB/includes/notifications/type/bookmark.php index a452583c77..51f23bc294 100644 --- a/phpBB/includes/notifications/type/bookmark.php +++ b/phpBB/includes/notifications/type/bookmark.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) * * @package notifications */ -class phpbb_notifications_type_bookmark extends phpbb_notifications_type_post +class phpbb_notification_type_bookmark extends phpbb_notification_type_post { /** * Email template to use to send notifications @@ -41,7 +41,7 @@ class phpbb_notifications_type_bookmark extends phpbb_notifications_type_post /** * Get the type of notification this is - * phpbb_notifications_type_ + * phpbb_notification_type_ */ public static function get_item_type() { diff --git a/phpBB/includes/notifications/type/disapprove_post.php b/phpBB/includes/notifications/type/disapprove_post.php index 6911af5b08..8fa0102e3d 100644 --- a/phpBB/includes/notifications/type/disapprove_post.php +++ b/phpBB/includes/notifications/type/disapprove_post.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) * * @package notifications */ -class phpbb_notifications_type_disapprove_post extends phpbb_notifications_type_approve_post +class phpbb_notification_type_disapprove_post extends phpbb_notification_type_approve_post { /** * Email template to use to send notifications @@ -52,7 +52,7 @@ class phpbb_notifications_type_disapprove_post extends phpbb_notifications_type_ /** * Get the type of notification this is - * phpbb_notifications_type_ + * phpbb_notification_type_ */ public static function get_item_type() { diff --git a/phpBB/includes/notifications/type/disapprove_topic.php b/phpBB/includes/notifications/type/disapprove_topic.php index dab5ec1b02..186c42d2b6 100644 --- a/phpBB/includes/notifications/type/disapprove_topic.php +++ b/phpBB/includes/notifications/type/disapprove_topic.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) * * @package notifications */ -class phpbb_notifications_type_disapprove_topic extends phpbb_notifications_type_approve_topic +class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_approve_topic { /** * Email template to use to send notifications @@ -52,7 +52,7 @@ class phpbb_notifications_type_disapprove_topic extends phpbb_notifications_type /** * Get the type of notification this is - * phpbb_notifications_type_ + * phpbb_notification_type_ */ public static function get_item_type() { diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php index 95c307013e..aa54c62a97 100644 --- a/phpBB/includes/notifications/type/interface.php +++ b/phpBB/includes/notifications/type/interface.php @@ -19,7 +19,7 @@ if (!defined('IN_PHPBB')) * Base notifications interface * @package notifications */ -interface phpbb_notifications_type_interface +interface phpbb_notification_type_interface { public static function get_item_type(); diff --git a/phpBB/includes/notifications/type/pm.php b/phpBB/includes/notifications/type/pm.php index f0730f285c..8252a8577b 100644 --- a/phpBB/includes/notifications/type/pm.php +++ b/phpBB/includes/notifications/type/pm.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) * * @package notifications */ -class phpbb_notifications_type_pm extends phpbb_notifications_type_base +class phpbb_notification_type_pm extends phpbb_notification_type_base { /** * Email template to use to send notifications @@ -34,7 +34,7 @@ class phpbb_notifications_type_pm extends phpbb_notifications_type_base /** * Get the type of notification this is - * phpbb_notifications_type_ + * phpbb_notification_type_ */ public static function get_item_type() { diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php index d654a2e3a3..1e654ef51b 100644 --- a/phpBB/includes/notifications/type/post.php +++ b/phpBB/includes/notifications/type/post.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) * * @package notifications */ -class phpbb_notifications_type_post extends phpbb_notifications_type_base +class phpbb_notification_type_post extends phpbb_notification_type_base { /** * Email template to use to send notifications @@ -41,7 +41,7 @@ class phpbb_notifications_type_post extends phpbb_notifications_type_base /** * Get the type of notification this is - * phpbb_notifications_type_ + * phpbb_notification_type_ */ public static function get_item_type() { diff --git a/phpBB/includes/notifications/type/post_in_queue.php b/phpBB/includes/notifications/type/post_in_queue.php index 64f68c07e2..f0a5e0baec 100644 --- a/phpBB/includes/notifications/type/post_in_queue.php +++ b/phpBB/includes/notifications/type/post_in_queue.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) * * @package notifications */ -class phpbb_notifications_type_post_in_queue extends phpbb_notifications_type_post +class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post { /** * Email template to use to send notifications @@ -52,7 +52,7 @@ class phpbb_notifications_type_post_in_queue extends phpbb_notifications_type_po /** * Get the type of notification this is - * phpbb_notifications_type_ + * phpbb_notification_type_ */ public static function get_item_type() { diff --git a/phpBB/includes/notifications/type/quote.php b/phpBB/includes/notifications/type/quote.php index f162b37126..dd3cbedee2 100644 --- a/phpBB/includes/notifications/type/quote.php +++ b/phpBB/includes/notifications/type/quote.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) * * @package notifications */ -class phpbb_notifications_type_quote extends phpbb_notifications_type_post +class phpbb_notification_type_quote extends phpbb_notification_type_post { /** * Email template to use to send notifications @@ -48,7 +48,7 @@ class phpbb_notifications_type_quote extends phpbb_notifications_type_post /** * Get the type of notification this is - * phpbb_notifications_type_ + * phpbb_notification_type_ */ public static function get_item_type() { diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php index ddef0147ba..7753b196e8 100644 --- a/phpBB/includes/notifications/type/topic.php +++ b/phpBB/includes/notifications/type/topic.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) * * @package notifications */ -class phpbb_notifications_type_topic extends phpbb_notifications_type_base +class phpbb_notification_type_topic extends phpbb_notification_type_base { /** * Email template to use to send notifications @@ -41,7 +41,7 @@ class phpbb_notifications_type_topic extends phpbb_notifications_type_base /** * Get the type of notification this is - * phpbb_notifications_type_ + * phpbb_notification_type_ */ public static function get_item_type() { diff --git a/phpBB/includes/notifications/type/topic_in_queue.php b/phpBB/includes/notifications/type/topic_in_queue.php index dc7f7aa105..385578cec8 100644 --- a/phpBB/includes/notifications/type/topic_in_queue.php +++ b/phpBB/includes/notifications/type/topic_in_queue.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) * * @package notifications */ -class phpbb_notifications_type_topic_in_queue extends phpbb_notifications_type_topic +class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_topic { /** * Email template to use to send notifications @@ -62,7 +62,7 @@ class phpbb_notifications_type_topic_in_queue extends phpbb_notifications_type_t /** * Get the type of notification this is - * phpbb_notifications_type_ + * phpbb_notification_type_ */ public static function get_item_type() { diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index 950b70a156..d248099b06 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -85,11 +85,11 @@ class ucp_notifications * Output all the notification types to the template * * @param string $block - * @param phpbb_notifications_service $phpbb_notifications + * @param phpbb_notification_manager $phpbb_notifications * @param phpbb_template $template * @param phpbb_user $user */ - public function output_notification_types($block = 'notification_types', phpbb_notifications_service $phpbb_notifications, phpbb_template $template, phpbb_user $user) + public function output_notification_types($block = 'notification_types', phpbb_notification_manager $phpbb_notifications, phpbb_template $template, phpbb_user $user) { $notification_methods = $phpbb_notifications->get_subscription_methods(); $subscriptions = $phpbb_notifications->get_subscriptions(false, true); @@ -121,11 +121,11 @@ class ucp_notifications * Output all the notification methods to the template * * @param string $block - * @param phpbb_notifications_service $phpbb_notifications + * @param phpbb_notification_manager $phpbb_notifications * @param phpbb_template $template * @param phpbb_user $user */ - public function output_notification_methods($block = 'notification_methods', phpbb_notifications_service $phpbb_notifications, phpbb_template $template, phpbb_user $user) + public function output_notification_methods($block = 'notification_methods', phpbb_notification_manager $phpbb_notifications, phpbb_template $template, phpbb_user $user) { $notification_methods = $phpbb_notifications->get_subscription_methods(); -- cgit v1.2.1 From 64820546d758b34720888311d0abffcf95609436 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 4 Oct 2012 13:40:40 -0500 Subject: [ticket/11103] Move notification files to includes/notification/ PHPBB3-11103 --- phpBB/includes/notification/manager.php | 688 +++++++++++++++++++++ phpBB/includes/notification/method/base.php | 92 +++ phpBB/includes/notification/method/email.php | 104 ++++ phpBB/includes/notification/method/interface.php | 27 + phpBB/includes/notification/method/jabber.php | 62 ++ phpBB/includes/notification/type/approve_post.php | 132 ++++ phpBB/includes/notification/type/approve_topic.php | 130 ++++ phpBB/includes/notification/type/base.php | 345 +++++++++++ phpBB/includes/notification/type/bookmark.php | 117 ++++ .../includes/notification/type/disapprove_post.php | 116 ++++ .../notification/type/disapprove_topic.php | 116 ++++ phpBB/includes/notification/type/interface.php | 49 ++ phpBB/includes/notification/type/pm.php | 191 ++++++ phpBB/includes/notification/type/post.php | 242 ++++++++ phpBB/includes/notification/type/post_in_queue.php | 137 ++++ phpBB/includes/notification/type/quote.php | 209 +++++++ phpBB/includes/notification/type/topic.php | 237 +++++++ .../includes/notification/type/topic_in_queue.php | 137 ++++ phpBB/includes/notifications/method/base.php | 92 --- phpBB/includes/notifications/method/email.php | 104 ---- phpBB/includes/notifications/method/interface.php | 27 - phpBB/includes/notifications/method/jabber.php | 62 -- phpBB/includes/notifications/service.php | 688 --------------------- phpBB/includes/notifications/type/approve_post.php | 132 ---- .../includes/notifications/type/approve_topic.php | 130 ---- phpBB/includes/notifications/type/base.php | 345 ----------- phpBB/includes/notifications/type/bookmark.php | 117 ---- .../notifications/type/disapprove_post.php | 116 ---- .../notifications/type/disapprove_topic.php | 116 ---- phpBB/includes/notifications/type/interface.php | 49 -- phpBB/includes/notifications/type/pm.php | 191 ------ phpBB/includes/notifications/type/post.php | 242 -------- .../includes/notifications/type/post_in_queue.php | 137 ---- phpBB/includes/notifications/type/quote.php | 209 ------- phpBB/includes/notifications/type/topic.php | 237 ------- .../includes/notifications/type/topic_in_queue.php | 137 ---- 36 files changed, 3131 insertions(+), 3131 deletions(-) create mode 100644 phpBB/includes/notification/manager.php create mode 100644 phpBB/includes/notification/method/base.php create mode 100644 phpBB/includes/notification/method/email.php create mode 100644 phpBB/includes/notification/method/interface.php create mode 100644 phpBB/includes/notification/method/jabber.php create mode 100644 phpBB/includes/notification/type/approve_post.php create mode 100644 phpBB/includes/notification/type/approve_topic.php create mode 100644 phpBB/includes/notification/type/base.php create mode 100644 phpBB/includes/notification/type/bookmark.php create mode 100644 phpBB/includes/notification/type/disapprove_post.php create mode 100644 phpBB/includes/notification/type/disapprove_topic.php create mode 100644 phpBB/includes/notification/type/interface.php create mode 100644 phpBB/includes/notification/type/pm.php create mode 100644 phpBB/includes/notification/type/post.php create mode 100644 phpBB/includes/notification/type/post_in_queue.php create mode 100644 phpBB/includes/notification/type/quote.php create mode 100644 phpBB/includes/notification/type/topic.php create mode 100644 phpBB/includes/notification/type/topic_in_queue.php delete mode 100644 phpBB/includes/notifications/method/base.php delete mode 100644 phpBB/includes/notifications/method/email.php delete mode 100644 phpBB/includes/notifications/method/interface.php delete mode 100644 phpBB/includes/notifications/method/jabber.php delete mode 100644 phpBB/includes/notifications/service.php delete mode 100644 phpBB/includes/notifications/type/approve_post.php delete mode 100644 phpBB/includes/notifications/type/approve_topic.php delete mode 100644 phpBB/includes/notifications/type/base.php delete mode 100644 phpBB/includes/notifications/type/bookmark.php delete mode 100644 phpBB/includes/notifications/type/disapprove_post.php delete mode 100644 phpBB/includes/notifications/type/disapprove_topic.php delete mode 100644 phpBB/includes/notifications/type/interface.php delete mode 100644 phpBB/includes/notifications/type/pm.php delete mode 100644 phpBB/includes/notifications/type/post.php delete mode 100644 phpBB/includes/notifications/type/post_in_queue.php delete mode 100644 phpBB/includes/notifications/type/quote.php delete mode 100644 phpBB/includes/notifications/type/topic.php delete mode 100644 phpBB/includes/notifications/type/topic_in_queue.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php new file mode 100644 index 0000000000..15db3f89fd --- /dev/null +++ b/phpBB/includes/notification/manager.php @@ -0,0 +1,688 @@ +phpbb_container = $phpbb_container; + + // Some common things we're going to use + $this->db = $phpbb_container->get('dbal.conn'); + } + + /** + * Load the user's notifications + * + * @param array $options Optional options to control what notifications are loaded + * notification_id Notification id to load (or array of notification ids) + * user_id User id to load notifications for (Default: $user->data['user_id']) + * order_by Order by (Default: time) + * order_dir Order direction (Default: DESC) + * limit Number of notifications to load (Default: 5) + * start Notifications offset (Default: 0) + * all_unread Load all unread messages? If set to true, count_unread is set to true (Default: false) + * count_unread Count all unread messages? (Default: false) + */ + public function load_notifications($options = array()) + { + $user = $this->phpbb_container->get('user'); + + // Merge default options + $options = array_merge(array( + 'notification_id' => false, + 'user_id' => $user->data['user_id'], + 'order_by' => 'time', + 'order_dir' => 'DESC', + 'limit' => 0, + 'start' => 0, + 'all_unread' => false, + 'count_unread' => false, + ), $options); + + // If all_unread, count_unread mus be true + $options['count_unread'] = ($options['all_unread']) ? true : $options['count_unread']; + + // Anonymous users and bots never receive notifications + if ($options['user_id'] == $user->data['user_id'] && ($user->data['user_id'] == ANONYMOUS || $user->data['user_type'] == USER_IGNORE)) + { + return array( + 'notifications' => array(), + 'unread_count' => 0, + ); + } + + $notifications = $user_ids = array(); + $load_special = array(); + $count = 0; + + if ($options['count_unread']) + { + // Get the total number of unread notifications + $sql = 'SELECT COUNT(*) AS count + FROM ' . NOTIFICATIONS_TABLE . ' + WHERE user_id = ' . (int) $options['user_id'] . ' + AND unread = 1'; + $result = $this->db->sql_query($sql); + $count = (int) $this->db->sql_fetchfield('count', $result); + $this->db->sql_freeresult($result); + } + + $rowset = array(); + + // 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']) : '') . ' + 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); + + // Get all unread notifications + if ($count && $options['all_unread'] && !empty($rowset)) + { + $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) . ' + 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); + } + + foreach ($rowset as $row) + { + $item_type_class_name = $this->get_item_type_class_name($row['item_type'], true); + + $notification = new $item_type_class_name($this->phpbb_container, $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(); + } + $load_special[$row['item_type']] = array_merge($load_special[$row['item_type']], $notification->get_load_special()); + + $notifications[] = $notification; + } + + $this->load_users($user_ids); + + // Allow each type to load it's own special items + foreach ($load_special as $item_type => $data) + { + $item_type_class_name = $this->get_item_type_class_name($item_type, true); + + $item_type_class_name::load_special($this->phpbb_container, $data, $notifications); + } + + return array( + 'notifications' => $notifications, + 'unread_count' => $count, + ); + } + + /** + * Mark notifications read + * + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) + * @param bool|int|array $item_id Item id or array of item ids. False to mark read for all item ids + * @param bool|int|array $user_id User id or array of user ids. False to mark read for all user ids + * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False) + */ + public function mark_notifications_read($item_type, $item_id, $user_id, $time = false) + { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->mark_notifications_read($type, $item_id, $user_id, $time); + } + + return; + } + + $time = ($time) ?: time(); + + $this->get_item_type_class_name($item_type); + + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + SET unread = 0 + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND time <= " . $time . + (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : '') . + (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); + $this->db->sql_query($sql); + } + + /** + * Mark notifications read from a parent identifier + * + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) + * @param bool|int|array $item_parent_id Item parent id or array of item parent ids. False to mark read for all item parent ids + * @param bool|int|array $user_id User id or array of user ids. False to mark read for all user ids + * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False) + */ + public function mark_notifications_read_by_parent($item_type, $item_parent_id, $user_id, $time = false) + { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->mark_notifications_read_by_parent($type, $item_parent_id, $user_id, $time); + } + + return; + } + + $time = ($time) ?: time(); + + $item_type_class_name = $this->get_item_type_class_name($item_type); + + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + SET unread = 0 + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND time <= " . $time . + (($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id) : 'item_parent_id = ' . (int) $item_parent_id) : '') . + (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); + $this->db->sql_query($sql); + } + + /** + * Mark notifications read + * + * @param int|array $notification_id Notification id or array of notification ids. + * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False) + */ + public function mark_notifications_read_by_id($notification_id, $time = false) + { + $time = ($time) ?: time(); + + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + SET unread = 0 + WHERE time <= " . $time . ' + AND ' . ((is_array($notification_id)) ? $this->db->sql_in_set('notification_id', $notification_id) : 'notification_id = ' . (int) $notification_id); + $this->db->sql_query($sql); + } + + /** + * Add a notification + * + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) + * Note: If you send an array of types, any user who could receive multiple notifications from this single item will only receive + * a single notification. If they MUST receive multiple notifications, call this function multiple times instead of sending an array + * @param array $data Data specific for this type that will be inserted + */ + public function add_notifications($item_type, $data, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + if (is_array($item_type)) + { + $notified_users = array(); + $temp_options = $options; + + foreach ($item_type as $type) + { + $temp_options['ignore_users'] = $options['ignore_users'] + $notified_users; + $notified_users += $this->add_notifications($type, $data, $temp_options); + } + + return $notified_users; + } + + $item_type_class_name = $this->get_item_type_class_name($item_type); + + $item_id = $item_type_class_name::get_item_id($data); + + // find out which users want to receive this type of notification + $notify_users = $item_type_class_name::find_users_for_notification($this->phpbb_container, $data, $options); + + $this->add_notifications_for_users($item_type, $data, $notify_users); + + return $notify_users; + } + + /** + * Add a notification for specific users + * + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) + * @param array $data Data specific for this type that will be inserted + * @param array $notify_users User list to notify + */ + public function add_notifications_for_users($item_type, $data, $notify_users) + { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->add_notifications_for_users($type, $data, $notify_users); + } + + return; + } + + $item_type_class_name = $this->get_item_type_class_name($item_type); + + $item_id = $item_type_class_name::get_item_id($data); + + $user_ids = array(); + $notification_objects = $notification_methods = array(); + $new_rows = array(); + + // Never send notifications to the anonymous user! + unset($notify_users[ANONYMOUS]); + + // Make sure not to send new notifications to users who've already been notified about this item + // This may happen when an item was added, but now new users are able to see the item + // todo Users should not receive notifications from multiple events from the same item (ex: for a topic reply with a quote including your username) + // Probably should be handled within each type? + $sql = 'SELECT user_id + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + unset($notify_users[$row['user_id']]); + } + $this->db->sql_freeresult($result); + + if (!sizeof($notify_users)) + { + return; + } + + // 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) + { + $notification = new $item_type_class_name($this->phpbb_container); + + $notification->user_id = (int) $user; + + // Store the creation array in our new rows that will be inserted later + $new_rows[] = $notification->create_insert_array($data); + + // Users are needed to send notifications + $user_ids = array_merge($user_ids, $notification->users_to_query()); + + foreach ($methods as $method) + { + // setup the notification methods and add the notification to the queue + if ($method) // blank means we just insert it as a notification, but do not notify them by any other means + { + if (!isset($notification_methods[$method])) + { + $method_class_name = 'phpbb_notification_method_' . $method; + $notification_methods[$method] = new $method_class_name($this->phpbb_container); + } + + $notification_methods[$method]->add_to_queue($notification); + } + } + } + + // insert into the db + $this->db->sql_multi_insert(NOTIFICATIONS_TABLE, $new_rows); + + // We need to load all of the users to send notifications + $this->load_users($user_ids); + + // run the queue for each method to send notifications + foreach ($notification_methods as $method) + { + $method->notify(); + } + } + + /** + * Update a notification + * + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) + * @param array $data Data specific for this type that will be updated + */ + public function update_notifications($item_type, $data) + { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->update_notifications($type, $data); + } + + return; + } + + $item_type_class_name = $this->get_item_type_class_name($item_type); + + // Allow the notifications class to over-ride the update_notifications functionality + if (method_exists($item_type_class_name, 'update_notifications')) + { + // Return False to over-ride the rest of the update + if ($item_type_class_name::update_notifications($this->phpbb_container, $data) === false) + { + return; + } + } + + $item_id = $item_type_class_name::get_item_id($data); + + $notification = new $item_type_class_name($this->phpbb_container); + $update_array = $notification->create_update_array($data); + + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $update_array) . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id; + $this->db->sql_query($sql); + } + + /** + * Delete a notification + * + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $item_id is identical for the specified types) + * @param int|array $item_id Identifier within the type (or array of ids) + * @param array $data Data specific for this type that will be updated + */ + public function delete_notifications($item_type, $item_id) + { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->delete_notifications($type, $item_id); + } + + return; + } + + $this->get_item_type_class_name($item_type); + + $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " + 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); + $this->db->sql_query($sql); + } + + /** + * Get all of the subscription types + * + * @return array Array of item types + */ + public function get_subscription_types() + { + $subscription_types = array(); + + foreach ($this->get_subscription_files('notifications/type/') as $class => $file) + { + $class = $this->get_item_type_class_name($class); + + if (!class_exists($class)) + { + include($file); + } + + if ($class::is_available($this->phpbb_container) && method_exists($class, 'get_item_type')) + { + if ($class::$notification_option === false) + { + $subscription_types[$class::get_item_type()] = $class::get_item_type(); + } + else + { + $subscription_types[$class::$notification_option['id']] = $class::$notification_option; + } + } + } + + return $subscription_types; + } + + /** + * Get all of the subscription methods + * + * @return array Array of methods + */ + public function get_subscription_methods() + { + $subscription_methods = array(); + + foreach ($this->get_subscription_files('notifications/method/') as $method_name => $file) + { + $class_name = 'phpbb_notification_method_' . $method_name; + + if (!class_exists($class_name)) + { + include($file); + } + + $method = new $class_name($this->phpbb_container); + + if ($method->is_available()) + { + $subscription_methods[] = $method_name; + } + } + + return $subscription_methods; + } + + /** + * Get subscriptions + * + * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) + * @param bool $only_global True to select only global subscription options (item_id = 0) + * + * @return array Subscriptions + */ + public function get_subscriptions($user_id = false, $only_global = false) + { + $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; + + $subscriptions = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . ' + WHERE user_id = ' . (int) $user_id . + (($only_global) ? ' AND item_id = 0' : ''); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + if ($only_global) + { + if (!isset($subscriptions[$row['item_type']])) + { + $subscriptions[$row['item_type']] = array(); + } + + $subscriptions[$row['item_type']][] = $row['method']; + } + else + { + $subscriptions[] = $row; + } + } + $this->db->sql_freeresult($result); + + return $subscriptions; + } + + /** + * Add a subscription + * + * @param string $item_type Type identifier of the subscription + * @param int $item_id The id of the item + * @param string $method The method of the notification e.g. '', 'email', or 'jabber' + * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) + */ + public function add_subscription($item_type, $item_id = 0, $method = '', $user_id = false) + { + $this->get_item_type_class_name($item_type); + + $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; + + $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . + $this->db->sql_build_array('INSERT', array( + 'item_type' => $item_type, + 'item_id' => (int) $item_id, + 'user_id' => (int) $user_id, + 'method' => $method, + )); + $this->db->sql_query($sql); + } + + /** + * Delete a subscription + * + * @param string $item_type Type identifier of the subscription + * @param int $item_id The id of the item + * @param string $method The method of the notification e.g. '', 'email', or 'jabber' + * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) + */ + public function delete_subscription($item_type, $item_id = 0, $method = '', $user_id = false) + { + $this->get_item_type_class_name($item_type); + + $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; + + $sql = 'DELETE FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id . ' + AND user_id = ' .(int) $user_id . " + AND method = '" . $this->db->sql_escape($method) . "'"; + $this->db->sql_query($sql); + } + + /** + * Load user helper + * + * @param array $user_ids + */ + public function load_users($user_ids) + { + $user_ids[] = ANONYMOUS; + + // Load the users + $user_ids = array_unique($user_ids); + + // Do not load users we already have in $this->users + $user_ids = array_diff($user_ids, array_keys($this->users)); + + if (sizeof($user_ids)) + { + $sql = 'SELECT * + FROM ' . USERS_TABLE . ' + WHERE ' . $this->db->sql_in_set('user_id', $user_ids); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->users[$row['user_id']] = $row; + } + $this->db->sql_freeresult($result); + } + } + + /** + * Get a user row from our users cache + * + * @param int $user_id + * @return array + */ + public function get_user($user_id) + { + 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); + } + + return 'phpbb_notification_type_' . $item_type; + } + + /** + * Helper to get subscription related files with the finder + */ + private function get_subscription_files($path) + { + $ext_manager = $this->phpbb_container->get('ext.manager'); + $php_ext = $this->phpbb_container->getParameter('core.php_ext'); + + $finder = $ext_manager->get_finder(); + + $subscription_files = array(); + + $files = $finder + ->core_path('includes/' . $path) + ->extension_directory($path) + ->get_files(); + foreach ($files as $file) + { + $class = substr($file, strrpos($file, '/')); + $class = substr($class, 1, (strpos($class, '.' . $php_ext) - 1)); + + if ($class == 'interface' || $class == 'base') + { + continue; + } + + $subscription_files[$class] = $file; + } + + return $subscription_files; + } +} diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php new file mode 100644 index 0000000000..b502d3afd0 --- /dev/null +++ b/phpBB/includes/notification/method/base.php @@ -0,0 +1,92 @@ +phpbb_container = $phpbb_container; + + // Service + $this->service = $phpbb_container->get('notifications'); + + // Some common things we're going to use + $this->db = $phpbb_container->get('dbal.conn'); + $this->user = $phpbb_container->get('user'); + + $this->phpbb_root_path = $phpbb_container->getParameter('core.root_path'); + $this->php_ext = $phpbb_container->getParameter('core.php_ext'); + } + + /** + * Add a notification to the queue + * + * @param phpbb_notification_type_interface $notification + */ + public function add_to_queue(phpbb_notification_type_interface $notification) + { + $this->queue[] = $notification; + } + + /** + * Empty the queue + */ + protected function empty_queue() + { + $this->queue = array(); + } +} diff --git a/phpBB/includes/notification/method/email.php b/phpBB/includes/notification/method/email.php new file mode 100644 index 0000000000..1b6b44d137 --- /dev/null +++ b/phpBB/includes/notification/method/email.php @@ -0,0 +1,104 @@ +queue)) + { + return; + } + + // Load all users we want to notify (we need their email address) + $user_ids = $users = array(); + foreach ($this->queue as $notification) + { + $user_ids[] = $notification->user_id; + } + + // We do not send emails to banned users + if (!function_exists('phpbb_get_banned_user_ids')) + { + include($this->phpbb_container->getParameter('core.root_path') . 'includes/functions_user.' . $this->phpbb_container->getParameter('core.php_ext')); + } + $banned_users = phpbb_get_banned_user_ids($user_ids); + + // Load all the users we need + $this->service->load_users($user_ids); + + // Load the messenger + if (!class_exists('messenger')) + { + include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext); + } + $messenger = new messenger(); + $board_url = generate_board_url(); + + // Time to go through the queue and send emails + foreach ($this->queue as $notification) + { + $user = $this->service->get_user($notification->user_id); + + if ($user['user_type'] == USER_IGNORE || in_array($notification->user_id, $banned_users)) + { + continue; + } + + $messenger->template($notification->email_template, $user['user_lang']); + + $messenger->to($user['user_email'], $user['username']); + + $messenger->assign_vars(array_merge(array( + 'USERNAME' => $user['username'], + + 'U_NOTIFICATION_SETTINGS' => generate_board_url() . '/ucp.' . $this->php_ext . '?i=ucp_notifications', + ), $notification->get_email_template_variables())); + + $messenger->send($this->notify_method); + } + + // Save the queue in the messenger class (has to be called or these emails could be lost?) + $messenger->save_queue(); + + // We're done, empty the queue + $this->empty_queue(); + } +} diff --git a/phpBB/includes/notification/method/interface.php b/phpBB/includes/notification/method/interface.php new file mode 100644 index 0000000000..4b990ec9fa --- /dev/null +++ b/phpBB/includes/notification/method/interface.php @@ -0,0 +1,27 @@ +global_available() && $this->phpbb_container->get('user')->data['jabber']); + } + + /** + * Is this method available at all? + * This is checked before notifications are sent + */ + public function global_available() + { + $config = $this->phpbb_container->get('config'); + + return ($config['jab_enable'] && @extension_loaded('xml')); + } + + public function notify() + { + if (!$this->global_available()) + { + return; + } + + return parent::notify(); + } +} diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php new file mode 100644 index 0000000000..9a3def6217 --- /dev/null +++ b/phpBB/includes/notification/type/approve_post.php @@ -0,0 +1,132 @@ + 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + ); + + /** + * Get the type of notification this is + * phpbb_notification_type_ + */ + public static function get_item_type() + { + return 'approve_post'; + } + + /** + * Find the users who want to receive notifications + * + * @param ContainerBuilder $phpbb_container + * @param array $post Data from + * + * @return array + */ + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + $db = $phpbb_container->get('dbal.conn'); + + $users = array(); + $users[$post['poster_id']] = array(''); + + $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::$notification_option['id'] . "' + AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + return $notify_users; + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $this->set_data('post_subject', $post['post_subject']); + + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); + + return $data; + } +} diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php new file mode 100644 index 0000000000..00af312018 --- /dev/null +++ b/phpBB/includes/notification/type/approve_topic.php @@ -0,0 +1,130 @@ + 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + ); + + /** + * Get the type of notification this is + * phpbb_notification_type_ + */ + public static function get_item_type() + { + return 'approve_topic'; + } + + /** + * Find the users who want to receive notifications + * + * @param ContainerBuilder $phpbb_container + * @param array $post Data from + * + * @return array + */ + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + $db = $phpbb_container->get('dbal.conn'); + + $users = array(); + $users[$post['poster_id']] = array(''); + + $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::$notification_option['id'] . "' + AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + return $notify_users; + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); + + return $data; + } +} diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php new file mode 100644 index 0000000000..40462bccfb --- /dev/null +++ b/phpBB/includes/notification/type/base.php @@ -0,0 +1,345 @@ + forum_id, for post => topic_id, etc) + * user_id + * unread + * + * time + * data (special serialized field that each notification type can use to store stuff) + * + * @var array $data Notification row from the database + * This must be private, all interaction should use __get(), __set(), get_data(), set_data() + */ + private $data = array(); + + public function __construct(ContainerBuilder $phpbb_container, $data = array()) + { + // phpBB Container + $this->phpbb_container = $phpbb_container; + + // Service + $this->service = $phpbb_container->get('notifications'); + + // Some common things we're going to use + $this->db = $phpbb_container->get('dbal.conn'); + + $this->phpbb_root_path = $phpbb_container->getParameter('core.root_path'); + $this->php_ext = $phpbb_container->getParameter('core.php_ext'); + + // The row from the database (unless this is a new notification we're going to add) + $this->data = $data; + $this->data['data'] = (isset($this->data['data'])) ? unserialize($this->data['data']) : array(); + } + + public function __get($name) + { + return $this->data[$name]; + } + + public function __set($name, $value) + { + $this->data[$name] = $value; + } + + /** + * Get special data (only important for the classes that extend this) + * + * @param string $name Name of the variable to get + * + * @return mixed + */ + protected function get_data($name) + { + return (isset($this->data['data'][$name])) ? $this->data['data'][$name] : null; + } + + /** + * Set special data (only important for the classes that extend this) + * + * @param string $name Name of the variable to set + * @param mixed $value Value to set to the variable + */ + protected function set_data($name, $value) + { + $this->data['data'][$name] = $value; + } + + /** + * Prepare to output the notification to the template + */ + public function prepare_for_display() + { + $user = $this->phpbb_container->get('user'); + + return array( + 'AVATAR' => $this->get_avatar(), + + 'FORMATTED_TITLE' => $this->get_title(), + + 'URL' => $this->get_url(), + 'TIME' => $user->format_date($this->time), + + 'UNREAD' => $this->unread, + + 'U_MARK_READ' => append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification[]=' . $this->notification_id), + ); + } + + /** + * Mark this item read + * + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + public function mark_read($return = true) + { + return $this->mark(false, $return); + } + + /** + * Mark this item unread + * + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + public function mark_unread($return = true) + { + return $this->mark(true, $return); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $type_data Data unique to this notification type + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($type_data) + { + // Defaults + $this->data = array_merge(array( + 'item_id' => static::get_item_id($type_data), + 'item_type' => $this->get_item_type(), + 'item_parent_id' => static::get_item_parent_id($type_data), + + 'time' => time(), + 'unread' => true, + + 'data' => array(), + ), $this->data); + + $data = $this->data; + + $data['data'] = serialize($data['data']); + + return $data; + } + + /** + * Function for preparing the data for update in an SQL query + * (The service handles insertion) + * + * @param array $type_data Data unique to this notification type + * + * @return array Array of data ready to be updated in the database + */ + 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; + } + + /** + * -------------- Fall back functions ------------------- + */ + + /** + * URL to unsubscribe to this notification (fall-back) + * + * @param string|bool $method Method name to unsubscribe from (email|jabber|etc), False to unsubscribe from all notifications for this item + */ + public function get_unsubscribe_url($method = false) + { + return false; + } + + /** + * Get the user's avatar (fall-back) + */ + public function get_avatar() + { + return ''; + } + + /** + * Get the special items to load (fall-back) + */ + public function get_load_special() + { + return array(); + } + + /** + * Load the special items (fall-back) + */ + public static function load_special(ContainerBuilder $phpbb_container, $data, $notifications) + { + return; + } + + /** + * Is available (fall-back) + */ + public static function is_available(ContainerBuilder $phpbb_container) + { + return true; + } + + /** + * -------------- Helper functions ------------------- + */ + + /** + * Find the users who want to receive notifications (helper) + * + * @param ContainerBuilder $phpbb_container + * @param array $item_id The item_id to search for + * + * @return array + */ + protected static function _find_users_for_notification(ContainerBuilder $phpbb_container, $item_id, $options) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + $db = $phpbb_container->get('dbal.conn'); + + $rowset = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . static::get_item_type() . "' + AND item_id = " . (int) $item_id; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $rowset[$row['user_id']] = array(); + } + + $rowset[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + return $rowset; + } + + /** + * Get avatar helper + * + * @param int $user_id + * @return string + */ + protected function _get_avatar($user_id) + { + $user = $this->service->get_user($user_id); + + if (!function_exists('get_user_avatar')) + { + include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); + } + + return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height'], $user['username'], false, 'notifications-avatar'); + } + + /** + * Mark this item read/unread helper + * + * @param bool $unread Unread (True/False) (Default: False) + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + protected function mark($unread = true, $return = false) + { + $where = array( + 'item_type = ' . $this->db->sql_escape($this->item_type), + 'item_id = ' . (int) $this->item_id, + 'user_id = ' . (int) $this->user_id, + ); + $where = implode(' AND ' . $where); + + if ($return) + { + return $where; + } + + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + SET unread = ' . (bool) $unread . ' + WHERE ' . $where; + $this->db->sql_query($sql); + } +} diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php new file mode 100644 index 0000000000..51f23bc294 --- /dev/null +++ b/phpBB/includes/notification/type/bookmark.php @@ -0,0 +1,117 @@ + array(), + ), $options); + + $db = $phpbb_container->get('dbal.conn'); + + $users = array(); + + $sql = 'SELECT user_id + FROM ' . BOOKMARKS_TABLE . ' + WHERE ' . $db->sql_in_set('topic_id', $post['topic_id']) . ' + AND user_id <> ' . (int) $post['poster_id']; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $users[] = $row['user_id']; + } + $db->sql_freeresult($result); + + if (empty($users)) + { + return array(); + } + + $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + return $notify_users; + } +} diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php new file mode 100644 index 0000000000..8fa0102e3d --- /dev/null +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -0,0 +1,116 @@ + 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + ); + + /** + * 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 + * + * @return string + */ + public function get_title() + { + return $this->phpbb_container->get('user')->lang( + $this->language_key, + censor_text($this->get_data('topic_title')), + $this->get_data('disapprove_reason') + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return ''; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + return array_merge(parent::get_email_template_variables(), array( + 'REASON' => htmlspecialchars_decode($this->get_data('disapprove_reason')), + )); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $this->set_data('disapprove_reason', $post['disapprove_reason']); + + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); + + return $data; + } +} diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php new file mode 100644 index 0000000000..186c42d2b6 --- /dev/null +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -0,0 +1,116 @@ + 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + ); + + /** + * 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 + * + * @return string + */ + public function get_title() + { + return $this->phpbb_container->get('user')->lang( + $this->language_key, + censor_text($this->get_data('topic_title')), + $this->get_data('disapprove_reason') + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return ''; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + return array_merge(parent::get_email_template_variables(), array( + 'REASON' => htmlspecialchars_decode($this->get_data('disapprove_reason')), + )); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $this->set_data('disapprove_reason', $post['disapprove_reason']); + + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); + + return $data; + } +} diff --git a/phpBB/includes/notification/type/interface.php b/phpBB/includes/notification/type/interface.php new file mode 100644 index 0000000000..aa54c62a97 --- /dev/null +++ b/phpBB/includes/notification/type/interface.php @@ -0,0 +1,49 @@ + array(), + ), $options); + + $service = $phpbb_container->get('notifications'); + $db = $phpbb_container->get('dbal.conn'); + $user = $phpbb_container->get('user'); + + if (!sizeof($pm['recipients'])) + { + return array(); + } + + $service->load_users(array_keys($pm['recipients'])); + + $notify_users = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND " . $db->sql_in_set('user_id', array_keys($pm['recipients'])); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + return $notify_users; + } + + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('from_user_id')); + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + $user_data = $this->service->get_user($this->get_data('from_user_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + + return $this->phpbb_container->get('user')->lang('NOTIFICATION_PM', $username, $this->get_data('message_subject')); + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + $user_data = $this->service->get_user($this->get_data('from_user_id')); + + return array( + 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), + 'SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('message_subject'))), + + 'U_VIEW_MESSAGE' => generate_board_url() . '/ucp.' . $this->php_ext . "?i=pm&mode=view&p={$this->item_id}", + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=pm&mode=view&p={$this->item_id}"); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['from_user_id']); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($pm) + { + $this->set_data('from_user_id', $pm['from_user_id']); + + $this->set_data('message_subject', $pm['message_subject']); + + return parent::create_insert_array($pm); + } +} diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php new file mode 100644 index 0000000000..1e654ef51b --- /dev/null +++ b/phpBB/includes/notification/type/post.php @@ -0,0 +1,242 @@ + array(), + ), $options); + + // Let's continue to use the phpBB subscriptions system, at least for now. + // It may not be the nicest thing, but it is already working and it would be significant work to replace it + //$users = parent::_find_users_for_notification($phpbb_container, $post['topic_id']); + + $db = $phpbb_container->get('dbal.conn'); + + $users = array(); + + $sql = 'SELECT user_id + FROM ' . TOPICS_WATCH_TABLE . ' + WHERE topic_id = ' . (int) $post['topic_id'] . ' + AND notify_status = ' . NOTIFY_YES . ' + AND user_id <> ' . (int) $post['poster_id']; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $users[] = $row['user_id']; + } + $db->sql_freeresult($result); + + if (empty($users)) + { + return array(); + } + + $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + return $notify_users; + } + + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('poster_id')); + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + if ($this->get_data('post_username')) + { + $username = $this->get_data('post_username'); + } + else + { + $user_data = $this->service->get_user($this->get_data('poster_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + } + + return $this->phpbb_container->get('user')->lang( + $this->language_key, + $username, + censor_text($this->get_data('topic_title')) + ); + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + return array( + 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), + 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), + + 'U_VIEW_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", + 'U_NEWEST_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&view=unread#unread", + 'U_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + 'U_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}", + 'U_STOP_WATCHING_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?uid={$this->user_id}&f={$this->get_data('forum_id')}&t={$this->item_parent_id}&unwatch=topic", + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}"); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['poster_id']); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $this->set_data('poster_id', $post['poster_id']); + + $this->set_data('topic_title', $post['topic_title']); + + $this->set_data('post_subject', $post['post_subject']); + + $this->set_data('post_username', (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : '')); + + $this->set_data('forum_id', $post['forum_id']); + + $this->set_data('forum_name', $post['forum_name']); + + $this->time = $post['post_time']; + + return parent::create_insert_array($post); + } +} diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php new file mode 100644 index 0000000000..f0a5e0baec --- /dev/null +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -0,0 +1,137 @@ + 'needs_approval', + 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', + ); + + /** + * Get the type of notification this is + * phpbb_notification_type_ + */ + public static function get_item_type() + { + return 'post_in_queue'; + } + + /** + * Is available + */ + public static function is_available(ContainerBuilder $phpbb_container) + { + $m_approve = $phpbb_container->get('auth')->acl_getf('m_approve', true); + + return (!empty($m_approve)); + } + + /** + * Find the users who want to receive notifications + * + * @param ContainerBuilder $phpbb_container + * @param array $post Data from the post + * + * @return array + */ + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + $db = $phpbb_container->get('dbal.conn'); + + $auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $post['forum_id']); + + if (empty($auth_approve)) + { + return array(); + } + + $notify_users = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::$notification_option['id'] . "' + AND " . $db->sql_in_set('user_id', $auth_approve[$post['forum_id']]['m_approve']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + return $notify_users; + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); + + return $data; + } +} diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php new file mode 100644 index 0000000000..dd3cbedee2 --- /dev/null +++ b/phpBB/includes/notification/type/quote.php @@ -0,0 +1,209 @@ + array(), + ), $options); + + $db = $phpbb_container->get('dbal.conn'); + + $usernames = false; + preg_match_all(self::$regular_expression_match, $post['post_text'], $usernames); + + if (empty($usernames[1])) + { + return array(); + } + + $usernames[1] = array_unique($usernames[1]); + + $usernames = array_map('utf8_clean_string', $usernames[1]); + + $users = array(); + + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . ' + WHERE ' . $db->sql_in_set('username_clean', $usernames) . ' + AND user_id <> ' . (int) $post['poster_id']; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $users[] = $row['user_id']; + } + $db->sql_freeresult($result); + + if (empty($users)) + { + return array(); + } + + $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + return $notify_users; + } + + /** + * Update a notification + * + * @param ContainerBuilder $phpbb_container + * @param array $data Data specific for this type that will be updated + */ + public static function update_notifications(ContainerBuilder $phpbb_container, $post) + { + $service = $phpbb_container->get('notifications'); + $db = $phpbb_container->get('dbal.conn'); + + $old_notifications = array(); + $sql = 'SELECT user_id + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND item_id = " . self::get_item_id($post); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $old_notifications[] = $row['user_id']; + } + $db->sql_freeresult($result); + + // Find the new users to notify + $notifications = self::find_users_for_notification($phpbb_container, $post); + + // Find the notifications we must delete + $remove_notifications = array_diff($old_notifications, array_keys($notifications)); + + // Find the notifications we must add + $add_notifications = array(); + foreach (array_diff(array_keys($notifications), $old_notifications) as $user_id) + { + $add_notifications[$user_id] = $notifications[$user_id]; + } + + // todo Adding notifications while editing a post can be funky. + // If the user has read the topic/post already, and the user is newly quoted it an edit, + // The notification will be stuck as unread until another post is made and the user visits + // the topic again because the posts will not be marked as read since the topic is already + // marked as read + + // Add the necessary notifications + $service->add_notifications_for_users(self::get_item_type(), $post, $add_notifications); + + // Remove the necessary notifications + if (!empty($remove_notifications)) + { + $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND item_id = " . self::get_item_id($post) . ' + AND ' . $db->sql_in_set('user_id', $remove_notifications); + $db->sql_query($sql); + } + + // return true to continue with the update code in the notifications service (this will update the rest of the notifications) + return true; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + $user_data = $this->service->get_user($this->get_data('poster_id')); + + return array_merge(parent::get_email_template_variables(), array( + 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), + )); + } +} diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php new file mode 100644 index 0000000000..7753b196e8 --- /dev/null +++ b/phpBB/includes/notification/type/topic.php @@ -0,0 +1,237 @@ + array(), + ), $options); + + // Let's continue to use the phpBB subscriptions system, at least for now. + // It may not be the nicest thing, but it is already working and it would be significant work to replace it + //$users = parent::_find_users_for_notification($phpbb_container, $topic['forum_id']); + + $db = $phpbb_container->get('dbal.conn'); + + $users = array(); + + $sql = 'SELECT user_id + FROM ' . FORUMS_WATCH_TABLE . ' + WHERE forum_id = ' . (int) $topic['forum_id'] . ' + AND notify_status = ' . NOTIFY_YES . ' + AND user_id <> ' . (int) $topic['poster_id']; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $users[] = $row['user_id']; + } + $db->sql_freeresult($result); + + if (empty($users)) + { + return array(); + } + + $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $topic['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND " . $db->sql_in_set('user_id', $auth_read[$topic['forum_id']]['f_read']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + return $notify_users; + } + + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('poster_id')); + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + if ($this->get_data('post_username')) + { + $username = $this->get_data('post_username'); + } + else + { + $user_data = $this->service->get_user($this->get_data('poster_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + } + + return $this->phpbb_container->get('user')->lang( + $this->language_key, + $username, + censor_text($this->get_data('topic_title')), + $this->get_data('forum_name') + ); + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + return array( + 'FORUM_NAME' => htmlspecialchars_decode($this->get_data('forum_name')), + 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), + + 'U_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}", + 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}", + 'U_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->item_parent_id}", + 'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?uid={$this->user_id}&f={$this->item_parent_id}&unwatch=forum", + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "f={$this->item_parent_id}&t={$this->item_id}"); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['poster_id']); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $this->set_data('poster_id', $post['poster_id']); + + $this->set_data('topic_title', $post['topic_title']); + + $this->set_data('post_username', (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : '')); + + $this->set_data('forum_name', $post['forum_name']); + + $this->time = $post['post_time']; + + return parent::create_insert_array($post); + } +} diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php new file mode 100644 index 0000000000..385578cec8 --- /dev/null +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -0,0 +1,137 @@ + 'needs_approval', + 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', + ); + + /** + * Is available + */ + public static function is_available(ContainerBuilder $phpbb_container) + { + $m_approve = $phpbb_container->get('auth')->acl_getf('m_approve', true); + + 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 + * + * @param ContainerBuilder $phpbb_container + * @param array $topic Data from the topic + * + * @return array + */ + public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + $db = $phpbb_container->get('dbal.conn'); + + $auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $topic['forum_id']); + + if (empty($auth_approve)) + { + return array(); + } + + $notify_users = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::$notification_option['id'] . "' + AND " . $db->sql_in_set('user_id', $auth_approve[$topic['forum_id']]['m_approve']); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $db->sql_freeresult($result); + + return $notify_users; + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $topic Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($topic) + { + $data = parent::create_insert_array($topic); + + $this->time = $data['time'] = time(); + + return $data; + } +} diff --git a/phpBB/includes/notifications/method/base.php b/phpBB/includes/notifications/method/base.php deleted file mode 100644 index b502d3afd0..0000000000 --- a/phpBB/includes/notifications/method/base.php +++ /dev/null @@ -1,92 +0,0 @@ -phpbb_container = $phpbb_container; - - // Service - $this->service = $phpbb_container->get('notifications'); - - // Some common things we're going to use - $this->db = $phpbb_container->get('dbal.conn'); - $this->user = $phpbb_container->get('user'); - - $this->phpbb_root_path = $phpbb_container->getParameter('core.root_path'); - $this->php_ext = $phpbb_container->getParameter('core.php_ext'); - } - - /** - * Add a notification to the queue - * - * @param phpbb_notification_type_interface $notification - */ - public function add_to_queue(phpbb_notification_type_interface $notification) - { - $this->queue[] = $notification; - } - - /** - * Empty the queue - */ - protected function empty_queue() - { - $this->queue = array(); - } -} diff --git a/phpBB/includes/notifications/method/email.php b/phpBB/includes/notifications/method/email.php deleted file mode 100644 index 1b6b44d137..0000000000 --- a/phpBB/includes/notifications/method/email.php +++ /dev/null @@ -1,104 +0,0 @@ -queue)) - { - return; - } - - // Load all users we want to notify (we need their email address) - $user_ids = $users = array(); - foreach ($this->queue as $notification) - { - $user_ids[] = $notification->user_id; - } - - // We do not send emails to banned users - if (!function_exists('phpbb_get_banned_user_ids')) - { - include($this->phpbb_container->getParameter('core.root_path') . 'includes/functions_user.' . $this->phpbb_container->getParameter('core.php_ext')); - } - $banned_users = phpbb_get_banned_user_ids($user_ids); - - // Load all the users we need - $this->service->load_users($user_ids); - - // Load the messenger - if (!class_exists('messenger')) - { - include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext); - } - $messenger = new messenger(); - $board_url = generate_board_url(); - - // Time to go through the queue and send emails - foreach ($this->queue as $notification) - { - $user = $this->service->get_user($notification->user_id); - - if ($user['user_type'] == USER_IGNORE || in_array($notification->user_id, $banned_users)) - { - continue; - } - - $messenger->template($notification->email_template, $user['user_lang']); - - $messenger->to($user['user_email'], $user['username']); - - $messenger->assign_vars(array_merge(array( - 'USERNAME' => $user['username'], - - 'U_NOTIFICATION_SETTINGS' => generate_board_url() . '/ucp.' . $this->php_ext . '?i=ucp_notifications', - ), $notification->get_email_template_variables())); - - $messenger->send($this->notify_method); - } - - // Save the queue in the messenger class (has to be called or these emails could be lost?) - $messenger->save_queue(); - - // We're done, empty the queue - $this->empty_queue(); - } -} diff --git a/phpBB/includes/notifications/method/interface.php b/phpBB/includes/notifications/method/interface.php deleted file mode 100644 index 4b990ec9fa..0000000000 --- a/phpBB/includes/notifications/method/interface.php +++ /dev/null @@ -1,27 +0,0 @@ -global_available() && $this->phpbb_container->get('user')->data['jabber']); - } - - /** - * Is this method available at all? - * This is checked before notifications are sent - */ - public function global_available() - { - $config = $this->phpbb_container->get('config'); - - return ($config['jab_enable'] && @extension_loaded('xml')); - } - - public function notify() - { - if (!$this->global_available()) - { - return; - } - - return parent::notify(); - } -} diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php deleted file mode 100644 index 2bf21cefa5..0000000000 --- a/phpBB/includes/notifications/service.php +++ /dev/null @@ -1,688 +0,0 @@ -phpbb_container = $phpbb_container; - - // Some common things we're going to use - $this->db = $phpbb_container->get('dbal.conn'); - } - - /** - * Load the user's notifications - * - * @param array $options Optional options to control what notifications are loaded - * notification_id Notification id to load (or array of notification ids) - * user_id User id to load notifications for (Default: $user->data['user_id']) - * order_by Order by (Default: time) - * order_dir Order direction (Default: DESC) - * limit Number of notifications to load (Default: 5) - * start Notifications offset (Default: 0) - * all_unread Load all unread messages? If set to true, count_unread is set to true (Default: false) - * count_unread Count all unread messages? (Default: false) - */ - public function load_notifications($options = array()) - { - $user = $this->phpbb_container->get('user'); - - // Merge default options - $options = array_merge(array( - 'notification_id' => false, - 'user_id' => $user->data['user_id'], - 'order_by' => 'time', - 'order_dir' => 'DESC', - 'limit' => 0, - 'start' => 0, - 'all_unread' => false, - 'count_unread' => false, - ), $options); - - // If all_unread, count_unread mus be true - $options['count_unread'] = ($options['all_unread']) ? true : $options['count_unread']; - - // Anonymous users and bots never receive notifications - if ($options['user_id'] == $user->data['user_id'] && ($user->data['user_id'] == ANONYMOUS || $user->data['user_type'] == USER_IGNORE)) - { - return array( - 'notifications' => array(), - 'unread_count' => 0, - ); - } - - $notifications = $user_ids = array(); - $load_special = array(); - $count = 0; - - if ($options['count_unread']) - { - // Get the total number of unread notifications - $sql = 'SELECT COUNT(*) AS count - FROM ' . NOTIFICATIONS_TABLE . ' - WHERE user_id = ' . (int) $options['user_id'] . ' - AND unread = 1'; - $result = $this->db->sql_query($sql); - $count = (int) $this->db->sql_fetchfield('count', $result); - $this->db->sql_freeresult($result); - } - - $rowset = array(); - - // 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']) : '') . ' - 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); - - // Get all unread notifications - if ($count && $options['all_unread'] && !empty($rowset)) - { - $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) . ' - 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); - } - - foreach ($rowset as $row) - { - $item_type_class_name = $this->get_item_type_class_name($row['item_type'], true); - - $notification = new $item_type_class_name($this->phpbb_container, $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(); - } - $load_special[$row['item_type']] = array_merge($load_special[$row['item_type']], $notification->get_load_special()); - - $notifications[] = $notification; - } - - $this->load_users($user_ids); - - // Allow each type to load it's own special items - foreach ($load_special as $item_type => $data) - { - $item_type_class_name = $this->get_item_type_class_name($item_type, true); - - $item_type_class_name::load_special($this->phpbb_container, $data, $notifications); - } - - return array( - 'notifications' => $notifications, - 'unread_count' => $count, - ); - } - - /** - * Mark notifications read - * - * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) - * @param bool|int|array $item_id Item id or array of item ids. False to mark read for all item ids - * @param bool|int|array $user_id User id or array of user ids. False to mark read for all user ids - * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False) - */ - public function mark_notifications_read($item_type, $item_id, $user_id, $time = false) - { - if (is_array($item_type)) - { - foreach ($item_type as $type) - { - $this->mark_notifications_read($type, $item_id, $user_id, $time); - } - - return; - } - - $time = ($time) ?: time(); - - $this->get_item_type_class_name($item_type); - - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " - SET unread = 0 - WHERE item_type = '" . $this->db->sql_escape($item_type) . "' - AND time <= " . $time . - (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : '') . - (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); - $this->db->sql_query($sql); - } - - /** - * Mark notifications read from a parent identifier - * - * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) - * @param bool|int|array $item_parent_id Item parent id or array of item parent ids. False to mark read for all item parent ids - * @param bool|int|array $user_id User id or array of user ids. False to mark read for all user ids - * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False) - */ - public function mark_notifications_read_by_parent($item_type, $item_parent_id, $user_id, $time = false) - { - if (is_array($item_type)) - { - foreach ($item_type as $type) - { - $this->mark_notifications_read_by_parent($type, $item_parent_id, $user_id, $time); - } - - return; - } - - $time = ($time) ?: time(); - - $item_type_class_name = $this->get_item_type_class_name($item_type); - - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " - SET unread = 0 - WHERE item_type = '" . $this->db->sql_escape($item_type) . "' - AND time <= " . $time . - (($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id) : 'item_parent_id = ' . (int) $item_parent_id) : '') . - (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); - $this->db->sql_query($sql); - } - - /** - * Mark notifications read - * - * @param int|array $notification_id Notification id or array of notification ids. - * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False) - */ - public function mark_notifications_read_by_id($notification_id, $time = false) - { - $time = ($time) ?: time(); - - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " - SET unread = 0 - WHERE time <= " . $time . ' - AND ' . ((is_array($notification_id)) ? $this->db->sql_in_set('notification_id', $notification_id) : 'notification_id = ' . (int) $notification_id); - $this->db->sql_query($sql); - } - - /** - * Add a notification - * - * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) - * Note: If you send an array of types, any user who could receive multiple notifications from this single item will only receive - * a single notification. If they MUST receive multiple notifications, call this function multiple times instead of sending an array - * @param array $data Data specific for this type that will be inserted - */ - public function add_notifications($item_type, $data, $options = array()) - { - $options = array_merge(array( - 'ignore_users' => array(), - ), $options); - - if (is_array($item_type)) - { - $notified_users = array(); - $temp_options = $options; - - foreach ($item_type as $type) - { - $temp_options['ignore_users'] = $options['ignore_users'] + $notified_users; - $notified_users += $this->add_notifications($type, $data, $temp_options); - } - - return $notified_users; - } - - $item_type_class_name = $this->get_item_type_class_name($item_type); - - $item_id = $item_type_class_name::get_item_id($data); - - // find out which users want to receive this type of notification - $notify_users = $item_type_class_name::find_users_for_notification($this->phpbb_container, $data, $options); - - $this->add_notifications_for_users($item_type, $data, $notify_users); - - return $notify_users; - } - - /** - * Add a notification for specific users - * - * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) - * @param array $data Data specific for this type that will be inserted - * @param array $notify_users User list to notify - */ - public function add_notifications_for_users($item_type, $data, $notify_users) - { - if (is_array($item_type)) - { - foreach ($item_type as $type) - { - $this->add_notifications_for_users($type, $data, $notify_users); - } - - return; - } - - $item_type_class_name = $this->get_item_type_class_name($item_type); - - $item_id = $item_type_class_name::get_item_id($data); - - $user_ids = array(); - $notification_objects = $notification_methods = array(); - $new_rows = array(); - - // Never send notifications to the anonymous user! - unset($notify_users[ANONYMOUS]); - - // Make sure not to send new notifications to users who've already been notified about this item - // This may happen when an item was added, but now new users are able to see the item - // todo Users should not receive notifications from multiple events from the same item (ex: for a topic reply with a quote including your username) - // Probably should be handled within each type? - $sql = 'SELECT user_id - FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . $this->db->sql_escape($item_type) . "' - AND item_id = " . (int) $item_id; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - unset($notify_users[$row['user_id']]); - } - $this->db->sql_freeresult($result); - - if (!sizeof($notify_users)) - { - return; - } - - // 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) - { - $notification = new $item_type_class_name($this->phpbb_container); - - $notification->user_id = (int) $user; - - // Store the creation array in our new rows that will be inserted later - $new_rows[] = $notification->create_insert_array($data); - - // Users are needed to send notifications - $user_ids = array_merge($user_ids, $notification->users_to_query()); - - foreach ($methods as $method) - { - // setup the notification methods and add the notification to the queue - if ($method) // blank means we just insert it as a notification, but do not notify them by any other means - { - if (!isset($notification_methods[$method])) - { - $method_class_name = 'phpbb_notifications_method_' . $method; - $notification_methods[$method] = new $method_class_name($this->phpbb_container); - } - - $notification_methods[$method]->add_to_queue($notification); - } - } - } - - // insert into the db - $this->db->sql_multi_insert(NOTIFICATIONS_TABLE, $new_rows); - - // We need to load all of the users to send notifications - $this->load_users($user_ids); - - // run the queue for each method to send notifications - foreach ($notification_methods as $method) - { - $method->notify(); - } - } - - /** - * Update a notification - * - * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) - * @param array $data Data specific for this type that will be updated - */ - public function update_notifications($item_type, $data) - { - if (is_array($item_type)) - { - foreach ($item_type as $type) - { - $this->update_notifications($type, $data); - } - - return; - } - - $item_type_class_name = $this->get_item_type_class_name($item_type); - - // Allow the notifications class to over-ride the update_notifications functionality - if (method_exists($item_type_class_name, 'update_notifications')) - { - // Return False to over-ride the rest of the update - if ($item_type_class_name::update_notifications($this->phpbb_container, $data) === false) - { - return; - } - } - - $item_id = $item_type_class_name::get_item_id($data); - - $notification = new $item_type_class_name($this->phpbb_container); - $update_array = $notification->create_update_array($data); - - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $update_array) . " - WHERE item_type = '" . $this->db->sql_escape($item_type) . "' - AND item_id = " . (int) $item_id; - $this->db->sql_query($sql); - } - - /** - * Delete a notification - * - * @param string|array $item_type Type identifier or array of item types (only acceptable if the $item_id is identical for the specified types) - * @param int|array $item_id Identifier within the type (or array of ids) - * @param array $data Data specific for this type that will be updated - */ - public function delete_notifications($item_type, $item_id) - { - if (is_array($item_type)) - { - foreach ($item_type as $type) - { - $this->delete_notifications($type, $item_id); - } - - return; - } - - $this->get_item_type_class_name($item_type); - - $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " - 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); - $this->db->sql_query($sql); - } - - /** - * Get all of the subscription types - * - * @return array Array of item types - */ - public function get_subscription_types() - { - $subscription_types = array(); - - foreach ($this->get_subscription_files('notifications/type/') as $class => $file) - { - $class = $this->get_item_type_class_name($class); - - if (!class_exists($class)) - { - include($file); - } - - if ($class::is_available($this->phpbb_container) && method_exists($class, 'get_item_type')) - { - if ($class::$notification_option === false) - { - $subscription_types[$class::get_item_type()] = $class::get_item_type(); - } - else - { - $subscription_types[$class::$notification_option['id']] = $class::$notification_option; - } - } - } - - return $subscription_types; - } - - /** - * Get all of the subscription methods - * - * @return array Array of methods - */ - public function get_subscription_methods() - { - $subscription_methods = array(); - - foreach ($this->get_subscription_files('notifications/method/') as $method_name => $file) - { - $class_name = 'phpbb_notifications_method_' . $method_name; - - if (!class_exists($class_name)) - { - include($file); - } - - $method = new $class_name($this->phpbb_container); - - if ($method->is_available()) - { - $subscription_methods[] = $method_name; - } - } - - return $subscription_methods; - } - - /** - * Get subscriptions - * - * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) - * @param bool $only_global True to select only global subscription options (item_id = 0) - * - * @return array Subscriptions - */ - public function get_subscriptions($user_id = false, $only_global = false) - { - $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; - - $subscriptions = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . ' - WHERE user_id = ' . (int) $user_id . - (($only_global) ? ' AND item_id = 0' : ''); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if ($only_global) - { - if (!isset($subscriptions[$row['item_type']])) - { - $subscriptions[$row['item_type']] = array(); - } - - $subscriptions[$row['item_type']][] = $row['method']; - } - else - { - $subscriptions[] = $row; - } - } - $this->db->sql_freeresult($result); - - return $subscriptions; - } - - /** - * Add a subscription - * - * @param string $item_type Type identifier of the subscription - * @param int $item_id The id of the item - * @param string $method The method of the notification e.g. '', 'email', or 'jabber' - * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) - */ - public function add_subscription($item_type, $item_id = 0, $method = '', $user_id = false) - { - $this->get_item_type_class_name($item_type); - - $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; - - $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . - $this->db->sql_build_array('INSERT', array( - 'item_type' => $item_type, - 'item_id' => (int) $item_id, - 'user_id' => (int) $user_id, - 'method' => $method, - )); - $this->db->sql_query($sql); - } - - /** - * Delete a subscription - * - * @param string $item_type Type identifier of the subscription - * @param int $item_id The id of the item - * @param string $method The method of the notification e.g. '', 'email', or 'jabber' - * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) - */ - public function delete_subscription($item_type, $item_id = 0, $method = '', $user_id = false) - { - $this->get_item_type_class_name($item_type); - - $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; - - $sql = 'DELETE FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . $this->db->sql_escape($item_type) . "' - AND item_id = " . (int) $item_id . ' - AND user_id = ' .(int) $user_id . " - AND method = '" . $this->db->sql_escape($method) . "'"; - $this->db->sql_query($sql); - } - - /** - * Load user helper - * - * @param array $user_ids - */ - public function load_users($user_ids) - { - $user_ids[] = ANONYMOUS; - - // Load the users - $user_ids = array_unique($user_ids); - - // Do not load users we already have in $this->users - $user_ids = array_diff($user_ids, array_keys($this->users)); - - if (sizeof($user_ids)) - { - $sql = 'SELECT * - FROM ' . USERS_TABLE . ' - WHERE ' . $this->db->sql_in_set('user_id', $user_ids); - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $this->users[$row['user_id']] = $row; - } - $this->db->sql_freeresult($result); - } - } - - /** - * Get a user row from our users cache - * - * @param int $user_id - * @return array - */ - public function get_user($user_id) - { - 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); - } - - return 'phpbb_notifications_type_' . $item_type; - } - - /** - * Helper to get subscription related files with the finder - */ - private function get_subscription_files($path) - { - $ext_manager = $this->phpbb_container->get('ext.manager'); - $php_ext = $this->phpbb_container->getParameter('core.php_ext'); - - $finder = $ext_manager->get_finder(); - - $subscription_files = array(); - - $files = $finder - ->core_path('includes/' . $path) - ->extension_directory($path) - ->get_files(); - foreach ($files as $file) - { - $class = substr($file, strrpos($file, '/')); - $class = substr($class, 1, (strpos($class, '.' . $php_ext) - 1)); - - if ($class == 'interface' || $class == 'base') - { - continue; - } - - $subscription_files[$class] = $file; - } - - return $subscription_files; - } -} diff --git a/phpBB/includes/notifications/type/approve_post.php b/phpBB/includes/notifications/type/approve_post.php deleted file mode 100644 index 9a3def6217..0000000000 --- a/phpBB/includes/notifications/type/approve_post.php +++ /dev/null @@ -1,132 +0,0 @@ - 'moderation_queue', - 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', - ); - - /** - * Get the type of notification this is - * phpbb_notification_type_ - */ - public static function get_item_type() - { - return 'approve_post'; - } - - /** - * Find the users who want to receive notifications - * - * @param ContainerBuilder $phpbb_container - * @param array $post Data from - * - * @return array - */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) - { - $options = array_merge(array( - 'ignore_users' => array(), - ), $options); - - $db = $phpbb_container->get('dbal.conn'); - - $users = array(); - $users[$post['poster_id']] = array(''); - - $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); - - if (empty($auth_read)) - { - return array(); - } - - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $db->sql_freeresult($result); - - return $notify_users; - } - - /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $post Data from submit_post - * - * @return array Array of data ready to be inserted into the database - */ - public function create_insert_array($post) - { - $this->set_data('post_subject', $post['post_subject']); - - $data = parent::create_insert_array($post); - - $this->time = $data['time'] = time(); - - return $data; - } -} diff --git a/phpBB/includes/notifications/type/approve_topic.php b/phpBB/includes/notifications/type/approve_topic.php deleted file mode 100644 index 00af312018..0000000000 --- a/phpBB/includes/notifications/type/approve_topic.php +++ /dev/null @@ -1,130 +0,0 @@ - 'moderation_queue', - 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', - ); - - /** - * Get the type of notification this is - * phpbb_notification_type_ - */ - public static function get_item_type() - { - return 'approve_topic'; - } - - /** - * Find the users who want to receive notifications - * - * @param ContainerBuilder $phpbb_container - * @param array $post Data from - * - * @return array - */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) - { - $options = array_merge(array( - 'ignore_users' => array(), - ), $options); - - $db = $phpbb_container->get('dbal.conn'); - - $users = array(); - $users[$post['poster_id']] = array(''); - - $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); - - if (empty($auth_read)) - { - return array(); - } - - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $db->sql_freeresult($result); - - return $notify_users; - } - - /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $post Data from submit_post - * - * @return array Array of data ready to be inserted into the database - */ - public function create_insert_array($post) - { - $data = parent::create_insert_array($post); - - $this->time = $data['time'] = time(); - - return $data; - } -} diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php deleted file mode 100644 index 40462bccfb..0000000000 --- a/phpBB/includes/notifications/type/base.php +++ /dev/null @@ -1,345 +0,0 @@ - forum_id, for post => topic_id, etc) - * user_id - * unread - * - * time - * data (special serialized field that each notification type can use to store stuff) - * - * @var array $data Notification row from the database - * This must be private, all interaction should use __get(), __set(), get_data(), set_data() - */ - private $data = array(); - - public function __construct(ContainerBuilder $phpbb_container, $data = array()) - { - // phpBB Container - $this->phpbb_container = $phpbb_container; - - // Service - $this->service = $phpbb_container->get('notifications'); - - // Some common things we're going to use - $this->db = $phpbb_container->get('dbal.conn'); - - $this->phpbb_root_path = $phpbb_container->getParameter('core.root_path'); - $this->php_ext = $phpbb_container->getParameter('core.php_ext'); - - // The row from the database (unless this is a new notification we're going to add) - $this->data = $data; - $this->data['data'] = (isset($this->data['data'])) ? unserialize($this->data['data']) : array(); - } - - public function __get($name) - { - return $this->data[$name]; - } - - public function __set($name, $value) - { - $this->data[$name] = $value; - } - - /** - * Get special data (only important for the classes that extend this) - * - * @param string $name Name of the variable to get - * - * @return mixed - */ - protected function get_data($name) - { - return (isset($this->data['data'][$name])) ? $this->data['data'][$name] : null; - } - - /** - * Set special data (only important for the classes that extend this) - * - * @param string $name Name of the variable to set - * @param mixed $value Value to set to the variable - */ - protected function set_data($name, $value) - { - $this->data['data'][$name] = $value; - } - - /** - * Prepare to output the notification to the template - */ - public function prepare_for_display() - { - $user = $this->phpbb_container->get('user'); - - return array( - 'AVATAR' => $this->get_avatar(), - - 'FORMATTED_TITLE' => $this->get_title(), - - 'URL' => $this->get_url(), - 'TIME' => $user->format_date($this->time), - - 'UNREAD' => $this->unread, - - 'U_MARK_READ' => append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification[]=' . $this->notification_id), - ); - } - - /** - * Mark this item read - * - * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) - * @return string - */ - public function mark_read($return = true) - { - return $this->mark(false, $return); - } - - /** - * Mark this item unread - * - * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) - * @return string - */ - public function mark_unread($return = true) - { - return $this->mark(true, $return); - } - - /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $type_data Data unique to this notification type - * - * @return array Array of data ready to be inserted into the database - */ - public function create_insert_array($type_data) - { - // Defaults - $this->data = array_merge(array( - 'item_id' => static::get_item_id($type_data), - 'item_type' => $this->get_item_type(), - 'item_parent_id' => static::get_item_parent_id($type_data), - - 'time' => time(), - 'unread' => true, - - 'data' => array(), - ), $this->data); - - $data = $this->data; - - $data['data'] = serialize($data['data']); - - return $data; - } - - /** - * Function for preparing the data for update in an SQL query - * (The service handles insertion) - * - * @param array $type_data Data unique to this notification type - * - * @return array Array of data ready to be updated in the database - */ - 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; - } - - /** - * -------------- Fall back functions ------------------- - */ - - /** - * URL to unsubscribe to this notification (fall-back) - * - * @param string|bool $method Method name to unsubscribe from (email|jabber|etc), False to unsubscribe from all notifications for this item - */ - public function get_unsubscribe_url($method = false) - { - return false; - } - - /** - * Get the user's avatar (fall-back) - */ - public function get_avatar() - { - return ''; - } - - /** - * Get the special items to load (fall-back) - */ - public function get_load_special() - { - return array(); - } - - /** - * Load the special items (fall-back) - */ - public static function load_special(ContainerBuilder $phpbb_container, $data, $notifications) - { - return; - } - - /** - * Is available (fall-back) - */ - public static function is_available(ContainerBuilder $phpbb_container) - { - return true; - } - - /** - * -------------- Helper functions ------------------- - */ - - /** - * Find the users who want to receive notifications (helper) - * - * @param ContainerBuilder $phpbb_container - * @param array $item_id The item_id to search for - * - * @return array - */ - protected static function _find_users_for_notification(ContainerBuilder $phpbb_container, $item_id, $options) - { - $options = array_merge(array( - 'ignore_users' => array(), - ), $options); - - $db = $phpbb_container->get('dbal.conn'); - - $rowset = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . static::get_item_type() . "' - AND item_id = " . (int) $item_id; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $rowset[$row['user_id']] = array(); - } - - $rowset[$row['user_id']][] = $row['method']; - } - $db->sql_freeresult($result); - - return $rowset; - } - - /** - * Get avatar helper - * - * @param int $user_id - * @return string - */ - protected function _get_avatar($user_id) - { - $user = $this->service->get_user($user_id); - - if (!function_exists('get_user_avatar')) - { - include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); - } - - return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height'], $user['username'], false, 'notifications-avatar'); - } - - /** - * Mark this item read/unread helper - * - * @param bool $unread Unread (True/False) (Default: False) - * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) - * @return string - */ - protected function mark($unread = true, $return = false) - { - $where = array( - 'item_type = ' . $this->db->sql_escape($this->item_type), - 'item_id = ' . (int) $this->item_id, - 'user_id = ' . (int) $this->user_id, - ); - $where = implode(' AND ' . $where); - - if ($return) - { - return $where; - } - - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' - SET unread = ' . (bool) $unread . ' - WHERE ' . $where; - $this->db->sql_query($sql); - } -} diff --git a/phpBB/includes/notifications/type/bookmark.php b/phpBB/includes/notifications/type/bookmark.php deleted file mode 100644 index 51f23bc294..0000000000 --- a/phpBB/includes/notifications/type/bookmark.php +++ /dev/null @@ -1,117 +0,0 @@ - array(), - ), $options); - - $db = $phpbb_container->get('dbal.conn'); - - $users = array(); - - $sql = 'SELECT user_id - FROM ' . BOOKMARKS_TABLE . ' - WHERE ' . $db->sql_in_set('topic_id', $post['topic_id']) . ' - AND user_id <> ' . (int) $post['poster_id']; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - $users[] = $row['user_id']; - } - $db->sql_freeresult($result); - - if (empty($users)) - { - return array(); - } - - $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); - - if (empty($auth_read)) - { - return array(); - } - - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $db->sql_freeresult($result); - - return $notify_users; - } -} diff --git a/phpBB/includes/notifications/type/disapprove_post.php b/phpBB/includes/notifications/type/disapprove_post.php deleted file mode 100644 index 8fa0102e3d..0000000000 --- a/phpBB/includes/notifications/type/disapprove_post.php +++ /dev/null @@ -1,116 +0,0 @@ - 'moderation_queue', - 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', - ); - - /** - * 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 - * - * @return string - */ - public function get_title() - { - return $this->phpbb_container->get('user')->lang( - $this->language_key, - censor_text($this->get_data('topic_title')), - $this->get_data('disapprove_reason') - ); - } - - /** - * Get the url to this item - * - * @return string URL - */ - public function get_url() - { - return ''; - } - - /** - * Get email template variables - * - * @return array - */ - public function get_email_template_variables() - { - return array_merge(parent::get_email_template_variables(), array( - 'REASON' => htmlspecialchars_decode($this->get_data('disapprove_reason')), - )); - } - - /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $post Data from submit_post - * - * @return array Array of data ready to be inserted into the database - */ - public function create_insert_array($post) - { - $this->set_data('disapprove_reason', $post['disapprove_reason']); - - $data = parent::create_insert_array($post); - - $this->time = $data['time'] = time(); - - return $data; - } -} diff --git a/phpBB/includes/notifications/type/disapprove_topic.php b/phpBB/includes/notifications/type/disapprove_topic.php deleted file mode 100644 index 186c42d2b6..0000000000 --- a/phpBB/includes/notifications/type/disapprove_topic.php +++ /dev/null @@ -1,116 +0,0 @@ - 'moderation_queue', - 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', - ); - - /** - * 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 - * - * @return string - */ - public function get_title() - { - return $this->phpbb_container->get('user')->lang( - $this->language_key, - censor_text($this->get_data('topic_title')), - $this->get_data('disapprove_reason') - ); - } - - /** - * Get the url to this item - * - * @return string URL - */ - public function get_url() - { - return ''; - } - - /** - * Get email template variables - * - * @return array - */ - public function get_email_template_variables() - { - return array_merge(parent::get_email_template_variables(), array( - 'REASON' => htmlspecialchars_decode($this->get_data('disapprove_reason')), - )); - } - - /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $post Data from submit_post - * - * @return array Array of data ready to be inserted into the database - */ - public function create_insert_array($post) - { - $this->set_data('disapprove_reason', $post['disapprove_reason']); - - $data = parent::create_insert_array($post); - - $this->time = $data['time'] = time(); - - return $data; - } -} diff --git a/phpBB/includes/notifications/type/interface.php b/phpBB/includes/notifications/type/interface.php deleted file mode 100644 index aa54c62a97..0000000000 --- a/phpBB/includes/notifications/type/interface.php +++ /dev/null @@ -1,49 +0,0 @@ - array(), - ), $options); - - $service = $phpbb_container->get('notifications'); - $db = $phpbb_container->get('dbal.conn'); - $user = $phpbb_container->get('user'); - - if (!sizeof($pm['recipients'])) - { - return array(); - } - - $service->load_users(array_keys($pm['recipients'])); - - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', array_keys($pm['recipients'])); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $db->sql_freeresult($result); - - return $notify_users; - } - - /** - * Get the user's avatar - */ - public function get_avatar() - { - return $this->_get_avatar($this->get_data('from_user_id')); - } - - /** - * Get the HTML formatted title of this notification - * - * @return string - */ - public function get_title() - { - $user_data = $this->service->get_user($this->get_data('from_user_id')); - - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); - - return $this->phpbb_container->get('user')->lang('NOTIFICATION_PM', $username, $this->get_data('message_subject')); - } - - /** - * Get email template variables - * - * @return array - */ - public function get_email_template_variables() - { - $user_data = $this->service->get_user($this->get_data('from_user_id')); - - return array( - 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), - 'SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('message_subject'))), - - 'U_VIEW_MESSAGE' => generate_board_url() . '/ucp.' . $this->php_ext . "?i=pm&mode=view&p={$this->item_id}", - ); - } - - /** - * Get the url to this item - * - * @return string URL - */ - public function get_url() - { - return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=pm&mode=view&p={$this->item_id}"); - } - - /** - * Users needed to query before this notification can be displayed - * - * @return array Array of user_ids - */ - public function users_to_query() - { - return array($this->data['from_user_id']); - } - - /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $post Data from submit_post - * - * @return array Array of data ready to be inserted into the database - */ - public function create_insert_array($pm) - { - $this->set_data('from_user_id', $pm['from_user_id']); - - $this->set_data('message_subject', $pm['message_subject']); - - return parent::create_insert_array($pm); - } -} diff --git a/phpBB/includes/notifications/type/post.php b/phpBB/includes/notifications/type/post.php deleted file mode 100644 index 1e654ef51b..0000000000 --- a/phpBB/includes/notifications/type/post.php +++ /dev/null @@ -1,242 +0,0 @@ - array(), - ), $options); - - // Let's continue to use the phpBB subscriptions system, at least for now. - // It may not be the nicest thing, but it is already working and it would be significant work to replace it - //$users = parent::_find_users_for_notification($phpbb_container, $post['topic_id']); - - $db = $phpbb_container->get('dbal.conn'); - - $users = array(); - - $sql = 'SELECT user_id - FROM ' . TOPICS_WATCH_TABLE . ' - WHERE topic_id = ' . (int) $post['topic_id'] . ' - AND notify_status = ' . NOTIFY_YES . ' - AND user_id <> ' . (int) $post['poster_id']; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - $users[] = $row['user_id']; - } - $db->sql_freeresult($result); - - if (empty($users)) - { - return array(); - } - - $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); - - if (empty($auth_read)) - { - return array(); - } - - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $db->sql_freeresult($result); - - return $notify_users; - } - - /** - * Get the user's avatar - */ - public function get_avatar() - { - return $this->_get_avatar($this->get_data('poster_id')); - } - - /** - * Get the HTML formatted title of this notification - * - * @return string - */ - public function get_title() - { - if ($this->get_data('post_username')) - { - $username = $this->get_data('post_username'); - } - else - { - $user_data = $this->service->get_user($this->get_data('poster_id')); - - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); - } - - return $this->phpbb_container->get('user')->lang( - $this->language_key, - $username, - censor_text($this->get_data('topic_title')) - ); - } - - /** - * Get email template variables - * - * @return array - */ - public function get_email_template_variables() - { - return array( - 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), - 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), - - 'U_VIEW_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", - 'U_NEWEST_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&view=unread#unread", - 'U_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", - 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", - 'U_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}", - 'U_STOP_WATCHING_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?uid={$this->user_id}&f={$this->get_data('forum_id')}&t={$this->item_parent_id}&unwatch=topic", - ); - } - - /** - * Get the url to this item - * - * @return string URL - */ - public function get_url() - { - return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}"); - } - - /** - * Users needed to query before this notification can be displayed - * - * @return array Array of user_ids - */ - public function users_to_query() - { - return array($this->data['poster_id']); - } - - /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $post Data from submit_post - * - * @return array Array of data ready to be inserted into the database - */ - public function create_insert_array($post) - { - $this->set_data('poster_id', $post['poster_id']); - - $this->set_data('topic_title', $post['topic_title']); - - $this->set_data('post_subject', $post['post_subject']); - - $this->set_data('post_username', (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : '')); - - $this->set_data('forum_id', $post['forum_id']); - - $this->set_data('forum_name', $post['forum_name']); - - $this->time = $post['post_time']; - - return parent::create_insert_array($post); - } -} diff --git a/phpBB/includes/notifications/type/post_in_queue.php b/phpBB/includes/notifications/type/post_in_queue.php deleted file mode 100644 index f0a5e0baec..0000000000 --- a/phpBB/includes/notifications/type/post_in_queue.php +++ /dev/null @@ -1,137 +0,0 @@ - 'needs_approval', - 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', - ); - - /** - * Get the type of notification this is - * phpbb_notification_type_ - */ - public static function get_item_type() - { - return 'post_in_queue'; - } - - /** - * Is available - */ - public static function is_available(ContainerBuilder $phpbb_container) - { - $m_approve = $phpbb_container->get('auth')->acl_getf('m_approve', true); - - return (!empty($m_approve)); - } - - /** - * Find the users who want to receive notifications - * - * @param ContainerBuilder $phpbb_container - * @param array $post Data from the post - * - * @return array - */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) - { - $options = array_merge(array( - 'ignore_users' => array(), - ), $options); - - $db = $phpbb_container->get('dbal.conn'); - - $auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $post['forum_id']); - - if (empty($auth_approve)) - { - return array(); - } - - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $db->sql_in_set('user_id', $auth_approve[$post['forum_id']]['m_approve']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $db->sql_freeresult($result); - - return $notify_users; - } - - /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $post Data from submit_post - * - * @return array Array of data ready to be inserted into the database - */ - public function create_insert_array($post) - { - $data = parent::create_insert_array($post); - - $this->time = $data['time'] = time(); - - return $data; - } -} diff --git a/phpBB/includes/notifications/type/quote.php b/phpBB/includes/notifications/type/quote.php deleted file mode 100644 index dd3cbedee2..0000000000 --- a/phpBB/includes/notifications/type/quote.php +++ /dev/null @@ -1,209 +0,0 @@ - array(), - ), $options); - - $db = $phpbb_container->get('dbal.conn'); - - $usernames = false; - preg_match_all(self::$regular_expression_match, $post['post_text'], $usernames); - - if (empty($usernames[1])) - { - return array(); - } - - $usernames[1] = array_unique($usernames[1]); - - $usernames = array_map('utf8_clean_string', $usernames[1]); - - $users = array(); - - $sql = 'SELECT user_id - FROM ' . USERS_TABLE . ' - WHERE ' . $db->sql_in_set('username_clean', $usernames) . ' - AND user_id <> ' . (int) $post['poster_id']; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - $users[] = $row['user_id']; - } - $db->sql_freeresult($result); - - if (empty($users)) - { - return array(); - } - - $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); - - if (empty($auth_read)) - { - return array(); - } - - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $db->sql_freeresult($result); - - return $notify_users; - } - - /** - * Update a notification - * - * @param ContainerBuilder $phpbb_container - * @param array $data Data specific for this type that will be updated - */ - public static function update_notifications(ContainerBuilder $phpbb_container, $post) - { - $service = $phpbb_container->get('notifications'); - $db = $phpbb_container->get('dbal.conn'); - - $old_notifications = array(); - $sql = 'SELECT user_id - FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::get_item_type() . "' - AND item_id = " . self::get_item_id($post); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - $old_notifications[] = $row['user_id']; - } - $db->sql_freeresult($result); - - // Find the new users to notify - $notifications = self::find_users_for_notification($phpbb_container, $post); - - // Find the notifications we must delete - $remove_notifications = array_diff($old_notifications, array_keys($notifications)); - - // Find the notifications we must add - $add_notifications = array(); - foreach (array_diff(array_keys($notifications), $old_notifications) as $user_id) - { - $add_notifications[$user_id] = $notifications[$user_id]; - } - - // todo Adding notifications while editing a post can be funky. - // If the user has read the topic/post already, and the user is newly quoted it an edit, - // The notification will be stuck as unread until another post is made and the user visits - // the topic again because the posts will not be marked as read since the topic is already - // marked as read - - // Add the necessary notifications - $service->add_notifications_for_users(self::get_item_type(), $post, $add_notifications); - - // Remove the necessary notifications - if (!empty($remove_notifications)) - { - $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::get_item_type() . "' - AND item_id = " . self::get_item_id($post) . ' - AND ' . $db->sql_in_set('user_id', $remove_notifications); - $db->sql_query($sql); - } - - // return true to continue with the update code in the notifications service (this will update the rest of the notifications) - return true; - } - - /** - * Get email template variables - * - * @return array - */ - public function get_email_template_variables() - { - $user_data = $this->service->get_user($this->get_data('poster_id')); - - return array_merge(parent::get_email_template_variables(), array( - 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), - )); - } -} diff --git a/phpBB/includes/notifications/type/topic.php b/phpBB/includes/notifications/type/topic.php deleted file mode 100644 index 7753b196e8..0000000000 --- a/phpBB/includes/notifications/type/topic.php +++ /dev/null @@ -1,237 +0,0 @@ - array(), - ), $options); - - // Let's continue to use the phpBB subscriptions system, at least for now. - // It may not be the nicest thing, but it is already working and it would be significant work to replace it - //$users = parent::_find_users_for_notification($phpbb_container, $topic['forum_id']); - - $db = $phpbb_container->get('dbal.conn'); - - $users = array(); - - $sql = 'SELECT user_id - FROM ' . FORUMS_WATCH_TABLE . ' - WHERE forum_id = ' . (int) $topic['forum_id'] . ' - AND notify_status = ' . NOTIFY_YES . ' - AND user_id <> ' . (int) $topic['poster_id']; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - $users[] = $row['user_id']; - } - $db->sql_freeresult($result); - - if (empty($users)) - { - return array(); - } - - $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $topic['forum_id']); - - if (empty($auth_read)) - { - return array(); - } - - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', $auth_read[$topic['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $db->sql_freeresult($result); - - return $notify_users; - } - - /** - * Get the user's avatar - */ - public function get_avatar() - { - return $this->_get_avatar($this->get_data('poster_id')); - } - - /** - * Get the HTML formatted title of this notification - * - * @return string - */ - public function get_title() - { - if ($this->get_data('post_username')) - { - $username = $this->get_data('post_username'); - } - else - { - $user_data = $this->service->get_user($this->get_data('poster_id')); - - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); - } - - return $this->phpbb_container->get('user')->lang( - $this->language_key, - $username, - censor_text($this->get_data('topic_title')), - $this->get_data('forum_name') - ); - } - - /** - * Get email template variables - * - * @return array - */ - public function get_email_template_variables() - { - return array( - 'FORUM_NAME' => htmlspecialchars_decode($this->get_data('forum_name')), - 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), - - 'U_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}", - 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}", - 'U_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->item_parent_id}", - 'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?uid={$this->user_id}&f={$this->item_parent_id}&unwatch=forum", - ); - } - - /** - * Get the url to this item - * - * @return string URL - */ - public function get_url() - { - return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "f={$this->item_parent_id}&t={$this->item_id}"); - } - - /** - * Users needed to query before this notification can be displayed - * - * @return array Array of user_ids - */ - public function users_to_query() - { - return array($this->data['poster_id']); - } - - /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $post Data from submit_post - * - * @return array Array of data ready to be inserted into the database - */ - public function create_insert_array($post) - { - $this->set_data('poster_id', $post['poster_id']); - - $this->set_data('topic_title', $post['topic_title']); - - $this->set_data('post_username', (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : '')); - - $this->set_data('forum_name', $post['forum_name']); - - $this->time = $post['post_time']; - - return parent::create_insert_array($post); - } -} diff --git a/phpBB/includes/notifications/type/topic_in_queue.php b/phpBB/includes/notifications/type/topic_in_queue.php deleted file mode 100644 index 385578cec8..0000000000 --- a/phpBB/includes/notifications/type/topic_in_queue.php +++ /dev/null @@ -1,137 +0,0 @@ - 'needs_approval', - 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', - ); - - /** - * Is available - */ - public static function is_available(ContainerBuilder $phpbb_container) - { - $m_approve = $phpbb_container->get('auth')->acl_getf('m_approve', true); - - 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 - * - * @param ContainerBuilder $phpbb_container - * @param array $topic Data from the topic - * - * @return array - */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic, $options = array()) - { - $options = array_merge(array( - 'ignore_users' => array(), - ), $options); - - $db = $phpbb_container->get('dbal.conn'); - - $auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $topic['forum_id']); - - if (empty($auth_approve)) - { - return array(); - } - - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $db->sql_in_set('user_id', $auth_approve[$topic['forum_id']]['m_approve']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $db->sql_freeresult($result); - - return $notify_users; - } - - /** - * Function for preparing the data for insertion in an SQL query - * (The service handles insertion) - * - * @param array $topic Data from submit_post - * - * @return array Array of data ready to be inserted into the database - */ - public function create_insert_array($topic) - { - $data = parent::create_insert_array($topic); - - $this->time = $data['time'] = time(); - - return $data; - } -} -- cgit v1.2.1 From cea94d89848a806f449610ddb2a7df7b7eec1328 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 4 Oct 2012 14:27:43 -0500 Subject: [ticket/11103] Use dependency injection instead of phpbb_container PHPBB3-11103 --- phpBB/includes/notification/manager.php | 93 ++++++++++++++-------- phpBB/includes/notification/method/base.php | 30 +++---- phpBB/includes/notification/method/email.php | 6 +- phpBB/includes/notification/method/jabber.php | 6 +- phpBB/includes/notification/type/approve_post.php | 15 ++-- phpBB/includes/notification/type/approve_topic.php | 15 ++-- phpBB/includes/notification/type/base.php | 60 +++++++------- phpBB/includes/notification/type/bookmark.php | 23 +++--- .../includes/notification/type/disapprove_post.php | 2 +- .../notification/type/disapprove_topic.php | 2 +- phpBB/includes/notification/type/interface.php | 6 +- phpBB/includes/notification/type/pm.php | 23 +++--- phpBB/includes/notification/type/post.php | 25 +++--- phpBB/includes/notification/type/post_in_queue.php | 19 ++--- phpBB/includes/notification/type/quote.php | 43 +++++----- phpBB/includes/notification/type/topic.php | 25 +++--- .../includes/notification/type/topic_in_queue.php | 19 ++--- 17 files changed, 195 insertions(+), 217 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 15db3f89fd..e2c6c9d0f4 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -23,8 +23,7 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_manager { - protected $phpbb_container; - protected $db; + protected $db, $cache, $template, $extension_manager, $user, $auth, $config, $phpbb_root_path, $php_ext = null; /** * Users loaded from the DB @@ -33,12 +32,17 @@ class phpbb_notification_manager */ protected $users = array(); - public function __construct(ContainerBuilder $phpbb_container) + public function __construct(dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { - $this->phpbb_container = $phpbb_container; - - // Some common things we're going to use - $this->db = $phpbb_container->get('dbal.conn'); + $this->db = $db; + $this->cache = $cache; + $this->template = $template; + $this->extension_manager = $extension_manager; + $this->user = $user; + $this->auth = $auth; + $this->config = $config; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; } /** @@ -56,12 +60,10 @@ class phpbb_notification_manager */ public function load_notifications($options = array()) { - $user = $this->phpbb_container->get('user'); - // Merge default options $options = array_merge(array( 'notification_id' => false, - 'user_id' => $user->data['user_id'], + 'user_id' => $this->user->data['user_id'], 'order_by' => 'time', 'order_dir' => 'DESC', 'limit' => 0, @@ -74,7 +76,7 @@ class phpbb_notification_manager $options['count_unread'] = ($options['all_unread']) ? true : $options['count_unread']; // Anonymous users and bots never receive notifications - if ($options['user_id'] == $user->data['user_id'] && ($user->data['user_id'] == ANONYMOUS || $user->data['user_type'] == USER_IGNORE)) + if ($options['user_id'] == $this->user->data['user_id'] && ($this->user->data['user_id'] == ANONYMOUS || $this->user->data['user_type'] == USER_IGNORE)) { return array( 'notifications' => array(), @@ -136,7 +138,7 @@ class phpbb_notification_manager { $item_type_class_name = $this->get_item_type_class_name($row['item_type'], true); - $notification = new $item_type_class_name($this->phpbb_container, $row); + $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()); @@ -153,12 +155,14 @@ class phpbb_notification_manager $this->load_users($user_ids); - // Allow each type to load it's own special items + // Allow each type to load its own special items foreach ($load_special as $item_type => $data) { $item_type_class_name = $this->get_item_type_class_name($item_type, true); - $item_type_class_name::load_special($this->phpbb_container, $data, $notifications); + $item_class = $this->get_item_type_class($item_type_class_name); + + $item_class->load_special($data, $notifications); } return array( @@ -283,7 +287,7 @@ class phpbb_notification_manager $item_id = $item_type_class_name::get_item_id($data); // find out which users want to receive this type of notification - $notify_users = $item_type_class_name::find_users_for_notification($this->phpbb_container, $data, $options); + $notify_users = $this->get_item_type_class($item_type_class_name)->find_users_for_notification($data, $options); $this->add_notifications_for_users($item_type, $data, $notify_users); @@ -343,7 +347,7 @@ class phpbb_notification_manager // 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) { - $notification = new $item_type_class_name($this->phpbb_container); + $notification = $this->get_item_type_class($item_type_class_name); $notification->user_id = (int) $user; @@ -361,7 +365,7 @@ class phpbb_notification_manager if (!isset($notification_methods[$method])) { $method_class_name = 'phpbb_notification_method_' . $method; - $notification_methods[$method] = new $method_class_name($this->phpbb_container); + $notification_methods[$method] = $this->get_method_class($method_class_name); } $notification_methods[$method]->add_to_queue($notification); @@ -406,7 +410,7 @@ class phpbb_notification_manager if (method_exists($item_type_class_name, 'update_notifications')) { // Return False to over-ride the rest of the update - if ($item_type_class_name::update_notifications($this->phpbb_container, $data) === false) + if ($this->get_item_type_class($item_type_class_name)->update_notifications($data) === false) { return; } @@ -414,7 +418,7 @@ class phpbb_notification_manager $item_id = $item_type_class_name::get_item_id($data); - $notification = new $item_type_class_name($this->phpbb_container); + $notification = $this->get_item_type_class($item_type_class_name); $update_array = $notification->create_update_array($data); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' @@ -460,24 +464,26 @@ class phpbb_notification_manager { $subscription_types = array(); - foreach ($this->get_subscription_files('notifications/type/') as $class => $file) + foreach ($this->get_subscription_files('notifications/type/') as $class_name => $file) { - $class = $this->get_item_type_class_name($class); + $class_name = $this->get_item_type_class_name($class_name); - if (!class_exists($class)) + if (!class_exists($class_name)) { include($file); } - if ($class::is_available($this->phpbb_container) && method_exists($class, 'get_item_type')) + $class = $this->get_item_type_class($class_name); + + if ($class->is_available() && method_exists($class_name, 'get_item_type')) { - if ($class::$notification_option === false) + if ($class_name::$notification_option === false) { - $subscription_types[$class::get_item_type()] = $class::get_item_type(); + $subscription_types[$class_name::get_item_type()] = $class_name::get_item_type(); } else { - $subscription_types[$class::$notification_option['id']] = $class::$notification_option; + $subscription_types[$class_name::$notification_option['id']] = $class_name::$notification_option; } } } @@ -503,7 +509,7 @@ class phpbb_notification_manager include($file); } - $method = new $class_name($this->phpbb_container); + $method = $this->get_method_class($class_name); if ($method->is_available()) { @@ -524,7 +530,7 @@ class phpbb_notification_manager */ public function get_subscriptions($user_id = false, $only_global = false) { - $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; + $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; $subscriptions = array(); @@ -566,7 +572,7 @@ class phpbb_notification_manager { $this->get_item_type_class_name($item_type); - $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; + $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( @@ -590,7 +596,7 @@ class phpbb_notification_manager { $this->get_item_type_class_name($item_type); - $user_id = ($user_id === false) ? $this->phpbb_container->get('user')->data['user_id'] : $user_id; + $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; $sql = 'DELETE FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' @@ -654,15 +660,32 @@ class phpbb_notification_manager return 'phpbb_notification_type_' . $item_type; } + /** + * Helper to get the notifications item type class and set it up + */ + private function get_item_type_class($item_type, $data = array()) + { + $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); + + return $item; + } + + /** + * Helper to get the notifications method class and set it up + */ + private function get_method_class($method_name) + { + return new $method_name($this, $this->db, $this->cache, $this->template, $this->extension_manager, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext); + } + /** * Helper to get subscription related files with the finder */ private function get_subscription_files($path) { - $ext_manager = $this->phpbb_container->get('ext.manager'); - $php_ext = $this->phpbb_container->getParameter('core.php_ext'); - - $finder = $ext_manager->get_finder(); + $finder = $this->extension_manager->get_finder(); $subscription_files = array(); @@ -673,7 +696,7 @@ class phpbb_notification_manager foreach ($files as $file) { $class = substr($file, strrpos($file, '/')); - $class = substr($class, 1, (strpos($class, '.' . $php_ext) - 1)); + $class = substr($class, 1, (strpos($class, '.' . $this->php_ext) - 1)); if ($class == 'interface' || $class == 'base') { diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index b502d3afd0..ced85e2582 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -23,12 +23,7 @@ if (!defined('IN_PHPBB')) */ abstract class phpbb_notification_method_base implements phpbb_notification_method_interface { - protected $phpbb_container; - protected $service; - protected $db; - protected $user; - protected $phpbb_root_path; - protected $php_ext; + protected $notification_manager, $db, $cache, $template, $extension_manager, $user, $auth, $config, $phpbb_root_path, $php_ext = null; /** * Desired notifications @@ -56,20 +51,17 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth */ protected $queue = array(); - public function __construct(ContainerBuilder $phpbb_container) + public function __construct(dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { - // phpBB Container - $this->phpbb_container = $phpbb_container; - - // Service - $this->service = $phpbb_container->get('notifications'); - - // Some common things we're going to use - $this->db = $phpbb_container->get('dbal.conn'); - $this->user = $phpbb_container->get('user'); - - $this->phpbb_root_path = $phpbb_container->getParameter('core.root_path'); - $this->php_ext = $phpbb_container->getParameter('core.php_ext'); + $this->db = $db; + $this->cache = $cache; + $this->template = $template; + $this->extension_manager = $extension_manager; + $this->user = $user; + $this->auth = $auth; + $this->config = $config; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; } /** diff --git a/phpBB/includes/notification/method/email.php b/phpBB/includes/notification/method/email.php index 1b6b44d137..c2e272aca1 100644 --- a/phpBB/includes/notification/method/email.php +++ b/phpBB/includes/notification/method/email.php @@ -57,12 +57,12 @@ class phpbb_notification_method_email extends phpbb_notification_method_base // We do not send emails to banned users if (!function_exists('phpbb_get_banned_user_ids')) { - include($this->phpbb_container->getParameter('core.root_path') . 'includes/functions_user.' . $this->phpbb_container->getParameter('core.php_ext')); + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); } $banned_users = phpbb_get_banned_user_ids($user_ids); // Load all the users we need - $this->service->load_users($user_ids); + $this->notification_manager->load_users($user_ids); // Load the messenger if (!class_exists('messenger')) @@ -75,7 +75,7 @@ class phpbb_notification_method_email extends phpbb_notification_method_base // Time to go through the queue and send emails foreach ($this->queue as $notification) { - $user = $this->service->get_user($notification->user_id); + $user = $this->notification_manager->get_user($notification->user_id); if ($user['user_type'] == USER_IGNORE || in_array($notification->user_id, $banned_users)) { diff --git a/phpBB/includes/notification/method/jabber.php b/phpBB/includes/notification/method/jabber.php index 9232d8fc45..664e387d61 100644 --- a/phpBB/includes/notification/method/jabber.php +++ b/phpBB/includes/notification/method/jabber.php @@ -36,7 +36,7 @@ class phpbb_notification_method_jabber extends phpbb_notification_method_email */ public function is_available() { - return ($this->global_available() && $this->phpbb_container->get('user')->data['jabber']); + return ($this->global_available() && $this->user->data['jabber']); } /** @@ -45,9 +45,7 @@ class phpbb_notification_method_jabber extends phpbb_notification_method_email */ public function global_available() { - $config = $this->phpbb_container->get('config'); - - return ($config['jab_enable'] && @extension_loaded('xml')); + return ($this->config['jab_enable'] && @extension_loaded('xml')); } public function notify() diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 9a3def6217..3a88d9f54a 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -62,23 +62,20 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $post Data from * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) + public function find_users_for_notification($post, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - $users = array(); $users[$post['poster_id']] = array(''); - $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + $auth_read = $this->auth->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); if (empty($auth_read)) { @@ -90,9 +87,9 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -106,7 +103,7 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 00af312018..0a6ca14a84 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -62,23 +62,20 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $post Data from * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) + public function find_users_for_notification($post, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - $users = array(); $users[$post['poster_id']] = array(''); - $auth_read = $phpbb_container->get('auth')->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + $auth_read = $this->auth->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); if (empty($auth_read)) { @@ -90,9 +87,9 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -106,7 +103,7 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 40462bccfb..626fe821e6 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -23,11 +23,7 @@ if (!defined('IN_PHPBB')) */ abstract class phpbb_notification_type_base implements phpbb_notification_type_interface { - protected $phpbb_container; - protected $service; - protected $db; - protected $phpbb_root_path; - protected $php_ext; + protected $notification_manager, $db, $cache, $template, $extension_manager, $user, $auth, $config, $phpbb_root_path, $php_ext = null; /** * Array of user data containing information needed to output the notifications to the template @@ -39,7 +35,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Notification option data (for outputting to the user) * - * @var bool|array False if the service should use it's default data + * @var bool|array False if the service should use its default data * Array of data (including keys 'id' and 'lang') */ public static $notification_option = false; @@ -60,20 +56,27 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ private $data = array(); - public function __construct(ContainerBuilder $phpbb_container, $data = array()) + public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { - // phpBB Container - $this->phpbb_container = $phpbb_container; - - // Service - $this->service = $phpbb_container->get('notifications'); - - // Some common things we're going to use - $this->db = $phpbb_container->get('dbal.conn'); - - $this->phpbb_root_path = $phpbb_container->getParameter('core.root_path'); - $this->php_ext = $phpbb_container->getParameter('core.php_ext'); + $this->notification_manager = $notification_manager; + $this->db = $db; + $this->cache = $cache; + $this->template = $template; + $this->extension_manager = $extension_manager; + $this->user = $user; + $this->auth = $auth; + $this->config = $config; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + /** + * Set initial data from the database + * + * @param array $data Row directly from the database + */ + public function set_initial_data($data = array()) + { // The row from the database (unless this is a new notification we're going to add) $this->data = $data; $this->data['data'] = (isset($this->data['data'])) ? unserialize($this->data['data']) : array(); @@ -117,15 +120,13 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ public function prepare_for_display() { - $user = $this->phpbb_container->get('user'); - return array( 'AVATAR' => $this->get_avatar(), 'FORMATTED_TITLE' => $this->get_title(), 'URL' => $this->get_url(), - 'TIME' => $user->format_date($this->time), + 'TIME' => $this->user->format_date($this->time), 'UNREAD' => $this->unread, @@ -239,7 +240,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Load the special items (fall-back) */ - public static function load_special(ContainerBuilder $phpbb_container, $data, $notifications) + public function load_special($data, $notifications) { return; } @@ -247,7 +248,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Is available (fall-back) */ - public static function is_available(ContainerBuilder $phpbb_container) + public function is_available() { return true; } @@ -259,27 +260,24 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Find the users who want to receive notifications (helper) * - * @param ContainerBuilder $phpbb_container * @param array $item_id The item_id to search for * * @return array */ - protected static function _find_users_for_notification(ContainerBuilder $phpbb_container, $item_id, $options) + protected function _find_users_for_notification($item_id, $options) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - $rowset = array(); $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . static::get_item_type() . "' AND item_id = " . (int) $item_id; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -293,7 +291,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $rowset[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $rowset; } @@ -306,7 +304,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ protected function _get_avatar($user_id) { - $user = $this->service->get_user($user_id); + $user = $this->notification_manager->get_user($user_id); if (!function_exists('get_user_avatar')) { diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index 51f23bc294..5ff39821dc 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -51,38 +51,35 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $post Data from * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) + public function find_users_for_notification($post, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - $users = array(); $sql = 'SELECT user_id FROM ' . BOOKMARKS_TABLE . ' - WHERE ' . $db->sql_in_set('topic_id', $post['topic_id']) . ' + WHERE ' . $this->db->sql_in_set('topic_id', $post['topic_id']) . ' AND user_id <> ' . (int) $post['poster_id']; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { $users[] = $row['user_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (empty($users)) { return array(); } - $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); + $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); if (empty($auth_read)) { @@ -94,9 +91,9 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -110,7 +107,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index 8fa0102e3d..3ef45fb8e3 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -66,7 +66,7 @@ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_ap */ public function get_title() { - return $this->phpbb_container->get('user')->lang( + return $this->user->lang( $this->language_key, censor_text($this->get_data('topic_title')), $this->get_data('disapprove_reason') diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index 186c42d2b6..afd293a94f 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -66,7 +66,7 @@ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_a */ public function get_title() { - return $this->phpbb_container->get('user')->lang( + return $this->user->lang( $this->language_key, censor_text($this->get_data('topic_title')), $this->get_data('disapprove_reason') diff --git a/phpBB/includes/notification/type/interface.php b/phpBB/includes/notification/type/interface.php index aa54c62a97..c17f248080 100644 --- a/phpBB/includes/notification/type/interface.php +++ b/phpBB/includes/notification/type/interface.php @@ -25,9 +25,9 @@ interface phpbb_notification_type_interface public static function get_item_id($type_data); - public static function is_available(ContainerBuilder $phpbb_container); + public function is_available(); - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $type_data, $options); + public function find_users_for_notification($type_data, $options); public function get_title(); @@ -45,5 +45,5 @@ interface phpbb_notification_type_interface public function get_load_special(); - public static function load_special(ContainerBuilder $phpbb_container, $data, $notifications); + public function load_special($data, $notifications); } diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index 8252a8577b..9c1f353514 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -65,36 +65,31 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $pm Data from * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $pm, $options = array()) + public function find_users_for_notification($pm, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $service = $phpbb_container->get('notifications'); - $db = $phpbb_container->get('dbal.conn'); - $user = $phpbb_container->get('user'); - if (!sizeof($pm['recipients'])) { return array(); } - $service->load_users(array_keys($pm['recipients'])); + $this->notification_manager->load_users(array_keys($pm['recipients'])); $notify_users = array(); $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', array_keys($pm['recipients'])); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', array_keys($pm['recipients'])); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -108,7 +103,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } @@ -128,11 +123,11 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base */ public function get_title() { - $user_data = $this->service->get_user($this->get_data('from_user_id')); + $user_data = $this->notification_manager->get_user($this->get_data('from_user_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); - return $this->phpbb_container->get('user')->lang('NOTIFICATION_PM', $username, $this->get_data('message_subject')); + return $this->user->lang('NOTIFICATION_PM', $username, $this->get_data('message_subject')); } /** @@ -142,7 +137,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base */ public function get_email_template_variables() { - $user_data = $this->service->get_user($this->get_data('from_user_id')); + $user_data = $this->notification_manager->get_user($this->get_data('from_user_id')); return array( 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 1e654ef51b..37020825d3 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -71,12 +71,11 @@ class phpbb_notification_type_post extends phpbb_notification_type_base /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $post Data from * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) + public function find_users_for_notification($post, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), @@ -86,8 +85,6 @@ class phpbb_notification_type_post extends phpbb_notification_type_base // It may not be the nicest thing, but it is already working and it would be significant work to replace it //$users = parent::_find_users_for_notification($phpbb_container, $post['topic_id']); - $db = $phpbb_container->get('dbal.conn'); - $users = array(); $sql = 'SELECT user_id @@ -95,19 +92,19 @@ class phpbb_notification_type_post extends phpbb_notification_type_base WHERE topic_id = ' . (int) $post['topic_id'] . ' AND notify_status = ' . NOTIFY_YES . ' AND user_id <> ' . (int) $post['poster_id']; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { $users[] = $row['user_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (empty($users)) { return array(); } - $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); + $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); if (empty($auth_read)) { @@ -119,9 +116,9 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -135,7 +132,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } @@ -161,12 +158,12 @@ class phpbb_notification_type_post extends phpbb_notification_type_base } else { - $user_data = $this->service->get_user($this->get_data('poster_id')); + $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } - return $this->phpbb_container->get('user')->lang( + return $this->user->lang( $this->language_key, $username, censor_text($this->get_data('topic_title')) diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index f0a5e0baec..44f4f9391c 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -62,9 +62,9 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post /** * Is available */ - public static function is_available(ContainerBuilder $phpbb_container) + public function is_available() { - $m_approve = $phpbb_container->get('auth')->acl_getf('m_approve', true); + $m_approve = $this->auth->acl_getf('m_approve', true); return (!empty($m_approve)); } @@ -72,20 +72,17 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $post Data from the post * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) + public function find_users_for_notification($post, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - - $auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $post['forum_id']); + $auth_approve = $this->auth->acl_get_list(false, 'm_approve', $post['forum_id']); if (empty($auth_approve)) { @@ -97,9 +94,9 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $db->sql_in_set('user_id', $auth_approve[$post['forum_id']]['m_approve']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_approve[$post['forum_id']]['m_approve']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -113,7 +110,7 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index dd3cbedee2..32ee06787c 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -58,19 +58,16 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $post Data from * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $post, $options = array()) + public function find_users_for_notification($post, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - $usernames = false; preg_match_all(self::$regular_expression_match, $post['post_text'], $usernames); @@ -87,21 +84,21 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $sql = 'SELECT user_id FROM ' . USERS_TABLE . ' - WHERE ' . $db->sql_in_set('username_clean', $usernames) . ' + WHERE ' . $this->db->sql_in_set('username_clean', $usernames) . ' AND user_id <> ' . (int) $post['poster_id']; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { $users[] = $row['user_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (empty($users)) { return array(); } - $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $post['forum_id']); + $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); if (empty($auth_read)) { @@ -113,9 +110,9 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -129,7 +126,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } @@ -137,28 +134,24 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post /** * Update a notification * - * @param ContainerBuilder $phpbb_container * @param array $data Data specific for this type that will be updated */ - public static function update_notifications(ContainerBuilder $phpbb_container, $post) + public function update_notifications($post) { - $service = $phpbb_container->get('notifications'); - $db = $phpbb_container->get('dbal.conn'); - $old_notifications = array(); $sql = 'SELECT user_id FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' AND item_id = " . self::get_item_id($post); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { $old_notifications[] = $row['user_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); // Find the new users to notify - $notifications = self::find_users_for_notification($phpbb_container, $post); + $notifications = $this->find_users_for_notification($post); // Find the notifications we must delete $remove_notifications = array_diff($old_notifications, array_keys($notifications)); @@ -185,8 +178,8 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' AND item_id = " . self::get_item_id($post) . ' - AND ' . $db->sql_in_set('user_id', $remove_notifications); - $db->sql_query($sql); + AND ' . $this->db->sql_in_set('user_id', $remove_notifications); + $this->db->sql_query($sql); } // return true to continue with the update code in the notifications service (this will update the rest of the notifications) @@ -200,7 +193,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post */ public function get_email_template_variables() { - $user_data = $this->service->get_user($this->get_data('poster_id')); + $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); return array_merge(parent::get_email_template_variables(), array( 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 7753b196e8..01f394ccd2 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -71,12 +71,11 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $topic Data from the topic * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic, $options = array()) + public function find_users_for_notification($topic, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), @@ -86,8 +85,6 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base // It may not be the nicest thing, but it is already working and it would be significant work to replace it //$users = parent::_find_users_for_notification($phpbb_container, $topic['forum_id']); - $db = $phpbb_container->get('dbal.conn'); - $users = array(); $sql = 'SELECT user_id @@ -95,19 +92,19 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base WHERE forum_id = ' . (int) $topic['forum_id'] . ' AND notify_status = ' . NOTIFY_YES . ' AND user_id <> ' . (int) $topic['poster_id']; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { $users[] = $row['user_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (empty($users)) { return array(); } - $auth_read = $phpbb_container->get('auth')->acl_get_list($users, 'f_read', $topic['forum_id']); + $auth_read = $this->auth->acl_get_list($users, 'f_read', $topic['forum_id']); if (empty($auth_read)) { @@ -119,9 +116,9 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' - AND " . $db->sql_in_set('user_id', $auth_read[$topic['forum_id']]['f_read']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_read[$topic['forum_id']]['f_read']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -135,7 +132,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } @@ -161,12 +158,12 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base } else { - $user_data = $this->service->get_user($this->get_data('poster_id')); + $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } - return $this->phpbb_container->get('user')->lang( + return $this->user->lang( $this->language_key, $username, censor_text($this->get_data('topic_title')), diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index 385578cec8..d931168013 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -53,9 +53,9 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top /** * Is available */ - public static function is_available(ContainerBuilder $phpbb_container) + public function is_available() { - $m_approve = $phpbb_container->get('auth')->acl_getf('m_approve', true); + $m_approve = $this->auth->acl_getf('m_approve', true); return (!empty($m_approve)); } @@ -72,20 +72,17 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top /** * Find the users who want to receive notifications * - * @param ContainerBuilder $phpbb_container * @param array $topic Data from the topic * * @return array */ - public static function find_users_for_notification(ContainerBuilder $phpbb_container, $topic, $options = array()) + public function find_users_for_notification($topic, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), ), $options); - $db = $phpbb_container->get('dbal.conn'); - - $auth_approve = $phpbb_container->get('auth')->acl_get_list(false, 'm_approve', $topic['forum_id']); + $auth_approve = $this->auth->acl_get_list(false, 'm_approve', $topic['forum_id']); if (empty($auth_approve)) { @@ -97,9 +94,9 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $db->sql_in_set('user_id', $auth_approve[$topic['forum_id']]['m_approve']); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + AND " . $this->db->sql_in_set('user_id', $auth_approve[$topic['forum_id']]['m_approve']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) { @@ -113,7 +110,7 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top $notify_users[$row['user_id']][] = $row['method']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $notify_users; } -- cgit v1.2.1 From 07fb66ac1090dfe92431ed749b520115595f7927 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 4 Oct 2012 14:31:00 -0500 Subject: [ticket/11103] Do not abbreviate template output PHPBB3-11103 --- phpBB/includes/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 162b0046b5..d005ccaaab 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5020,8 +5020,8 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'RECORD_USERS' => $l_online_record, 'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text, 'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread, - 'NUM_UNREAD_NOTIFICATIONS' => $notifications['unread_count'], - 'NOTIFICATIONS_CNT' => $user->lang('NOTIFICATIONS_CNT', $notifications['unread_count']), + 'UNREAD_NOTIFICATIONS_COUNT' => $notifications['unread_count'], + 'NOTIFICATIONS_COUNT' => $user->lang('NOTIFICATIONS_COUNT', $notifications['unread_count']), 'S_USER_NEW_PRIVMSG' => $user->data['user_new_privmsg'], 'S_USER_UNREAD_PRIVMSG' => $user->data['user_unread_privmsg'], -- cgit v1.2.1 From b9bc65eed88bbd2dff12102909903cbf4dc9b368 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 4 Oct 2012 14:47:13 -0500 Subject: [ticket/11103] Make $phpbb_notifications a global and use it everywhere Do not use phpbb_container everywhere (makes testing difficult) PHPBB3-11103 --- phpBB/includes/functions.php | 8 ++------ phpBB/includes/functions_admin.php | 6 ++---- phpBB/includes/functions_posting.php | 4 ++-- phpBB/includes/functions_privmsgs.php | 35 +++++++++++++------------------- phpBB/includes/mcp/mcp_queue.php | 6 ++---- phpBB/includes/ucp/ucp_notifications.php | 7 +------ 6 files changed, 23 insertions(+), 43 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index d005ccaaab..9513c6919f 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1285,7 +1285,7 @@ function phpbb_timezone_select($user, $default = '', $truncate = false) function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $user_id = 0) { global $db, $user, $config; - global $request, $phpbb_container; + global $request, $phpbb_notifications; if ($mode == 'all') { @@ -1294,7 +1294,6 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ // Mark all forums read (index page) // Mark all topic notifications read for this user - $phpbb_notifications = $phpbb_container->get('notifications'); $phpbb_notifications->mark_notifications_read(array('topic', 'quote', 'bookmark', 'post', 'approve_topic', 'approve_post'), false, $user->data['user_id'], $post_time); if ($config['load_db_lastread'] && $user->data['is_registered']) @@ -1336,7 +1335,6 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ } // Mark topic notifications read for this user in this forum - $phpbb_notifications = $phpbb_container->get('notifications'); $phpbb_notifications->mark_notifications_read_by_parent(array('topic', 'approve_topic'), $forum_id, $user->data['user_id'], $post_time); // Mark all post/quote notifications read for this user in this forum @@ -1448,7 +1446,6 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ } // Mark post notifications read for this user in this topic - $phpbb_notifications = $phpbb_container->get('notifications'); $phpbb_notifications->mark_notifications_read(array('topic', 'approve_topic'), $topic_id, $user->data['user_id'], $post_time); $phpbb_notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post', 'approve_post'), $topic_id, $user->data['user_id'], $post_time); @@ -4806,7 +4803,7 @@ function phpbb_http_login($param) function page_header($page_title = '', $display_online_list = true, $item_id = 0, $item = 'forum') { global $db, $config, $template, $SID, $_SID, $_EXTRA_URL, $user, $auth, $phpEx, $phpbb_root_path; - global $phpbb_dispatcher, $phpbb_container; + global $phpbb_dispatcher, $phpbb_notifications; if (defined('HEADER_INC')) { @@ -4996,7 +4993,6 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 } // Output the notifications - $phpbb_notifications = $phpbb_container->get('notifications'); $notifications = $phpbb_notifications->load_notifications(array( 'all_unread' => true, 'limit' => 5, diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 27128aafac..3deb2e9c59 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -619,7 +619,7 @@ function move_posts($post_ids, $topic_id, $auto_sync = true) function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_sync = true, $call_delete_posts = true) { global $db, $config; - global $phpbb_container; + global $phpbb_notifications; $approved_topics = 0; $forum_ids = $topic_ids = array(); @@ -717,7 +717,6 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s } // Delete notifications - $phpbb_notifications = $phpbb_container->get('notifications'); $phpbb_notifications->delete_notifications(array('topic', 'approve_topic', 'topic_in_queue'), $topic_ids); return $return; @@ -729,7 +728,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = true, $post_count_sync = true, $call_delete_topics = true) { global $db, $config, $phpbb_root_path, $phpEx, $auth, $user; - global $phpbb_container; + global $phpbb_notifications; if ($where_type === 'range') { @@ -899,7 +898,6 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = } // Delete notifications - $phpbb_notifications = $phpbb_container->get('notifications'); $phpbb_notifications->delete_notifications(array('quote', 'bookmark', 'post', 'approve_post', 'post_in_queue'), $post_ids); return sizeof($post_ids); diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 6262cee4ad..3658757e5e 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1409,7 +1409,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true, $update_search_index = true) { global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path; - global $phpbb_container; + global $phpbb_notifications; // We do not handle erasing posts here if ($mode == 'delete') @@ -2220,7 +2220,6 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } // Send Notifications - $phpbb_notifications = $phpbb_container->get('notifications'); $notification_data = array_merge($data, array( 'topic_title' => (isset($data['topic_title'])) ? $data['topic_title'] : $subject, 'post_username' => $username, @@ -2229,6 +2228,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'post_time' => $current_time, 'post_subject' => $subject, )); + if ($post_approval) { switch ($mode) diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 8545cc7ef5..6c31c6d6c3 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -269,46 +269,46 @@ function check_rule(&$rules, &$rule_row, &$message_row, $user_id) case RULE_IS_LIKE: $result = preg_match("/" . preg_quote($rule_row['rule_string'], '/') . '/i', $check0); break; - + case RULE_IS_NOT_LIKE: $result = !preg_match("/" . preg_quote($rule_row['rule_string'], '/') . '/i', $check0); break; - + case RULE_IS: $result = ($check0 == $rule_row['rule_string']); break; - + case RULE_IS_NOT: $result = ($check0 != $rule_row['rule_string']); break; - + case RULE_BEGINS_WITH: $result = preg_match("/^" . preg_quote($rule_row['rule_string'], '/') . '/i', $check0); break; - + case RULE_ENDS_WITH: $result = preg_match("/" . preg_quote($rule_row['rule_string'], '/') . '$/i', $check0); break; - + case RULE_IS_FRIEND: case RULE_IS_FOE: case RULE_ANSWERED: case RULE_FORWARDED: $result = ($check0 == 1); break; - + case RULE_IS_USER: $result = ($check0 == $rule_row['rule_user_id']); break; - + case RULE_IS_GROUP: $result = in_array($rule_row['rule_group_id'], $check0); break; - + case RULE_TO_GROUP: $result = (in_array('g_' . $message_row[$check_ary['check2']], $check0) || in_array('g_' . $message_row[$check_ary['check2']], $message_row[$check_ary['check1']])); break; - + case RULE_TO_ME: $result = (in_array('u_' . $user_id, $check0) || in_array('u_' . $user_id, $message_row[$check_ary['check1']])); break; @@ -876,10 +876,9 @@ function update_unread_status($unread, $msg_id, $user_id, $folder_id) return; } - global $db, $user, $phpbb_container; + global $db, $user, $phpbb_notifications; // Mark the PM as read - $phpbb_notifications = $phpbb_container->get('notifications'); $phpbb_notifications->mark_notifications_read('pm', $msg_id, $user_id); $sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . " @@ -986,7 +985,7 @@ function handle_mark_actions($user_id, $mark_action) function delete_pm($user_id, $msg_ids, $folder_id) { global $db, $user, $phpbb_root_path, $phpEx; - global $phpbb_container; + global $phpbb_notifications; $user_id = (int) $user_id; $folder_id = (int) $folder_id; @@ -1099,7 +1098,6 @@ function delete_pm($user_id, $msg_ids, $folder_id) } // Delete Notifications - $phpbb_notifications = $phpbb_container->get('notifications'); $phpbb_notifications->delete_notifications('pm', array_keys($delete_rows)); // Now we have to check which messages we can delete completely @@ -1146,7 +1144,7 @@ function delete_pm($user_id, $msg_ids, $folder_id) function phpbb_delete_user_pms($user_id) { global $db, $user, $phpbb_root_path, $phpEx; - global $phpbb_container; + global $phpbb_notifications; $user_id = (int) $user_id; @@ -1265,7 +1263,6 @@ function phpbb_delete_user_pms($user_id) $db->sql_query($sql); // Delete Notifications - $phpbb_notifications = $phpbb_container->get('notifications'); $phpbb_notifications->delete_notifications('pm', $delivered_msg); } @@ -1280,7 +1277,6 @@ function phpbb_delete_user_pms($user_id) $db->sql_query($sql); // Delete Notifications - $phpbb_notifications = $phpbb_container->get('notifications'); $phpbb_notifications->delete_notifications('pm', $undelivered_msg); } } @@ -1326,7 +1322,6 @@ function phpbb_delete_user_pms($user_id) $db->sql_query($sql); // Delete Notifications - $phpbb_notifications = $phpbb_container->get('notifications'); $phpbb_notifications->delete_notifications('pm', $delete_ids); } } @@ -1565,7 +1560,7 @@ function get_folder_status($folder_id, $folder) function submit_pm($mode, $subject, &$data, $put_in_outbox = true) { global $db, $auth, $config, $phpEx, $template, $user, $phpbb_root_path; - global $phpbb_container; + global $phpbb_notifications; // We do not handle erasing pms here if ($mode == 'delete') @@ -1865,8 +1860,6 @@ function submit_pm($mode, $subject, &$data, $put_in_outbox = true) $db->sql_transaction('commit'); // Send Notifications - $phpbb_notifications = $phpbb_container->get('notifications'); - $pm_data = array_merge($data, array( 'message_subject' => $subject, 'recipients' => $recipients, diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 1d2caa38d5..77e778fc38 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -451,7 +451,7 @@ function approve_post($post_id_list, $id, $mode) { global $db, $template, $user, $config; global $phpEx, $phpbb_root_path; - global $request, $phpbb_container; + global $request, $phpbb_notifications; if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) { @@ -601,7 +601,6 @@ function approve_post($post_id_list, $id, $mode) $email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']); // Handle notifications - $phpbb_notifications = $phpbb_container->get('notifications'); foreach ($post_info as $post_id => $post_data) { if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) @@ -720,7 +719,7 @@ function disapprove_post($post_id_list, $id, $mode) { global $db, $template, $user, $config; global $phpEx, $phpbb_root_path; - global $request, $phpbb_container; + global $request, $phpbb_notifications; if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) { @@ -854,7 +853,6 @@ function disapprove_post($post_id_list, $id, $mode) } // Handle notifications (topic/post in queue) - $phpbb_notifications = $phpbb_container->get('notifications'); foreach ($post_info as $post_id => $post_data) { if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index d248099b06..9ea44f49bf 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -21,15 +21,10 @@ class ucp_notifications public function main($id, $mode) { - global $phpbb_container; + global $template, $user, $request, $phpbb_notifications; add_form_key('ucp_notification_options'); - $phpbb_notifications = $phpbb_container->get('notifications'); - $template = $phpbb_container->get('template'); - $user = $phpbb_container->get('user'); - $request = $phpbb_container->get('request'); - $subscriptions = $phpbb_notifications->get_subscriptions(false, true); // Add/remove subscriptions -- cgit v1.2.1 From ff136cc96a62147bc7468b716b86a30f12754e77 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 4 Oct 2012 15:21:07 -0500 Subject: [ticket/11103] Do not use Symfony\...\ContainerBuilder; It's no longer needed PHPBB3-11103 --- phpBB/includes/notification/manager.php | 2 -- phpBB/includes/notification/method/base.php | 1 - phpBB/includes/notification/type/approve_post.php | 1 - phpBB/includes/notification/type/approve_topic.php | 1 - phpBB/includes/notification/type/base.php | 1 - phpBB/includes/notification/type/bookmark.php | 1 - phpBB/includes/notification/type/disapprove_post.php | 1 - phpBB/includes/notification/type/disapprove_topic.php | 1 - phpBB/includes/notification/type/pm.php | 1 - phpBB/includes/notification/type/post.php | 1 - phpBB/includes/notification/type/post_in_queue.php | 1 - phpBB/includes/notification/type/quote.php | 1 - phpBB/includes/notification/type/topic.php | 1 - phpBB/includes/notification/type/topic_in_queue.php | 1 - 14 files changed, 15 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index e2c6c9d0f4..be29f37a3e 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -7,8 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; - /** * @ignore */ diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index ced85e2582..d95a65fa72 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 3a88d9f54a..bbd2bccfc0 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 0a6ca14a84..5006e3bbb8 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 626fe821e6..31150477bb 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index 5ff39821dc..ee06a6d33b 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index 3ef45fb8e3..6ef4de5cd9 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index afd293a94f..6f92c1de77 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index 9c1f353514..a647106a53 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 37020825d3..de224776db 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 44f4f9391c..19c3ed9fc9 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 32ee06787c..0920cea428 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 01f394ccd2..621c0f484b 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index d931168013..c549cb12a1 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -7,7 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; /** * @ignore -- cgit v1.2.1 From ceb56da965f12245bca6b735cb71f3bbaf505307 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 4 Oct 2012 21:39:17 -0500 Subject: [ticket/11103] Fixing a few bugs from the previous changes PHPBB3-11103 --- phpBB/includes/notification/manager.php | 6 +++--- phpBB/includes/notification/method/base.php | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index be29f37a3e..854d72009e 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -30,7 +30,7 @@ class phpbb_notification_manager */ protected $users = array(); - public function __construct(dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) + public function __construct(dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { $this->db = $db; $this->cache = $cache; @@ -462,7 +462,7 @@ class phpbb_notification_manager { $subscription_types = array(); - foreach ($this->get_subscription_files('notifications/type/') as $class_name => $file) + foreach ($this->get_subscription_files('notification/type/') as $class_name => $file) { $class_name = $this->get_item_type_class_name($class_name); @@ -498,7 +498,7 @@ class phpbb_notification_manager { $subscription_methods = array(); - foreach ($this->get_subscription_files('notifications/method/') as $method_name => $file) + foreach ($this->get_subscription_files('notification/method/') as $method_name => $file) { $class_name = 'phpbb_notification_method_' . $method_name; diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index d95a65fa72..9f1db6d9f5 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -50,8 +50,9 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth */ protected $queue = array(); - public function __construct(dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) + public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { + $this->notification_manager = $notification_manager; $this->db = $db; $this->cache = $cache; $this->template = $template; -- cgit v1.2.1 From 3f2e3ad633930744e1ed92cc529ca473ccfa09e0 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 5 Oct 2012 00:07:48 -0500 Subject: [ticket/11103] Working on test case Fixing extension type/method naming scheme so they can be autoloaded. Other bugs PHPBB3-11103 --- phpBB/includes/notification/manager.php | 39 +++++++++++++++----------- phpBB/includes/notification/method/base.php | 2 +- phpBB/includes/notification/type/base.php | 7 ++++- phpBB/includes/notification/type/interface.php | 2 ++ 4 files changed, 31 insertions(+), 19 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 854d72009e..c1ae61e08a 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -466,11 +466,6 @@ class phpbb_notification_manager { $class_name = $this->get_item_type_class_name($class_name); - if (!class_exists($class_name)) - { - include($file); - } - $class = $this->get_item_type_class($class_name); if ($class->is_available() && method_exists($class_name, 'get_item_type')) @@ -502,11 +497,6 @@ class phpbb_notification_manager { $class_name = 'phpbb_notification_method_' . $method_name; - if (!class_exists($class_name)) - { - include($file); - } - $method = $this->get_method_class($class_name); if ($method->is_available()) @@ -652,7 +642,14 @@ class phpbb_notification_manager { if (!$safe) { - $item_type = preg_replace('#[^a-z_]#', '', $item_type); + $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; @@ -661,7 +658,7 @@ class phpbb_notification_manager /** * Helper to get the notifications item type class and set it up */ - private function get_item_type_class($item_type, $data = array()) + public function get_item_type_class($item_type, $data = array()) { $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); @@ -673,7 +670,7 @@ class phpbb_notification_manager /** * Helper to get the notifications method class and set it up */ - private function get_method_class($method_name) + public function get_method_class($method_name) { return new $method_name($this, $this->db, $this->cache, $this->template, $this->extension_manager, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext); } @@ -693,15 +690,23 @@ class phpbb_notification_manager ->get_files(); foreach ($files as $file) { - $class = substr($file, strrpos($file, '/')); - $class = substr($class, 1, (strpos($class, '.' . $this->php_ext) - 1)); + $name = substr($file, strrpos($file, '/')); + $name = substr($name, 1, (strpos($name, '.' . $this->php_ext) - 1)); - if ($class == 'interface' || $class == 'base') + if ($name == 'interface' || $name == 'base') { continue; } - $subscription_files[$class] = $file; + if (!strpos($file, 'includes/')) // is an extension + { + $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; diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index 9f1db6d9f5..6410b1f519 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -50,7 +50,7 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth */ protected $queue = array(); - public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) + public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { $this->notification_manager = $notification_manager; $this->db = $db; diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 31150477bb..9e31d57108 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -55,7 +55,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ private $data = array(); - public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, phpbb_user $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) + public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { $this->notification_manager = $notification_manager; $this->db = $db; @@ -91,6 +91,11 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $this->data[$name] = $value; } + public function __toString() + { + return (!empty($this->data)) ? var_export($this->data, true) : static::get_item_type(); + } + /** * Get special data (only important for the classes that extend this) * diff --git a/phpBB/includes/notification/type/interface.php b/phpBB/includes/notification/type/interface.php index c17f248080..56fad9fd80 100644 --- a/phpBB/includes/notification/type/interface.php +++ b/phpBB/includes/notification/type/interface.php @@ -43,6 +43,8 @@ interface phpbb_notification_type_interface public function create_insert_array($type_data); + public function users_to_query(); + public function get_load_special(); public function load_special($data, $notifications); -- cgit v1.2.1 From 2d69707a88fdb618730243cbe65ebc055cf68bae Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 5 Oct 2012 00:23:14 -0500 Subject: [ticket/11103] Remove extra line break in the header Was introduced with ff136cc96a62147bc7468b716b86a30f12754e77 PHPBB3-11103 --- phpBB/includes/notification/method/base.php | 1 - phpBB/includes/notification/type/approve_post.php | 1 - phpBB/includes/notification/type/approve_topic.php | 1 - phpBB/includes/notification/type/base.php | 1 - phpBB/includes/notification/type/bookmark.php | 1 - phpBB/includes/notification/type/disapprove_post.php | 1 - phpBB/includes/notification/type/disapprove_topic.php | 1 - phpBB/includes/notification/type/pm.php | 1 - phpBB/includes/notification/type/post.php | 1 - phpBB/includes/notification/type/post_in_queue.php | 1 - phpBB/includes/notification/type/quote.php | 1 - phpBB/includes/notification/type/topic.php | 1 - phpBB/includes/notification/type/topic_in_queue.php | 1 - 13 files changed, 13 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index 6410b1f519..5457ca99b2 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index bbd2bccfc0..98dfe678c2 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 5006e3bbb8..496dc688ad 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 9e31d57108..2ba0dd3bf7 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index ee06a6d33b..6c42f1d860 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index 6ef4de5cd9..d1f7dfa85d 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index 6f92c1de77..89c06b344f 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index a647106a53..9f9a3e2892 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index de224776db..d83ecf4fae 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 19c3ed9fc9..9c4f0ab8d3 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 0920cea428..48d8f24a25 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 621c0f484b..1c3d216b18 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index c549cb12a1..bee0ebbb22 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -7,7 +7,6 @@ * */ - /** * @ignore */ -- cgit v1.2.1 From 0bab8ff777bcb82361b75441c085ee2e510db5cc Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 5 Oct 2012 13:43:03 -0500 Subject: [ticket/11103] ACP option to enable/disable notifications output in header PHPBB3-11103 --- phpBB/includes/acp/acp_board.php | 1 + phpBB/includes/functions.php | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 322e1c55d8..aed27d7122 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -314,6 +314,7 @@ class acp_board 'load_online_time' => array('lang' => 'ONLINE_LENGTH', 'validate' => 'int:0', 'type' => 'text:4:3', 'explain' => true, 'append' => ' ' . $user->lang['MINUTES']), 'legend2' => 'GENERAL_OPTIONS', + 'load_notifications' => array('lang' => 'LOAD_NOTIFICATIONS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'load_db_track' => array('lang' => 'YES_POST_MARKING', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'load_db_lastread' => array('lang' => 'YES_READ_MARKING', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'load_anon_lastread' => array('lang' => 'YES_ANON_READ_MARKING', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 9513c6919f..795bfb77bf 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4993,13 +4993,17 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 } // Output the notifications - $notifications = $phpbb_notifications->load_notifications(array( - 'all_unread' => true, - 'limit' => 5, - )); - foreach ($notifications['notifications'] as $notification) + if ($config['load_notifications']) { - $template->assign_block_vars('notifications', $notification->prepare_for_display()); + $notifications = $phpbb_notifications->load_notifications(array( + 'all_unread' => true, + 'limit' => 5, + )); + + foreach ($notifications['notifications'] as $notification) + { + $template->assign_block_vars('notifications', $notification->prepare_for_display()); + } } // The following assigns all _common_ variables that may be used at any point in a template. @@ -5016,8 +5020,9 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'RECORD_USERS' => $l_online_record, 'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text, 'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread, - 'UNREAD_NOTIFICATIONS_COUNT' => $notifications['unread_count'], - 'NOTIFICATIONS_COUNT' => $user->lang('NOTIFICATIONS_COUNT', $notifications['unread_count']), + 'UNREAD_NOTIFICATIONS_COUNT' => ($config['load_notifications']) ? $notifications['unread_count'] : '', + 'NOTIFICATIONS_COUNT' => ($config['load_notifications']) ? $user->lang('NOTIFICATIONS_COUNT', $notifications['unread_count']) : '', + 'S_NOTIFICATIONS_DISPLAY' => $config['load_notifications'], 'S_USER_NEW_PRIVMSG' => $user->data['user_new_privmsg'], 'S_USER_UNREAD_PRIVMSG' => $user->data['user_unread_privmsg'], -- cgit v1.2.1 From 54629aa87d3ef6f6fcb8ce8708e85ac039b98fa3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 5 Oct 2012 13:46:52 -0500 Subject: [ticket/11103] Bug fixing PHPBB3-11103 --- phpBB/includes/notification/type/quote.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 48d8f24a25..1eea8f1066 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -168,7 +168,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post // marked as read // Add the necessary notifications - $service->add_notifications_for_users(self::get_item_type(), $post, $add_notifications); + $this->notification_manager->add_notifications_for_users(self::get_item_type(), $post, $add_notifications); // Remove the necessary notifications if (!empty($remove_notifications)) -- cgit v1.2.1 From 868554cbaeaf7a23db2af4c97aa07c77e6ea98b0 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 5 Oct 2012 13:50:59 -0500 Subject: [ticket/11103] trigger_error message when preferences updated in UCP PHPBB3-11103 --- phpBB/includes/ucp/ucp_notifications.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index 9ea44f49bf..2cb14d05c9 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -64,6 +64,10 @@ class ucp_notifications } } } + + meta_refresh(3, $this->u_action); + $message = $user->lang['PREFERENCES_UPDATED'] . '

' . sprintf($user->lang['RETURN_UCP'], '', ''); + trigger_error($message); } // todo include language files for extensions? -- cgit v1.2.1 From 948bd69495175db6967c0f5e99c3e0ba31e1882a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 5 Oct 2012 13:54:27 -0500 Subject: [ticket/11103] Move UCP Notification Options to Board Preferences tab Also rename to "Edit notification options" for consistency PHPBB3-11103 --- phpBB/includes/ucp/info/ucp_notifications.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/info/ucp_notifications.php b/phpBB/includes/ucp/info/ucp_notifications.php index 4bc9ae2cea..3c7ea80bee 100644 --- a/phpBB/includes/ucp/info/ucp_notifications.php +++ b/phpBB/includes/ucp/info/ucp_notifications.php @@ -19,7 +19,7 @@ class ucp_notifications_info 'title' => 'UCP_NOTIFICATION_OPTIONS', 'version' => '1.0.0', 'modes' => array( - 'notification_options' => array('title' => 'UCP_NOTIFICATION_OPTIONS', 'auth' => '', 'cat' => array('UCP_MAIN')), + 'notification_options' => array('title' => 'UCP_NOTIFICATION_OPTIONS', 'auth' => '', 'cat' => array('UCP_PREFS')), ), ); } -- cgit v1.2.1 From bafb5b0ecad7266c9641624bae2de2f3c7efe500 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 5 Oct 2012 18:12:48 -0500 Subject: [ticket/11103] Starting work on combining notifications Just for posts currently and not yet outputted. PHPBB3-11103 --- phpBB/includes/notification/manager.php | 6 ++++ phpBB/includes/notification/type/base.php | 2 +- phpBB/includes/notification/type/post.php | 58 +++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index c1ae61e08a..c5fd41c901 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -660,6 +660,12 @@ class phpbb_notification_manager */ 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->set_initial_data($data); diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 2ba0dd3bf7..b72875fb85 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -104,7 +104,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ protected function get_data($name) { - return (isset($this->data['data'][$name])) ? $this->data['data'][$name] : null; + return ($name === false) ? $this->data['data'] : ((isset($this->data['data'][$name])) ? $this->data['data'][$name] : null); } /** diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index d83ecf4fae..65b0c1adf2 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -132,6 +132,28 @@ class phpbb_notification_type_post extends phpbb_notification_type_base } $this->db->sql_freeresult($result); + // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications + $update_notifications = array(); + $sql = 'SELECT * + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' + AND unread = 1'; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + // Do not create a new notification + unset($notify_users[$row['user_id']]); + + $notification = $this->notification_manager->get_item_type_class(self::get_item_type(), $row); + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' + WHERE notification_id = ' . $row['notification_id']; + echo $sql; + $this->db->sql_query($sql); + } + $this->db->sql_freeresult($result); + return $notify_users; } @@ -234,4 +256,40 @@ class phpbb_notification_type_post extends phpbb_notification_type_base return parent::create_insert_array($post); } + + /** + * Add responders to the notification + * + * @param mixed $post + */ + public function add_responders($post) + { + // Do not add them as a responder if they were the original poster that created the notification + if ($this->get_data('poster_id') == $post['poster_id']) + { + return array('data' => serialize($this->get_data(false))); + } + + $responders = $this->get_data('responders'); + + $responders = ($responders === null) ? array() : $responders; + + foreach ($responders as $responder) + { + // Do not add them as a responder multiple times + if ($responder['poster_id'] == $post['poster_id']) + { + return array('data' => serialize($this->get_data(false))); + } + } + + $responders[] = array( + 'poster_id' => $post['poster_id'], + 'username' => (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : ''), + ); + + $this->set_data('responders', $responders); + + return array('data' => serialize($this->get_data(false))); + } } -- cgit v1.2.1 From 7a92594bc0b2985019559e85c7d6067c7e9cd1b1 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 9 Oct 2012 10:09:10 -0500 Subject: [ticket/11103] Fix the issue of time changing when editing items PHPBB3-11103 --- phpBB/includes/notification/type/base.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index b72875fb85..a41a5a8ac3 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -82,7 +82,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i public function __get($name) { - return $this->data[$name]; + return (!isset($this->data[$name])) ? null : $this->data[$name]; } public function __set($name, $value) @@ -202,6 +202,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i // Unset data unique to each row unset( + $data['time'], // Also unsetting time, since it always tries to change the time to current (if you actually need to change the time, over-ride this function) $data['notification_id'], $data['unread'], $data['user_id'] -- cgit v1.2.1 From 7411d1d1bdb2e6cc61d5e97d15e184351ea67c64 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 9 Oct 2012 10:30:55 -0500 Subject: [ticket/11103] Starting work on the reported posts notification PHPBB3-11103 --- phpBB/includes/notification/type/post_in_queue.php | 11 ++- phpBB/includes/notification/type/report.php | 85 ++++++++++++++++++++++ 2 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 phpBB/includes/notification/type/report.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 9c4f0ab8d3..60b4bb4937 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -48,6 +48,13 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', ); + /** + * Permission to check for (in find_users_for_notification) + * + * @var string Permission name + */ + protected $permission = 'm_approve'; + /** * Get the type of notification this is * phpbb_notification_type_ @@ -62,7 +69,7 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post */ public function is_available() { - $m_approve = $this->auth->acl_getf('m_approve', true); + $m_approve = $this->auth->acl_getf($this->permission, true); return (!empty($m_approve)); } @@ -80,7 +87,7 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post 'ignore_users' => array(), ), $options); - $auth_approve = $this->auth->acl_get_list(false, 'm_approve', $post['forum_id']); + $auth_approve = $this->auth->acl_get_list(false, $this->permission, $post['forum_id']); if (empty($auth_approve)) { diff --git a/phpBB/includes/notification/type/report.php b/phpBB/includes/notification/type/report.php new file mode 100644 index 0000000000..76c37c99f0 --- /dev/null +++ b/phpBB/includes/notification/type/report.php @@ -0,0 +1,85 @@ + htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), + 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), + + 'U_VIEW_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", + 'U_NEWEST_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&view=unread#unread", + 'U_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + 'U_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}", + 'U_STOP_WATCHING_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?uid={$this->user_id}&f={$this->get_data('forum_id')}&t={$this->item_parent_id}&unwatch=topic", + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports"); + } +} -- cgit v1.2.1 From b33e5273942c4f67e8168763eec224fd61edaa8f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 9 Oct 2012 22:02:49 -0500 Subject: [ticket/11103] Working on report notifications (post/pm) PHPBB3-11103 --- phpBB/includes/mcp/mcp_reports.php | 6 +- phpBB/includes/notification/type/post_in_queue.php | 2 +- phpBB/includes/notification/type/report.php | 85 ---------- phpBB/includes/notification/type/report_pm.php | 178 +++++++++++++++++++++ phpBB/includes/notification/type/report_post.php | 139 ++++++++++++++++ 5 files changed, 323 insertions(+), 87 deletions(-) delete mode 100644 phpBB/includes/notification/type/report.php create mode 100644 phpBB/includes/notification/type/report_pm.php create mode 100644 phpBB/includes/notification/type/report_post.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php index 2890cd56e2..b43f9d6ec4 100644 --- a/phpBB/includes/mcp/mcp_reports.php +++ b/phpBB/includes/mcp/mcp_reports.php @@ -34,6 +34,7 @@ class mcp_reports { global $auth, $db, $user, $template, $cache; global $config, $phpbb_root_path, $phpEx, $action; + global $phpbb_notifications; include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); @@ -87,6 +88,9 @@ class mcp_reports trigger_error('NO_REPORT'); } + // Mark the notification as read + $phpbb_notifications->mark_notifications_read('report_post', $post_id, $user->data['user_id']); + if (!$report_id && $report['report_closed']) { trigger_error('REPORT_CLOSED'); @@ -413,7 +417,7 @@ class mcp_reports $base_url = $this->u_action . "&f=$forum_id&t=$topic_id&st=$sort_days&sk=$sort_key&sd=$sort_dir"; phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start); - + // Now display the page $template->assign_vars(array( 'L_EXPLAIN' => ($mode == 'reports') ? $user->lang['MCP_REPORTS_OPEN_EXPLAIN'] : $user->lang['MCP_REPORTS_CLOSED_EXPLAIN'], diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 60b4bb4937..1d75ca4dc9 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -99,7 +99,7 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $this->db->sql_in_set('user_id', $auth_approve[$post['forum_id']]['m_approve']); + AND " . $this->db->sql_in_set('user_id', $auth_approve[$post['forum_id']][$this->permission]); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { diff --git a/phpBB/includes/notification/type/report.php b/phpBB/includes/notification/type/report.php deleted file mode 100644 index 76c37c99f0..0000000000 --- a/phpBB/includes/notification/type/report.php +++ /dev/null @@ -1,85 +0,0 @@ - htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), - 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), - - 'U_VIEW_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", - 'U_NEWEST_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&view=unread#unread", - 'U_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", - 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", - 'U_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}", - 'U_STOP_WATCHING_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?uid={$this->user_id}&f={$this->get_data('forum_id')}&t={$this->item_parent_id}&unwatch=topic", - ); - } - - /** - * Get the url to this item - * - * @return string URL - */ - public function get_url() - { - return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports"); - } -} diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php new file mode 100644 index 0000000000..9c680ce6a9 --- /dev/null +++ b/phpBB/includes/notification/type/report_pm.php @@ -0,0 +1,178 @@ + 'report', + 'lang' => 'NOTIFICATION_TYPE_REPORT', + ); + + /** + * Get the type of notification this is + * phpbb_notification_type_ + */ + public static function get_item_type() + { + return 'report_pm'; + } + + /** + * Find the users who want to receive notifications + * + * @param array $post Data from the post + * + * @return array + */ + public function find_users_for_notification($post, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + $auth_approve = $this->auth->acl_get_list(false, $this->permission, $post['forum_id']); + + if (empty($auth_approve)) + { + return array(); + } + + $notify_users = array(); + + $sql = 'SELECT * + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::$notification_option['id'] . "' + AND " . $this->db->sql_in_set('user_id', $auth_approve[$post['forum_id']][$this->permission]); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $notify_users[$row['user_id']] = array(); + } + + $notify_users[$row['user_id']][] = $row['method']; + } + $this->db->sql_freeresult($result); + + return $notify_users; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + $board_url = generate_board_url(); + + return array( + 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), + 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), + + 'U_VIEW_REPORT' => "{$board_url}mcp.{$this->php_ext}?f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports", + 'U_VIEW_POST' => "{$board_url}/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", + 'U_NEWEST_POST' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&view=unread#unread", + 'U_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + 'U_VIEW_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + 'U_FORUM' => "{$board_url}/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}", + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports"); + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + $this->user->add_lang('mcp'); + + if (isset($this->user->lang[$this->get_data('reason_title')])) + { + return $this->user->lang( + $this->language_key, + censor_text($this->get_data('post_subject')), + $this->user->lang[$this->get_data('reason_title')] + ); + } + + return $this->user->lang( + $this->language_key, + censor_text($this->get_data('post_subject')), + $this->get_data('reason_description') + ); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $this->set_data('reason_title', strtoupper($post['reason_title'])); + $this->set_data('reason_description', $post['reason_description']); + + return parent::create_insert_array($post); + } +} diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php new file mode 100644 index 0000000000..70d3a4c114 --- /dev/null +++ b/phpBB/includes/notification/type/report_post.php @@ -0,0 +1,139 @@ + 'report', + 'lang' => 'NOTIFICATION_TYPE_REPORT', + ); + + /** + * Get the type of notification this is + * phpbb_notification_type_ + */ + public static function get_item_type() + { + return 'report_post'; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + $board_url = generate_board_url(); + + return array( + 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), + 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), + + 'U_VIEW_REPORT' => "{$board_url}mcp.{$this->php_ext}?f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports", + 'U_VIEW_POST' => "{$board_url}/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", + 'U_NEWEST_POST' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&view=unread#unread", + 'U_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + 'U_VIEW_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + 'U_FORUM' => "{$board_url}/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}", + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports"); + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + $this->user->add_lang('mcp'); + + if (isset($this->user->lang[$this->get_data('reason_title')])) + { + return $this->user->lang( + $this->language_key, + censor_text($this->get_data('post_subject')), + $this->user->lang[$this->get_data('reason_title')] + ); + } + + return $this->user->lang( + $this->language_key, + censor_text($this->get_data('post_subject')), + $this->get_data('reason_description') + ); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $this->set_data('reason_title', strtoupper($post['reason_title'])); + $this->set_data('reason_description', $post['reason_description']); + + return parent::create_insert_array($post); + } +} -- cgit v1.2.1 From 6d53bd4675e00419bcfcf476b03166b9774bebca Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 9 Oct 2012 22:28:41 -0500 Subject: [ticket/11103] Finishing up PM Report notifications PHPBB3-11103 --- phpBB/includes/mcp/mcp_pm_reports.php | 4 +++ phpBB/includes/notification/type/report_pm.php | 44 ++++++++++++++++-------- phpBB/includes/notification/type/report_post.php | 2 +- 3 files changed, 34 insertions(+), 16 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_pm_reports.php b/phpBB/includes/mcp/mcp_pm_reports.php index 24e531517c..227c89bb79 100644 --- a/phpBB/includes/mcp/mcp_pm_reports.php +++ b/phpBB/includes/mcp/mcp_pm_reports.php @@ -34,6 +34,7 @@ class mcp_pm_reports { global $auth, $db, $user, $template, $cache; global $config, $phpbb_root_path, $phpEx, $action; + global $phpbb_notifications; include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); include_once($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx); @@ -89,6 +90,9 @@ class mcp_pm_reports trigger_error('NO_REPORT'); } + // Mark the notification as read + $phpbb_notifications->mark_notifications_read_by_parent('report_pm', $report_id, $user->data['user_id']); + $pm_id = $report['pm_id']; $report_id = $report['report_id']; diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 9c680ce6a9..e9fa4c0f11 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -28,7 +28,14 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm * * @var string */ - public $email_template = 'notifications/report_post'; + public $email_template = 'notifications/report_pm'; + + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_REPORT_PM'; /** * Permission to check for (in find_users_for_notification) @@ -57,8 +64,19 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm return 'report_pm'; } + /** + * Get the id of the parent + * + * @param array $pm The data from the pm + */ + public static function get_item_parent_id($pm) + { + return (int) $pm['report_id']; + } + /** * Find the users who want to receive notifications + * (copied from post_in_queue) * * @param array $post Data from the post * @@ -70,6 +88,9 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm 'ignore_users' => array(), ), $options); + // Global + $post['forum_id'] = 0; + $auth_approve = $this->auth->acl_get_list(false, $this->permission, $post['forum_id']); if (empty($auth_approve)) @@ -110,18 +131,11 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm */ public function get_email_template_variables() { - $board_url = generate_board_url(); - return array( - 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), - 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), - - 'U_VIEW_REPORT' => "{$board_url}mcp.{$this->php_ext}?f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports", - 'U_VIEW_POST' => "{$board_url}/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", - 'U_NEWEST_POST' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&view=unread#unread", - 'U_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", - 'U_VIEW_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", - 'U_FORUM' => "{$board_url}/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}", + 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), + 'SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('message_subject'))), + + 'U_VIEW_REPORT' => generate_board_url() . "mcp.{$this->php_ext}?r={$this->item_parent_id}&i=pm_reports&mode=pm_report_details", ); } @@ -132,7 +146,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm */ public function get_url() { - return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports"); + return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "r={$this->item_parent_id}&i=pm_reports&mode=pm_report_details"); } /** @@ -148,14 +162,14 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm { return $this->user->lang( $this->language_key, - censor_text($this->get_data('post_subject')), + censor_text($this->get_data('message_subject')), $this->user->lang[$this->get_data('reason_title')] ); } return $this->user->lang( $this->language_key, - censor_text($this->get_data('post_subject')), + censor_text($this->get_data('message_subject')), $this->get_data('reason_description') ); } diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index 70d3a4c114..df67a8e338 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -35,7 +35,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i * * @var string */ - protected $language_key = 'NOTIFICATION_REPORT'; + protected $language_key = 'NOTIFICATION_REPORT_POST'; /** * Permission to check for (in find_users_for_notification) -- cgit v1.2.1 From 1b56a1d6be12afb851a158a5e09965a6528d1435 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 11 Oct 2012 22:36:48 -0500 Subject: [ticket/11103] Finishing up report post/pm and adding report closed PHPBB3-11103 --- phpBB/includes/mcp/mcp_reports.php | 34 ++--- phpBB/includes/notification/type/report_pm.php | 25 ++++ .../notification/type/report_pm_closed.php | 140 +++++++++++++++++++++ phpBB/includes/notification/type/report_post.php | 25 ++++ .../notification/type/report_post_closed.php | 140 +++++++++++++++++++++ 5 files changed, 342 insertions(+), 22 deletions(-) create mode 100644 phpBB/includes/notification/type/report_pm_closed.php create mode 100644 phpBB/includes/notification/type/report_post_closed.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php index b43f9d6ec4..7c6352a244 100644 --- a/phpBB/includes/mcp/mcp_reports.php +++ b/phpBB/includes/mcp/mcp_reports.php @@ -448,6 +448,7 @@ function close_report($report_id_list, $mode, $action, $pm = false) { global $db, $template, $user, $config, $auth; global $phpEx, $phpbb_root_path; + global $phpbb_notifications; $pm_where = ($pm) ? ' AND r.post_id = 0 ' : ' AND r.pm_id = 0 '; $id_column = ($pm) ? 'pm_id' : 'post_id'; @@ -633,8 +634,6 @@ function close_report($report_id_list, $mode, $action, $pm = false) } } - $messenger = new messenger(); - // Notify reporters if (sizeof($notify_reporters)) { @@ -647,30 +646,23 @@ function close_report($report_id_list, $mode, $action, $pm = false) $post_id = $reporter[$id_column]; - $messenger->template((($pm) ? 'pm_report_' : 'report_') . $action . 'd', $reporter['user_lang']); - - $messenger->to($reporter['user_email'], $reporter['username']); - $messenger->im($reporter['user_jabber'], $reporter['username']); - if ($pm) { - $messenger->assign_vars(array( - 'USERNAME' => htmlspecialchars_decode($reporter['username']), - 'CLOSER_NAME' => htmlspecialchars_decode($user->data['username']), - 'PM_SUBJECT' => htmlspecialchars_decode(censor_text($post_info[$post_id]['message_subject'])), - )); + $phpbb_notifications->add_notifications('report_pm_closed', array_merge($post_info[$post_id], array( + 'reporter' => $reporter['user_id'], + 'closer_id' => $user->data['user_id'], + 'from_user_id' => $post_info[$post_id]['author_id'], + ))); + $phpbb_notifications->delete_notifications('report_pm', $post_id); } else { - $messenger->assign_vars(array( - 'USERNAME' => htmlspecialchars_decode($reporter['username']), - 'CLOSER_NAME' => htmlspecialchars_decode($user->data['username']), - 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_info[$post_id]['post_subject'])), - 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_info[$post_id]['topic_title']))) - ); + $phpbb_notifications->add_notifications('report_post_closed', array_merge($post_info[$post_id], array( + 'reporter' => $reporter['user_id'], + 'closer_id' => $user->data['user_id'], + ))); + $phpbb_notifications->delete_notifications('report_post', $post_id); } - - $messenger->send($reporter['user_notify_type']); } } @@ -685,8 +677,6 @@ function close_report($report_id_list, $mode, $action, $pm = false) unset($notify_reporters, $post_info, $reports); - $messenger->save_queue(); - $success_msg = (sizeof($report_id_list) == 1) ? "{$pm_prefix}REPORT_" . strtoupper($action) . 'D_SUCCESS' : "{$pm_prefix}REPORTS_" . strtoupper($action) . 'D_SUCCESS'; } else diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index e9fa4c0f11..af1f71433c 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -158,10 +158,15 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm { $this->user->add_lang('mcp'); + $user_data = $this->notification_manager->get_user($this->get_data('reporter_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + if (isset($this->user->lang[$this->get_data('reason_title')])) { return $this->user->lang( $this->language_key, + $username, censor_text($this->get_data('message_subject')), $this->user->lang[$this->get_data('reason_title')] ); @@ -169,11 +174,30 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm return $this->user->lang( $this->language_key, + $username, censor_text($this->get_data('message_subject')), $this->get_data('reason_description') ); } + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('reporter_id')); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['reporter_id']); + } + /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) @@ -184,6 +208,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm */ public function create_insert_array($post) { + $this->set_data('reporter_id', $this->user->data['user_id']); $this->set_data('reason_title', strtoupper($post['reason_title'])); $this->set_data('reason_description', $post['reason_description']); diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php new file mode 100644 index 0000000000..534e1288a6 --- /dev/null +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -0,0 +1,140 @@ + array('')); + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + return array(); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return ''; + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + $user_data = $this->notification_manager->get_user($this->get_data('closer_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + + return $this->user->lang( + $this->language_key, + $username, + censor_text($this->get_data('message_subject')) + ); + } + + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('closer_id')); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['closer_id']); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $this->set_data('closer_id', $post['closer_id']); + + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); + + return $data; + } +} diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index df67a8e338..2346e4e57c 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -105,10 +105,15 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i { $this->user->add_lang('mcp'); + $user_data = $this->notification_manager->get_user($this->get_data('reporter_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + if (isset($this->user->lang[$this->get_data('reason_title')])) { return $this->user->lang( $this->language_key, + $username, censor_text($this->get_data('post_subject')), $this->user->lang[$this->get_data('reason_title')] ); @@ -116,11 +121,30 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i return $this->user->lang( $this->language_key, + $username, censor_text($this->get_data('post_subject')), $this->get_data('reason_description') ); } + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('reporter_id')); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['reporter_id']); + } + /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) @@ -131,6 +155,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i */ public function create_insert_array($post) { + $this->set_data('reporter_id', $this->user->data['user_id']); $this->set_data('reason_title', strtoupper($post['reason_title'])); $this->set_data('reason_description', $post['reason_description']); diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php new file mode 100644 index 0000000000..d8537a8152 --- /dev/null +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -0,0 +1,140 @@ + array('')); + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + return array(); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return ''; + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + $user_data = $this->notification_manager->get_user($this->get_data('closer_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + + return $this->user->lang( + $this->language_key, + $username, + censor_text($this->get_data('post_subject')) + ); + } + + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->_get_avatar($this->get_data('closer_id')); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['closer_id']); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post) + { + $this->set_data('closer_id', $post['closer_id']); + + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); + + return $data; + } +} -- cgit v1.2.1 From 1e3abdc49fa1d51703127033b0d8f2cd45da9741 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 11 Oct 2012 22:40:48 -0500 Subject: [ticket/11103] Remove debug code PHPBB3-11103 --- phpBB/includes/notification/type/post.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 65b0c1adf2..a2b1fbf82a 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -149,7 +149,6 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; - echo $sql; $this->db->sql_query($sql); } $this->db->sql_freeresult($result); -- cgit v1.2.1 From 43e3af4b46bdfe0935c766489a66c5c0f8786e3f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 12 Oct 2012 11:37:51 -0500 Subject: [ticket/11103] Notification grouping output for posts. PHPBB3-11103 --- phpBB/includes/notification/type/post.php | 48 ++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index a2b1fbf82a..d6f6c16e59 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -171,20 +171,36 @@ class phpbb_notification_type_post extends phpbb_notification_type_base */ public function get_title() { - if ($this->get_data('post_username')) + $responders = $this->get_data('responders'); + $usernames = array(); + + if (!is_array($responders)) { - $username = $this->get_data('post_username'); + $responders = array(); } - else + + $responders = array_merge(array(array( + 'poster_id' => $this->get_data('poster_id'), + 'username' => $this->get_data('post_username'), + )), $responders); + + foreach ($responders as $responder) { - $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); + if ($responder['username']) + { + $usernames[] = $responder['username']; + } + else + { + $user_data = $this->notification_manager->get_user($responder['poster_id']); - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $usernames[] = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + } } return $this->user->lang( $this->language_key, - $username, + implode(', ', $usernames), censor_text($this->get_data('topic_title')) ); } @@ -226,7 +242,25 @@ class phpbb_notification_type_post extends phpbb_notification_type_base */ public function users_to_query() { - return array($this->data['poster_id']); + /*$responders[] = array( + 'poster_id' => $post['poster_id'], + 'username' => (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : ''), + );*/ + + $responders = $this->get_data('responders'); + $users = array( + $this->get_data('poster_id'), + ); + + if (is_array($responders)) + { + foreach ($responders as $responder) + { + $users[] = $responder['poster_id']; + } + } + + return $users; } /** -- cgit v1.2.1 From 8b2f1127e4167e241c41f8709964c203e401de94 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 12 Oct 2012 11:40:13 -0500 Subject: [ticket/11103] Notification grouping output for bookmark/quote PHPBB3-11103 --- phpBB/includes/notification/type/bookmark.php | 21 +++++++++++++++++++++ phpBB/includes/notification/type/quote.php | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index 6c42f1d860..8a23859d05 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -107,6 +107,27 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post } $this->db->sql_freeresult($result); + // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications + $update_notifications = array(); + $sql = 'SELECT * + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' + AND unread = 1'; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + // Do not create a new notification + unset($notify_users[$row['user_id']]); + + $notification = $this->notification_manager->get_item_type_class(self::get_item_type(), $row); + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' + WHERE notification_id = ' . $row['notification_id']; + $this->db->sql_query($sql); + } + $this->db->sql_freeresult($result); + return $notify_users; } } diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 1eea8f1066..34907ef8d6 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -126,6 +126,27 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post } $this->db->sql_freeresult($result); + // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications + $update_notifications = array(); + $sql = 'SELECT * + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . self::get_item_type() . "' + AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' + AND unread = 1'; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + // Do not create a new notification + unset($notify_users[$row['user_id']]); + + $notification = $this->notification_manager->get_item_type_class(self::get_item_type(), $row); + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' + WHERE notification_id = ' . $row['notification_id']; + $this->db->sql_query($sql); + } + $this->db->sql_freeresult($result); + return $notify_users; } -- cgit v1.2.1 From 3d79ce28031b4c85ee34bd4d43f0c64b18b1a80b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 12 Oct 2012 16:54:42 -0500 Subject: [ticket/11103] Ability to query data before running create_insert_array() Mark post/topic in queue notifications read when visiting mcp Change post/topic in queue notification url to use MCP. Fix the bug: Approving a topic marks the topic as read, but before the notification is created for the user approving the topic (if they would get a notification that the topic has been made). This causes it to be stuck "unread". PHPBB3-11103 --- phpBB/includes/mcp/mcp_queue.php | 7 ++++ phpBB/includes/notification/manager.php | 9 ++-- phpBB/includes/notification/type/approve_post.php | 5 ++- phpBB/includes/notification/type/approve_topic.php | 5 ++- phpBB/includes/notification/type/base.php | 19 ++++++++- .../includes/notification/type/disapprove_post.php | 3 +- .../notification/type/disapprove_topic.php | 5 ++- phpBB/includes/notification/type/interface.php | 4 +- phpBB/includes/notification/type/pm.php | 5 ++- phpBB/includes/notification/type/post.php | 48 ++++++++++++++++++---- phpBB/includes/notification/type/post_in_queue.php | 15 ++++++- phpBB/includes/notification/type/report_pm.php | 5 ++- .../notification/type/report_pm_closed.php | 5 ++- phpBB/includes/notification/type/report_post.php | 5 ++- .../notification/type/report_post_closed.php | 5 ++- phpBB/includes/notification/type/topic.php | 45 ++++++++++++++++++-- .../includes/notification/type/topic_in_queue.php | 15 ++++++- 17 files changed, 169 insertions(+), 36 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 77e778fc38..b23e5f4e45 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -34,6 +34,7 @@ class mcp_queue { global $auth, $db, $user, $template, $cache; global $config, $phpbb_root_path, $phpEx, $action; + global $phpbb_notifications; include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); @@ -84,6 +85,9 @@ class mcp_queue if (isset($topic_info[$topic_id]['topic_first_post_id'])) { $post_id = (int) $topic_info[$topic_id]['topic_first_post_id']; + + // Mark the notification as read + $phpbb_notifications->mark_notifications_read('topic_in_queue', $topic_id, $user->data['user_id']); } else { @@ -91,6 +95,9 @@ class mcp_queue } } + // Mark the notification as read + $phpbb_notifications->mark_notifications_read('post_in_queue', $post_id, $user->data['user_id']); + $post_info = get_post_data(array($post_id), 'm_approve', true); if (!sizeof($post_info)) diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index c5fd41c901..6c74fa965e 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -324,8 +324,6 @@ class phpbb_notification_manager // Make sure not to send new notifications to users who've already been notified about this item // This may happen when an item was added, but now new users are able to see the item - // todo Users should not receive notifications from multiple events from the same item (ex: for a topic reply with a quote including your username) - // Probably should be handled within each type? $sql = 'SELECT user_id FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' @@ -342,6 +340,11 @@ class phpbb_notification_manager return; } + // 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); + $pre_create_data = $notification->pre_create_insert_array($data, $notify_users); + unset($notification); + // 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) { @@ -350,7 +353,7 @@ class phpbb_notification_manager $notification->user_id = (int) $user; // Store the creation array in our new rows that will be inserted later - $new_rows[] = $notification->create_insert_array($data); + $new_rows[] = $notification->create_insert_array($data, $pre_create_data); // Users are needed to send notifications $user_ids = array_merge($user_ids, $notification->users_to_query()); diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 98dfe678c2..9275ec2f6d 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -111,14 +111,15 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('post_subject', $post['post_subject']); - $data = parent::create_insert_array($post); + $data = parent::create_insert_array($post, $pre_create_data); $this->time = $data['time'] = time(); diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 496dc688ad..325ccd0eab 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -111,12 +111,13 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { - $data = parent::create_insert_array($post); + $data = parent::create_insert_array($post, $pre_create_data); $this->time = $data['time'] = time(); diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index a41a5a8ac3..45dc463061 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -164,10 +164,11 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * (The service handles insertion) * * @param array $type_data Data unique to this notification type + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($type_data) + public function create_insert_array($type_data, $pre_create_data = array()) { // Defaults $this->data = array_merge(array( @@ -257,6 +258,22 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i return true; } + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $type_data Data unique to this notification type + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ + public function pre_create_insert_array($type_data, $notify_users) + { + return array(); + } + /** * -------------- Helper functions ------------------- */ diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index d1f7dfa85d..1bf9242c52 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -98,10 +98,11 @@ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_ap * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('disapprove_reason', $post['disapprove_reason']); diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index 89c06b344f..f3e0be4883 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -98,14 +98,15 @@ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_a * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('disapprove_reason', $post['disapprove_reason']); - $data = parent::create_insert_array($post); + $data = parent::create_insert_array($post, $pre_create_data); $this->time = $data['time'] = time(); diff --git a/phpBB/includes/notification/type/interface.php b/phpBB/includes/notification/type/interface.php index 56fad9fd80..084a819af7 100644 --- a/phpBB/includes/notification/type/interface.php +++ b/phpBB/includes/notification/type/interface.php @@ -41,7 +41,9 @@ interface phpbb_notification_type_interface public function mark_unread($return); - public function create_insert_array($type_data); + public function pre_create_insert_array($type_data, $notify_users); + + public function create_insert_array($type_data, $pre_create_data); public function users_to_query(); diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index 9f9a3e2892..c2065fef99 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -170,15 +170,16 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($pm) + public function create_insert_array($pm, $pre_create_data = array()) { $this->set_data('from_user_id', $pm['from_user_id']); $this->set_data('message_subject', $pm['message_subject']); - return parent::create_insert_array($pm); + return parent::create_insert_array($pm, $pre_create_data); } } diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index d6f6c16e59..76a7846f30 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -242,11 +242,6 @@ class phpbb_notification_type_post extends phpbb_notification_type_base */ public function users_to_query() { - /*$responders[] = array( - 'poster_id' => $post['poster_id'], - 'username' => (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : ''), - );*/ - $responders = $this->get_data('responders'); $users = array( $this->get_data('poster_id'), @@ -263,15 +258,47 @@ class phpbb_notification_type_post extends phpbb_notification_type_base return $users; } + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $post Post data from submit_post + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ + public function pre_create_insert_array($post, $notify_users) + { + if (!sizeof($notify_users)) + { + return array(); + } + + $tracking_data = array(); + $sql = 'SELECT user_id, mark_time FROM ' . TOPICS_TRACK_TABLE . ' + WHERE topic_id = ' . (int) $post['topic_id'] . ' + AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users)); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $tracking_data[$row['user_id']] = $row['mark_time']; + } + + return $tracking_data; + } + /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('poster_id', $post['poster_id']); @@ -287,7 +314,14 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $this->time = $post['post_time']; - return parent::create_insert_array($post); + // Topics can be "read" before they are public (while awaiting approval). + // Make sure that if the user has read the topic, it's marked as read in the notification + if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->time) + { + $this->unread = false; + } + + return parent::create_insert_array($post, $pre_create_data); } /** diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 1d75ca4dc9..f00a83de36 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -120,17 +120,28 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post return $notify_users; } + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "i=queue&mode=approve_details&f={$this->get_data('forum_id')}&p={$this->item_id}"); + } + /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { - $data = parent::create_insert_array($post); + $data = parent::create_insert_array($post, $pre_create_data); $this->time = $data['time'] = time(); diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index af1f71433c..db0ad6ac6e 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -203,15 +203,16 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('reporter_id', $this->user->data['user_id']); $this->set_data('reason_title', strtoupper($post['reason_title'])); $this->set_data('reason_description', $post['reason_description']); - return parent::create_insert_array($post); + return parent::create_insert_array($post, $pre_create_data); } } diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index 534e1288a6..f5790ba449 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -124,14 +124,15 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('closer_id', $post['closer_id']); - $data = parent::create_insert_array($post); + $data = parent::create_insert_array($post, $pre_create_data); $this->time = $data['time'] = time(); diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index 2346e4e57c..d7a0d58167 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -150,15 +150,16 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('reporter_id', $this->user->data['user_id']); $this->set_data('reason_title', strtoupper($post['reason_title'])); $this->set_data('reason_description', $post['reason_description']); - return parent::create_insert_array($post); + return parent::create_insert_array($post, $pre_create_data); } } diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index d8537a8152..0d5c5b292e 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -124,14 +124,15 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('closer_id', $post['closer_id']); - $data = parent::create_insert_array($post); + $data = parent::create_insert_array($post, $pre_create_data); $this->time = $data['time'] = time(); diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 1c3d216b18..cb38b0274e 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -76,7 +76,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base public function find_users_for_notification($topic, $options = array()) { $options = array_merge(array( - 'ignore_users' => array(), + 'ignore_users' => array(), ), $options); // Let's continue to use the phpBB subscriptions system, at least for now. @@ -207,15 +207,47 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base return array($this->data['poster_id']); } + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $post Post data from submit_post + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ + public function pre_create_insert_array($post, $notify_users) + { + if (!sizeof($notify_users)) + { + return array(); + } + + $tracking_data = array(); + $sql = 'SELECT user_id, mark_time FROM ' . TOPICS_TRACK_TABLE . ' + WHERE topic_id = ' . (int) $post['topic_id'] . ' + AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users)); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $tracking_data[$row['user_id']] = $row['mark_time']; + } + + return $tracking_data; + } + /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) * * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post) + public function create_insert_array($post, $pre_create_data = array()) { $this->set_data('poster_id', $post['poster_id']); @@ -227,6 +259,13 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base $this->time = $post['post_time']; - return parent::create_insert_array($post); + // Topics can be "read" before they are public (while awaiting approval). + // Make sure that if the user has read the topic, it's marked as read in the notification + if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->time) + { + $this->unread = false; + } + + return parent::create_insert_array($post, $pre_create_data); } } diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index bee0ebbb22..176ec0b901 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -113,17 +113,28 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top return $notify_users; } + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "i=queue&mode=approve_details&f={$this->item_parent_id}&t={$this->item_id}"); + } + /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) * * @param array $topic Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($topic) + public function create_insert_array($topic, $pre_create_data = array()) { - $data = parent::create_insert_array($topic); + $data = parent::create_insert_array($topic, $pre_create_data); $this->time = $data['time'] = time(); -- cgit v1.2.1 From 4392054044d3bf63481098cca9e27e17ae306fa0 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 13 Oct 2012 17:06:01 -0500 Subject: [ticket/11103] Reported pm notifications require m_report permissions PHPBB3-11103 --- phpBB/includes/notification/type/report_pm.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index db0ad6ac6e..3619c5510c 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -74,6 +74,17 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm return (int) $pm['report_id']; } + /** + * Is available + */ + public function is_available() + { + $m_approve = $this->auth->acl_getf($this->permission, true); + + return (!empty($m_approve)); + } + + /** * Find the users who want to receive notifications * (copied from post_in_queue) -- cgit v1.2.1 From 397d039ce5c7b61145b4ff8daa41e511a75122c6 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 13 Oct 2012 17:37:59 -0500 Subject: [ticket/11103] Allow global moderators to receive moderator notifications PHPBB3-11103 --- phpBB/includes/notification/type/post_in_queue.php | 5 ++++- phpBB/includes/notification/type/topic_in_queue.php | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index f00a83de36..4f92eb157a 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -87,13 +87,16 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post 'ignore_users' => array(), ), $options); - $auth_approve = $this->auth->acl_get_list(false, $this->permission, $post['forum_id']); + // 0 is for global + $auth_approve = $this->auth->acl_get_list(false, $this->permission, array($post['forum_id'], 0)); if (empty($auth_approve)) { return array(); } + $auth_approve[$post['forum_id']] = array_unique(array_merge($auth_approve[$post['forum_id']], $auth_approve[0])); + $notify_users = array(); $sql = 'SELECT * diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index 176ec0b901..96f09cef9e 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -80,13 +80,16 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top 'ignore_users' => array(), ), $options); - $auth_approve = $this->auth->acl_get_list(false, 'm_approve', $topic['forum_id']); + // 0 is for global + $auth_approve = $this->auth->acl_get_list(false, 'm_approve', array($topic['forum_id'], 0)); if (empty($auth_approve)) { return array(); } + $auth_approve[$topic['forum_id']] = array_unique(array_merge($auth_approve[$topic['forum_id']], $auth_approve[0])); + $notify_users = array(); $sql = 'SELECT * -- cgit v1.2.1 From c60b15294a72d5a2be8e7d23fd1b4052ec944ec8 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 13 Oct 2012 17:49:12 -0500 Subject: [ticket/11103] Global moderators with m_approve permission never need approval They do not need to receive notifications if their post/topic is approved or disapproved PHPBB3-11103 --- phpBB/includes/notification/type/approve_post.php | 8 ++++++++ phpBB/includes/notification/type/approve_topic.php | 8 ++++++++ 2 files changed, 16 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 9275ec2f6d..dbd2e4417f 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -57,6 +57,14 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post return 'approve_post'; } + /** + * Is available + */ + public function is_available() + { + return !$this->auth->acl_get('m_approve'); + } + /** * Find the users who want to receive notifications * diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 325ccd0eab..3608bfba85 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -57,6 +57,14 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi return 'approve_topic'; } + /** + * Is available + */ + public function is_available() + { + return !$this->auth->acl_get('m_approve'); + } + /** * Find the users who want to receive notifications * -- cgit v1.2.1 From 39fd31d3aedd5d583041b1ee76bed3e7d0edcf36 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 13 Oct 2012 18:12:33 -0500 Subject: [ticket/11103] Trying to fix an odd issue with unread status on approved posts From a recent change, when your posts/topics are approved, they will be marked read automatically because you've read the topic/post already. To change that I've forced the notification to be marked unread and attempted to reset the read status on the post/topic to be unread before the post that was approved. This does not seem to work so well and I don't know of any way this can really be properly fixed, so the code I was working on I've commented out. For now, users will just need to manually mark these types of notifications as read. I cannot think of a way for this to be fixed without running two additional queries on every viewtopic. PHPBB3-11103 --- phpBB/includes/notification/type/approve_post.php | 32 ++++++++++++++++++++++ phpBB/includes/notification/type/approve_topic.php | 30 ++++++++++++++++++++ 2 files changed, 62 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index dbd2e4417f..68e8352a13 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -114,6 +114,38 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post return $notify_users; } + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $post Post data from submit_post + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ + public function pre_create_insert_array($post, $notify_users) + { + /*if (!sizeof($notify_users)) + { + return array(); + } + + // Mark the topic unread before the post + $sql = 'UPDATE ' . TOPICS_TRACK_TABLE . ' + SET mark_time = ' . (int) ($post['post_time'] - 1) . ' + WHERE topic_id = ' . (int) $post['topic_id'] . ' + AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users)); + $this->db->sql_query($sql);*/ + + // In the parent class, this is used to check if the post is already + // read by a user and marks the notification read if it was marked read. + // Returning an empty array in effect, forces it to be marked as unread + // (and also saves a query) + return array(); + } + /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 3608bfba85..f3a94e44b8 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -114,6 +114,36 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi return $notify_users; } + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $post Post data from submit_post + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ + public function pre_create_insert_array($post, $notify_users) + { + /*if (!sizeof($notify_users)) + { + return array(); + } + + // Mark the topic unread + $sql = 'DELETE FROM ' . TOPICS_TRACK_TABLE . ' + WHERE topic_id = ' . (int) $post['topic_id'] . ' + AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users)); + $this->db->sql_query($sql*/ + + // In the parent class, this is used to check if the post is already + // read by a user and marks the notification read if it was marked read. + // Returning an empty array in effect, forces it to be marked as unread + return array(); + } + /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) -- cgit v1.2.1 From 6df3de2b9c723ef3fe190ba85a0b5fa419f86b6f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 13 Oct 2012 18:58:29 -0500 Subject: [ticket/11103] Starting work on UCP Notifications list PHPBB3-11103 --- phpBB/includes/ucp/ucp_notifications.php | 89 +++++++++++++++++--------------- 1 file changed, 48 insertions(+), 41 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index 2cb14d05c9..8ce12dae35 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -25,59 +25,66 @@ class ucp_notifications add_form_key('ucp_notification_options'); - $subscriptions = $phpbb_notifications->get_subscriptions(false, true); - - // Add/remove subscriptions - if ($request->is_set_post('submit')) + switch ($mode) { - if (!check_form_key('ucp_notification_options')) - { - trigger_error('FORM_INVALID'); - } - - $notification_methods = $phpbb_notifications->get_subscription_methods(); + case 'notification_options': + $subscriptions = $phpbb_notifications->get_subscriptions(false, true); - foreach($phpbb_notifications->get_subscription_types() as $type => $data) - { - if ($request->is_set_post($type . '_notification') && !isset($subscriptions[$type])) - { - // add - $phpbb_notifications->add_subscription($type); - } - else if (!$request->is_set_post($type . '_notification') && isset($subscriptions[$type])) + // Add/remove subscriptions + if ($request->is_set_post('submit')) { - // remove - $phpbb_notifications->delete_subscription($type); - } - - foreach($notification_methods as $method) - { - if ($request->is_set_post($type . '_' . $method) && (!isset($subscriptions[$type]) || !in_array($method, $subscriptions[$type]))) + if (!check_form_key('ucp_notification_options')) { - // add - $phpbb_notifications->add_subscription($type, 0, $method); + trigger_error('FORM_INVALID'); } - else if (!$request->is_set_post($type . '_' . $method) && isset($subscriptions[$type]) && in_array($method, $subscriptions[$type])) + + $notification_methods = $phpbb_notifications->get_subscription_methods(); + + foreach($phpbb_notifications->get_subscription_types() as $type => $data) { - // remove - $phpbb_notifications->delete_subscription($type, 0, $method); + if ($request->is_set_post($type . '_notification') && !isset($subscriptions[$type])) + { + // add + $phpbb_notifications->add_subscription($type); + } + else if (!$request->is_set_post($type . '_notification') && isset($subscriptions[$type])) + { + // remove + $phpbb_notifications->delete_subscription($type); + } + + foreach($notification_methods as $method) + { + if ($request->is_set_post($type . '_' . $method) && (!isset($subscriptions[$type]) || !in_array($method, $subscriptions[$type]))) + { + // add + $phpbb_notifications->add_subscription($type, 0, $method); + } + else if (!$request->is_set_post($type . '_' . $method) && isset($subscriptions[$type]) && in_array($method, $subscriptions[$type])) + { + // remove + $phpbb_notifications->delete_subscription($type, 0, $method); + } + } } - } - } - meta_refresh(3, $this->u_action); - $message = $user->lang['PREFERENCES_UPDATED'] . '

' . sprintf($user->lang['RETURN_UCP'], '', ''); - trigger_error($message); - } + meta_refresh(3, $this->u_action); + $message = $user->lang['PREFERENCES_UPDATED'] . '

' . sprintf($user->lang['RETURN_UCP'], '', ''); + trigger_error($message); + } + // todo include language files for extensions? - // todo include language files for extensions? + $this->output_notification_methods('notification_methods', $phpbb_notifications, $template, $user); - $this->output_notification_methods('notification_methods', $phpbb_notifications, $template, $user); + $this->output_notification_types('notification_types', $phpbb_notifications, $template, $user); - $this->output_notification_types('notification_types', $phpbb_notifications, $template, $user); + $this->tpl_name = 'ucp_notifications'; + $this->page_title = 'UCP_NOTIFICATIONS'; + break; - $this->tpl_name = 'ucp_notifications'; - $this->page_title = 'UCP_NOTIFICATIONS'; + default: + //$phpbb_notifications->load_notifications(); + break; } /** -- cgit v1.2.1 From cb937841269017d13058208378e4c9ad79718c6e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 13 Oct 2012 20:02:38 -0500 Subject: [ticket/11103] UCP Notification List PHPBB3-11103 --- phpBB/includes/notification/manager.php | 33 ++++++++--- phpBB/includes/notification/type/base.php | 6 +- phpBB/includes/ucp/info/ucp_notifications.php | 1 + phpBB/includes/ucp/ucp_notifications.php | 82 +++++++++++++++++++++++++-- 4 files changed, 108 insertions(+), 14 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 6c74fa965e..22fa12967a 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -68,6 +68,7 @@ class phpbb_notification_manager 'start' => 0, 'all_unread' => false, 'count_unread' => false, + 'count_total' => false, ), $options); // If all_unread, count_unread mus be true @@ -79,12 +80,13 @@ class phpbb_notification_manager return array( 'notifications' => array(), 'unread_count' => 0, + 'total_count' => 0, ); } $notifications = $user_ids = array(); $load_special = array(); - $count = 0; + $total_count = $unread_count = 0; if ($options['count_unread']) { @@ -94,7 +96,18 @@ class phpbb_notification_manager WHERE user_id = ' . (int) $options['user_id'] . ' AND unread = 1'; $result = $this->db->sql_query($sql); - $count = (int) $this->db->sql_fetchfield('count', $result); + $unread_count = (int) $this->db->sql_fetchfield('count', $result); + $this->db->sql_freeresult($result); + } + + if ($options['count_total']) + { + // Get the total number of notifications + $sql = 'SELECT COUNT(*) AS count + FROM ' . NOTIFICATIONS_TABLE . ' + WHERE user_id = ' . (int) $options['user_id']; + $result = $this->db->sql_query($sql); + $total_count = (int) $this->db->sql_fetchfield('count', $result); $this->db->sql_freeresult($result); } @@ -115,7 +128,7 @@ class phpbb_notification_manager $this->db->sql_freeresult($result); // Get all unread notifications - if ($count && $options['all_unread'] && !empty($rowset)) + if ($unread_count && $options['all_unread'] && !empty($rowset)) { $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . ' @@ -165,14 +178,15 @@ class phpbb_notification_manager return array( 'notifications' => $notifications, - 'unread_count' => $count, + 'unread_count' => $unread_count, + 'total_count' => $total_count, ); } /** * Mark notifications read * - * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) + * @param bool|string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types). False to mark read for all item types * @param bool|int|array $item_id Item id or array of item ids. False to mark read for all item ids * @param bool|int|array $user_id User id or array of user ids. False to mark read for all user ids * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False) @@ -191,12 +205,15 @@ class phpbb_notification_manager $time = ($time) ?: time(); - $this->get_item_type_class_name($item_type); + if ($item_type !== false) + { + $this->get_item_type_class_name($item_type); + } $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " SET unread = 0 - WHERE item_type = '" . $this->db->sql_escape($item_type) . "' - AND time <= " . $time . + WHERE time <= " . $time . + (($item_type !== false) ? ' AND ' . (is_array($item_type) ? $this->db->sql_in_set('item_type', $item_type) : " item_type = '" . $this->db->sql_escape($item_type) . "'") : '') . (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : '') . (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 45dc463061..f6b61aee49 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -124,6 +124,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i public function prepare_for_display() { return array( + 'NOTIFICATION_ID' => $this->notification_id, + 'AVATAR' => $this->get_avatar(), 'FORMATTED_TITLE' => $this->get_title(), @@ -344,6 +346,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ protected function mark($unread = true, $return = false) { + $this->unread = (bool) $unread; + $where = array( 'item_type = ' . $this->db->sql_escape($this->item_type), 'item_id = ' . (int) $this->item_id, @@ -357,7 +361,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i } $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' - SET unread = ' . (bool) $unread . ' + SET unread = ' . $this->unread . ' WHERE ' . $where; $this->db->sql_query($sql); } diff --git a/phpBB/includes/ucp/info/ucp_notifications.php b/phpBB/includes/ucp/info/ucp_notifications.php index 3c7ea80bee..98d8b9db61 100644 --- a/phpBB/includes/ucp/info/ucp_notifications.php +++ b/phpBB/includes/ucp/info/ucp_notifications.php @@ -20,6 +20,7 @@ class ucp_notifications_info 'version' => '1.0.0', 'modes' => array( 'notification_options' => array('title' => 'UCP_NOTIFICATION_OPTIONS', 'auth' => '', 'cat' => array('UCP_PREFS')), + 'notification_list' => array('title' => 'UCP_NOTIFICATION_LIST', 'auth' => '', 'cat' => array('UCP_MAIN')), ), ); } diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index 8ce12dae35..35783e1b56 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -21,9 +21,13 @@ class ucp_notifications public function main($id, $mode) { - global $template, $user, $request, $phpbb_notifications; + global $config, $template, $user, $request, $phpbb_notifications; + global $phpbb_root_path, $phpEx; - add_form_key('ucp_notification_options'); + add_form_key('ucp_notification'); + + $start = request_var('start', 0); + $form_time = min(request_var('form_time', 0), time()); switch ($mode) { @@ -33,7 +37,7 @@ class ucp_notifications // Add/remove subscriptions if ($request->is_set_post('submit')) { - if (!check_form_key('ucp_notification_options')) + if (!check_form_key('ucp_notification')) { trigger_error('FORM_INVALID'); } @@ -79,12 +83,80 @@ class ucp_notifications $this->output_notification_types('notification_types', $phpbb_notifications, $template, $user); $this->tpl_name = 'ucp_notifications'; - $this->page_title = 'UCP_NOTIFICATIONS'; + $this->page_title = 'UCP_NOTIFICATION_OPTIONS'; break; + case 'notification_list': default: - //$phpbb_notifications->load_notifications(); + // Mark all items read + if (request_var('mark', '') == 'all' && (confirm_box(true) || check_link_hash(request_var('token', ''), 'mark_all_notifications_read'))) + { + if (confirm_box(true)) + { + $phpbb_notifications->mark_notifications_read(false, false, $user->data['user_id'], $form_time); + + meta_refresh(3, $this->u_action); + $message = $user->lang['NOTIFICATIONS_MARK_ALL_READ_SUCCESS'] . '

' . sprintf($user->lang['RETURN_UCP'], '', ''); + trigger_error($message); + } + else + { + confirm_box(false, 'NOTIFICATIONS_MARK_ALL_READ', build_hidden_fields(array( + 'mark' => 'all', + 'form_time' => $form_time, + ))); + } + } + + // Mark specific notifications read + if ($request->is_set_post('submit')) + { + if (!check_form_key('ucp_notification')) + { + trigger_error('FORM_INVALID'); + } + + $mark_read = request_var('mark', array(0)); + + if (!empty($mark_read)) + { + $phpbb_notifications->mark_notifications_read_by_id($mark_read, $form_time); + } + } + + $notifications = $phpbb_notifications->load_notifications(array( + 'start' => $start, + 'limit' => $config['topics_per_page'], + 'count_total' => true, + )); + + foreach ($notifications['notifications'] as $notification) + { + $template->assign_block_vars('notification_list', $notification->prepare_for_display()); + } + + $base_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=ucp_notifications&mode=notification_list"); + phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $notifications['total_count'], $config['topics_per_page'], $start); + + $template->assign_vars(array( + 'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $notifications['total_count'], $config['topics_per_page'], $start), + 'TOTAL_COUNT' => $user->lang('NOTIFICATIONS_COUNT', $notifications['total_count']), + 'U_MARK_ALL' => $base_url . '&mark=all&token=' . generate_link_hash('mark_all_notifications_read'), + )); + + $this->tpl_name = 'ucp_notifications'; + $this->page_title = 'UCP_NOTIFICATION_LIST'; break; + } + + $template->assign_vars(array( + 'TITLE' => $user->lang($this->page_title), + 'TITLE_EXPLAIN' => $user->lang($this->page_title . '_EXPLAIN'), + + 'MODE' => $mode, + + 'FORM_TIME' => time(), + )); } /** -- cgit v1.2.1 From 94ffbb4050b2985ee62be0ecc0c6a244532e43ca Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 13 Oct 2012 23:24:30 -0500 Subject: [ticket/11103] Add is_disabled column to notifications table EXTENSION AUTHORS TAKE NOTE! This is to prevent errors with notifications from extensions! Set is_disabled to 1 for all your notifications when your extension is disabled so they are ignored and do not cause errors. When your extension is enabled again, set is_disabled to 0 and your notifications will be working again. PHPBB3-11103 --- phpBB/includes/notification/manager.php | 15 ++++++++++----- phpBB/includes/notification/type/base.php | 5 ++++- phpBB/includes/notification/type/bookmark.php | 3 ++- phpBB/includes/notification/type/post.php | 3 ++- phpBB/includes/notification/type/quote.php | 6 ++++-- 5 files changed, 22 insertions(+), 10 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 22fa12967a..16fdae6dd0 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -94,7 +94,8 @@ class phpbb_notification_manager $sql = 'SELECT COUNT(*) AS count FROM ' . NOTIFICATIONS_TABLE . ' WHERE user_id = ' . (int) $options['user_id'] . ' - AND unread = 1'; + AND unread = 1 + AND is_disabled = 0'; $result = $this->db->sql_query($sql); $unread_count = (int) $this->db->sql_fetchfield('count', $result); $this->db->sql_freeresult($result); @@ -105,7 +106,8 @@ class phpbb_notification_manager // Get the total number of notifications $sql = 'SELECT COUNT(*) AS count FROM ' . NOTIFICATIONS_TABLE . ' - WHERE user_id = ' . (int) $options['user_id']; + WHERE user_id = ' . (int) $options['user_id'] . ' + AND is_disabled = 0'; $result = $this->db->sql_query($sql); $total_count = (int) $this->db->sql_fetchfield('count', $result); $this->db->sql_freeresult($result); @@ -118,7 +120,8 @@ class phpbb_notification_manager 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']) : '') . ' - ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']); + AND is_disabled = 0 + 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)) @@ -135,7 +138,8 @@ class phpbb_notification_manager WHERE user_id = ' . (int) $options['user_id'] . ' AND unread = 1 AND ' . $this->db->sql_in_set('notification_id', array_keys($rowset), true) . ' - ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']); + AND is_disabled = 0 + 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)) @@ -344,7 +348,8 @@ class phpbb_notification_manager $sql = 'SELECT user_id FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' - AND item_id = " . (int) $item_id; + AND item_id = " . (int) $item_id . ' + AND is_disabled = 0'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index f6b61aee49..3aac8a7dd3 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -42,9 +42,12 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * Indentification data * item_type * item_id - * item_parent_id // Parent item id (ex: for topic => forum_id, for post => topic_id, etc) + * item_parent_id - Parent item id (ex: for topic => forum_id, for post => topic_id, etc) * user_id * unread + * is_disabled - EXTENSION AUTHORS TAKE NOTE! This is to prevent errors with notifications from extensions! + * - Set is_disabled to 1 for all your notifications when your extension is disabled so they are ignored and do not cause errors. + * - When your extension is enabled again, set is_disabled to 0 and your notifications will be working again. * * time * data (special serialized field that each notification type can use to store stuff) diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index 8a23859d05..e5435b5829 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -113,7 +113,8 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' - AND unread = 1'; + AND unread = 1 + AND is_disabled = 0'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 76a7846f30..a4792cd7f2 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -138,7 +138,8 @@ class phpbb_notification_type_post extends phpbb_notification_type_base FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' - AND unread = 1'; + AND unread = 1 + AND is_disabled = 0'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 34907ef8d6..4d1e637820 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -132,7 +132,8 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' - AND unread = 1'; + AND unread = 1 + AND is_disabled = 0'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { @@ -161,7 +162,8 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $sql = 'SELECT user_id FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' - AND item_id = " . self::get_item_id($post); + AND item_id = " . self::get_item_id($post) . ' + AND is_disabled = 0'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { -- cgit v1.2.1 From c5f280351a96aaebd90c27da095c9b1ff28624a5 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 13 Oct 2012 23:52:49 -0500 Subject: [ticket/11103] UCP Notification option grouping Also add the ability to specify an _EXPLAIN text for the notification option PHPBB3-11103 --- phpBB/includes/notification/manager.php | 23 +++++--- phpBB/includes/notification/type/approve_post.php | 3 +- phpBB/includes/notification/type/approve_topic.php | 3 +- phpBB/includes/notification/type/base.php | 2 +- .../includes/notification/type/disapprove_post.php | 3 +- .../notification/type/disapprove_topic.php | 3 +- phpBB/includes/notification/type/post.php | 10 ++++ phpBB/includes/notification/type/post_in_queue.php | 3 +- phpBB/includes/notification/type/report_pm.php | 3 +- phpBB/includes/notification/type/report_post.php | 1 + phpBB/includes/notification/type/topic.php | 10 ++++ .../includes/notification/type/topic_in_queue.php | 3 +- phpBB/includes/ucp/ucp_notifications.php | 67 +++++++++++++--------- 13 files changed, 90 insertions(+), 44 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 16fdae6dd0..fc9b48c624 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -495,17 +495,24 @@ class phpbb_notification_manager if ($class->is_available() && method_exists($class_name, 'get_item_type')) { - if ($class_name::$notification_option === false) - { - $subscription_types[$class_name::get_item_type()] = $class_name::get_item_type(); - } - else - { - $subscription_types[$class_name::$notification_option['id']] = $class_name::$notification_option; - } + $options = array_merge(array( + 'id' => $class_name::get_item_type(), + 'lang' => 'NOTIFICATION_TYPE_' . strtoupper($class_name::get_item_type()), + 'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS', + ), (($class_name::$notification_option !== false) ? $class_name::$notification_option : array())); + + $subscription_types[$options['group']][$options['id']] = $options; } } + // Move Miscellaneous to the very last section + if (isset($subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'])) + { + $miscellaneous = $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']; + unset($subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']); + $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'] = $miscellaneous; + } + return $subscription_types; } diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 68e8352a13..6ed9b6c67c 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -41,11 +41,12 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post * Notification option data (for outputting to the user) * * @var bool|array False if the service should use it's default data - * Array of data (including keys 'id' and 'lang') + * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = array( 'id' => 'moderation_queue', 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + 'group' => 'NOTIFICATION_GROUP_POSTING', ); /** diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index f3a94e44b8..1ff5ae43bd 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -41,11 +41,12 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi * Notification option data (for outputting to the user) * * @var bool|array False if the service should use it's default data - * Array of data (including keys 'id' and 'lang') + * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = array( 'id' => 'moderation_queue', 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + 'group' => 'NOTIFICATION_GROUP_POSTING', ); /** diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 3aac8a7dd3..e8959d1352 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -34,7 +34,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * Notification option data (for outputting to the user) * * @var bool|array False if the service should use its default data - * Array of data (including keys 'id' and 'lang') + * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = false; diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index 1bf9242c52..8044a3e0ea 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -41,11 +41,12 @@ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_ap * Notification option data (for outputting to the user) * * @var bool|array False if the service should use it's default data - * Array of data (including keys 'id' and 'lang') + * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = array( 'id' => 'moderation_queue', 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + 'group' => 'NOTIFICATION_GROUP_POSTING', ); /** diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index f3e0be4883..04fec87014 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -41,11 +41,12 @@ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_a * Notification option data (for outputting to the user) * * @var bool|array False if the service should use it's default data - * Array of data (including keys 'id' and 'lang') + * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = array( 'id' => 'moderation_queue', 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + 'group' => 'NOTIFICATION_GROUP_POSTING', ); /** diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index a4792cd7f2..ee26a8c33e 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -37,6 +37,16 @@ class phpbb_notification_type_post extends phpbb_notification_type_base */ protected $language_key = 'NOTIFICATION_POST'; + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id', 'lang', and 'group') + */ + public static $notification_option = array( + 'group' => 'NOTIFICATION_GROUP_POSTING', + ); + /** * Get the type of notification this is * phpbb_notification_type_ diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 4f92eb157a..499fd1e8ed 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -41,11 +41,12 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post * Notification option data (for outputting to the user) * * @var bool|array False if the service should use it's default data - * Array of data (including keys 'id' and 'lang') + * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = array( 'id' => 'needs_approval', 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', + 'group' => 'NOTIFICATION_GROUP_MODERATION', ); /** diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 3619c5510c..440092afdc 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -48,11 +48,12 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm * Notification option data (for outputting to the user) * * @var bool|array False if the service should use it's default data - * Array of data (including keys 'id' and 'lang') + * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = array( 'id' => 'report', 'lang' => 'NOTIFICATION_TYPE_REPORT', + 'group' => 'NOTIFICATION_GROUP_MODERATION', ); /** diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index d7a0d58167..d860fb1b38 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -53,6 +53,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i public static $notification_option = array( 'id' => 'report', 'lang' => 'NOTIFICATION_TYPE_REPORT', + 'group' => 'NOTIFICATION_GROUP_MODERATION', ); /** diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index cb38b0274e..237f430003 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -37,6 +37,16 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base */ protected $language_key = 'NOTIFICATION_TOPIC'; + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id', 'lang', and 'group') + */ + public static $notification_option = array( + 'group' => 'NOTIFICATION_GROUP_POSTING', + ); + /** * Get the type of notification this is * phpbb_notification_type_ diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index 96f09cef9e..eb14c098e1 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -41,11 +41,12 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top * Notification option data (for outputting to the user) * * @var bool|array False if the service should use it's default data - * Array of data (including keys 'id' and 'lang') + * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = array( 'id' => 'needs_approval', 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', + 'group' => 'NOTIFICATION_GROUP_MODERATION', ); /** diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index 35783e1b56..98165a7bf7 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -44,30 +44,33 @@ class ucp_notifications $notification_methods = $phpbb_notifications->get_subscription_methods(); - foreach($phpbb_notifications->get_subscription_types() as $type => $data) + foreach($phpbb_notifications->get_subscription_types() as $group => $subscription_types) { - if ($request->is_set_post($type . '_notification') && !isset($subscriptions[$type])) + foreach($subscription_types as $type => $data) { - // add - $phpbb_notifications->add_subscription($type); - } - else if (!$request->is_set_post($type . '_notification') && isset($subscriptions[$type])) - { - // remove - $phpbb_notifications->delete_subscription($type); - } - - foreach($notification_methods as $method) - { - if ($request->is_set_post($type . '_' . $method) && (!isset($subscriptions[$type]) || !in_array($method, $subscriptions[$type]))) + if ($request->is_set_post($type . '_notification') && !isset($subscriptions[$type])) { // add - $phpbb_notifications->add_subscription($type, 0, $method); + $phpbb_notifications->add_subscription($type); } - else if (!$request->is_set_post($type . '_' . $method) && isset($subscriptions[$type]) && in_array($method, $subscriptions[$type])) + else if (!$request->is_set_post($type . '_notification') && isset($subscriptions[$type])) { // remove - $phpbb_notifications->delete_subscription($type, 0, $method); + $phpbb_notifications->delete_subscription($type); + } + + foreach($notification_methods as $method) + { + if ($request->is_set_post($type . '_' . $method) && (!isset($subscriptions[$type]) || !in_array($method, $subscriptions[$type]))) + { + // add + $phpbb_notifications->add_subscription($type, 0, $method); + } + else if (!$request->is_set_post($type . '_' . $method) && isset($subscriptions[$type]) && in_array($method, $subscriptions[$type])) + { + // remove + $phpbb_notifications->delete_subscription($type, 0, $method); + } } } } @@ -172,25 +175,33 @@ class ucp_notifications $notification_methods = $phpbb_notifications->get_subscription_methods(); $subscriptions = $phpbb_notifications->get_subscriptions(false, true); - foreach($phpbb_notifications->get_subscription_types() as $type => $data) + foreach($phpbb_notifications->get_subscription_types() as $group => $subscription_types) { $template->assign_block_vars($block, array( - 'TYPE' => $type, - - 'NAME' => (is_array($data) && isset($data['lang'])) ? $user->lang($data['lang']) : $user->lang('NOTIFICATION_TYPE_' . strtoupper($type)), - - 'SUBSCRIBED' => (isset($subscriptions[$type])) ? true : false, + 'GROUP_NAME' => $user->lang($group), )); - foreach($notification_methods as $method) + foreach($subscription_types as $type => $data) { - $template->assign_block_vars($block . '.notification_methods', array( - 'METHOD' => $method, + $template->assign_block_vars($block, array( + 'TYPE' => $type, - 'NAME' => $user->lang('NOTIFICATION_METHOD_' . strtoupper($method)), + 'NAME' => $user->lang($data['lang']), + 'EXPLAIN' => (isset($user->lang[$data['lang'] . '_EXPLAIN'])) ? $user->lang($data['lang'] . '_EXPLAIN') : '', - 'SUBSCRIBED' => (isset($subscriptions[$type]) && in_array($method, $subscriptions[$type])) ? true : false, + 'SUBSCRIBED' => (isset($subscriptions[$type])) ? true : false, )); + + foreach($notification_methods as $method) + { + $template->assign_block_vars($block . '.notification_methods', array( + 'METHOD' => $method, + + 'NAME' => $user->lang('NOTIFICATION_METHOD_' . strtoupper($method)), + + 'SUBSCRIBED' => (isset($subscriptions[$type]) && in_array($method, $subscriptions[$type])) ? true : false, + )); + } } } } -- cgit v1.2.1 From a48f09033810148fd9b2d5a0b6a683f14ac73a6a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 14 Oct 2012 12:35:35 -0500 Subject: [ticket/11103] Make sure notifications are marked read when clicking them How do we do this? If an item is unread, the URL to view that item will be the URL to mark it as read (index.php?mark_notification=$id). When the URL is visited it marks the item as read and redirects them to the correct URL for the item. If the item is read, the URL is directly to the item. Prettify the html output PHPBB-11103 --- phpBB/includes/notification/manager.php | 2 +- phpBB/includes/notification/type/base.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index fc9b48c624..03776de2b4 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -165,7 +165,7 @@ class phpbb_notification_manager } $load_special[$row['item_type']] = array_merge($load_special[$row['item_type']], $notification->get_load_special()); - $notifications[] = $notification; + $notifications[$row['notification_id']] = $notification; } $this->load_users($user_ids); diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index e8959d1352..9ef0e71009 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -138,7 +138,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i 'UNREAD' => $this->unread, - 'U_MARK_READ' => append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification[]=' . $this->notification_id), + 'U_MARK_READ' => append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id), ); } @@ -148,7 +148,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) * @return string */ - public function mark_read($return = true) + public function mark_read($return = false) { return $this->mark(false, $return); } @@ -159,7 +159,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) * @return string */ - public function mark_unread($return = true) + public function mark_unread($return = false) { return $this->mark(true, $return); } @@ -352,11 +352,11 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $this->unread = (bool) $unread; $where = array( - 'item_type = ' . $this->db->sql_escape($this->item_type), + "item_type = '" . $this->db->sql_escape($this->item_type) . "'", 'item_id = ' . (int) $this->item_id, 'user_id = ' . (int) $this->user_id, ); - $where = implode(' AND ' . $where); + $where = implode(' AND ', $where); if ($return) { @@ -364,7 +364,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i } $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' - SET unread = ' . $this->unread . ' + SET unread = ' . (int) $this->unread . ' WHERE ' . $where; $this->db->sql_query($sql); } -- cgit v1.2.1 From 0d5d328c81362acdcbccffc28288505db8517616 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 14 Oct 2012 12:42:18 -0500 Subject: [ticket/11103] Spacing consistency PHPBB3-11103 --- phpBB/includes/functions_posting.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 3658757e5e..4deffe653b 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2233,19 +2233,19 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u { switch ($mode) { - case 'post' : + case 'post': $phpbb_notifications->add_notifications(array('quote', 'topic'), $notification_data); break; - case 'reply' : - case 'quote' : + case 'reply': + case 'quote': $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), $notification_data); break; - case 'edit_topic' : - case 'edit_first_post' : - case 'edit' : - case 'edit_last_post' : + case 'edit_topic': + case 'edit_first_post': + case 'edit': + case 'edit_last_post': $phpbb_notifications->update_notifications(array('quote', 'bookmark', 'topic', 'post'), $notification_data); break; } @@ -2254,19 +2254,19 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u { switch ($mode) { - case 'post' : + case 'post': $phpbb_notifications->add_notifications(array('topic_in_queue'), $notification_data); break; - case 'reply' : - case 'quote' : + case 'reply': + case 'quote': $phpbb_notifications->add_notifications(array('post_in_queue'), $notification_data); break; - case 'edit_topic' : - case 'edit_first_post' : - case 'edit' : - case 'edit_last_post' : + case 'edit_topic': + case 'edit_first_post': + case 'edit': + case 'edit_last_post': $phpbb_notifications->delete_notifications('topic', $data['topic_id']); $phpbb_notifications->delete_notifications(array('quote', 'bookmark', 'post'), $data['post_id']); break; -- cgit v1.2.1 From fa6d60401656ee875ef18b35dc7ce43bd270ff4e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 14 Oct 2012 12:49:09 -0500 Subject: [ticket/11103] Remove todo comments that are no longer todo PHPBB3-11103 --- phpBB/includes/notification/type/quote.php | 6 ------ phpBB/includes/ucp/ucp_notifications.php | 1 - 2 files changed, 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 4d1e637820..0cc183346f 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -184,12 +184,6 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $add_notifications[$user_id] = $notifications[$user_id]; } - // todo Adding notifications while editing a post can be funky. - // If the user has read the topic/post already, and the user is newly quoted it an edit, - // The notification will be stuck as unread until another post is made and the user visits - // the topic again because the posts will not be marked as read since the topic is already - // marked as read - // Add the necessary notifications $this->notification_manager->add_notifications_for_users(self::get_item_type(), $post, $add_notifications); diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index 98165a7bf7..321730a64b 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -79,7 +79,6 @@ class ucp_notifications $message = $user->lang['PREFERENCES_UPDATED'] . '

' . sprintf($user->lang['RETURN_UCP'], '', ''); trigger_error($message); } - // todo include language files for extensions? $this->output_notification_methods('notification_methods', $phpbb_notifications, $template, $user); -- cgit v1.2.1 From c8b66a26ef4f6ac2a71980c75a13356dcda72dd6 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 16 Oct 2012 10:51:07 -0500 Subject: [ticket/11103] Mark read link if notification has no URL to view it Other style stuff PHPBB3-11103 --- phpBB/includes/notification/type/base.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 9ef0e71009..afd6a9fc9b 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -126,6 +126,17 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ public function prepare_for_display() { + if ($this->get_url()) + { + $u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id); + } + else + { + $redirect = (($this->user->page['page_dir']) ? $this->user->page['page_dir'] . '/' : '') . $this->user->page['page_name'] . (($this->user->page['query_string']) ? '?' . $this->user->page['query_string'] : ''); + + $u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id . '&redirect=' . urlencode($redirect)); + } + return array( 'NOTIFICATION_ID' => $this->notification_id, @@ -138,7 +149,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i 'UNREAD' => $this->unread, - 'U_MARK_READ' => append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id), + 'U_MARK_READ' => ($this->unread) ? $u_mark_read : '', ); } -- cgit v1.2.1 From 61a1467c90e865f43c359bb8678d27b5e571f21f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 16 Oct 2012 16:47:18 -0500 Subject: [ticket/11103] U_VIEW_ALL_NOTIFICATIONS Link PHPBB3-11103 --- phpBB/includes/functions.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 2645e55446..790724d3c5 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5020,8 +5020,10 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'RECORD_USERS' => $l_online_record, 'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text, 'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread, + 'UNREAD_NOTIFICATIONS_COUNT' => ($config['load_notifications']) ? $notifications['unread_count'] : '', 'NOTIFICATIONS_COUNT' => ($config['load_notifications']) ? $user->lang('NOTIFICATIONS_COUNT', $notifications['unread_count']) : '', + 'U_VIEW_ALL_NOTIFICATIONS' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=ucp_notifications'), 'S_NOTIFICATIONS_DISPLAY' => $config['load_notifications'], 'S_USER_NEW_PRIVMSG' => $user->data['user_new_privmsg'], -- cgit v1.2.1 From 3839fe69027836d0c9083095208e4ed548a7ea38 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 16 Oct 2012 17:44:46 -0500 Subject: [ticket/11103] Use report text for report notification, never notify reporter PHPBB3-11103 --- phpBB/includes/notification/type/report_pm.php | 14 +++++++++++- phpBB/includes/notification/type/report_post.php | 28 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 440092afdc..3327dbe734 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -115,7 +115,8 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $this->db->sql_in_set('user_id', $auth_approve[$post['forum_id']][$this->permission]); + AND " . $this->db->sql_in_set('user_id', $auth_approve[$post['forum_id']][$this->permission]) . ' + AND user_id <> ' . $this->user->data['user_id']; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { @@ -174,6 +175,16 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + if ($this->get_data('report_text')) + { + return $this->user->lang( + $this->language_key, + $username, + censor_text($this->get_data('message_subject')), + $this->get_data('report_text') + ); + } + if (isset($this->user->lang[$this->get_data('reason_title')])) { return $this->user->lang( @@ -224,6 +235,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm $this->set_data('reporter_id', $this->user->data['user_id']); $this->set_data('reason_title', strtoupper($post['reason_title'])); $this->set_data('reason_description', $post['reason_description']); + $this->set_data('report_text', $post['report_text']); return parent::create_insert_array($post, $pre_create_data); } diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index d860fb1b38..151841ef02 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -65,6 +65,23 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i return 'report_post'; } + /** + * Find the users who want to receive notifications + * + * @param array $post Data from the post + * + * @return array + */ + public function find_users_for_notification($post, $options = array()) + { + $notify_users = parent::find_users_for_notification($post, $options); + + // never notify reporter + unset($notify_users[$this->user->data['user_id']]); + + return $notify_users; + } + /** * Get email template variables * @@ -110,6 +127,16 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + if ($this->get_data('report_text')) + { + return $this->user->lang( + $this->language_key, + $username, + censor_text($this->get_data('post_subject')), + $this->get_data('report_text') + ); + } + if (isset($this->user->lang[$this->get_data('reason_title')])) { return $this->user->lang( @@ -160,6 +187,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i $this->set_data('reporter_id', $this->user->data['user_id']); $this->set_data('reason_title', strtoupper($post['reason_title'])); $this->set_data('reason_description', $post['reason_description']); + $this->set_data('report_text', $post['report_text']); return parent::create_insert_array($post, $pre_create_data); } -- cgit v1.2.1 From 230e9d2e322e707c46c6d99c18a0591fb56b6f74 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 16 Oct 2012 17:47:27 -0500 Subject: [ticket/11103] Do not send PM received notifications to the author (you won't be notified if you PM yourself) PHPBB3-11103 --- phpBB/includes/notification/type/pm.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index c2065fef99..dc4bd3b3a5 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -85,7 +85,8 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' - 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']; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { -- cgit v1.2.1 From 92b533aad381ae1da8ccb1cd33fa19f31d8a0e98 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 16 Oct 2012 17:49:54 -0500 Subject: [ticket/11103] Do not notify yourself when you close your own report PHPBB3-11103 --- .../includes/notification/type/report_pm_closed.php | 21 +++++++++++++-------- .../notification/type/report_post_closed.php | 5 +++++ 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index f5790ba449..8d79c8446b 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -16,7 +16,7 @@ if (!defined('IN_PHPBB')) } /** -* Reported post notifications class +* Reported pm notifications class * This class handles notifications for reported pms * * @package notifications @@ -54,13 +54,18 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p /** * Find the users who want to receive notifications * - * @param array $post Data from + * @param array $pm Data from * * @return array */ - public function find_users_for_notification($post, $options = array()) + public function find_users_for_notification($pm, $options = array()) { - return array($post['reporter'] => array('')); + if ($pm['reporter'] == $this->user->data['user_id']) + { + return array(); + } + + return array($pm['reporter'] => array('')); } /** @@ -123,16 +128,16 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p * Function for preparing the data for insertion in an SQL query * (The service handles insertion) * - * @param array $post Data from submit_post + * @param array $pm PM Data * @param array $pre_create_data Data from pre_create_insert_array() * * @return array Array of data ready to be inserted into the database */ - public function create_insert_array($post, $pre_create_data = array()) + public function create_insert_array($pm, $pre_create_data = array()) { - $this->set_data('closer_id', $post['closer_id']); + $this->set_data('closer_id', $pm['closer_id']); - $data = parent::create_insert_array($post, $pre_create_data); + $data = parent::create_insert_array($pm, $pre_create_data); $this->time = $data['time'] = time(); diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index 0d5c5b292e..3e66bde9bc 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -60,6 +60,11 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type */ public function find_users_for_notification($post, $options = array()) { + if ($post['reporter'] == $this->user->data['user_id']) + { + return array(); + } + return array($post['reporter'] => array('')); } -- cgit v1.2.1 From 77bc12d334167ec5d1c7e3bc7c2b582218df32f6 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 16 Oct 2012 23:27:49 -0500 Subject: [ticket/11103] Add author name output to post/topic email templates For a recent merge: https://github.com/phpbb/phpbb3/pull/624 PHPBB3-11103 --- phpBB/includes/notification/type/post.php | 12 ++++++++++++ phpBB/includes/notification/type/topic.php | 12 ++++++++++++ 2 files changed, 24 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index ee26a8c33e..0681b4418c 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -223,7 +223,19 @@ class phpbb_notification_type_post extends phpbb_notification_type_base */ public function get_email_template_variables() { + if ($this->get_data('post_username')) + { + $username = $this->get_data('post_username'); + } + else + { + $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); + + $username = get_username_string('username', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + } + return array( + 'AUTHOR_NAME' => htmlspecialchars_decode($username), 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 237f430003..a9beb469c3 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -186,7 +186,19 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base */ public function get_email_template_variables() { + if ($this->get_data('post_username')) + { + $username = $this->get_data('post_username'); + } + else + { + $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); + + $username = get_username_string('username', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + } + return array( + 'AUTHOR_NAME' => htmlspecialchars_decode($username), 'FORUM_NAME' => htmlspecialchars_decode($this->get_data('forum_name')), 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), -- cgit v1.2.1 From ae670cc87df197e44b768667b853e1dae3009b4d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 18 Oct 2012 18:32:13 -0500 Subject: [ticket/11103] Remove unnecessary comments Comments that are not needed because the actions are completely self-explanatory PHPBB3-11103 --- phpBB/includes/functions.php | 1 - phpBB/includes/functions_admin.php | 2 -- phpBB/includes/functions_privmsgs.php | 5 ----- phpBB/includes/mcp/mcp_pm_reports.php | 1 - phpBB/includes/mcp/mcp_queue.php | 11 ----------- phpBB/includes/mcp/mcp_reports.php | 1 - phpBB/includes/ucp/ucp_notifications.php | 4 ---- 7 files changed, 25 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 0af8e824c8..2827dae1a8 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1386,7 +1386,6 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ $forum_id = array($forum_id); } - // Mark topic notifications read for this user in this forum $phpbb_notifications->mark_notifications_read_by_parent(array('topic', 'approve_topic'), $forum_id, $user->data['user_id'], $post_time); // Mark all post/quote notifications read for this user in this forum diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 3deb2e9c59..893c7a247d 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -716,7 +716,6 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s set_config_count('num_topics', $approved_topics * (-1), true); } - // Delete notifications $phpbb_notifications->delete_notifications(array('topic', 'approve_topic', 'topic_in_queue'), $topic_ids); return $return; @@ -897,7 +896,6 @@ 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 notifications $phpbb_notifications->delete_notifications(array('quote', 'bookmark', 'post', 'approve_post', 'post_in_queue'), $post_ids); return sizeof($post_ids); diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 6c31c6d6c3..4638091601 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -878,7 +878,6 @@ function update_unread_status($unread, $msg_id, $user_id, $folder_id) global $db, $user, $phpbb_notifications; - // Mark the PM as read $phpbb_notifications->mark_notifications_read('pm', $msg_id, $user_id); $sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . " @@ -1097,7 +1096,6 @@ function delete_pm($user_id, $msg_ids, $folder_id) $user->data['user_unread_privmsg'] -= $num_unread; } - // Delete Notifications $phpbb_notifications->delete_notifications('pm', array_keys($delete_rows)); // Now we have to check which messages we can delete completely @@ -1262,7 +1260,6 @@ function phpbb_delete_user_pms($user_id) AND ' . $db->sql_in_set('msg_id', $delivered_msg); $db->sql_query($sql); - // Delete Notifications $phpbb_notifications->delete_notifications('pm', $delivered_msg); } @@ -1276,7 +1273,6 @@ function phpbb_delete_user_pms($user_id) WHERE ' . $db->sql_in_set('msg_id', $undelivered_msg); $db->sql_query($sql); - // Delete Notifications $phpbb_notifications->delete_notifications('pm', $undelivered_msg); } } @@ -1321,7 +1317,6 @@ function phpbb_delete_user_pms($user_id) WHERE ' . $db->sql_in_set('msg_id', $delete_ids); $db->sql_query($sql); - // Delete Notifications $phpbb_notifications->delete_notifications('pm', $delete_ids); } } diff --git a/phpBB/includes/mcp/mcp_pm_reports.php b/phpBB/includes/mcp/mcp_pm_reports.php index 227c89bb79..001edfd8db 100644 --- a/phpBB/includes/mcp/mcp_pm_reports.php +++ b/phpBB/includes/mcp/mcp_pm_reports.php @@ -90,7 +90,6 @@ class mcp_pm_reports trigger_error('NO_REPORT'); } - // Mark the notification as read $phpbb_notifications->mark_notifications_read_by_parent('report_pm', $report_id, $user->data['user_id']); $pm_id = $report['pm_id']; diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index b23e5f4e45..72f1c00c72 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -86,7 +86,6 @@ class mcp_queue { $post_id = (int) $topic_info[$topic_id]['topic_first_post_id']; - // Mark the notification as read $phpbb_notifications->mark_notifications_read('topic_in_queue', $topic_id, $user->data['user_id']); } else @@ -95,7 +94,6 @@ class mcp_queue } } - // Mark the notification as read $phpbb_notifications->mark_notifications_read('post_in_queue', $post_id, $user->data['user_id']); $post_info = get_post_data(array($post_id), 'm_approve', true); @@ -612,13 +610,10 @@ 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']) { - // Delete topic in queue notifications $phpbb_notifications->delete_notifications(array('topic_in_queue'), $post_data['topic_id']); - // Forum Notifications $phpbb_notifications->add_notifications('topic', $post_data); - // Notify poster? if ($notify_poster) { $phpbb_notifications->add_notifications('approve_topic', $post_data); @@ -626,13 +621,10 @@ function approve_post($post_id_list, $id, $mode) } else { - // Delete post in queue notification $phpbb_notifications->delete_notifications(array('post_in_queue'), $post_id); - // Topic Notifications $phpbb_notifications->add_notifications(array('quote', 'bookmark', 'post'), $post_data); - // Notify poster? if ($notify_poster) { $phpbb_notifications->add_notifications('approve_post', $post_data); @@ -859,7 +851,6 @@ function disapprove_post($post_id_list, $id, $mode) } } - // Handle notifications (topic/post in queue) foreach ($post_info as $post_id => $post_data) { if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) @@ -912,7 +903,6 @@ 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']) { - // Notify poster? if ($notify_poster) { $phpbb_notifications->add_notifications('disapprove_topic', $post_data); @@ -920,7 +910,6 @@ function disapprove_post($post_id_list, $id, $mode) } else { - // Notify poster? if ($notify_poster) { $phpbb_notifications->add_notifications('disapprove_post', $post_data); diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php index 7c6352a244..f6121e7e03 100644 --- a/phpBB/includes/mcp/mcp_reports.php +++ b/phpBB/includes/mcp/mcp_reports.php @@ -88,7 +88,6 @@ class mcp_reports trigger_error('NO_REPORT'); } - // Mark the notification as read $phpbb_notifications->mark_notifications_read('report_post', $post_id, $user->data['user_id']); if (!$report_id && $report['report_closed']) diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index 321730a64b..aeace13968 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -50,12 +50,10 @@ class ucp_notifications { if ($request->is_set_post($type . '_notification') && !isset($subscriptions[$type])) { - // add $phpbb_notifications->add_subscription($type); } else if (!$request->is_set_post($type . '_notification') && isset($subscriptions[$type])) { - // remove $phpbb_notifications->delete_subscription($type); } @@ -63,12 +61,10 @@ class ucp_notifications { if ($request->is_set_post($type . '_' . $method) && (!isset($subscriptions[$type]) || !in_array($method, $subscriptions[$type]))) { - // add $phpbb_notifications->add_subscription($type, 0, $method); } else if (!$request->is_set_post($type . '_' . $method) && isset($subscriptions[$type]) && in_array($method, $subscriptions[$type])) { - // remove $phpbb_notifications->delete_subscription($type, 0, $method); } } -- cgit v1.2.1 From eb07b3ad9cfb37fd2943088170e380bff2db94a3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 18 Oct 2012 18:45:43 -0500 Subject: [ticket/11103] Expand class vars and use docblocks for phpBB classes PHPBB3-11103 --- phpBB/includes/notification/manager.php | 29 ++++++++++++++++-- phpBB/includes/notification/method/base.php | 47 +++++++++++++++++------------ phpBB/includes/notification/type/base.php | 30 +++++++++++++++++- 3 files changed, 84 insertions(+), 22 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 03776de2b4..a98e1f7af3 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -21,7 +21,32 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_manager { - protected $db, $cache, $template, $extension_manager, $user, $auth, $config, $phpbb_root_path, $php_ext = null; + /** @var dbal */ + protected $db = null; + + /** @var phpbb_cache_service */ + protected $cache = null; + + /** @var phpbb_template */ + protected $template = null; + + /** @var phpbb_extension_manager */ + protected $extension_manager = null; + + /** @var phpbb_user */ + protected $user = null; + + /** @var phpbb_auth */ + protected $auth = null; + + /** @var phpbb_config */ + protected $config = null; + + /** @var string */ + protected $phpbb_root_path = null; + + /** @var string */ + protected $php_ext = null; /** * Users loaded from the DB @@ -71,7 +96,7 @@ class phpbb_notification_manager 'count_total' => false, ), $options); - // If all_unread, count_unread mus be true + // If all_unread, count_unread must be true $options['count_unread'] = ($options['all_unread']) ? true : $options['count_unread']; // Anonymous users and bots never receive notifications diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index 5457ca99b2..88ec2674be 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -21,26 +21,35 @@ if (!defined('IN_PHPBB')) */ abstract class phpbb_notification_method_base implements phpbb_notification_method_interface { - protected $notification_manager, $db, $cache, $template, $extension_manager, $user, $auth, $config, $phpbb_root_path, $php_ext = null; + /** @var phpbb_notification_manager */ + protected $notification_manager = null; - /** - * Desired notifications - * unique by (type, type_id, user_id, method) - * if multiple methods are desired, multiple rows will exist. - * - * method of "none" will over-ride any other options - * - * item_type - * item_id - * user_id - * method - * none (will never receive notifications) - * standard (listed in notifications window - * popup? - * email - * jabber - * sms? - */ + /** @var dbal */ + protected $db = null; + + /** @var phpbb_cache_service */ + protected $cache = null; + + /** @var phpbb_template */ + protected $template = null; + + /** @var phpbb_extension_manager */ + protected $extension_manager = null; + + /** @var phpbb_user */ + protected $user = null; + + /** @var phpbb_auth */ + protected $auth = null; + + /** @var phpbb_config */ + protected $config = null; + + /** @var string */ + protected $phpbb_root_path = null; + + /** @var string */ + protected $php_ext = null; /** * Queue of messages to be sent diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index afd6a9fc9b..39a21a1054 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -21,7 +21,35 @@ if (!defined('IN_PHPBB')) */ abstract class phpbb_notification_type_base implements phpbb_notification_type_interface { - protected $notification_manager, $db, $cache, $template, $extension_manager, $user, $auth, $config, $phpbb_root_path, $php_ext = null; + /** @var phpbb_notification_manager */ + protected $notification_manager = null; + + /** @var dbal */ + protected $db = null; + + /** @var phpbb_cache_service */ + protected $cache = null; + + /** @var phpbb_template */ + protected $template = null; + + /** @var phpbb_extension_manager */ + protected $extension_manager = null; + + /** @var phpbb_user */ + protected $user = null; + + /** @var phpbb_auth */ + protected $auth = null; + + /** @var phpbb_config */ + protected $config = null; + + /** @var string */ + protected $phpbb_root_path = null; + + /** @var string */ + protected $php_ext = null; /** * Array of user data containing information needed to output the notifications to the template -- cgit v1.2.1 From f96dac335287f2fd51ff6628facbc8b6af6a517f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 18 Oct 2012 19:13:47 -0500 Subject: [ticket/11103] Interface docblocks PHPBB3-11103 --- phpBB/includes/notification/method/email.php | 3 + phpBB/includes/notification/method/interface.php | 19 +++ phpBB/includes/notification/type/base.php | 128 ++++++++++---------- phpBB/includes/notification/type/interface.php | 146 +++++++++++++++++++++-- phpBB/includes/notification/type/post.php | 4 - phpBB/includes/notification/type/report_pm.php | 4 +- 6 files changed, 222 insertions(+), 82 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/method/email.php b/phpBB/includes/notification/method/email.php index c2e272aca1..e902ea1e85 100644 --- a/phpBB/includes/notification/method/email.php +++ b/phpBB/includes/notification/method/email.php @@ -40,6 +40,9 @@ class phpbb_notification_method_email extends phpbb_notification_method_base return true; } + /** + * Parse the queue and notify the users + */ public function notify() { if (!sizeof($this->queue)) diff --git a/phpBB/includes/notification/method/interface.php b/phpBB/includes/notification/method/interface.php index 4b990ec9fa..f5c210a2fc 100644 --- a/phpBB/includes/notification/method/interface.php +++ b/phpBB/includes/notification/method/interface.php @@ -21,7 +21,26 @@ if (!defined('IN_PHPBB')) */ interface phpbb_notification_method_interface { + /** + * Is this method available for the user? + * This is checked on the notifications options + */ public function is_available(); + /** + * Add a notification to the queue + * + * @param phpbb_notification_type_interface $notification + */ + public function add_to_queue(phpbb_notification_type_interface $notification); + + /** + * Empty the queue + */ + protected function empty_queue(); + + /** + * Parse the queue and notify the users + */ public function notify(); } diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 39a21a1054..22824dc2ed 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -149,60 +149,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $this->data['data'][$name] = $value; } - /** - * Prepare to output the notification to the template - */ - public function prepare_for_display() - { - if ($this->get_url()) - { - $u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id); - } - else - { - $redirect = (($this->user->page['page_dir']) ? $this->user->page['page_dir'] . '/' : '') . $this->user->page['page_name'] . (($this->user->page['query_string']) ? '?' . $this->user->page['query_string'] : ''); - - $u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id . '&redirect=' . urlencode($redirect)); - } - - return array( - 'NOTIFICATION_ID' => $this->notification_id, - - 'AVATAR' => $this->get_avatar(), - - 'FORMATTED_TITLE' => $this->get_title(), - - 'URL' => $this->get_url(), - 'TIME' => $this->user->format_date($this->time), - - 'UNREAD' => $this->unread, - - 'U_MARK_READ' => ($this->unread) ? $u_mark_read : '', - ); - } - - /** - * Mark this item read - * - * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) - * @return string - */ - public function mark_read($return = false) - { - return $this->mark(false, $return); - } - - /** - * Mark this item unread - * - * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) - * @return string - */ - public function mark_unread($return = false) - { - return $this->mark(true, $return); - } - /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) @@ -256,12 +202,66 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i return $data; } + /** + * Mark this item read + * + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + public function mark_read($return = false) + { + return $this->mark(false, $return); + } + + /** + * Mark this item unread + * + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + public function mark_unread($return = false) + { + return $this->mark(true, $return); + } + + /** + * Prepare to output the notification to the template + */ + public function prepare_for_display() + { + if ($this->get_url()) + { + $u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id); + } + else + { + $redirect = (($this->user->page['page_dir']) ? $this->user->page['page_dir'] . '/' : '') . $this->user->page['page_name'] . (($this->user->page['query_string']) ? '?' . $this->user->page['query_string'] : ''); + + $u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id . '&redirect=' . urlencode($redirect)); + } + + return array( + 'NOTIFICATION_ID' => $this->notification_id, + + 'AVATAR' => $this->get_avatar(), + + 'FORMATTED_TITLE' => $this->get_title(), + + 'URL' => $this->get_url(), + 'TIME' => $this->user->format_date($this->time), + + 'UNREAD' => $this->unread, + + 'U_MARK_READ' => ($this->unread) ? $u_mark_read : '', + ); + } + /** * -------------- Fall back functions ------------------- */ /** - * URL to unsubscribe to this notification (fall-back) + * URL to unsubscribe to this notification (fall back) * * @param string|bool $method Method name to unsubscribe from (email|jabber|etc), False to unsubscribe from all notifications for this item */ @@ -271,7 +271,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i } /** - * Get the user's avatar (fall-back) + * Get the user's avatar (fall back) */ public function get_avatar() { @@ -279,7 +279,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i } /** - * Get the special items to load (fall-back) + * Get the special items to load (fall back) */ public function get_load_special() { @@ -287,7 +287,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i } /** - * Load the special items (fall-back) + * Load the special items (fall back) */ public function load_special($data, $notifications) { @@ -295,7 +295,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i } /** - * Is available (fall-back) + * Is available (fall back) */ public function is_available() { @@ -303,15 +303,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i } /** - * Pre create insert array function - * This allows you to perform certain actions, like run a query - * and load data, before create_insert_array() is run. The data - * returned from this function will be sent to create_insert_array(). - * - * @param array $type_data Data unique to this notification type - * @param array $notify_users Notify users list - * Formated from find_users_for_notification() - * @return array Whatever you want to send to create_insert_array(). + * Pre create insert array function (fall back) */ public function pre_create_insert_array($type_data, $notify_users) { diff --git a/phpBB/includes/notification/type/interface.php b/phpBB/includes/notification/type/interface.php index 084a819af7..1d79a2c8d8 100644 --- a/phpBB/includes/notification/type/interface.php +++ b/phpBB/includes/notification/type/interface.php @@ -21,33 +21,161 @@ if (!defined('IN_PHPBB')) */ interface phpbb_notification_type_interface { + /** + * Set initial data from the database + * + * @param array $data Row directly from the database + */ + 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 + * + * @param array $type_data The type specific data + */ public static function get_item_id($type_data); + /** + * Get the id of the parent + * + * @param array $type_data The type specific data + */ + public static function get_item_parent_id($type_data); + + /** + * Is this type available to the current user (defines whether or not it will be shown in the UCP Edit notification options) + * + * @return bool True/False whether or not this is available to the user + */ public function is_available(); + /** + * Find the users who want to receive notifications + * + * @param array $type_data The type specific data + * @param array $options Options for finding users for notification + * ignore_users => array of users and user types that should not receive notifications from this type because they've already been notified + * e.g.: array(2 => array(''), 3 => array('', 'email'), ...) + * + * @return array + */ public function find_users_for_notification($type_data, $options); - public function get_title(); + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query(); - public function get_email_template_variables(); + /** + * Get the special items to load + * + * @return array Data will be combined sent to load_special() so you can run a single query and get data required for this notification type + */ + public function get_load_special(); + /** + * Load the special items + * + * @param array $data Data from get_load_special() + * @param array $notifications Array of notifications (key is notification_id, value is the notification objects) + */ + public function load_special($data, $notifications); + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title(); + + /** + * Get the url to this item + * + * @return string URL + */ public function get_url(); + /** + * URL to unsubscribe to this notification + * + * @param string|bool $method Method name to unsubscribe from (email|jabber|etc), False to unsubscribe from all notifications for this item + */ public function get_unsubscribe_url($method); - public function mark_read($return); - - public function mark_unread($return); + /** + * Get the user's avatar (the user who caused the notification typically) + * + * @return string + */ + public function get_avatar(); + + /** + * Prepare to output the notification to the template + */ + public function prepare_for_display(); + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables(); + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $type_data The type specific data + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ public function pre_create_insert_array($type_data, $notify_users); + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $type_data The type specific data + * @param array $pre_create_data Data from pre_create_insert_array() + * + * @return array Array of data ready to be inserted into the database + */ public function create_insert_array($type_data, $pre_create_data); - public function users_to_query(); - - public function get_load_special(); + /** + * Function for preparing the data for update in an SQL query + * (The service handles insertion) + * + * @param array $type_data Data unique to this notification type + * + * @return array Array of data ready to be updated in the database + */ + public function create_update_array($type_data); + + /** + * Mark this item read + * + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + public function mark_read($return); - public function load_special($data, $notifications); + /** + * Mark this item unread + * + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + public function mark_unread($return); } diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 0681b4418c..f5f3936c63 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -89,10 +89,6 @@ class phpbb_notification_type_post extends phpbb_notification_type_base 'ignore_users' => array(), ), $options); - // Let's continue to use the phpBB subscriptions system, at least for now. - // It may not be the nicest thing, but it is already working and it would be significant work to replace it - //$users = parent::_find_users_for_notification($phpbb_container, $post['topic_id']); - $users = array(); $sql = 'SELECT user_id diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 3327dbe734..d78c108f56 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -76,7 +76,9 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm } /** - * Is available + * Is this type available to the current user (defines whether or not it will be shown in the UCP Edit notification options) + * + * @return bool True/False whether or not this is available to the user */ public function is_available() { -- cgit v1.2.1 From 2c06c2bd3646585a5b02e6269be655287352a667 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 18 Oct 2012 19:20:54 -0500 Subject: [ticket/11103] Declare $ for jQuery, check for instance of, newlines at eof PHPBB3-11103 --- phpBB/includes/notification/manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index a98e1f7af3..38c72ad755 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -518,7 +518,7 @@ class phpbb_notification_manager $class = $this->get_item_type_class($class_name); - if ($class->is_available() && method_exists($class_name, 'get_item_type')) + if ($class instanceof phpbb_notification_type_interface && $class->is_available() && method_exists($class_name, 'get_item_type')) { $options = array_merge(array( 'id' => $class_name::get_item_type(), @@ -556,7 +556,7 @@ class phpbb_notification_manager $method = $this->get_method_class($class_name); - if ($method->is_available()) + if ($method instanceof phpbb_notification_method_interface && $method->is_available()) { $subscription_methods[] = $method_name; } -- cgit v1.2.1 From 471ca5e7dc8276e80e790e05a2ae36dfe35cfe10 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 19 Oct 2012 15:49:49 -0500 Subject: [ticket/11103] Change is_disabled to is_enabled If you're following along and would like to update your DB, you can run the following queries to do so: ALTER TABLE phpbb_notifications CHANGE `is_disabled` `is_enabled` TINYINT( 1 ) NOT NULL DEFAULT '1'; UPDATE `phpbb_notifications` SET is_enabled = 1; PHPBB3-11103 --- phpBB/includes/notification/manager.php | 10 +++++----- phpBB/includes/notification/type/base.php | 12 ++++++------ phpBB/includes/notification/type/bookmark.php | 2 +- phpBB/includes/notification/type/post.php | 2 +- phpBB/includes/notification/type/quote.php | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 38c72ad755..3a4c4cd696 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -120,7 +120,7 @@ class phpbb_notification_manager FROM ' . NOTIFICATIONS_TABLE . ' WHERE user_id = ' . (int) $options['user_id'] . ' AND unread = 1 - AND is_disabled = 0'; + AND is_enabled = 1'; $result = $this->db->sql_query($sql); $unread_count = (int) $this->db->sql_fetchfield('count', $result); $this->db->sql_freeresult($result); @@ -132,7 +132,7 @@ class phpbb_notification_manager $sql = 'SELECT COUNT(*) AS count FROM ' . NOTIFICATIONS_TABLE . ' WHERE user_id = ' . (int) $options['user_id'] . ' - AND is_disabled = 0'; + AND is_enabled = 1'; $result = $this->db->sql_query($sql); $total_count = (int) $this->db->sql_fetchfield('count', $result); $this->db->sql_freeresult($result); @@ -145,7 +145,7 @@ class phpbb_notification_manager 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_disabled = 0 + 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']); @@ -163,7 +163,7 @@ class phpbb_notification_manager WHERE user_id = ' . (int) $options['user_id'] . ' AND unread = 1 AND ' . $this->db->sql_in_set('notification_id', array_keys($rowset), true) . ' - AND is_disabled = 0 + AND is_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']); @@ -374,7 +374,7 @@ class phpbb_notification_manager FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id . ' - AND is_disabled = 0'; + AND is_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 22824dc2ed..ab2f76c650 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -68,14 +68,14 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Indentification data - * item_type - * item_id - * item_parent_id - Parent item id (ex: for topic => forum_id, for post => topic_id, etc) + * item_type - Type of the item (translates to the notification type) + * item_id - ID of the item (e.g. post_id, msg_id) + * item_parent_id - Parent item id (ex: for topic => forum_id, for post => topic_id, etc) * user_id * unread - * is_disabled - EXTENSION AUTHORS TAKE NOTE! This is to prevent errors with notifications from extensions! - * - Set is_disabled to 1 for all your notifications when your extension is disabled so they are ignored and do not cause errors. - * - When your extension is enabled again, set is_disabled to 0 and your notifications will be working again. + * is_enabled - EXTENSION AUTHORS TAKE NOTE! This is to prevent errors with notifications from extensions! + * - Set is_enabled to 0 for all your notifications when your extension is disabled so they are ignored and do not cause errors. + * - When your extension is enabled again, set is_enabled to 1 and your notifications will be working again. * * time * data (special serialized field that each notification type can use to store stuff) diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index e5435b5829..dff7ac4c7d 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -114,7 +114,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post WHERE item_type = '" . self::get_item_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 - AND is_disabled = 0'; + AND is_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index f5f3936c63..a5e822336d 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -145,7 +145,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base WHERE item_type = '" . self::get_item_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 - AND is_disabled = 0'; + AND is_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 0cc183346f..4c615d8dc6 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -133,7 +133,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post WHERE item_type = '" . self::get_item_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 - AND is_disabled = 0'; + AND is_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { @@ -163,7 +163,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post FROM ' . NOTIFICATIONS_TABLE . " WHERE item_type = '" . self::get_item_type() . "' AND item_id = " . self::get_item_id($post) . ' - AND is_disabled = 0'; + AND is_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { -- cgit v1.2.1 From 0ac9079d1c4e32ae04bb7b5da55fa030279ec9b5 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 20 Oct 2012 18:55:13 -0500 Subject: [ticket/11103] Replace $email_template with get_email_template() PHPBB3-11103 --- phpBB/includes/notification/method/email.php | 7 ++++++- phpBB/includes/notification/type/approve_post.php | 17 ++++++++++------- phpBB/includes/notification/type/approve_topic.php | 17 ++++++++++------- phpBB/includes/notification/type/base.php | 7 ------- phpBB/includes/notification/type/bookmark.php | 17 ++++++++++------- phpBB/includes/notification/type/disapprove_post.php | 17 ++++++++++------- phpBB/includes/notification/type/disapprove_topic.php | 17 ++++++++++------- phpBB/includes/notification/type/interface.php | 7 +++++++ phpBB/includes/notification/type/pm.php | 17 ++++++++++------- phpBB/includes/notification/type/post.php | 17 ++++++++++------- phpBB/includes/notification/type/post_in_queue.php | 17 ++++++++++------- phpBB/includes/notification/type/quote.php | 17 ++++++++++------- phpBB/includes/notification/type/report_pm.php | 17 ++++++++++------- phpBB/includes/notification/type/report_pm_closed.php | 10 ++++++++++ phpBB/includes/notification/type/report_post.php | 17 ++++++++++------- phpBB/includes/notification/type/report_post_closed.php | 10 ++++++++++ phpBB/includes/notification/type/topic.php | 17 ++++++++++------- phpBB/includes/notification/type/topic_in_queue.php | 17 ++++++++++------- 18 files changed, 163 insertions(+), 99 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/method/email.php b/phpBB/includes/notification/method/email.php index e902ea1e85..df7edb13e7 100644 --- a/phpBB/includes/notification/method/email.php +++ b/phpBB/includes/notification/method/email.php @@ -78,6 +78,11 @@ class phpbb_notification_method_email extends phpbb_notification_method_base // Time to go through the queue and send emails foreach ($this->queue as $notification) { + if ($notification->get_email_template() === false) + { + continue; + } + $user = $this->notification_manager->get_user($notification->user_id); if ($user['user_type'] == USER_IGNORE || in_array($notification->user_id, $banned_users)) @@ -85,7 +90,7 @@ class phpbb_notification_method_email extends phpbb_notification_method_base continue; } - $messenger->template($notification->email_template, $user['user_lang']); + $messenger->template($notification->get_email_template(), $user['user_lang']); $messenger->to($user['user_email'], $user['username']); diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 6ed9b6c67c..4ed5124415 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_approve_post extends phpbb_notification_type_post { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'post_approved'; - /** * Language key used to output the text * @@ -166,4 +159,14 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post return $data; } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'post_approved'; + } } diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 1ff5ae43bd..32a1de8cf8 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topic { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'topic_approved'; - /** * Language key used to output the text * @@ -162,4 +155,14 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi return $data; } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'topic_approved'; + } } diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index ab2f76c650..4c496f0a22 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -51,13 +51,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** @var string */ protected $php_ext = null; - /** - * Array of user data containing information needed to output the notifications to the template - * - * @var array - */ - protected $users = array(); - /** * Notification option data (for outputting to the user) * diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index dff7ac4c7d..eb1a735249 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_bookmark extends phpbb_notification_type_post { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'notifications/bookmark'; - /** * Language key used to output the text * @@ -131,4 +124,14 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post return $notify_users; } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'notifications/bookmark'; + } } diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index 8044a3e0ea..d4e659c5f3 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_approve_post { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'post_disapproved'; - /** * Language key used to output the text * @@ -113,4 +106,14 @@ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_ap return $data; } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'post_disapproved'; + } } diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index 04fec87014..4bbf458d4a 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_approve_topic { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'topic_disapproved'; - /** * Language key used to output the text * @@ -113,4 +106,14 @@ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_a return $data; } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'topic_disapproved'; + } } diff --git a/phpBB/includes/notification/type/interface.php b/phpBB/includes/notification/type/interface.php index 1d79a2c8d8..25dc24d922 100644 --- a/phpBB/includes/notification/type/interface.php +++ b/phpBB/includes/notification/type/interface.php @@ -122,6 +122,13 @@ interface phpbb_notification_type_interface */ public function prepare_for_display(); + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template(); + /** * Get email template variables * diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index dc4bd3b3a5..721af4bce5 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_pm extends phpbb_notification_type_base { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'privmsg_notify'; - /** * Get the type of notification this is * phpbb_notification_type_ @@ -129,6 +122,16 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base return $this->user->lang('NOTIFICATION_PM', $username, $this->get_data('message_subject')); } + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'privmsg_notify'; + } + /** * Get email template variables * diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index a5e822336d..9bb06e3620 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_post extends phpbb_notification_type_base { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'topic_notify'; - /** * Language key used to output the text * @@ -212,6 +205,16 @@ class phpbb_notification_type_post extends phpbb_notification_type_base ); } + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'topic_notify'; + } + /** * Get email template variables * diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 499fd1e8ed..0bf8685660 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'notifications/post_in_queue'; - /** * Language key used to output the text * @@ -151,4 +144,14 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post return $data; } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'notifications/post_in_queue'; + } } diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 4c615d8dc6..f700821353 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_quote extends phpbb_notification_type_post { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'notifications/quote'; - /** * regular expression to match to find usernames * @@ -201,6 +194,16 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post return true; } + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'notifications/quote'; + } + /** * Get email template variables * diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index d78c108f56..b18493ff29 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'notifications/report_pm'; - /** * Language key used to output the text * @@ -139,6 +132,16 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm return $notify_users; } + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'notifications/report_pm'; + } + /** * Get email template variables * diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index 8d79c8446b..0bde7dfe48 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -68,6 +68,16 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p return array($pm['reporter'] => array('')); } + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return false; + } + /** * Get email template variables * diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index 151841ef02..f1ee073a4d 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_report_post extends phpbb_notification_type_post_in_queue { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'notifications/report_post'; - /** * Language key used to output the text * @@ -82,6 +75,16 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i return $notify_users; } + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'notifications/report_post'; + } + /** * Get email template variables * diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index 3e66bde9bc..52bdadc547 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -68,6 +68,16 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type return array($post['reporter'] => array('')); } + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return false; + } + /** * Get email template variables * diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index a9beb469c3..4737031e87 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_topic extends phpbb_notification_type_base { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'newtopic_notify'; - /** * Language key used to output the text * @@ -179,6 +172,16 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base ); } + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'newtopic_notify'; + } + /** * Get email template variables * diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index eb14c098e1..ee565ab6e6 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -23,13 +23,6 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_topic { - /** - * Email template to use to send notifications - * - * @var string - */ - public $email_template = 'notifications/topic_in_queue'; - /** * Language key used to output the text * @@ -144,4 +137,14 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top return $data; } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'notifications/topic_in_queue'; + } } -- cgit v1.2.1 From 52bb4a1bd60dfcaad99d1ac181d8a0372db9cc2b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 20 Oct 2012 19:00:37 -0500 Subject: [ticket/11103] Do not have empty queue in the interface This is not needed as it is not public. PHPBB3-11103 --- phpBB/includes/notification/method/interface.php | 5 ----- 1 file changed, 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/method/interface.php b/phpBB/includes/notification/method/interface.php index f5c210a2fc..3c6c757d5c 100644 --- a/phpBB/includes/notification/method/interface.php +++ b/phpBB/includes/notification/method/interface.php @@ -34,11 +34,6 @@ interface phpbb_notification_method_interface */ public function add_to_queue(phpbb_notification_type_interface $notification); - /** - * Empty the queue - */ - protected function empty_queue(); - /** * Parse the queue and notify the users */ -- cgit v1.2.1 From 94d682f77431add84867bb0b196ad0719b293606 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 20 Oct 2012 20:54:18 -0500 Subject: [ticket/11103] Use the full class name as the item_type/method This is going to require you recreate the db tables. PHPBB3-11103 --- phpBB/includes/functions.php | 33 +++- phpBB/includes/functions_admin.php | 14 +- phpBB/includes/functions_posting.php | 30 +++- phpBB/includes/functions_privmsgs.php | 14 +- phpBB/includes/mcp/mcp_pm_reports.php | 2 +- phpBB/includes/mcp/mcp_queue.php | 28 +-- phpBB/includes/mcp/mcp_reports.php | 10 +- phpBB/includes/notification/manager.php | 200 +++++++-------------- phpBB/includes/notification/type/approve_post.php | 9 - phpBB/includes/notification/type/approve_topic.php | 9 - phpBB/includes/notification/type/base.php | 6 +- phpBB/includes/notification/type/bookmark.php | 20 ++- .../includes/notification/type/disapprove_post.php | 9 - .../notification/type/disapprove_topic.php | 9 - phpBB/includes/notification/type/interface.php | 6 - phpBB/includes/notification/type/pm.php | 15 +- phpBB/includes/notification/type/post.php | 16 +- phpBB/includes/notification/type/post_in_queue.php | 9 - phpBB/includes/notification/type/quote.php | 26 +-- phpBB/includes/notification/type/report_pm.php | 9 - .../notification/type/report_pm_closed.php | 9 - phpBB/includes/notification/type/report_post.php | 9 - .../notification/type/report_post_closed.php | 9 - phpBB/includes/notification/type/topic.php | 12 +- .../includes/notification/type/topic_in_queue.php | 9 - phpBB/includes/ucp/ucp_notifications.php | 4 +- 26 files changed, 203 insertions(+), 323 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 2827dae1a8..3488a3003b 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1330,7 +1330,14 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ // Mark all forums read (index page) // 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']) { @@ -1386,7 +1393,10 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ $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 $topic_ids = array(); @@ -1400,7 +1410,12 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ } $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 // $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 - $phpbb_notifications->mark_notifications_read(array('topic', 'approve_topic'), $topic_id, $user->data['user_id'], $post_time); - $phpbb_notifications->mark_notifications_read_by_parent(array('quote', 'bookmark', 'post', 'approve_post'), $topic_id, $user->data['user_id'], $post_time); + $phpbb_notifications->mark_notifications_read(array( + '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']) { diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 893c7a247d..fdae1905a0 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -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); } - $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; } @@ -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); } - $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); } diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 4deffe653b..02c31eb6cc 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2234,19 +2234,31 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u switch ($mode) { 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; case 'reply': 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; case 'edit_topic': case 'edit_first_post': case 'edit': 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; } } @@ -2255,20 +2267,24 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u switch ($mode) { 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; case 'reply': 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; case 'edit_topic': case 'edit_first_post': case 'edit': case 'edit_last_post': - $phpbb_notifications->delete_notifications('topic', $data['topic_id']); - $phpbb_notifications->delete_notifications(array('quote', 'bookmark', 'post'), $data['post_id']); + $phpbb_notifications->delete_notifications('phpbb_notification_type_topic', $data['topic_id']); + $phpbb_notifications->delete_notifications(array( + 'phpbb_notification_type_quote', + 'phpbb_notification_type_bookmark', + 'phpbb_notification_type_post', + ), $data['post_id']); break; } } diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 4638091601..ec671e4f41 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -878,7 +878,7 @@ function update_unread_status($unread, $msg_id, $user_id, $folder_id) 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 . " SET pm_unread = 0 @@ -1096,7 +1096,7 @@ function delete_pm($user_id, $msg_ids, $folder_id) $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 $sql = 'SELECT msg_id @@ -1260,7 +1260,7 @@ function phpbb_delete_user_pms($user_id) AND ' . $db->sql_in_set('msg_id', $delivered_msg); $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)) @@ -1273,7 +1273,7 @@ function phpbb_delete_user_pms($user_id) WHERE ' . $db->sql_in_set('msg_id', $undelivered_msg); $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); $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') { - $phpbb_notifications->update_notifications('pm', $pm_data); + $phpbb_notifications->update_notifications('phpbb_notification_type_pm', $pm_data); } else { - $phpbb_notifications->add_notifications('pm', $pm_data); + $phpbb_notifications->add_notifications('phpbb_notification_type_pm', $pm_data); } return $data['msg_id']; diff --git a/phpBB/includes/mcp/mcp_pm_reports.php b/phpBB/includes/mcp/mcp_pm_reports.php index 001edfd8db..572969af4a 100644 --- a/phpBB/includes/mcp/mcp_pm_reports.php +++ b/phpBB/includes/mcp/mcp_pm_reports.php @@ -90,7 +90,7 @@ class mcp_pm_reports 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']; $report_id = $report['report_id']; diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 72f1c00c72..f13ce914bf 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -86,7 +86,7 @@ class mcp_queue { $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 { @@ -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); @@ -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']) { - $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) { - $phpbb_notifications->add_notifications('approve_topic', $post_data); + $phpbb_notifications->add_notifications('phpbb_notification_type_approve_topic', $post_data); } } 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) { - $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']) { - $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 { - $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) { - $phpbb_notifications->add_notifications('disapprove_topic', $post_data); + $phpbb_notifications->add_notifications('phpbb_notification_type_disapprove_topic', $post_data); } } else { if ($notify_poster) { - $phpbb_notifications->add_notifications('disapprove_post', $post_data); + $phpbb_notifications->add_notifications('phpbb_notification_type_disapprove_post', $post_data); } } } diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php index f6121e7e03..5bda6f2de7 100644 --- a/phpBB/includes/mcp/mcp_reports.php +++ b/phpBB/includes/mcp/mcp_reports.php @@ -88,7 +88,7 @@ class mcp_reports 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']) { @@ -647,20 +647,20 @@ function close_report($report_id_list, $mode, $action, $pm = false) 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'], 'closer_id' => $user->data['user_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 { - $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'], '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); } } } diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 3a4c4cd696..06ebaf24c4 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -138,32 +138,16 @@ class phpbb_notification_manager $this->db->sql_freeresult($result); } - $rowset = array(); - - // 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)) + if (!$options['count_total'] || $total_count) { - $rowset[$row['notification_id']] = $row; - } - $this->db->sql_freeresult($result); + $rowset = array(); - // Get all unread notifications - if ($unread_count && $options['all_unread'] && !empty($rowset)) - { + // Get the main notifications $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_is_enabled = 1 + 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']); @@ -172,37 +156,52 @@ class phpbb_notification_manager $rowset[$row['notification_id']] = $row; } $this->db->sql_freeresult($result); - } - - foreach ($rowset as $row) - { - $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']])) + // Get all unread notifications + if ($unread_count && $options['all_unread'] && !empty($rowset)) { - $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 - foreach ($load_special as $item_type => $data) - { - $item_type_class_name = $this->get_item_type_class_name($item_type, true); + // Some notification types also require querying additional tables themselves + if (!isset($load_special[$row['item_type']])) + { + $load_special[$row['item_type']] = array(); + } + $load_special[$row['item_type']] = array_merge($load_special[$row['item_type']], $notification->get_load_special()); + + $notifications[$row['notification_id']] = $notification; + } + + $this->load_users($user_ids); - $item_class = $this->get_item_type_class($item_type_class_name); + // 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); + $item_class->load_special($data, $notifications); + } } return array( @@ -234,11 +233,6 @@ class phpbb_notification_manager $time = ($time) ?: time(); - if ($item_type !== false) - { - $this->get_item_type_class_name($item_type); - } - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " SET unread = 0 WHERE time <= " . $time . @@ -270,8 +264,6 @@ class phpbb_notification_manager $time = ($time) ?: time(); - $item_type_class_name = $this->get_item_type_class_name($item_type); - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " SET unread = 0 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' @@ -326,12 +318,10 @@ class phpbb_notification_manager return $notified_users; } - $item_type_class_name = $this->get_item_type_class_name($item_type); - - $item_id = $item_type_class_name::get_item_id($data); + $item_id = $item_type::get_item_id($data); // 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); @@ -357,9 +347,7 @@ class phpbb_notification_manager return; } - $item_type_class_name = $this->get_item_type_class_name($item_type); - - $item_id = $item_type_class_name::get_item_id($data); + $item_id = $item_type::get_item_id($data); $user_ids = 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) - $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); unset($notification); // 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) { - $notification = $this->get_item_type_class($item_type_class_name); + $notification = $this->get_item_type_class($item_type); $notification->user_id = (int) $user; @@ -412,8 +400,7 @@ class phpbb_notification_manager { if (!isset($notification_methods[$method])) { - $method_class_name = 'phpbb_notification_method_' . $method; - $notification_methods[$method] = $this->get_method_class($method_class_name); + $notification_methods[$method] = $this->get_method_class($method); } $notification_methods[$method]->add_to_queue($notification); @@ -452,21 +439,19 @@ class phpbb_notification_manager 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 - 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 - if ($this->get_item_type_class($item_type_class_name)->update_notifications($data) === false) + if ($notification->update_notifications($data) === false) { return; } } - $item_id = $item_type_class_name::get_item_id($data); - - $notification = $this->get_item_type_class($item_type_class_name); + $item_id = $item_type::get_item_id($data); $update_array = $notification->create_update_array($data); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' @@ -495,8 +480,6 @@ class phpbb_notification_manager return; } - $this->get_item_type_class_name($item_type); - $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " 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); @@ -512,17 +495,15 @@ class phpbb_notification_manager { $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); - 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( - 'id' => $class_name::get_item_type(), - 'lang' => 'NOTIFICATION_TYPE_' . strtoupper($class_name::get_item_type()), + 'id' => $class_name, + 'lang' => 'NOTIFICATION_TYPE_' . strtoupper($class_name), 'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS', ), (($class_name::$notification_option !== false) ? $class_name::$notification_option : array())); @@ -550,15 +531,13 @@ class phpbb_notification_manager { $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); 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) { - $this->get_item_type_class_name($item_type); - $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; $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) { - $this->get_item_type_class_name($item_type); - $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; $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]; } - /** - * 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 */ 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->set_initial_data($data); @@ -747,31 +696,16 @@ class phpbb_notification_manager $subscription_files = array(); - $files = $finder + $classes = $finder ->core_path('includes/' . $path) ->extension_directory($path) - ->get_files(); - foreach ($files as $file) - { - $name = substr($file, strrpos($file, '/')); - $name = substr($name, 1, (strpos($name, '.' . $this->php_ext) - 1)); + ->get_classes(); - if ($name == 'interface' || $name == 'base') - { - continue; - } - - if (!strpos($file, 'includes/')) // is an extension - { - $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; - } + unset($classes[array_search('phpbb_notification_type_interface', $classes)]); + unset($classes[array_search('phpbb_notification_type_base', $classes)]); + unset($classes[array_search('phpbb_notification_method_interface', $classes)]); + unset($classes[array_search('phpbb_notification_method_base', $classes)]); - return $subscription_files; + return $classes; } } diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 4ed5124415..46f2c16c14 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -42,15 +42,6 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post '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 */ diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 32a1de8cf8..0015858c2e 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -42,15 +42,6 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi '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 */ diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 4c496f0a22..df04dc2a49 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -116,7 +116,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i 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 $this->data = array_merge(array( '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), 'time' => time(), @@ -324,7 +324,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $sql = 'SELECT * FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . static::get_item_type() . "' + WHERE item_type = '" . get_class($this) . "' AND item_id = " . (int) $item_id; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index eb1a735249..4d5a1fd299 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -31,13 +31,15 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post protected $language_key = 'NOTIFICATION_BOOKMARK'; /** - * Get the type of notification this is - * phpbb_notification_type_ + * Notification option data (for outputting to the user) + * + * @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() - { - return 'bookmark'; - } + public static $notification_option = array( + 'lang' => 'NOTIFICATION_TYPE_BOOKMARK', + 'group' => 'NOTIFICATION_GROUP_POSTING', + ); /** * Find the users who want to receive notifications @@ -81,7 +83,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post $sql = 'SELECT * 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']); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) @@ -104,7 +106,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post $update_notifications = array(); $sql = 'SELECT * 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 unread = 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 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 . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index d4e659c5f3..3b5719c3fe 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -42,15 +42,6 @@ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_ap '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 * diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index 4bbf458d4a..7369fd64bd 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -42,15 +42,6 @@ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_a '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 * diff --git a/phpBB/includes/notification/type/interface.php b/phpBB/includes/notification/type/interface.php index 25dc24d922..9d9965261e 100644 --- a/phpBB/includes/notification/type/interface.php +++ b/phpBB/includes/notification/type/interface.php @@ -28,12 +28,6 @@ interface phpbb_notification_type_interface */ 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 * diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index 721af4bce5..adb03ab1a3 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -24,13 +24,14 @@ if (!defined('IN_PHPBB')) class phpbb_notification_type_pm extends phpbb_notification_type_base { /** - * Get the type of notification this is - * phpbb_notification_type_ + * Notification option data (for outputting to the user) + * + * @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() - { - return 'pm'; - } + public static $notification_option = array( + 'lang' => 'NOTIFICATION_TYPE_PM', + ); /** * Get the id of the @@ -77,7 +78,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base $sql = 'SELECT * 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 user_id <> ' . $pm['from_user_id']; $result = $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 9bb06e3620..9317669e57 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -37,18 +37,10 @@ class phpbb_notification_type_post extends phpbb_notification_type_base * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = array( + 'lang' => 'NOTIFICATION_TYPE_POST', '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 * @@ -112,7 +104,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $sql = 'SELECT * 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']); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) @@ -135,7 +127,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $update_notifications = array(); $sql = 'SELECT * 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 unread = 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 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 . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 0bf8685660..5771b60df7 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -49,15 +49,6 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post */ 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 */ diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index f700821353..e4b40e0aec 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -38,13 +38,15 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post protected $language_key = 'NOTIFICATION_QUOTE'; /** - * Get the type of notification this is - * phpbb_notification_type_ + * Notification option data (for outputting to the user) + * + * @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() - { - return 'quote'; - } + public static $notification_option = array( + 'lang' => 'NOTIFICATION_TYPE_QUOTE', + 'group' => 'NOTIFICATION_GROUP_POSTING', + ); /** * Find the users who want to receive notifications @@ -100,7 +102,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $sql = 'SELECT * 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']); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) @@ -123,7 +125,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $update_notifications = array(); $sql = 'SELECT * 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 unread = 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 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 . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; @@ -154,7 +156,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $old_notifications = array(); $sql = 'SELECT user_id 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 is_enabled = 1'; $result = $this->db->sql_query($sql); @@ -178,13 +180,13 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post } // 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 if (!empty($remove_notifications)) { $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 ' . $this->db->sql_in_set('user_id', $remove_notifications); $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index b18493ff29..42631ca97a 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -49,15 +49,6 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm '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 * diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index 0bde7dfe48..a7dd341d1d 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -42,15 +42,6 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p 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 * diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index f1ee073a4d..2a493d7f2a 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -49,15 +49,6 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i '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 * diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index 52bdadc547..38be1d9fee 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -42,15 +42,6 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type 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 * diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 4737031e87..db1d4028f0 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -37,18 +37,10 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base * Array of data (including keys 'id', 'lang', and 'group') */ public static $notification_option = array( + 'lang' => 'NOTIFICATION_TYPE_TOPIC', '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 * @@ -116,7 +108,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base $sql = 'SELECT * 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']); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index ee565ab6e6..91e12fcfbf 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -52,15 +52,6 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top 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 * diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index aeace13968..8749c88ba1 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -192,7 +192,7 @@ class ucp_notifications $template->assign_block_vars($block . '.notification_methods', array( '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, )); @@ -218,7 +218,7 @@ class ucp_notifications $template->assign_block_vars($block, array( 'METHOD' => $method, - 'NAME' => $user->lang('NOTIFICATION_METHOD_' . strtoupper($method)), + 'NAME' => $user->lang(strtoupper($method)), )); } } -- cgit v1.2.1 From de7e17b7321feebbefb5249febbbfe173e275ada Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 20 Oct 2012 21:22:06 -0500 Subject: [ticket/11103] Notifications for subscriptions/bookmarks must obey ACP options If bookmarks/subscriptions are disabled, they should not be listed in the UCP PHPBB3-11103 --- phpBB/includes/notification/type/bookmark.php | 8 ++++++++ phpBB/includes/notification/type/post.php | 8 ++++++++ phpBB/includes/notification/type/quote.php | 8 ++++++++ phpBB/includes/notification/type/topic.php | 8 ++++++++ 4 files changed, 32 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index 4d5a1fd299..4bbe9bbbf4 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -41,6 +41,14 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post 'group' => 'NOTIFICATION_GROUP_POSTING', ); + /** + * Is available + */ + public function is_available() + { + return $this->config['allow_bookmarks']; + } + /** * Find the users who want to receive notifications * diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 9317669e57..11202ee6e9 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -41,6 +41,14 @@ class phpbb_notification_type_post extends phpbb_notification_type_base 'group' => 'NOTIFICATION_GROUP_POSTING', ); + /** + * Is available + */ + public function is_available() + { + return $this->config['allow_topic_notify']; + } + /** * Get the id of the item * diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index e4b40e0aec..47337b1cda 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -48,6 +48,14 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post 'group' => 'NOTIFICATION_GROUP_POSTING', ); + /** + * Is available + */ + public function is_available() + { + return true; + } + /** * Find the users who want to receive notifications * diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index db1d4028f0..99f7b5bee4 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -41,6 +41,14 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base 'group' => 'NOTIFICATION_GROUP_POSTING', ); + /** + * Is available + */ + public function is_available() + { + return $this->config['allow_forum_notify']; + } + /** * Get the id of the item * -- cgit v1.2.1 From f62e55091aac6aa62c56dde172f2f2bb0371f7fd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 20 Oct 2012 21:26:39 -0500 Subject: [ticket/11103] PM notifications are not available if users cannot read them PHPBB3-11103 --- phpBB/includes/notification/type/pm.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index adb03ab1a3..697feca962 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -33,6 +33,14 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base 'lang' => 'NOTIFICATION_TYPE_PM', ); + /** + * Is available + */ + public function is_available() + { + return ($this->config['allow_privmsg'] && $this->auth->acl_get('u_readpm')); + } + /** * Get the id of the * -- cgit v1.2.1 From 7e6f31b51d51b1ea6416ed15c425acbb669c463d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 20 Oct 2012 21:45:15 -0500 Subject: [ticket/11103] Correct the comments on the notification classes PHPBB3-11103 --- phpBB/includes/notification/type/approve_post.php | 4 ++-- phpBB/includes/notification/type/approve_topic.php | 4 ++-- phpBB/includes/notification/type/disapprove_post.php | 4 ++-- phpBB/includes/notification/type/disapprove_topic.php | 4 ++-- phpBB/includes/notification/type/post_in_queue.php | 4 ++-- phpBB/includes/notification/type/report_pm.php | 4 ++-- phpBB/includes/notification/type/report_pm_closed.php | 4 ++-- phpBB/includes/notification/type/report_post_closed.php | 4 ++-- phpBB/includes/notification/type/topic_in_queue.php | 4 ++-- 9 files changed, 18 insertions(+), 18 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 46f2c16c14..e08039baa9 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -16,8 +16,8 @@ if (!defined('IN_PHPBB')) } /** -* Post notifications class -* This class handles notifications for replies to a topic +* Post approved notifications class +* This class handles notifications for posts when they are approved (to their authors) * * @package notifications */ diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 0015858c2e..6d3f8e60ae 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -16,8 +16,8 @@ if (!defined('IN_PHPBB')) } /** -* Post notifications class -* This class handles notifications for replies to a topic +* Topic approved notifications class +* This class handles notifications for topics when they are approved (for authors) * * @package notifications */ diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index 3b5719c3fe..ddacd4d367 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -16,8 +16,8 @@ if (!defined('IN_PHPBB')) } /** -* Post notifications class -* This class handles notifications for replies to a topic +* Post disapproved notifications class +* This class handles notifications for posts when they are disapproved (for authors) * * @package notifications */ diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index 7369fd64bd..dfda4f8371 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -16,8 +16,8 @@ if (!defined('IN_PHPBB')) } /** -* Post notifications class -* This class handles notifications for replies to a topic +* Topic disapproved notifications class +* This class handles notifications for topics when they are disapproved (for authors) * * @package notifications */ diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 5771b60df7..d0f5f22e0f 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -16,8 +16,8 @@ if (!defined('IN_PHPBB')) } /** -* Topic notifications class -* This class handles notifications for new topics +* Post in queue notifications class +* This class handles notifications for posts that are put in the moderation queue (for moderators) * * @package notifications */ diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 42631ca97a..b2f514d483 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -16,8 +16,8 @@ if (!defined('IN_PHPBB')) } /** -* Private message notifications class -* This class handles notifications for reporting private messages +* Private message reproted notifications class +* This class handles notifications for private messages when they are reported * * @package notifications */ diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index a7dd341d1d..46bca8d831 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -16,8 +16,8 @@ if (!defined('IN_PHPBB')) } /** -* Reported pm notifications class -* This class handles notifications for reported pms +* PM report closed notifications class +* This class handles notifications for when reports are closed on PMs (for the one who reported the PM) * * @package notifications */ diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index 38be1d9fee..34b69dbe47 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -16,8 +16,8 @@ if (!defined('IN_PHPBB')) } /** -* Reported post notifications class -* This class handles notifications for reported posts +* Post report closed notifications class +* This class handles notifications for when reports are closed on posts (for the one who reported the post) * * @package notifications */ diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index 91e12fcfbf..f99fde4c75 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -16,8 +16,8 @@ if (!defined('IN_PHPBB')) } /** -* Topic notifications class -* This class handles notifications for new topics +* Topic in queue notifications class +* This class handles notifications for topics when they are put in the moderation queue (for moderators) * * @package notifications */ -- cgit v1.2.1 From bc18e368c36af90b2e998913e827dc7be71f3bd0 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 20 Oct 2012 21:55:58 -0500 Subject: [ticket/11103] Correct the test case Fix a bug that broke it and make sure to set the needed config/auth settings PHPBB3-11103 --- phpBB/includes/notification/manager.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 06ebaf24c4..75155c5dc3 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -701,10 +701,25 @@ class phpbb_notification_manager ->extension_directory($path) ->get_classes(); - unset($classes[array_search('phpbb_notification_type_interface', $classes)]); - unset($classes[array_search('phpbb_notification_type_base', $classes)]); - unset($classes[array_search('phpbb_notification_method_interface', $classes)]); - unset($classes[array_search('phpbb_notification_method_base', $classes)]); + if (array_search('phpbb_notification_type_interface', $classes) !== false) + { + unset($classes[array_search('phpbb_notification_type_interface', $classes)]); + } + + if (array_search('phpbb_notification_type_base', $classes) !== false) + { + unset($classes[array_search('phpbb_notification_type_base', $classes)]); + } + + if (array_search('phpbb_notification_method_interface', $classes) !== false) + { + unset($classes[array_search('phpbb_notification_method_interface', $classes)]); + } + + if (array_search('phpbb_notification_method_base', $classes) !== false) + { + unset($classes[array_search('phpbb_notification_method_base', $classes)]); + } return $classes; } -- cgit v1.2.1 From 4874226b6e41df64959761ff53a61cfa190cabf1 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 20 Oct 2012 22:11:41 -0500 Subject: [ticket/11103] Re-add notify method to the UCP preferences I've noticed that this is used in other areas still in phpBB, so it should not be removed. PHPBB3-11103 --- phpBB/includes/ucp/ucp_prefs.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index 709d2a90b0..4b49d2092d 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -37,6 +37,7 @@ class ucp_prefs case 'personal': add_form_key('ucp_prefs_personal'); $data = array( + 'notifymethod' => request_var('notifymethod', $user->data['user_notify_type']), 'dateformat' => request_var('dateformat', $user->data['user_dateformat'], true), 'lang' => basename(request_var('lang', $user->data['user_lang'])), 'style' => request_var('style', (int) $user->data['user_style']), @@ -48,6 +49,12 @@ class ucp_prefs 'allowpm' => request_var('allowpm', (bool) $user->data['user_allow_pm']), ); + if ($data['notifymethod'] == NOTIFY_IM && (!$config['jab_enable'] || !$user->data['user_jabber'] || !@extension_loaded('xml'))) + { + // Jabber isnt enabled, or no jabber field filled in. Update the users table to be sure its correct. + $data['notifymethod'] = NOTIFY_BOTH; + } + if ($submit) { if ($config['override_user_style']) @@ -77,6 +84,7 @@ class ucp_prefs 'user_allow_viewemail' => $data['viewemail'], 'user_allow_massemail' => $data['massemail'], 'user_allow_viewonline' => ($auth->acl_get('u_hideonline')) ? !$data['hideonline'] : $user->data['user_allow_viewonline'], + 'user_notify_type' => $data['notifymethod'], 'user_options' => $user->data['user_options'], 'user_dateformat' => $data['dateformat'], @@ -122,6 +130,9 @@ class ucp_prefs $template->assign_vars(array( 'ERROR' => (sizeof($error)) ? implode('
', $error) : '', + 'S_NOTIFY_EMAIL' => ($data['notifymethod'] == NOTIFY_EMAIL) ? true : false, + 'S_NOTIFY_IM' => ($data['notifymethod'] == NOTIFY_IM) ? true : false, + 'S_NOTIFY_BOTH' => ($data['notifymethod'] == NOTIFY_BOTH) ? true : false, 'S_VIEW_EMAIL' => $data['viewemail'], 'S_MASS_EMAIL' => $data['massemail'], 'S_ALLOW_PM' => $data['allowpm'], -- cgit v1.2.1 From e549b7663da47d7518b93074e513c7e1d034bf52 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 29 Oct 2012 18:09:20 -0500 Subject: [ticket/11103] Set basic notifications to be enabled by default Now, if there is no row for the user in the user_notifications table, the user will receive basic notifications. If the user wishes to not receive notifications, a row must be added with notify = 0. For other methods besides the basic (e.g. email, jabber) a row must still be added with notify = 1 for them to receive notifications PHPBB3-11103 --- phpBB/includes/notification/manager.php | 131 +++++++++++++++++---- phpBB/includes/notification/type/approve_post.php | 27 +---- phpBB/includes/notification/type/approve_topic.php | 27 +---- phpBB/includes/notification/type/base.php | 54 +++++++-- phpBB/includes/notification/type/bookmark.php | 23 +--- phpBB/includes/notification/type/pm.php | 28 +---- phpBB/includes/notification/type/post.php | 23 +--- phpBB/includes/notification/type/post_in_queue.php | 27 +---- phpBB/includes/notification/type/quote.php | 23 +--- phpBB/includes/notification/type/report_pm.php | 27 +---- phpBB/includes/notification/type/topic.php | 29 +---- .../includes/notification/type/topic_in_queue.php | 27 +---- phpBB/includes/ucp/ucp_notifications.php | 25 ++-- 13 files changed, 187 insertions(+), 284 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 75155c5dc3..3e816108f4 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -545,41 +545,57 @@ class phpbb_notification_manager } /** - * Get subscriptions + * Get global subscriptions (item_id = 0) * * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) - * @param bool $only_global True to select only global subscription options (item_id = 0) * * @return array Subscriptions */ - public function get_subscriptions($user_id = false, $only_global = false) + public function get_global_subscriptions($user_id = false) { $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; $subscriptions = array(); - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . ' - WHERE user_id = ' . (int) $user_id . - (($only_global) ? ' AND item_id = 0' : ''); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) + foreach ($this->get_subscription_types() as $group_name => $types) { - if ($only_global) + foreach ($types as $id => $type) { - if (!isset($subscriptions[$row['item_type']])) + $sql = 'SELECT method, notify + FROM ' . USER_NOTIFICATIONS_TABLE . ' + WHERE user_id = ' . (int) $user_id . " + AND item_type = '" . $this->db->sql_escape($id) . "' + AND item_id = 0"; + $result = $this->db->sql_query($sql); + + $row = $this->db->sql_fetchrow($result); + if (!$row) { - $subscriptions[$row['item_type']] = array(); + // No rows at all, default to '' + $subscriptions[$id] = array(''); } + else + { + do + { + if (!$row['notify']) + { + continue; + } - $subscriptions[$row['item_type']][] = $row['method']; - } - else - { - $subscriptions[] = $row; + if (!isset($subscriptions[$id])) + { + $subscriptions[$id] = array(); + } + + $subscriptions[$id][] = $row['method']; + } + while ($row = $this->db->sql_fetchrow($result)); + } + + $this->db->sql_freeresult($result); } } - $this->db->sql_freeresult($result); return $subscriptions; } @@ -594,16 +610,45 @@ class phpbb_notification_manager */ public function add_subscription($item_type, $item_id = 0, $method = '', $user_id = false) { + if ($method !== '') + { + $this->add_subscription($item_type, $item_type, '', $user_id); + } + $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; - $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . - $this->db->sql_build_array('INSERT', array( - 'item_type' => $item_type, - 'item_id' => (int) $item_id, - 'user_id' => (int) $user_id, - 'method' => $method, - )); + $sql = 'SELECT notify + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id . ' + AND user_id = ' .(int) $user_id . " + AND method = '" . $this->db->sql_escape($method) . "'"; $this->db->sql_query($sql); + $current = $this->db->sql_fetchfield('notify'); + $this->db->sql_freeresult(); + + if ($current === false) + { + $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . + $this->db->sql_build_array('INSERT', array( + 'item_type' => $item_type, + 'item_id' => (int) $item_id, + 'user_id' => (int) $user_id, + 'method' => $method, + 'notify' => 1, + )); + $this->db->sql_query($sql); + } + else if (!$current) + { + $sql = 'UPDATE ' . USER_NOTIFICATIONS_TABLE . " + SET notify = 1 + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id . ' + AND user_id = ' .(int) $user_id . " + AND method = '" . $this->db->sql_escape($method) . "'"; + $this->db->sql_query($sql); + } } /** @@ -618,12 +663,46 @@ class phpbb_notification_manager { $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; - $sql = 'DELETE FROM ' . USER_NOTIFICATIONS_TABLE . " + // If no method, make sure that no other notification methods for this item are selected before deleting + if ($method === '') + { + $sql = 'SELECT COUNT(*) as count + FROM ' . USER_NOTIFICATIONS_TABLE . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id . ' + AND user_id = ' .(int) $user_id . " + AND method <> '' + AND notify = 1"; + $this->db->sql_query($sql); + $count = $this->db->sql_fetchfield('count'); + $this->db->sql_freeresult(); + + if ($count) + { + return; + } + } + + $sql = 'UPDATE ' . USER_NOTIFICATIONS_TABLE . " + SET notify = 0 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id . ' AND user_id = ' .(int) $user_id . " AND method = '" . $this->db->sql_escape($method) . "'"; $this->db->sql_query($sql); + + if (!$this->db->sql_affectedrows()) + { + $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . + $this->db->sql_build_array('INSERT', array( + 'item_type' => $item_type, + 'item_id' => (int) $item_id, + 'user_id' => (int) $user_id, + 'method' => $method, + 'notify' => 0, + )); + $this->db->sql_query($sql); + } } /** diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index e08039baa9..26f56e6333 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -73,30 +73,9 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post return array(); } - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $this->db->sql_freeresult($result); - - return $notify_users; + return $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], array_merge($options, array( + 'item_type' => self::$notification_option['id'], + ))); } /** diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 6d3f8e60ae..78837f643d 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -73,30 +73,9 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi return array(); } - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $this->db->sql_freeresult($result); - - return $notify_users; + return $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], array_merge($options, array( + 'item_type' => self::$notification_option['id'], + ))); } /** diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index df04dc2a49..c2c52fe8e9 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -310,26 +310,54 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Find the users who want to receive notifications (helper) * - * @param array $item_id The item_id to search for + * @param array $user_ids User IDs to check if they want to receive notifications + * (Bool False to check all users besides anonymous and bots (USER_IGNORE)) * * @return array */ - protected function _find_users_for_notification($item_id, $options) + protected function check_user_notification_options($user_ids = false, $options = array()) { $options = array_merge(array( 'ignore_users' => array(), + 'item_type' => get_class($this), + 'item_id' => 0, // Global by default ), $options); - $rowset = array(); + if ($user_ids === false) + { + $user_ids = array(); + + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . ' + WHERE user_id <> ' . ANONYMOUS . ' + AND user_type <> ' . USER_IGNORE; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $user_ids[] = $row['user_id']; + } + $this->db->sql_freeresult($result); + } + + if (empty($user_ids)) + { + return array(); + } + + $rowset = $resulting_user_ids = array(); - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' - AND item_id = " . (int) $item_id; + $sql = 'SELECT user_id, method, notify + FROM ' . USER_NOTIFICATIONS_TABLE . ' + WHERE ' . $this->db->sql_in_set('user_id', $user_ids) . " + AND item_type = '" . $this->db->sql_escape($options['item_type']) . "' + AND item_id = " . (int) $options['item_id']; $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) + $resulting_user_ids[] = $row['user_id']; + + if (!$row['notify'] || (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']]))) { continue; } @@ -341,8 +369,18 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $rowset[$row['user_id']][] = $row['method']; } + $this->db->sql_freeresult($result); + foreach ($user_ids as $user_id) + { + if (!in_array($user_id, $resulting_user_ids) && !isset($options['ignore_users'][$user_id])) + { + // No rows at all for this user, default to '' + $rowset[$user_id] = array(''); + } + } + return $rowset; } diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index 4bbe9bbbf4..6fe00d9dd0 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -87,28 +87,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post return array(); } - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' - AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $this->db->sql_freeresult($result); + $notify_users = $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], $options); // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index 697feca962..a60d022a12 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -80,33 +80,11 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base return array(); } - $this->notification_manager->load_users(array_keys($pm['recipients'])); - - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' - AND " . $this->db->sql_in_set('user_id', array_keys($pm['recipients'])) . ' - AND user_id <> ' . $pm['from_user_id']; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } + unset($pm['recipients'][$pm['from_user_id']]); - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $this->db->sql_freeresult($result); + $this->notification_manager->load_users(array_keys($pm['recipients'])); - return $notify_users; + return $this->check_user_notification_options(array_keys($pm['recipients']), $options); } /** diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 11202ee6e9..22fb5cd980 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -108,28 +108,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base return array(); } - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' - AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $this->db->sql_freeresult($result); + $notify_users = $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], $options); // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index d0f5f22e0f..e9e7c6120e 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -82,30 +82,9 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post $auth_approve[$post['forum_id']] = array_unique(array_merge($auth_approve[$post['forum_id']], $auth_approve[0])); - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $this->db->sql_in_set('user_id', $auth_approve[$post['forum_id']][$this->permission]); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $this->db->sql_freeresult($result); - - return $notify_users; + return $this->check_user_notification_options($auth_approve[$post['forum_id']][$this->permission], array_merge($options, array( + 'item_type' => self::$notification_option['id'], + ))); } /** diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 47337b1cda..c9f0f923c1 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -106,28 +106,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post return array(); } - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' - AND " . $this->db->sql_in_set('user_id', $auth_read[$post['forum_id']]['f_read']); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $this->db->sql_freeresult($result); + $notify_users = $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], $options); // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index b2f514d483..7cf97402cc 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -96,31 +96,14 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm return array(); } - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $this->db->sql_in_set('user_id', $auth_approve[$post['forum_id']][$this->permission]) . ' - AND user_id <> ' . $this->user->data['user_id']; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) + if (($key = array_search($this->user->data['user_id'], $auth_approve[$post['forum_id']][$this->permission]))) { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; + unset($auth_approve[$post['forum_id']][$this->permission][$key]); } - $this->db->sql_freeresult($result); - return $notify_users; + return $this->check_user_notification_options($auth_approve[$post['forum_id']][$this->permission], array_merge($options, array( + 'item_type' => self::$notification_option['id'], + ))); } /** diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 99f7b5bee4..fbee650ad8 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -82,10 +82,6 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base 'ignore_users' => array(), ), $options); - // Let's continue to use the phpBB subscriptions system, at least for now. - // It may not be the nicest thing, but it is already working and it would be significant work to replace it - //$users = parent::_find_users_for_notification($phpbb_container, $topic['forum_id']); - $users = array(); $sql = 'SELECT user_id @@ -112,30 +108,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base return array(); } - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' - AND " . $this->db->sql_in_set('user_id', $auth_read[$topic['forum_id']]['f_read']); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $this->db->sql_freeresult($result); - - return $notify_users; + return $this->check_user_notification_options($auth_read[$topic['forum_id']]['f_read'], $options); } /** diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index f99fde4c75..66aecb0d05 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -75,30 +75,9 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top $auth_approve[$topic['forum_id']] = array_unique(array_merge($auth_approve[$topic['forum_id']], $auth_approve[0])); - $notify_users = array(); - - $sql = 'SELECT * - FROM ' . USER_NOTIFICATIONS_TABLE . " - WHERE item_type = '" . self::$notification_option['id'] . "' - AND " . $this->db->sql_in_set('user_id', $auth_approve[$topic['forum_id']]['m_approve']); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - if (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']])) - { - continue; - } - - if (!isset($rowset[$row['user_id']])) - { - $notify_users[$row['user_id']] = array(); - } - - $notify_users[$row['user_id']][] = $row['method']; - } - $this->db->sql_freeresult($result); - - return $notify_users; + return $this->check_user_notification_options($auth_approve[$topic['forum_id']]['m_approve'], array_merge($options, array( + 'item_type' => self::$notification_option['id'], + ))); } /** diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index 8749c88ba1..8810ac9ce6 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -32,7 +32,7 @@ class ucp_notifications switch ($mode) { case 'notification_options': - $subscriptions = $phpbb_notifications->get_subscriptions(false, true); + $subscriptions = $phpbb_notifications->get_global_subscriptions(false); // Add/remove subscriptions if ($request->is_set_post('submit')) @@ -48,15 +48,6 @@ class ucp_notifications { foreach($subscription_types as $type => $data) { - if ($request->is_set_post($type . '_notification') && !isset($subscriptions[$type])) - { - $phpbb_notifications->add_subscription($type); - } - else if (!$request->is_set_post($type . '_notification') && isset($subscriptions[$type])) - { - $phpbb_notifications->delete_subscription($type); - } - foreach($notification_methods as $method) { if ($request->is_set_post($type . '_' . $method) && (!isset($subscriptions[$type]) || !in_array($method, $subscriptions[$type]))) @@ -68,6 +59,15 @@ class ucp_notifications $phpbb_notifications->delete_subscription($type, 0, $method); } } + + if ($request->is_set_post($type . '_notification') && !isset($subscriptions[$type])) + { + $phpbb_notifications->add_subscription($type); + } + else if (!$request->is_set_post($type . '_notification') && isset($subscriptions[$type])) + { + $phpbb_notifications->delete_subscription($type); + } } } @@ -78,7 +78,7 @@ class ucp_notifications $this->output_notification_methods('notification_methods', $phpbb_notifications, $template, $user); - $this->output_notification_types('notification_types', $phpbb_notifications, $template, $user); + $this->output_notification_types($subscriptions, 'notification_types', $phpbb_notifications, $template, $user); $this->tpl_name = 'ucp_notifications'; $this->page_title = 'UCP_NOTIFICATION_OPTIONS'; @@ -165,10 +165,9 @@ class ucp_notifications * @param phpbb_template $template * @param phpbb_user $user */ - public function output_notification_types($block = 'notification_types', phpbb_notification_manager $phpbb_notifications, phpbb_template $template, phpbb_user $user) + public function output_notification_types($subscriptions, $block = 'notification_types', phpbb_notification_manager $phpbb_notifications, phpbb_template $template, phpbb_user $user) { $notification_methods = $phpbb_notifications->get_subscription_methods(); - $subscriptions = $phpbb_notifications->get_subscriptions(false, true); foreach($phpbb_notifications->get_subscription_types() as $group => $subscription_types) { -- cgit v1.2.1 From ecf6f1eb8ca34da43b14b2da642cc7f1aa397d36 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 29 Oct 2012 18:15:01 -0500 Subject: [ticket/11103] Code cleanup PHPBB3-11103 --- phpBB/includes/notification/manager.php | 2 +- phpBB/includes/notification/type/approve_post.php | 32 ---------------------- phpBB/includes/notification/type/approve_topic.php | 30 -------------------- 3 files changed, 1 insertion(+), 63 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 3e816108f4..ffdce2032d 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -231,7 +231,7 @@ class phpbb_notification_manager return; } - $time = ($time) ?: time(); + $time = ($time !== false) ? $time : time(); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " SET unread = 0 diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 26f56e6333..60b66fd4f6 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -78,38 +78,6 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post ))); } - /** - * Pre create insert array function - * This allows you to perform certain actions, like run a query - * and load data, before create_insert_array() is run. The data - * returned from this function will be sent to create_insert_array(). - * - * @param array $post Post data from submit_post - * @param array $notify_users Notify users list - * Formated from find_users_for_notification() - * @return array Whatever you want to send to create_insert_array(). - */ - public function pre_create_insert_array($post, $notify_users) - { - /*if (!sizeof($notify_users)) - { - return array(); - } - - // Mark the topic unread before the post - $sql = 'UPDATE ' . TOPICS_TRACK_TABLE . ' - SET mark_time = ' . (int) ($post['post_time'] - 1) . ' - WHERE topic_id = ' . (int) $post['topic_id'] . ' - AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users)); - $this->db->sql_query($sql);*/ - - // In the parent class, this is used to check if the post is already - // read by a user and marks the notification read if it was marked read. - // Returning an empty array in effect, forces it to be marked as unread - // (and also saves a query) - return array(); - } - /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 78837f643d..4fd247a789 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -78,36 +78,6 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi ))); } - /** - * Pre create insert array function - * This allows you to perform certain actions, like run a query - * and load data, before create_insert_array() is run. The data - * returned from this function will be sent to create_insert_array(). - * - * @param array $post Post data from submit_post - * @param array $notify_users Notify users list - * Formated from find_users_for_notification() - * @return array Whatever you want to send to create_insert_array(). - */ - public function pre_create_insert_array($post, $notify_users) - { - /*if (!sizeof($notify_users)) - { - return array(); - } - - // Mark the topic unread - $sql = 'DELETE FROM ' . TOPICS_TRACK_TABLE . ' - WHERE topic_id = ' . (int) $post['topic_id'] . ' - AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users)); - $this->db->sql_query($sql*/ - - // In the parent class, this is used to check if the post is already - // read by a user and marks the notification read if it was marked read. - // Returning an empty array in effect, forces it to be marked as unread - return array(); - } - /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) -- cgit v1.2.1 From a811e65147db4d5c98914d201f2e4478f31f64fc Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 29 Oct 2012 18:18:33 -0500 Subject: [ticket/11103] Revert an overwrite that occured on merging from develop PHPBB3-11103 --- phpBB/includes/functions_posting.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 02c31eb6cc..4df199d72d 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -296,13 +296,15 @@ function posting_gen_topic_icons($mode, $icon_id) if (sizeof($icons)) { + $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_root_path; + foreach ($icons as $id => $data) { if ($data['display']) { $template->assign_block_vars('topic_icon', array( 'ICON_ID' => $id, - 'ICON_IMG' => $phpbb_root_path . $config['icons_path'] . '/' . $data['img'], + 'ICON_IMG' => $root_path . $config['icons_path'] . '/' . $data['img'], 'ICON_WIDTH' => $data['width'], 'ICON_HEIGHT' => $data['height'], -- cgit v1.2.1 From b60ae30b02c411db5ce3711f25e8f43a019ef9ec Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 29 Oct 2012 18:20:07 -0500 Subject: [ticket/11103] More cleanup PHPBB3-11103 --- phpBB/includes/notification/manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index ffdce2032d..b8c9c9742e 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -262,7 +262,7 @@ class phpbb_notification_manager return; } - $time = ($time) ?: time(); + $time = ($time !== false) ? $time : time(); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " SET unread = 0 @@ -281,7 +281,7 @@ class phpbb_notification_manager */ public function mark_notifications_read_by_id($notification_id, $time = false) { - $time = ($time) ?: time(); + $time = ($time !== false) ? $time : time(); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " SET unread = 0 -- cgit v1.2.1 From b1ba7b27ad611d674ac54f97ea602ea95c8955b0 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 29 Oct 2012 18:35:54 -0500 Subject: [ticket/11103] _get_avatar -> get_user_avatar PHPBB3-11103 --- phpBB/includes/notification/type/base.php | 2 +- phpBB/includes/notification/type/pm.php | 2 +- phpBB/includes/notification/type/post.php | 2 +- phpBB/includes/notification/type/report_pm.php | 2 +- phpBB/includes/notification/type/report_pm_closed.php | 2 +- phpBB/includes/notification/type/report_post.php | 2 +- phpBB/includes/notification/type/report_post_closed.php | 2 +- phpBB/includes/notification/type/topic.php | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index c2c52fe8e9..fdd8a5b9cb 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -390,7 +390,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * @param int $user_id * @return string */ - protected function _get_avatar($user_id) + protected function get_user_avatar($user_id) { $user = $this->notification_manager->get_user($user_id); diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index a60d022a12..1c38002892 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -92,7 +92,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base */ public function get_avatar() { - return $this->_get_avatar($this->get_data('from_user_id')); + return $this->get_user_avatar($this->get_data('from_user_id')); } /** diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 22fb5cd980..b1a3ee9a26 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -140,7 +140,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base */ public function get_avatar() { - return $this->_get_avatar($this->get_data('poster_id')); + return $this->get_user_avatar($this->get_data('poster_id')); } /** diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 7cf97402cc..63d153bd27 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -187,7 +187,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm */ public function get_avatar() { - return $this->_get_avatar($this->get_data('reporter_id')); + return $this->get_user_avatar($this->get_data('reporter_id')); } /** diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index 46bca8d831..c86fe77b0e 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -112,7 +112,7 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p */ public function get_avatar() { - return $this->_get_avatar($this->get_data('closer_id')); + return $this->get_user_avatar($this->get_data('closer_id')); } /** diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index 2a493d7f2a..26dd9512bf 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -154,7 +154,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i */ public function get_avatar() { - return $this->_get_avatar($this->get_data('reporter_id')); + return $this->get_user_avatar($this->get_data('reporter_id')); } /** diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index 34b69dbe47..7454760dc0 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -112,7 +112,7 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type */ public function get_avatar() { - return $this->_get_avatar($this->get_data('closer_id')); + return $this->get_user_avatar($this->get_data('closer_id')); } /** diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index fbee650ad8..db268fa53e 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -116,7 +116,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base */ public function get_avatar() { - return $this->_get_avatar($this->get_data('poster_id')); + return $this->get_user_avatar($this->get_data('poster_id')); } /** -- cgit v1.2.1 From 6c213bd5fa4f93875e7771edbf519990580286c4 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 29 Oct 2012 23:20:59 -0500 Subject: [ticket/11103] Make sure post/topic approved notifications are always unread PHPBB3-11103 --- phpBB/includes/notification/type/approve_post.php | 20 ++++++++++++++++++++ phpBB/includes/notification/type/approve_topic.php | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 60b66fd4f6..d79bc6ae13 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -78,6 +78,26 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post ))); } + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $post Post data from submit_post + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ + public function pre_create_insert_array($post, $notify_users) + { + // In the parent class, this is used to check if the post is already + // read by a user and marks the notification read if it was marked read. + // Returning an empty array in effect, forces it to be marked as unread + // (and also saves a query) + return array(); + } + /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 4fd247a789..605965bf2f 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -78,6 +78,26 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi ))); } + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $post Post data from submit_post + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ + public function pre_create_insert_array($post, $notify_users) + { + // In the parent class, this is used to check if the post is already + // read by a user and marks the notification read if it was marked read. + // Returning an empty array in effect, forces it to be marked as unread + // (and also saves a query) + return array(); + } + /** * Function for preparing the data for insertion in an SQL query * (The service handles insertion) -- cgit v1.2.1 From 05e74b82ac5b65896b1a6aa5b7bca7aa1acd3ada Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 29 Oct 2012 23:34:51 -0500 Subject: [ticket/11103] enable/disable notifications functions disable_notifications This should be called when an extension which has notification types is disabled so that all those notifications are hidden and do not cause errors enable_notifications This should be called when an extension which has notification types that was disabled is re-enabled so that all those notifications that were hidden are shown again PHPBB3-11103 --- phpBB/includes/notification/manager.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index b8c9c9742e..fef93a30c2 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -705,6 +705,38 @@ class phpbb_notification_manager } } + /** + * Disable all notifications of a certain type + * This should be called when an extension which has notification types + * is disabled so that all those notifications are hidden and do not + * cause errors + * + * @param string $item_type + */ + public function disable_notifications($item_type) + { + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + SET is_enabled = 0 + WHERE item_type = '" . $this->db->sql_escape($item_type) . "'"; + $this->db->sql_query($sql); + } + + /** + * Enable all notifications of a certain type + * This should be called when an extension which has notification types + * that was disabled is re-enabled so that all those notifications that + * were hidden are shown again + * + * @param string $item_type + */ + public function enable_notifications($item_type) + { + $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + SET is_enabled = 1 + WHERE item_type = '" . $this->db->sql_escape($item_type) . "'"; + $this->db->sql_query($sql); + } + /** * Load user helper * -- cgit v1.2.1 From f09ee162528d931aabc3f216410d02d3a072c21d Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 9 Nov 2012 07:40:08 -0600 Subject: [ticket/11103] Use phpBB Container to load types/methods PHPBB3-11103 --- phpBB/includes/notification/manager.php | 70 +++++++--------------- phpBB/includes/notification/method/email.php | 10 ++++ phpBB/includes/notification/method/interface.php | 7 +++ phpBB/includes/notification/method/jabber.php | 10 ++++ phpBB/includes/notification/type/approve_post.php | 10 ++++ phpBB/includes/notification/type/approve_topic.php | 10 ++++ phpBB/includes/notification/type/base.php | 6 +- phpBB/includes/notification/type/bookmark.php | 14 ++++- .../includes/notification/type/disapprove_post.php | 10 ++++ .../notification/type/disapprove_topic.php | 10 ++++ phpBB/includes/notification/type/interface.php | 7 +++ phpBB/includes/notification/type/pm.php | 10 ++++ phpBB/includes/notification/type/post.php | 14 ++++- phpBB/includes/notification/type/post_in_queue.php | 10 ++++ phpBB/includes/notification/type/quote.php | 20 +++++-- phpBB/includes/notification/type/report_pm.php | 10 ++++ .../notification/type/report_pm_closed.php | 10 ++++ phpBB/includes/notification/type/report_post.php | 10 ++++ .../notification/type/report_post_closed.php | 10 ++++ phpBB/includes/notification/type/topic.php | 10 ++++ .../includes/notification/type/topic_in_queue.php | 10 ++++ phpBB/includes/ucp/ucp_notifications.php | 24 ++++---- 22 files changed, 229 insertions(+), 73 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index fef93a30c2..102623ab93 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -7,6 +7,8 @@ * */ +use Symfony\Component\DependencyInjection\ContainerBuilder; + /** * @ignore */ @@ -21,6 +23,9 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_manager { + /** @var ContainerBuilder */ + protected $phpbb_container = null; + /** @var dbal */ protected $db = null; @@ -55,8 +60,9 @@ class phpbb_notification_manager */ protected $users = array(); - public function __construct(dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) + public function __construct(ContainerBuilder $phpbb_container, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { + $this->phpbb_container = $phpbb_container; $this->db = $db; $this->cache = $cache; $this->template = $template; @@ -495,17 +501,17 @@ class phpbb_notification_manager { $subscription_types = array(); - foreach ($this->get_subscription_files('notification/type/') as $class_name) + foreach ($this->phpbb_container->findTaggedServiceIds('notification.type') as $type_name => $data) { - $class = $this->get_item_type_class($class_name); + $type = $this->get_item_type_class($type_name); - if ($class instanceof phpbb_notification_type_interface && $class->is_available()) + if ($type instanceof phpbb_notification_type_interface && $type->is_available()) { $options = array_merge(array( - 'id' => $class_name, - 'lang' => 'NOTIFICATION_TYPE_' . strtoupper($class_name), + 'id' => $type->get_type(), + 'lang' => 'NOTIFICATION_TYPE_' . strtoupper($type->get_type()), 'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS', - ), (($class_name::$notification_option !== false) ? $class_name::$notification_option : array())); + ), (($type::$notification_option !== false) ? $type::$notification_option : array())); $subscription_types[$options['group']][$options['id']] = $options; } @@ -531,13 +537,16 @@ class phpbb_notification_manager { $subscription_methods = array(); - foreach ($this->get_subscription_files('notification/method/') as $class_name) + foreach ($this->phpbb_container->findTaggedServiceIds('notification.method') as $method_name => $data) { - $method = $this->get_method_class($class_name); + $method = $this->get_method_class($method_name); if ($method instanceof phpbb_notification_method_interface && $method->is_available()) { - $subscription_methods[] = $class_name; + $subscription_methods[$method_name] = array( + 'id' => $method->get_type(), + 'lang' => 'NOTIFICATION_METHOD_' . strtoupper($method->get_type()), + ); } } @@ -783,7 +792,7 @@ class phpbb_notification_manager */ public function get_item_type_class($item_type, $data = array()) { - $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 = $this->phpbb_container->get($item_type); $item->set_initial_data($data); @@ -795,43 +804,6 @@ class phpbb_notification_manager */ public function get_method_class($method_name) { - return new $method_name($this, $this->db, $this->cache, $this->template, $this->extension_manager, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext); - } - - /** - * Helper to get subscription related files with the finder - */ - private function get_subscription_files($path) - { - $finder = $this->extension_manager->get_finder(); - - $subscription_files = array(); - - $classes = $finder - ->core_path('includes/' . $path) - ->extension_directory($path) - ->get_classes(); - - if (array_search('phpbb_notification_type_interface', $classes) !== false) - { - unset($classes[array_search('phpbb_notification_type_interface', $classes)]); - } - - if (array_search('phpbb_notification_type_base', $classes) !== false) - { - unset($classes[array_search('phpbb_notification_type_base', $classes)]); - } - - if (array_search('phpbb_notification_method_interface', $classes) !== false) - { - unset($classes[array_search('phpbb_notification_method_interface', $classes)]); - } - - if (array_search('phpbb_notification_method_base', $classes) !== false) - { - unset($classes[array_search('phpbb_notification_method_base', $classes)]); - } - - return $classes; + return $this->phpbb_container->get($method_name); } } diff --git a/phpBB/includes/notification/method/email.php b/phpBB/includes/notification/method/email.php index df7edb13e7..a47284bc61 100644 --- a/phpBB/includes/notification/method/email.php +++ b/phpBB/includes/notification/method/email.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_method_email extends phpbb_notification_method_base { + /** + * Get notification method name + * + * @return string + */ + public function get_type() + { + return 'email'; + } + /** * Notify method (since jabber gets sent through the same messenger, we let the jabber class inherit from this to reduce code duplication) * diff --git a/phpBB/includes/notification/method/interface.php b/phpBB/includes/notification/method/interface.php index 3c6c757d5c..ef875942cc 100644 --- a/phpBB/includes/notification/method/interface.php +++ b/phpBB/includes/notification/method/interface.php @@ -21,6 +21,13 @@ if (!defined('IN_PHPBB')) */ interface phpbb_notification_method_interface { + /** + * Get notification method name + * + * @return string + */ + public function get_type(); + /** * Is this method available for the user? * This is checked on the notifications options diff --git a/phpBB/includes/notification/method/jabber.php b/phpBB/includes/notification/method/jabber.php index 664e387d61..fc43d8d4b9 100644 --- a/phpBB/includes/notification/method/jabber.php +++ b/phpBB/includes/notification/method/jabber.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_method_jabber extends phpbb_notification_method_email { + /** + * Get notification method name + * + * @return string + */ + public function get_type() + { + return 'jabber'; + } + /** * Notify method (since jabber gets sent through the same messenger, we let the jabber class inherit from this to reduce code duplication) * diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index d79bc6ae13..38ff3f1d70 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_approve_post extends phpbb_notification_type_post { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'approve_post'; + } + /** * Language key used to output the text * diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 605965bf2f..5b9ea409fe 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topic { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'approve_topic'; + } + /** * Language key used to output the text * diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index fdd8a5b9cb..2b201c2752 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -116,7 +116,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i public function __toString() { - return (!empty($this->data)) ? var_export($this->data, true) : get_class($this); + return (!empty($this->data)) ? var_export($this->data, true) : $this->get_type(); } /** @@ -156,7 +156,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i // Defaults $this->data = array_merge(array( 'item_id' => static::get_item_id($type_data), - 'item_type' => get_class($this), + 'item_type' => $this->get_type(), 'item_parent_id' => static::get_item_parent_id($type_data), 'time' => time(), @@ -319,7 +319,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i { $options = array_merge(array( 'ignore_users' => array(), - 'item_type' => get_class($this), + 'item_type' => $this->get_type(), 'item_id' => 0, // Global by default ), $options); diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index 6fe00d9dd0..e5ad4132fb 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_bookmark extends phpbb_notification_type_post { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'bookmark'; + } + /** * Language key used to output the text * @@ -93,7 +103,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post $update_notifications = array(); $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' + WHERE item_type = '" . $this->get_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 AND is_enabled = 1'; @@ -103,7 +113,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post // Do not create a new notification unset($notify_users[$row['user_id']]); - $notification = $this->notification_manager->get_item_type_class(get_class($this), $row); + $notification = $this->notification_manager->get_item_type_class($this->get_type(), $row); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index ddacd4d367..d1d56086e7 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_approve_post { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'disapprove_post'; + } + /** * Language key used to output the text * diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index dfda4f8371..7affaa8afa 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_approve_topic { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'disapprove_topic'; + } + /** * Language key used to output the text * diff --git a/phpBB/includes/notification/type/interface.php b/phpBB/includes/notification/type/interface.php index 9d9965261e..a40fdafd09 100644 --- a/phpBB/includes/notification/type/interface.php +++ b/phpBB/includes/notification/type/interface.php @@ -21,6 +21,13 @@ if (!defined('IN_PHPBB')) */ interface phpbb_notification_type_interface { + /** + * Get notification type name + * + * @return string + */ + public function get_type(); + /** * Set initial data from the database * diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index 1c38002892..fbdf351062 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_pm extends phpbb_notification_type_base { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'pm'; + } + /** * Notification option data (for outputting to the user) * diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index b1a3ee9a26..a99558efe7 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_post extends phpbb_notification_type_base { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'post'; + } + /** * Language key used to output the text * @@ -114,7 +124,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $update_notifications = array(); $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' + WHERE item_type = '" . $this->get_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 AND is_enabled = 1'; @@ -124,7 +134,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base // Do not create a new notification unset($notify_users[$row['user_id']]); - $notification = $this->notification_manager->get_item_type_class(get_class($this), $row); + $notification = $this->notification_manager->get_item_type_class($this->get_type(), $row); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index e9e7c6120e..95e0ce02bb 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'post_in_queue'; + } + /** * Language key used to output the text * diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index c9f0f923c1..c3763da229 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_quote extends phpbb_notification_type_post { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'quote'; + } + /** * regular expression to match to find usernames * @@ -112,7 +122,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $update_notifications = array(); $sql = 'SELECT * FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' + WHERE item_type = '" . $this->get_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 AND is_enabled = 1'; @@ -122,7 +132,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post // Do not create a new notification unset($notify_users[$row['user_id']]); - $notification = $this->notification_manager->get_item_type_class(get_class($this), $row); + $notification = $this->notification_manager->get_item_type_class($this->get_type(), $row); $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; @@ -143,7 +153,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post $old_notifications = array(); $sql = 'SELECT user_id FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' + WHERE item_type = '" . $this->get_type() . "' AND item_id = " . self::get_item_id($post) . ' AND is_enabled = 1'; $result = $this->db->sql_query($sql); @@ -167,13 +177,13 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post } // Add the necessary notifications - $this->notification_manager->add_notifications_for_users(get_class($this), $post, $add_notifications); + $this->notification_manager->add_notifications_for_users($this->get_type(), $post, $add_notifications); // Remove the necessary notifications if (!empty($remove_notifications)) { $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . get_class($this) . "' + WHERE item_type = '" . $this->get_type() . "' AND item_id = " . self::get_item_id($post) . ' AND ' . $this->db->sql_in_set('user_id', $remove_notifications); $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 63d153bd27..2841468475 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'report_pm'; + } + /** * Language key used to output the text * diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index c86fe77b0e..de87c9f760 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_pm { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'report_pm_closed'; + } + /** * Email template to use to send notifications * diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index 26dd9512bf..433a5e835d 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_report_post extends phpbb_notification_type_post_in_queue { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'report_post'; + } + /** * Language key used to output the text * diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index 7454760dc0..cde0ff85a8 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_report_post_closed extends phpbb_notification_type_post { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'report_post_closed'; + } + /** * Email template to use to send notifications * diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index db268fa53e..4eb03194f5 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_topic extends phpbb_notification_type_base { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'topic'; + } + /** * Language key used to output the text * diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index 66aecb0d05..38bc2ab58d 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -23,6 +23,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_topic { + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'topic_in_queue'; + } + /** * Language key used to output the text * diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index 8810ac9ce6..e8ceac3f59 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -48,15 +48,15 @@ class ucp_notifications { foreach($subscription_types as $type => $data) { - foreach($notification_methods as $method) + foreach($notification_methods as $method => $method_data) { - if ($request->is_set_post($type . '_' . $method) && (!isset($subscriptions[$type]) || !in_array($method, $subscriptions[$type]))) + if ($request->is_set_post($type . '_' . $method_data['id']) && (!isset($subscriptions[$type]) || !in_array($method_data['id'], $subscriptions[$type]))) { - $phpbb_notifications->add_subscription($type, 0, $method); + $phpbb_notifications->add_subscription($type, 0, $method_data['id']); } - else if (!$request->is_set_post($type . '_' . $method) && isset($subscriptions[$type]) && in_array($method, $subscriptions[$type])) + else if (!$request->is_set_post($type . '_' . $method_data['id']) && isset($subscriptions[$type]) && in_array($method_data['id'], $subscriptions[$type])) { - $phpbb_notifications->delete_subscription($type, 0, $method); + $phpbb_notifications->delete_subscription($type, 0, $method_data['id']); } } @@ -186,14 +186,14 @@ class ucp_notifications 'SUBSCRIBED' => (isset($subscriptions[$type])) ? true : false, )); - foreach($notification_methods as $method) + foreach($notification_methods as $method => $method_data) { $template->assign_block_vars($block . '.notification_methods', array( - 'METHOD' => $method, + 'METHOD' => $method_data['id'], - 'NAME' => $user->lang(strtoupper($method)), + 'NAME' => $user->lang($method_data['lang']), - 'SUBSCRIBED' => (isset($subscriptions[$type]) && in_array($method, $subscriptions[$type])) ? true : false, + 'SUBSCRIBED' => (isset($subscriptions[$type]) && in_array($method_data['id'], $subscriptions[$type])) ? true : false, )); } } @@ -212,12 +212,12 @@ class ucp_notifications { $notification_methods = $phpbb_notifications->get_subscription_methods(); - foreach($notification_methods as $method) + foreach($notification_methods as $method => $method_data) { $template->assign_block_vars($block, array( - 'METHOD' => $method, + 'METHOD' => $method_data['id'], - 'NAME' => $user->lang(strtoupper($method)), + 'NAME' => $user->lang($method_data['lang']), )); } } -- cgit v1.2.1 From b8bdcc957bc49b96d43d74077c95a55f4f88e2fa Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 9 Nov 2012 07:45:23 -0600 Subject: [ticket/11103] count is reserved, do not use in a SQL query PHPBB3-11103 --- phpBB/includes/notification/manager.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 102623ab93..ca018fbf3b 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -122,25 +122,25 @@ class phpbb_notification_manager if ($options['count_unread']) { // Get the total number of unread notifications - $sql = 'SELECT COUNT(*) AS count + $sql = 'SELECT COUNT(*) AS unread_count FROM ' . NOTIFICATIONS_TABLE . ' WHERE user_id = ' . (int) $options['user_id'] . ' AND unread = 1 AND is_enabled = 1'; $result = $this->db->sql_query($sql); - $unread_count = (int) $this->db->sql_fetchfield('count', $result); + $unread_count = (int) $this->db->sql_fetchfield('unread_count', $result); $this->db->sql_freeresult($result); } if ($options['count_total']) { // Get the total number of notifications - $sql = 'SELECT COUNT(*) AS count + $sql = 'SELECT COUNT(*) AS total_count FROM ' . NOTIFICATIONS_TABLE . ' WHERE user_id = ' . (int) $options['user_id'] . ' AND is_enabled = 1'; $result = $this->db->sql_query($sql); - $total_count = (int) $this->db->sql_fetchfield('count', $result); + $total_count = (int) $this->db->sql_fetchfield('total_count', $result); $this->db->sql_freeresult($result); } @@ -675,7 +675,7 @@ class phpbb_notification_manager // If no method, make sure that no other notification methods for this item are selected before deleting if ($method === '') { - $sql = 'SELECT COUNT(*) as count + $sql = 'SELECT COUNT(*) as num_notifications FROM ' . USER_NOTIFICATIONS_TABLE . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id . ' @@ -683,10 +683,10 @@ class phpbb_notification_manager AND method <> '' AND notify = 1"; $this->db->sql_query($sql); - $count = $this->db->sql_fetchfield('count'); + $num_notifications = $this->db->sql_fetchfield('num_notifications'); $this->db->sql_freeresult(); - if ($count) + if ($num_notifications) { return; } -- cgit v1.2.1 From 6a0f6833e61532d28d7bebcc8ad0ec2b2b722e19 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 9 Nov 2012 07:48:18 -0600 Subject: [ticket/11103] Comment indentation PHPBB3-11103 --- phpBB/includes/notification/manager.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index ca018fbf3b..8392928bd2 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -716,9 +716,10 @@ class phpbb_notification_manager /** * Disable all notifications of a certain type - * This should be called when an extension which has notification types - * is disabled so that all those notifications are hidden and do not - * cause errors + * + * This should be called when an extension which has notification types + * is disabled so that all those notifications are hidden and do not + * cause errors * * @param string $item_type */ @@ -732,9 +733,10 @@ class phpbb_notification_manager /** * Enable all notifications of a certain type - * This should be called when an extension which has notification types - * that was disabled is re-enabled so that all those notifications that - * were hidden are shown again + * + * This should be called when an extension which has notification types + * that was disabled is re-enabled so that all those notifications that + * were hidden are shown again * * @param string $item_type */ -- cgit v1.2.1 From 6c8c54d4d2575cd40fe873cd2108b031ae5830a6 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 9 Nov 2012 08:48:41 -0600 Subject: [ticket/11103] Inject table prefix to notifications system instead of constants PHPBB3-11103 --- phpBB/includes/constants.php | 3 -- phpBB/includes/notification/manager.php | 52 ++++++++++++++++++------------- phpBB/includes/notification/type/base.php | 12 ++++++- 3 files changed, 42 insertions(+), 25 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index 7a3c73e987..5128321618 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -239,7 +239,6 @@ define('LOG_TABLE', $table_prefix . 'log'); define('LOGIN_ATTEMPT_TABLE', $table_prefix . 'login_attempts'); define('MODERATOR_CACHE_TABLE', $table_prefix . 'moderator_cache'); define('MODULES_TABLE', $table_prefix . 'modules'); -define('NOTIFICATIONS_TABLE', $table_prefix . 'notifications'); define('POLL_OPTIONS_TABLE', $table_prefix . 'poll_options'); define('POLL_VOTES_TABLE', $table_prefix . 'poll_votes'); define('POSTS_TABLE', $table_prefix . 'posts'); @@ -273,11 +272,9 @@ define('TOPICS_POSTED_TABLE', $table_prefix . 'topics_posted'); define('TOPICS_TRACK_TABLE', $table_prefix . 'topics_track'); define('TOPICS_WATCH_TABLE', $table_prefix . 'topics_watch'); define('USER_GROUP_TABLE', $table_prefix . 'user_group'); -define('USER_NOTIFICATIONS_TABLE', $table_prefix . 'user_notifications'); define('USERS_TABLE', $table_prefix . 'users'); define('WARNINGS_TABLE', $table_prefix . 'warnings'); define('WORDS_TABLE', $table_prefix . 'words'); define('ZEBRA_TABLE', $table_prefix . 'zebra'); // Additional tables - diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 8392928bd2..3d0ada4a43 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -53,6 +53,12 @@ class phpbb_notification_manager /** @var string */ protected $php_ext = null; + /** @var string */ + protected $notifications_table = null; + + /** @var string */ + protected $user_notifications_table = null; + /** * Users loaded from the DB * @@ -60,7 +66,7 @@ class phpbb_notification_manager */ protected $users = array(); - public function __construct(ContainerBuilder $phpbb_container, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) + public function __construct(ContainerBuilder $phpbb_container, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) { $this->phpbb_container = $phpbb_container; $this->db = $db; @@ -70,8 +76,12 @@ class phpbb_notification_manager $this->user = $user; $this->auth = $auth; $this->config = $config; + $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; + + $this->notifications_table = $notifications_table; + $this->user_notifications_table = $user_notifications_table; } /** @@ -123,7 +133,7 @@ class phpbb_notification_manager { // Get the total number of unread notifications $sql = 'SELECT COUNT(*) AS unread_count - FROM ' . NOTIFICATIONS_TABLE . ' + FROM ' . $this->notifications_table . ' WHERE user_id = ' . (int) $options['user_id'] . ' AND unread = 1 AND is_enabled = 1'; @@ -136,7 +146,7 @@ class phpbb_notification_manager { // Get the total number of notifications $sql = 'SELECT COUNT(*) AS total_count - FROM ' . NOTIFICATIONS_TABLE . ' + FROM ' . $this->notifications_table . ' WHERE user_id = ' . (int) $options['user_id'] . ' AND is_enabled = 1'; $result = $this->db->sql_query($sql); @@ -150,7 +160,7 @@ class phpbb_notification_manager // Get the main notifications $sql = 'SELECT * - FROM ' . NOTIFICATIONS_TABLE . ' + FROM ' . $this->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 @@ -167,7 +177,7 @@ class phpbb_notification_manager if ($unread_count && $options['all_unread'] && !empty($rowset)) { $sql = 'SELECT * - FROM ' . NOTIFICATIONS_TABLE . ' + FROM ' . $this->notifications_table . ' WHERE user_id = ' . (int) $options['user_id'] . ' AND unread = 1 AND ' . $this->db->sql_in_set('notification_id', array_keys($rowset), true) . ' @@ -239,7 +249,7 @@ class phpbb_notification_manager $time = ($time !== false) ? $time : time(); - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + $sql = 'UPDATE ' . $this->notifications_table . " SET unread = 0 WHERE time <= " . $time . (($item_type !== false) ? ' AND ' . (is_array($item_type) ? $this->db->sql_in_set('item_type', $item_type) : " item_type = '" . $this->db->sql_escape($item_type) . "'") : '') . @@ -270,7 +280,7 @@ class phpbb_notification_manager $time = ($time !== false) ? $time : time(); - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + $sql = 'UPDATE ' . $this->notifications_table . " SET unread = 0 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND time <= " . $time . @@ -289,7 +299,7 @@ class phpbb_notification_manager { $time = ($time !== false) ? $time : time(); - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + $sql = 'UPDATE ' . $this->notifications_table . " SET unread = 0 WHERE time <= " . $time . ' AND ' . ((is_array($notification_id)) ? $this->db->sql_in_set('notification_id', $notification_id) : 'notification_id = ' . (int) $notification_id); @@ -365,7 +375,7 @@ class phpbb_notification_manager // Make sure not to send new notifications to users who've already been notified about this item // This may happen when an item was added, but now new users are able to see the item $sql = 'SELECT user_id - FROM ' . NOTIFICATIONS_TABLE . " + FROM ' . $this->notifications_table . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id . ' AND is_enabled = 1'; @@ -415,7 +425,7 @@ class phpbb_notification_manager } // insert into the db - $this->db->sql_multi_insert(NOTIFICATIONS_TABLE, $new_rows); + $this->db->sql_multi_insert($this->notifications_table, $new_rows); // We need to load all of the users to send notifications $this->load_users($user_ids); @@ -460,7 +470,7 @@ class phpbb_notification_manager $item_id = $item_type::get_item_id($data); $update_array = $notification->create_update_array($data); - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + $sql = 'UPDATE ' . $this->notifications_table . ' SET ' . $this->db->sql_build_array('UPDATE', $update_array) . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id; @@ -486,7 +496,7 @@ class phpbb_notification_manager return; } - $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " + $sql = 'DELETE FROM ' . $this->notifications_table . " 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); $this->db->sql_query($sql); @@ -571,7 +581,7 @@ class phpbb_notification_manager foreach ($types as $id => $type) { $sql = 'SELECT method, notify - FROM ' . USER_NOTIFICATIONS_TABLE . ' + FROM ' . $this->user_notifications_table . ' WHERE user_id = ' . (int) $user_id . " AND item_type = '" . $this->db->sql_escape($id) . "' AND item_id = 0"; @@ -627,7 +637,7 @@ class phpbb_notification_manager $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; $sql = 'SELECT notify - FROM ' . USER_NOTIFICATIONS_TABLE . " + FROM ' . $this->user_notifications_table . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id . ' AND user_id = ' .(int) $user_id . " @@ -638,7 +648,7 @@ class phpbb_notification_manager if ($current === false) { - $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . + $sql = 'INSERT INTO ' . $this->user_notifications_table . ' ' . $this->db->sql_build_array('INSERT', array( 'item_type' => $item_type, 'item_id' => (int) $item_id, @@ -650,7 +660,7 @@ class phpbb_notification_manager } else if (!$current) { - $sql = 'UPDATE ' . USER_NOTIFICATIONS_TABLE . " + $sql = 'UPDATE ' . $this->user_notifications_table . " SET notify = 1 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id . ' @@ -676,7 +686,7 @@ class phpbb_notification_manager if ($method === '') { $sql = 'SELECT COUNT(*) as num_notifications - FROM ' . USER_NOTIFICATIONS_TABLE . " + FROM ' . $this->user_notifications_table . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id . ' AND user_id = ' .(int) $user_id . " @@ -692,7 +702,7 @@ class phpbb_notification_manager } } - $sql = 'UPDATE ' . USER_NOTIFICATIONS_TABLE . " + $sql = 'UPDATE ' . $this->user_notifications_table . " SET notify = 0 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' AND item_id = " . (int) $item_id . ' @@ -702,7 +712,7 @@ class phpbb_notification_manager if (!$this->db->sql_affectedrows()) { - $sql = 'INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . + $sql = 'INSERT INTO ' . $this->user_notifications_table . ' ' . $this->db->sql_build_array('INSERT', array( 'item_type' => $item_type, 'item_id' => (int) $item_id, @@ -725,7 +735,7 @@ class phpbb_notification_manager */ public function disable_notifications($item_type) { - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + $sql = 'UPDATE ' . $this->notifications_table . " SET is_enabled = 0 WHERE item_type = '" . $this->db->sql_escape($item_type) . "'"; $this->db->sql_query($sql); @@ -742,7 +752,7 @@ class phpbb_notification_manager */ public function enable_notifications($item_type) { - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . " + $sql = 'UPDATE ' . $this->notifications_table . " SET is_enabled = 1 WHERE item_type = '" . $this->db->sql_escape($item_type) . "'"; $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 2b201c2752..419dce3dd0 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -51,6 +51,12 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** @var string */ protected $php_ext = null; + /** @var string */ + protected $notifications_table = null; + + /** @var string */ + protected $user_notifications_table = null; + /** * Notification option data (for outputting to the user) * @@ -78,7 +84,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ private $data = array(); - public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) + public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) { $this->notification_manager = $notification_manager; $this->db = $db; @@ -88,8 +94,12 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $this->user = $user; $this->auth = $auth; $this->config = $config; + $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; + + $this->notifications_table = $notifications_table; + $this->user_notifications_table = $user_notifications_table; } /** -- cgit v1.2.1 From 106daa09ebb5b12bf9892c41f8c1de627cf6b0e9 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 10 Nov 2012 11:20:06 -0600 Subject: [ticket/11103] Fix failed automerge PHPBB3-11103 --- phpBB/includes/functions_privmsgs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 7acc37eb85..54e8ced679 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -1142,7 +1142,6 @@ function delete_pm($user_id, $msg_ids, $folder_id) function phpbb_delete_user_pms($user_id) { global $db, $user, $phpbb_root_path, $phpEx; - global $phpbb_notifications; $user_id = (int) $user_id; @@ -1164,6 +1163,7 @@ function phpbb_delete_user_pms($user_id) function phpbb_delete_users_pms($user_ids) { global $db, $user, $phpbb_root_path, $phpEx; + global $phpbb_notifications; $user_id_sql = $db->sql_in_set('user_id', $user_ids); $author_id_sql = $db->sql_in_set('author_id', $user_ids); -- cgit v1.2.1 From 985d234a29b22086a196dca427e6c474229e3d36 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sun, 11 Nov 2012 11:37:14 -0600 Subject: [ticket/11103] Move all email templates to the email/ directory & prep short Prepare short email templates (to be used in jabber) PHPBB3-11103 --- phpBB/includes/notification/type/bookmark.php | 2 +- phpBB/includes/notification/type/post_in_queue.php | 2 +- phpBB/includes/notification/type/quote.php | 2 +- phpBB/includes/notification/type/report_pm.php | 2 +- phpBB/includes/notification/type/report_post.php | 2 +- phpBB/includes/notification/type/topic_in_queue.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index e5ad4132fb..a40bbde5e4 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -131,6 +131,6 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post */ public function get_email_template() { - return 'notifications/bookmark'; + return 'bookmark'; } } diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 95e0ce02bb..3cd9b11283 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -132,6 +132,6 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post */ public function get_email_template() { - return 'notifications/post_in_queue'; + return 'post_in_queue'; } } diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index c3763da229..f45bb1ae7d 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -200,7 +200,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post */ public function get_email_template() { - return 'notifications/quote'; + return 'quote'; } /** diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 2841468475..9bdc59a4ef 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -123,7 +123,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm */ public function get_email_template() { - return 'notifications/report_pm'; + return 'report_pm'; } /** diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index 433a5e835d..d80c7b754f 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -83,7 +83,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i */ public function get_email_template() { - return 'notifications/report_post'; + return 'report_post'; } /** diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index 38bc2ab58d..170a98ca1b 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -125,6 +125,6 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top */ public function get_email_template() { - return 'notifications/topic_in_queue'; + return 'topic_in_queue'; } } -- cgit v1.2.1 From 7948aaa78ed7e543a0773ee1a858ef45f5e5a5bf Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sun, 11 Nov 2012 11:41:18 -0600 Subject: [ticket/11103] Make jabber use short/ email template files PHPBB3-11103 --- phpBB/includes/notification/method/email.php | 9 ++++++++- phpBB/includes/notification/method/jabber.php | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/method/email.php b/phpBB/includes/notification/method/email.php index a47284bc61..2ff30b177f 100644 --- a/phpBB/includes/notification/method/email.php +++ b/phpBB/includes/notification/method/email.php @@ -40,6 +40,13 @@ class phpbb_notification_method_email extends phpbb_notification_method_base */ protected $notify_method = NOTIFY_EMAIL; + /** + * Base directory to prepend to the email template name + * + * @var string + */ + protected $email_template_base_dir = ''; + /** * Is this method available for the user? * This is checked on the notifications options @@ -100,7 +107,7 @@ class phpbb_notification_method_email extends phpbb_notification_method_base continue; } - $messenger->template($notification->get_email_template(), $user['user_lang']); + $messenger->template($this->email_template_base_dir . $notification->get_email_template(), $user['user_lang']); $messenger->to($user['user_email'], $user['username']); diff --git a/phpBB/includes/notification/method/jabber.php b/phpBB/includes/notification/method/jabber.php index fc43d8d4b9..e3eb571fbc 100644 --- a/phpBB/includes/notification/method/jabber.php +++ b/phpBB/includes/notification/method/jabber.php @@ -40,6 +40,13 @@ class phpbb_notification_method_jabber extends phpbb_notification_method_email */ protected $notify_method = NOTIFY_IM; + /** + * Base directory to prepend to the email template name + * + * @var string + */ + protected $email_template_base_dir = 'short/'; + /** * Is this method available for the user? * This is checked on the notifications options -- cgit v1.2.1 From 2afb8b9df873c3f9572a32ab7a62ea8ba8d8a45b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 20 Nov 2012 18:14:48 -0600 Subject: [ticket/11103] Create user loader class, update for DIC Create a very basic user loader class to handle querying/storing user data in a centralized location. Use DIC collection service for notification types/methods. Cleanup unused dependencies. Fix some other issues. PHPBB3-11103 --- phpBB/includes/functions.php | 36 +++--- phpBB/includes/functions_admin.php | 16 +-- phpBB/includes/functions_posting.php | 30 ++--- phpBB/includes/functions_privmsgs.php | 14 +-- phpBB/includes/mcp/mcp_pm_reports.php | 2 +- phpBB/includes/mcp/mcp_queue.php | 28 ++--- phpBB/includes/mcp/mcp_reports.php | 10 +- phpBB/includes/notification/manager.php | 127 ++++++++------------- phpBB/includes/notification/method/base.php | 14 ++- phpBB/includes/notification/method/email.php | 4 +- phpBB/includes/notification/type/base.php | 39 ++----- phpBB/includes/notification/type/bookmark.php | 4 +- phpBB/includes/notification/type/pm.php | 8 +- phpBB/includes/notification/type/post.php | 10 +- phpBB/includes/notification/type/quote.php | 10 +- phpBB/includes/notification/type/report_pm.php | 4 +- .../notification/type/report_pm_closed.php | 2 +- phpBB/includes/notification/type/report_post.php | 4 +- .../notification/type/report_post_closed.php | 4 +- phpBB/includes/notification/type/topic.php | 6 +- phpBB/includes/user_loader.php | 118 +++++++++++++++++++ 21 files changed, 284 insertions(+), 206 deletions(-) create mode 100644 phpBB/includes/user_loader.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 4e26d2c642..283ed4a657 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1331,12 +1331,12 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ // Mark all topic notifications read for this user $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', + 'topic', + 'quote', + 'bookmark', + 'post', + 'approve_topic', + 'approve_post', ), false, $user->data['user_id'], $post_time); if ($config['load_db_lastread'] && $user->data['is_registered']) @@ -1394,8 +1394,8 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ } $phpbb_notifications->mark_notifications_read_by_parent(array( - 'phpbb_notification_type_topic', - 'phpbb_notification_type_approve_topic', + 'topic', + 'approve_topic', ), $forum_id, $user->data['user_id'], $post_time); // Mark all post/quote notifications read for this user in this forum @@ -1411,10 +1411,10 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ $db->sql_freeresult($result); $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', + 'quote', + 'bookmark', + 'post', + 'approve_post', ), $topic_ids, $user->data['user_id'], $post_time); // Add 0 to forums array to mark global announcements correctly @@ -1516,14 +1516,14 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ // Mark post notifications read for this user in this topic $phpbb_notifications->mark_notifications_read(array( - 'phpbb_notification_type_topic', - 'phpbb_notification_type_approve_topic', + 'topic', + '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', + 'quote', + 'bookmark', + 'post', + 'approve_post', ), $topic_id, $user->data['user_id'], $post_time); if ($config['load_db_lastread'] && $user->data['is_registered']) diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index fdae1905a0..e15bf12279 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -717,9 +717,9 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s } $phpbb_notifications->delete_notifications(array( - 'phpbb_notification_type_topic', - 'phpbb_notification_type_approve_topic', - 'phpbb_notification_type_topic_in_queue', + 'topic', + 'approve_topic', + 'topic_in_queue', ), $topic_ids); return $return; @@ -901,11 +901,11 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = } $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', + 'quote', + 'bookmark', + 'post', + 'approve_post', + 'post_in_queue', ), $post_ids); return sizeof($post_ids); diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 4df199d72d..8ba1fed6a7 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -2237,17 +2237,17 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u { case 'post': $phpbb_notifications->add_notifications(array( - 'phpbb_notification_type_quote', - 'phpbb_notification_type_topic', + 'quote', + 'topic', ), $notification_data); break; case 'reply': case 'quote': $phpbb_notifications->add_notifications(array( - 'phpbb_notification_type_quote', - 'phpbb_notification_type_bookmark', - 'phpbb_notification_type_post', + 'quote', + 'bookmark', + 'post', ), $notification_data); break; @@ -2256,10 +2256,10 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u case 'edit': case 'edit_last_post': $phpbb_notifications->update_notifications(array( - 'phpbb_notification_type_quote', - 'phpbb_notification_type_bookmark', - 'phpbb_notification_type_topic', - 'phpbb_notification_type_post', + 'quote', + 'bookmark', + 'topic', + 'post', ), $notification_data); break; } @@ -2269,23 +2269,23 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u switch ($mode) { case 'post': - $phpbb_notifications->add_notifications('phpbb_notification_type_topic_in_queue', $notification_data); + $phpbb_notifications->add_notifications('topic_in_queue', $notification_data); break; case 'reply': case 'quote': - $phpbb_notifications->add_notifications('phpbb_notification_type_post_in_queue', $notification_data); + $phpbb_notifications->add_notifications('post_in_queue', $notification_data); break; case 'edit_topic': case 'edit_first_post': case 'edit': case 'edit_last_post': - $phpbb_notifications->delete_notifications('phpbb_notification_type_topic', $data['topic_id']); + $phpbb_notifications->delete_notifications('topic', $data['topic_id']); $phpbb_notifications->delete_notifications(array( - 'phpbb_notification_type_quote', - 'phpbb_notification_type_bookmark', - 'phpbb_notification_type_post', + 'quote', + 'bookmark', + 'post', ), $data['post_id']); break; } diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 54e8ced679..ae8ffbe90e 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -878,7 +878,7 @@ function update_unread_status($unread, $msg_id, $user_id, $folder_id) global $db, $user, $phpbb_notifications; - $phpbb_notifications->mark_notifications_read('phpbb_notification_type_pm', $msg_id, $user_id); + $phpbb_notifications->mark_notifications_read('pm', $msg_id, $user_id); $sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . " SET pm_unread = 0 @@ -1096,7 +1096,7 @@ function delete_pm($user_id, $msg_ids, $folder_id) $user->data['user_unread_privmsg'] -= $num_unread; } - $phpbb_notifications->delete_notifications('phpbb_notification_type_pm', array_keys($delete_rows)); + $phpbb_notifications->delete_notifications('pm', array_keys($delete_rows)); // Now we have to check which messages we can delete completely $sql = 'SELECT msg_id @@ -1277,7 +1277,7 @@ function phpbb_delete_users_pms($user_ids) AND ' . $db->sql_in_set('msg_id', $delivered_msg); $db->sql_query($sql); - $phpbb_notifications->delete_notifications('phpbb_notification_type_pm', $delivered_msg); + $phpbb_notifications->delete_notifications('pm', $delivered_msg); } if (!empty($undelivered_msg)) @@ -1290,7 +1290,7 @@ function phpbb_delete_users_pms($user_ids) WHERE ' . $db->sql_in_set('msg_id', $undelivered_msg); $db->sql_query($sql); - $phpbb_notifications->delete_notifications('phpbb_notification_type_pm', $undelivered_msg); + $phpbb_notifications->delete_notifications('pm', $undelivered_msg); } } @@ -1334,7 +1334,7 @@ function phpbb_delete_users_pms($user_ids) WHERE ' . $db->sql_in_set('msg_id', $delete_ids); $db->sql_query($sql); - $phpbb_notifications->delete_notifications('phpbb_notification_type_pm', $delete_ids); + $phpbb_notifications->delete_notifications('pm', $delete_ids); } } @@ -1879,11 +1879,11 @@ function submit_pm($mode, $subject, &$data, $put_in_outbox = true) if ($mode == 'edit') { - $phpbb_notifications->update_notifications('phpbb_notification_type_pm', $pm_data); + $phpbb_notifications->update_notifications('pm', $pm_data); } else { - $phpbb_notifications->add_notifications('phpbb_notification_type_pm', $pm_data); + $phpbb_notifications->add_notifications('pm', $pm_data); } return $data['msg_id']; diff --git a/phpBB/includes/mcp/mcp_pm_reports.php b/phpBB/includes/mcp/mcp_pm_reports.php index 2a52a0b4fd..4ba1b2fd0c 100644 --- a/phpBB/includes/mcp/mcp_pm_reports.php +++ b/phpBB/includes/mcp/mcp_pm_reports.php @@ -90,7 +90,7 @@ class mcp_pm_reports trigger_error('NO_REPORT'); } - $phpbb_notifications->mark_notifications_read_by_parent('phpbb_notification_type_report_pm', $report_id, $user->data['user_id']); + $phpbb_notifications->mark_notifications_read_by_parent('report_pm', $report_id, $user->data['user_id']); $pm_id = $report['pm_id']; $report_id = $report['report_id']; diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index f13ce914bf..4a3d443006 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -86,7 +86,7 @@ class mcp_queue { $post_id = (int) $topic_info[$topic_id]['topic_first_post_id']; - $phpbb_notifications->mark_notifications_read('phpbb_notification_type_topic_in_queue', $topic_id, $user->data['user_id']); + $phpbb_notifications->mark_notifications_read('topic_in_queue', $topic_id, $user->data['user_id']); } else { @@ -94,7 +94,7 @@ class mcp_queue } } - $phpbb_notifications->mark_notifications_read('phpbb_notification_type_post_in_queue', $post_id, $user->data['user_id']); + $phpbb_notifications->mark_notifications_read('post_in_queue', $post_id, $user->data['user_id']); $post_info = get_post_data(array($post_id), 'm_approve', true); @@ -610,28 +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']) { - $phpbb_notifications->delete_notifications('phpbb_notification_type_topic_in_queue', $post_data['topic_id']); + $phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']); - $phpbb_notifications->add_notifications('phpbb_notification_type_topic', $post_data); + $phpbb_notifications->add_notifications('topic', $post_data); if ($notify_poster) { - $phpbb_notifications->add_notifications('phpbb_notification_type_approve_topic', $post_data); + $phpbb_notifications->add_notifications('approve_topic', $post_data); } } else { - $phpbb_notifications->delete_notifications('phpbb_notification_type_post_in_queue', $post_id); + $phpbb_notifications->delete_notifications('post_in_queue', $post_id); $phpbb_notifications->add_notifications(array( - 'phpbb_notification_type_quote', - 'phpbb_notification_type_bookmark', - 'phpbb_notification_type_post', + 'quote', + 'bookmark', + 'post', ), $post_data); if ($notify_poster) { - $phpbb_notifications->add_notifications('phpbb_notification_type_approve_post', $post_data); + $phpbb_notifications->add_notifications('approve_post', $post_data); } } } @@ -859,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']) { - $phpbb_notifications->delete_notifications('phpbb_notification_type_topic_in_queue', $post_data['topic_id']); + $phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']); } else { - $phpbb_notifications->delete_notifications('phpbb_notification_type_post_in_queue', $post_id); + $phpbb_notifications->delete_notifications('post_in_queue', $post_id); } } @@ -909,14 +909,14 @@ function disapprove_post($post_id_list, $id, $mode) { if ($notify_poster) { - $phpbb_notifications->add_notifications('phpbb_notification_type_disapprove_topic', $post_data); + $phpbb_notifications->add_notifications('disapprove_topic', $post_data); } } else { if ($notify_poster) { - $phpbb_notifications->add_notifications('phpbb_notification_type_disapprove_post', $post_data); + $phpbb_notifications->add_notifications('disapprove_post', $post_data); } } } diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php index 41cdbc75d6..85723ab3f7 100644 --- a/phpBB/includes/mcp/mcp_reports.php +++ b/phpBB/includes/mcp/mcp_reports.php @@ -88,7 +88,7 @@ class mcp_reports trigger_error('NO_REPORT'); } - $phpbb_notifications->mark_notifications_read('phpbb_notification_type_report_post', $post_id, $user->data['user_id']); + $phpbb_notifications->mark_notifications_read('report_post', $post_id, $user->data['user_id']); if (!$report_id && $report['report_closed']) { @@ -647,20 +647,20 @@ function close_report($report_id_list, $mode, $action, $pm = false) if ($pm) { - $phpbb_notifications->add_notifications('phpbb_notification_type_report_pm_closed', array_merge($post_info[$post_id], array( + $phpbb_notifications->add_notifications('report_pm_closed', array_merge($post_info[$post_id], array( 'reporter' => $reporter['user_id'], 'closer_id' => $user->data['user_id'], 'from_user_id' => $post_info[$post_id]['author_id'], ))); - $phpbb_notifications->delete_notifications('phpbb_notification_type_report_pm', $post_id); + $phpbb_notifications->delete_notifications('report_pm', $post_id); } else { - $phpbb_notifications->add_notifications('phpbb_notification_type_report_post_closed', array_merge($post_info[$post_id], array( + $phpbb_notifications->add_notifications('report_post_closed', array_merge($post_info[$post_id], array( 'reporter' => $reporter['user_id'], 'closer_id' => $user->data['user_id'], ))); - $phpbb_notifications->delete_notifications('phpbb_notification_type_report_post', $post_id); + $phpbb_notifications->delete_notifications('report_post', $post_id); } } } diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 3d0ada4a43..fbfe388c80 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -7,8 +7,6 @@ * */ -use Symfony\Component\DependencyInjection\ContainerBuilder; - /** * @ignore */ @@ -23,30 +21,24 @@ if (!defined('IN_PHPBB')) */ class phpbb_notification_manager { + /** @var array */ + protected $notification_types = null; + + /** @var array */ + protected $notification_methods = null; + /** @var ContainerBuilder */ protected $phpbb_container = null; - - /** @var dbal */ - protected $db = null; - - /** @var phpbb_cache_service */ - protected $cache = null; - /** @var phpbb_template */ - protected $template = null; + /** @var phpbb_user_loader */ + protected $user_loader = null; - /** @var phpbb_extension_manager */ - protected $extension_manager = null; + /** @var dbal */ + protected $db = null; /** @var phpbb_user */ protected $user = null; - /** @var phpbb_auth */ - protected $auth = null; - - /** @var phpbb_config */ - protected $config = null; - /** @var string */ protected $phpbb_root_path = null; @@ -59,23 +51,15 @@ class phpbb_notification_manager /** @var string */ protected $user_notifications_table = null; - /** - * Users loaded from the DB - * - * @var array Array of user data that we've loaded from the DB - */ - protected $users = array(); - - public function __construct(ContainerBuilder $phpbb_container, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) + public function __construct($notification_types, $notification_methods, $phpbb_container, phpbb_user_loader $user_loader, dbal $db, $user, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) { + $this->notification_types = $notification_types; + $this->notification_methods = $notification_methods; $this->phpbb_container = $phpbb_container; + + $this->user_loader = $user_loader; $this->db = $db; - $this->cache = $cache; - $this->template = $template; - $this->extension_manager = $extension_manager; $this->user = $user; - $this->auth = $auth; - $this->config = $config; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; @@ -209,7 +193,7 @@ class phpbb_notification_manager $notifications[$row['notification_id']] = $notification; } - $this->load_users($user_ids); + $this->user_loader->load_users($user_ids); // Allow each type to load its own special items foreach ($load_special as $item_type => $data) @@ -334,7 +318,7 @@ class phpbb_notification_manager return $notified_users; } - $item_id = $item_type::get_item_id($data); + $item_id = $this->get_item_type_class($item_type)->get_item_id($data); // find out which users want to receive this type of notification $notify_users = $this->get_item_type_class($item_type)->find_users_for_notification($data, $options); @@ -363,7 +347,7 @@ class phpbb_notification_manager return; } - $item_id = $item_type::get_item_id($data); + $item_id = $this->get_item_type_class($item_type)->get_item_id($data); $user_ids = array(); $notification_objects = $notification_methods = array(); @@ -428,7 +412,7 @@ class phpbb_notification_manager $this->db->sql_multi_insert($this->notifications_table, $new_rows); // We need to load all of the users to send notifications - $this->load_users($user_ids); + $this->user_loader->load_users($user_ids); // run the queue for each method to send notifications foreach ($notification_methods as $method) @@ -467,7 +451,7 @@ class phpbb_notification_manager } } - $item_id = $item_type::get_item_id($data); + $item_id = $notification->get_item_id($data); $update_array = $notification->create_update_array($data); $sql = 'UPDATE ' . $this->notifications_table . ' @@ -511,7 +495,7 @@ class phpbb_notification_manager { $subscription_types = array(); - foreach ($this->phpbb_container->findTaggedServiceIds('notification.type') as $type_name => $data) + foreach ($this->notification_types as $type_name => $data) { $type = $this->get_item_type_class($type_name); @@ -547,7 +531,7 @@ class phpbb_notification_manager { $subscription_methods = array(); - foreach ($this->phpbb_container->findTaggedServiceIds('notification.method') as $method_name => $data) + foreach ($this->notification_methods as $method_name => $data) { $method = $this->get_method_class($method_name); @@ -759,63 +743,48 @@ class phpbb_notification_manager } /** - * Load user helper - * - * @param array $user_ids + * Helper to get the notifications item type class and set it up */ - public function load_users($user_ids) + public function get_item_type_class($item_type, $data = array()) { - $user_ids[] = ANONYMOUS; - - // Load the users - $user_ids = array_unique($user_ids); - - // Do not load users we already have in $this->users - $user_ids = array_diff($user_ids, array_keys($this->users)); + $item = $this->load_object('notification.type.' . $item_type); - if (sizeof($user_ids)) - { - $sql = 'SELECT * - FROM ' . USERS_TABLE . ' - WHERE ' . $this->db->sql_in_set('user_id', $user_ids); - $result = $this->db->sql_query($sql); + $item->set_initial_data($data); - while ($row = $this->db->sql_fetchrow($result)) - { - $this->users[$row['user_id']] = $row; - } - $this->db->sql_freeresult($result); - } + return $item; } /** - * Get a user row from our users cache - * - * @param int $user_id - * @return array + * Helper to get the notifications method class and set it up */ - public function get_user($user_id) + public function get_method_class($method_name) { - return (isset($this->users[$user_id])) ? $this->users[$user_id] : $this->users[ANONYMOUS]; + return $this->load_object('notification.method.' . $method_name); } /** - * Helper to get the notifications item type class and set it up + * Helper to load objects (notification types/methods) */ - public function get_item_type_class($item_type, $data = array()) + protected function load_object($object_name) { - $item = $this->phpbb_container->get($item_type); + // Here we cannot just use ContainerBuilder->get(name) + // The reason for this is because get handles services + // which are initialized once and shared. Here we need + // separate new objects because we pass around objects + // that store row data in each object, which would lead + // to over-writing of data if we used get() - $item->set_initial_data($data); + $parameterBag = $this->phpbb_container->getParameterBag(); + $definition = $this->phpbb_container->getDefinition($object_name); + $arguments = $this->phpbb_container->resolveServices( + $parameterBag->unescapeValue($parameterBag->resolveValue($definition->getArguments())) + ); + $r = new \ReflectionClass($parameterBag->resolveValue($definition->getClass())); - return $item; - } + $object = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments); - /** - * Helper to get the notifications method class and set it up - */ - public function get_method_class($method_name) - { - return $this->phpbb_container->get($method_name); + $object->set_notification_manager($this); + + return $object; } } diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index 88ec2674be..3f85d62a09 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -24,6 +24,9 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth /** @var phpbb_notification_manager */ protected $notification_manager = null; + /** @var phpbb_user_loader */ + protected $user_loader = null; + /** @var dbal */ protected $db = null; @@ -58,13 +61,11 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth */ protected $queue = array(); - public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) + public function __construct(phpbb_user_loader $user_loader, dbal $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { - $this->notification_manager = $notification_manager; + $this->user_loader = $user_loader; $this->db = $db; $this->cache = $cache; - $this->template = $template; - $this->extension_manager = $extension_manager; $this->user = $user; $this->auth = $auth; $this->config = $config; @@ -72,6 +73,11 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth $this->php_ext = $php_ext; } + public function set_notification_manager(phpbb_notification_manager $notification_manager) + { + $this->notification_manager = $notification_manager; + } + /** * Add a notification to the queue * diff --git a/phpBB/includes/notification/method/email.php b/phpBB/includes/notification/method/email.php index 2ff30b177f..429dfda2ba 100644 --- a/phpBB/includes/notification/method/email.php +++ b/phpBB/includes/notification/method/email.php @@ -82,7 +82,7 @@ class phpbb_notification_method_email extends phpbb_notification_method_base $banned_users = phpbb_get_banned_user_ids($user_ids); // Load all the users we need - $this->notification_manager->load_users($user_ids); + $this->user_loader->load_users($user_ids); // Load the messenger if (!class_exists('messenger')) @@ -100,7 +100,7 @@ class phpbb_notification_method_email extends phpbb_notification_method_base continue; } - $user = $this->notification_manager->get_user($notification->user_id); + $user = $this->user_loader->get_user($notification->user_id); if ($user['user_type'] == USER_IGNORE || in_array($notification->user_id, $banned_users)) { diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 419dce3dd0..d596c06167 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -24,6 +24,9 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** @var phpbb_notification_manager */ protected $notification_manager = null; + /** @var phpbb_user_loader */ + protected $user_loader = null; + /** @var dbal */ protected $db = null; @@ -33,9 +36,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** @var phpbb_template */ protected $template = null; - /** @var phpbb_extension_manager */ - protected $extension_manager = null; - /** @var phpbb_user */ protected $user = null; @@ -84,13 +84,11 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ private $data = array(); - public function __construct(phpbb_notification_manager $notification_manager, dbal $db, phpbb_cache_driver_interface $cache, phpbb_template $template, phpbb_extension_manager $extension_manager, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) + public function __construct(phpbb_user_loader $user_loader, dbal $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) { - $this->notification_manager = $notification_manager; + $this->user_loader = $user_loader; $this->db = $db; $this->cache = $cache; - $this->template = $template; - $this->extension_manager = $extension_manager; $this->user = $user; $this->auth = $auth; $this->config = $config; @@ -102,6 +100,11 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $this->user_notifications_table = $user_notifications_table; } + public function set_notification_manager(phpbb_notification_manager $notification_manager) + { + $this->notification_manager = $notification_manager; + } + /** * Set initial data from the database * @@ -357,7 +360,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $rowset = $resulting_user_ids = array(); $sql = 'SELECT user_id, method, notify - FROM ' . USER_NOTIFICATIONS_TABLE . ' + FROM ' . $this->user_notifications_table . ' WHERE ' . $this->db->sql_in_set('user_id', $user_ids) . " AND item_type = '" . $this->db->sql_escape($options['item_type']) . "' AND item_id = " . (int) $options['item_id']; @@ -394,24 +397,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i return $rowset; } - /** - * Get avatar helper - * - * @param int $user_id - * @return string - */ - protected function get_user_avatar($user_id) - { - $user = $this->notification_manager->get_user($user_id); - - if (!function_exists('get_user_avatar')) - { - include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); - } - - return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height'], $user['username'], false, 'notifications-avatar'); - } - /** * Mark this item read/unread helper * @@ -435,7 +420,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i return $where; } - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + $sql = 'UPDATE ' . $this->notifications_table . ' SET unread = ' . (int) $this->unread . ' WHERE ' . $where; $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index a40bbde5e4..a17d8f5db7 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -102,7 +102,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); $sql = 'SELECT * - FROM ' . NOTIFICATIONS_TABLE . " + FROM ' . $this->notifications_table . " WHERE item_type = '" . $this->get_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 @@ -114,7 +114,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post unset($notify_users[$row['user_id']]); $notification = $this->notification_manager->get_item_type_class($this->get_type(), $row); - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + $sql = 'UPDATE ' . $this->notifications_table . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index fbdf351062..1eaeb1a250 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -92,7 +92,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base unset($pm['recipients'][$pm['from_user_id']]); - $this->notification_manager->load_users(array_keys($pm['recipients'])); + $this->user_loader->load_users(array_keys($pm['recipients'])); return $this->check_user_notification_options(array_keys($pm['recipients']), $options); } @@ -102,7 +102,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base */ public function get_avatar() { - return $this->get_user_avatar($this->get_data('from_user_id')); + return $this->user_loader->get_avatar($this->get_data('from_user_id')); } /** @@ -112,7 +112,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base */ public function get_title() { - $user_data = $this->notification_manager->get_user($this->get_data('from_user_id')); + $user_data = $this->user_loader->get_user($this->get_data('from_user_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); @@ -136,7 +136,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base */ public function get_email_template_variables() { - $user_data = $this->notification_manager->get_user($this->get_data('from_user_id')); + $user_data = $this->user_loader->get_user($this->get_data('from_user_id')); return array( 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index a99558efe7..7e06779982 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -123,7 +123,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); $sql = 'SELECT * - FROM ' . NOTIFICATIONS_TABLE . " + FROM ' . $this->notifications_table . " WHERE item_type = '" . $this->get_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 @@ -135,7 +135,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base unset($notify_users[$row['user_id']]); $notification = $this->notification_manager->get_item_type_class($this->get_type(), $row); - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + $sql = 'UPDATE ' . $this->notifications_table . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; $this->db->sql_query($sql); @@ -150,7 +150,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base */ public function get_avatar() { - return $this->get_user_avatar($this->get_data('poster_id')); + return $this->user_loader->get_avatar($this->get_data('poster_id')); } /** @@ -181,7 +181,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base } else { - $user_data = $this->notification_manager->get_user($responder['poster_id']); + $user_data = $this->user_loader->get_user($responder['poster_id']); $usernames[] = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } @@ -217,7 +217,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base } else { - $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); + $user_data = $this->user_loader->get_user($this->get_data('poster_id')); $username = get_username_string('username', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index f45bb1ae7d..1796343a0e 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -121,7 +121,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); $sql = 'SELECT * - FROM ' . NOTIFICATIONS_TABLE . " + FROM ' . $this->notifications_table . " WHERE item_type = '" . $this->get_type() . "' AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' AND unread = 1 @@ -133,7 +133,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post unset($notify_users[$row['user_id']]); $notification = $this->notification_manager->get_item_type_class($this->get_type(), $row); - $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . ' + $sql = 'UPDATE ' . $this->notifications_table . ' SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' WHERE notification_id = ' . $row['notification_id']; $this->db->sql_query($sql); @@ -152,7 +152,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post { $old_notifications = array(); $sql = 'SELECT user_id - FROM ' . NOTIFICATIONS_TABLE . " + FROM ' . $this->notifications_table . " WHERE item_type = '" . $this->get_type() . "' AND item_id = " . self::get_item_id($post) . ' AND is_enabled = 1'; @@ -182,7 +182,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post // Remove the necessary notifications if (!empty($remove_notifications)) { - $sql = 'DELETE FROM ' . NOTIFICATIONS_TABLE . " + $sql = 'DELETE FROM ' . $this->notifications_table . " WHERE item_type = '" . $this->get_type() . "' AND item_id = " . self::get_item_id($post) . ' AND ' . $this->db->sql_in_set('user_id', $remove_notifications); @@ -210,7 +210,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post */ public function get_email_template_variables() { - $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); + $user_data = $this->user_loader->get_user($this->get_data('poster_id')); return array_merge(parent::get_email_template_variables(), array( 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 9bdc59a4ef..73e22dc83b 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -160,7 +160,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm { $this->user->add_lang('mcp'); - $user_data = $this->notification_manager->get_user($this->get_data('reporter_id')); + $user_data = $this->user_loader->get_user($this->get_data('reporter_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); @@ -197,7 +197,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm */ public function get_avatar() { - return $this->get_user_avatar($this->get_data('reporter_id')); + return $this->user_loader->get_avatar($this->get_data('reporter_id')); } /** diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index de87c9f760..51e5204304 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -106,7 +106,7 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p */ public function get_title() { - $user_data = $this->notification_manager->get_user($this->get_data('closer_id')); + $user_data = $this->user_loader->get_user($this->get_data('closer_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index d80c7b754f..2508644b0b 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -127,7 +127,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i { $this->user->add_lang('mcp'); - $user_data = $this->notification_manager->get_user($this->get_data('reporter_id')); + $user_data = $this->user_loader->get_user($this->get_data('reporter_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); @@ -164,7 +164,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i */ public function get_avatar() { - return $this->get_user_avatar($this->get_data('reporter_id')); + return $this->user_loader->get_avatar($this->get_data('reporter_id')); } /** diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index cde0ff85a8..a7016a8f3d 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -106,7 +106,7 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type */ public function get_title() { - $user_data = $this->notification_manager->get_user($this->get_data('closer_id')); + $user_data = $this->user_loader->get_user($this->get_data('closer_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); @@ -122,7 +122,7 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type */ public function get_avatar() { - return $this->get_user_avatar($this->get_data('closer_id')); + return $this->user_loader->get_avatar($this->get_data('closer_id')); } /** diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 4eb03194f5..6e9347d4a8 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -126,7 +126,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base */ public function get_avatar() { - return $this->get_user_avatar($this->get_data('poster_id')); + return $this->user_loader->get_avatar($this->get_data('poster_id')); } /** @@ -142,7 +142,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base } else { - $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); + $user_data = $this->user_loader->get_user($this->get_data('poster_id')); $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } @@ -178,7 +178,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base } else { - $user_data = $this->notification_manager->get_user($this->get_data('poster_id')); + $user_data = $this->user_loader->get_user($this->get_data('poster_id')); $username = get_username_string('username', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); } diff --git a/phpBB/includes/user_loader.php b/phpBB/includes/user_loader.php new file mode 100644 index 0000000000..a530f21f75 --- /dev/null +++ b/phpBB/includes/user_loader.php @@ -0,0 +1,118 @@ +db = $db; + + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + + $this->users_table = $users_table; + } + + /** + * Load user helper + * + * @param array $user_ids + */ + public function load_users(array $user_ids) + { + $user_ids[] = ANONYMOUS; + + // Load the users + $user_ids = array_unique($user_ids); + + // Do not load users we already have in $this->users + $user_ids = array_diff($user_ids, array_keys($this->users)); + + if (sizeof($user_ids)) + { + $sql = 'SELECT * + FROM ' . $this->users_table . ' + WHERE ' . $this->db->sql_in_set('user_id', $user_ids); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->users[$row['user_id']] = $row; + } + $this->db->sql_freeresult($result); + } + } + + /** + * Get a user row from our users cache + * + * @param int $user_id + * @return array|bool Row from the database of the user or Anonymous if the user wasn't loaded/does not exist + * or bool False if the anonymous user was not loaded + */ + public function get_user($user_id) + { + return (isset($this->users[$user_id])) ? $this->users[$user_id] : (isset($this->users[ANONYMOUS]) ? $this->users[ANONYMOUS] : false); + } + + /** + * Get avatar + * + * @param int $user_id + * @return string + */ + public function get_avatar($user_id) + { + if (!($user = $this->get_user($user_id))) + { + return ''; + } + + if (!function_exists('get_user_avatar')) + { + include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); + } + + return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height']); + } +} \ No newline at end of file -- cgit v1.2.1 From 570c5ad3c08378f377385aaff7d3810ccb8db3ff Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 20 Nov 2012 23:12:37 -0600 Subject: [ticket/11103] Some comments PHPBB3-11103 --- phpBB/includes/notification/manager.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index fbfe388c80..ea91496fb9 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -78,10 +78,15 @@ class phpbb_notification_manager * order_dir Order direction (Default: DESC) * limit Number of notifications to load (Default: 5) * start Notifications offset (Default: 0) - * all_unread Load all unread messages? If set to true, count_unread is set to true (Default: false) - * count_unread Count all unread messages? (Default: false) + * all_unread Load all unread notifications? If set to true, count_unread is set to true (Default: false) + * count_unread Count all unread notifications? (Default: false) + * count_total Count all notifications? (Default: false) + * @return array Array of information based on the request with keys: + * 'notifications' array of notification type objects + * 'unread_count' number of unread notifications the user has if count_unread is true in the options + * 'total_count' number of notifications the user has if count_total is true in the options */ - public function load_notifications($options = array()) + public function load_notifications(array $options = array()) { // Merge default options $options = array_merge(array( @@ -297,8 +302,11 @@ class phpbb_notification_manager * Note: If you send an array of types, any user who could receive multiple notifications from this single item will only receive * a single notification. If they MUST receive multiple notifications, call this function multiple times instead of sending an array * @param array $data Data specific for this type that will be inserted + * @param array $options Optional options to control what notifications are loaded + * ignore_users array of data to specify which users should not receive certain types of notifications + * @return array Information about what users were notified and how they were notified */ - public function add_notifications($item_type, $data, $options = array()) + public function add_notifications($item_type, $data, array $options = array()) { $options = array_merge(array( 'ignore_users' => array(), -- cgit v1.2.1 From c911a34b5b7541b46ee2408da366d2dc7c302090 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 21 Nov 2012 16:04:01 -0600 Subject: [ticket/11103] Do not prepend notification.(type|method) unless necessary PHPBB3-11103 --- phpBB/includes/notification/manager.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index ea91496fb9..4c25fa72f0 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -755,7 +755,9 @@ class phpbb_notification_manager */ public function get_item_type_class($item_type, $data = array()) { - $item = $this->load_object('notification.type.' . $item_type); + $item_type = (strpos($item_type, 'notification.type.') === 0) ? $item_type : 'notification.type.' . $item_type; + + $item = $this->load_object($item_type); $item->set_initial_data($data); @@ -767,7 +769,9 @@ class phpbb_notification_manager */ public function get_method_class($method_name) { - return $this->load_object('notification.method.' . $method_name); + $method_name = (strpos($method_name, 'notification.method.') === 0) ? $method_name : 'notification.method.' . $method_name; + + return $this->load_object($method_name); } /** -- cgit v1.2.1 From b91ba8d5f1c05bc285e3f3b24fc5ffd50f6ee3ed Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Dec 2012 13:18:11 -0600 Subject: [ticket/11103] Newlines at end of files PHPBB3-11103 --- phpBB/includes/user_loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/user_loader.php b/phpBB/includes/user_loader.php index a530f21f75..c7a6a103f8 100644 --- a/phpBB/includes/user_loader.php +++ b/phpBB/includes/user_loader.php @@ -115,4 +115,4 @@ class phpbb_user_loader return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height']); } -} \ No newline at end of file +} -- cgit v1.2.1 From 2227ceab8bf0cccf95598f4e2a59cc7134adf7f0 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Dec 2012 13:56:39 -0600 Subject: [ticket/11103] Use $request->variable rather than request_var PHPBB3-11103 --- phpBB/includes/ucp/ucp_notifications.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index e8ceac3f59..76fc411584 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -26,8 +26,8 @@ class ucp_notifications add_form_key('ucp_notification'); - $start = request_var('start', 0); - $form_time = min(request_var('form_time', 0), time()); + $start = $request->variable('start', 0); + $form_time = min($request->variable('form_time', 0), time()); switch ($mode) { @@ -87,7 +87,7 @@ class ucp_notifications case 'notification_list': default: // Mark all items read - if (request_var('mark', '') == 'all' && (confirm_box(true) || check_link_hash(request_var('token', ''), 'mark_all_notifications_read'))) + if ($request->variable('mark', '') == 'all' && (confirm_box(true) || check_link_hash($request->variable('token', ''), 'mark_all_notifications_read'))) { if (confirm_box(true)) { @@ -114,7 +114,7 @@ class ucp_notifications trigger_error('FORM_INVALID'); } - $mark_read = request_var('mark', array(0)); + $mark_read = $request->variable('mark', array(0)); if (!empty($mark_read)) { -- cgit v1.2.1 From c0534f9e5d1527426f5a80276cf8a08323334ef1 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Dec 2012 14:28:38 -0600 Subject: [ticket/11103] User Loader constructor docs PHPBB3-11103 --- phpBB/includes/user_loader.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/user_loader.php b/phpBB/includes/user_loader.php index c7a6a103f8..914770e335 100644 --- a/phpBB/includes/user_loader.php +++ b/phpBB/includes/user_loader.php @@ -43,6 +43,14 @@ class phpbb_user_loader */ protected $users = array(); + /** + * User loader constructor + * + * @param dbal $db A database connection + * @param string $phpbb_root_path Path to the phpbb includes directory. + * @param string $php_ext php file extension + * @param string $users_table The name of the database table (phpbb_users) + */ public function __construct(dbal $db, $phpbb_root_path, $php_ext, $users_table) { $this->db = $db; -- cgit v1.2.1 From 37565f37e4363f257a160145bc7973a2d5738a86 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Dec 2012 18:40:41 -0600 Subject: [ticket/11103] Some improvements to the user loader PHPBB3-11103 --- phpBB/includes/notification/type/pm.php | 4 +- phpBB/includes/notification/type/post.php | 8 +- phpBB/includes/notification/type/report_pm.php | 6 +- .../notification/type/report_pm_closed.php | 4 +- phpBB/includes/notification/type/report_post.php | 4 +- .../notification/type/report_post_closed.php | 4 +- phpBB/includes/notification/type/topic.php | 8 +- phpBB/includes/user_loader.php | 117 +++++++++++++++++++-- 8 files changed, 121 insertions(+), 34 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index 1eaeb1a250..8d31c87817 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -112,9 +112,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base */ public function get_title() { - $user_data = $this->user_loader->get_user($this->get_data('from_user_id')); - - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $username = $this->user_loader->get_username($this->get_data('from_user_id'), 'no_profile'); return $this->user->lang('NOTIFICATION_PM', $username, $this->get_data('message_subject')); } diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 7e06779982..0646282c94 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -181,9 +181,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base } else { - $user_data = $this->user_loader->get_user($responder['poster_id']); - - $usernames[] = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $usernames[] = $this->user_loader->get_username($responder['poster_id'], 'no_profile'); } } @@ -217,9 +215,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base } else { - $user_data = $this->user_loader->get_user($this->get_data('poster_id')); - - $username = get_username_string('username', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $username = $this->user_loader->get_username($this->get_data('poster_id'), 'no_profile'); } return array( diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 73e22dc83b..877e8209e3 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -160,9 +160,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm { $this->user->add_lang('mcp'); - $user_data = $this->user_loader->get_user($this->get_data('reporter_id')); - - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $username = $this->user_loader->get_username($this->get_data('reporter_id'), 'no_profile'); if ($this->get_data('report_text')) { @@ -186,7 +184,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm return $this->user->lang( $this->language_key, - $username, + $username, censor_text($this->get_data('message_subject')), $this->get_data('reason_description') ); diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index 51e5204304..2d60ae21d4 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -106,9 +106,7 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p */ public function get_title() { - $user_data = $this->user_loader->get_user($this->get_data('closer_id')); - - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $username = $this->user_loader->get_username($this->get_data('closer_id'), 'no_profile'); return $this->user->lang( $this->language_key, diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index 2508644b0b..0334fdb109 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -127,9 +127,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i { $this->user->add_lang('mcp'); - $user_data = $this->user_loader->get_user($this->get_data('reporter_id')); - - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $username = $this->user_loader->get_username($this->get_data('reporter_id'), 'no_profile'); if ($this->get_data('report_text')) { diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index a7016a8f3d..3282ba7d8c 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -106,9 +106,7 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type */ public function get_title() { - $user_data = $this->user_loader->get_user($this->get_data('closer_id')); - - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $username = $this->user_loader->get_username($this->get_data('closer_id'), 'no_profile'); return $this->user->lang( $this->language_key, diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 6e9347d4a8..614d644501 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -142,9 +142,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base } else { - $user_data = $this->user_loader->get_user($this->get_data('poster_id')); - - $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $username = $this->user_loader->get_username($this->get_data('poster_id'), 'no_profile'); } return $this->user->lang( @@ -178,9 +176,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base } else { - $user_data = $this->user_loader->get_user($this->get_data('poster_id')); - - $username = get_username_string('username', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + $username = $this->user_loader->get_username($this->get_data('poster_id'), 'no_profile'); } return array( diff --git a/phpBB/includes/user_loader.php b/phpBB/includes/user_loader.php index 914770e335..db12854a60 100644 --- a/phpBB/includes/user_loader.php +++ b/phpBB/includes/user_loader.php @@ -91,27 +91,100 @@ class phpbb_user_loader } } + /** + * Load a user by username + * + * Stores the full data in the user cache so they do not need to be loaded again + * Returns the user id so you may use get_user() from the returned value + * + * @param string $username Raw username to load (will be cleaned) + * @return int User ID for the username + */ + public function load_user_by_username($username) + { + $sql = 'SELECT * + FROM ' . $this->users_table . " + WHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($username)) . "'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + $this->users[$row['user_id']] = $row; + + return $row['user_id']; + } + + return ANONYMOUS; + } + /** * Get a user row from our users cache * - * @param int $user_id + * @param int $user_id User ID of the user you want to retreive + * @param bool $query Should we query the database if this user has not yet been loaded? + * Typically this should be left as false and you should make sure + * you load users ahead of time with load_users() * @return array|bool Row from the database of the user or Anonymous if the user wasn't loaded/does not exist * or bool False if the anonymous user was not loaded */ - public function get_user($user_id) + public function get_user($user_id, $query = false) + { + if (isset($this->users[$user_id])) + { + return $this->users[$user_id]; + } + // Query them if we must (if ANONYMOUS is sent as the user_id and we have not loaded Anonymous yet, we must load Anonymous as a last resort) + else if ($query || $user_id == ANONYMOUS) + { + $this->load_users(array($user_id)); + + return $this->get_user($user_id); + } + + return $this->get_user(ANONYMOUS); + } + + /** + * Get username + * + * @param int $user_id User ID of the user you want to retreive the username for + * @param string $mode The mode to load (same as get_username_string). One of the following: + * profile (for getting an url to the profile) + * username (for obtaining the username) + * colour (for obtaining the user colour) + * full (for obtaining a html string representing a coloured link to the users profile) + * no_profile (the same as full but forcing no profile link) + * @param string $guest_username Optional parameter to specify the guest username. It will be used in favor of the GUEST language variable then. + * @param string $custom_profile_url Optional parameter to specify a profile url. The user id get appended to this url as &u={user_id} + * @param bool $query Should we query the database if this user has not yet been loaded? + * Typically this should be left as false and you should make sure + * you load users ahead of time with load_users() + * @return string + */ + public function get_username($user_id, $mode, $guest_username = false, $custom_profile_url = false, $query = false) { - return (isset($this->users[$user_id])) ? $this->users[$user_id] : (isset($this->users[ANONYMOUS]) ? $this->users[ANONYMOUS] : false); + if (!($user = $this->get_user($user_id, $query))) + { + return ''; + } + + return get_username_string($mode, $user['user_id'], $user['username'], $user['user_colour'], $guest_username, $custom_profile_url); } /** * Get avatar * - * @param int $user_id + * @param int $user_id User ID of the user you want to retreive the avatar for + * @param bool $query Should we query the database if this user has not yet been loaded? + * Typically this should be left as false and you should make sure + * you load users ahead of time with load_users() * @return string */ - public function get_avatar($user_id) + public function get_avatar($user_id, $query = false) { - if (!($user = $this->get_user($user_id))) + if (!($user = $this->get_user($user_id, $query))) { return ''; } @@ -123,4 +196,36 @@ class phpbb_user_loader return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height']); } + + /** + * Get rank + * + * @param int $user_id User ID of the user you want to retreive the rank for + * @param bool $query Should we query the database if this user has not yet been loaded? + * Typically this should be left as false and you should make sure + * you load users ahead of time with load_users() + * @return array Array with keys 'rank_title', 'rank_img', and 'rank_img_src' + */ + public function get_rank($user_id, $query = false) + { + if (!($user = $this->get_user($user_id, $query))) + { + return ''; + } + + if (!function_exists('get_user_rank')) + { + include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); + } + + $rank = array( + 'rank_title', + 'rank_img', + 'rank_img_src', + ); + + get_user_rank($user['user_rank'], (($user['user_id'] == ANONYMOUS) ? false : $user['user_posts']), $rank['rank_title'], $rank['rank_img'], $rank['rank_img_src']); + + return $rank; + } } -- cgit v1.2.1 From 84284a9ccee7d5ccc658c3d1f751a5254b3b9175 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Dec 2012 13:43:06 -0600 Subject: [ticket/11103] Use scope: prototype This lets us clean up the mess that was in load_object(), but requires scope: prototype to be added to the service definitions for all types or methods! PHPBB3-11103 --- phpBB/includes/notification/manager.php | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 4c25fa72f0..22f8f58783 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -779,24 +779,6 @@ class phpbb_notification_manager */ protected function load_object($object_name) { - // Here we cannot just use ContainerBuilder->get(name) - // The reason for this is because get handles services - // which are initialized once and shared. Here we need - // separate new objects because we pass around objects - // that store row data in each object, which would lead - // to over-writing of data if we used get() - - $parameterBag = $this->phpbb_container->getParameterBag(); - $definition = $this->phpbb_container->getDefinition($object_name); - $arguments = $this->phpbb_container->resolveServices( - $parameterBag->unescapeValue($parameterBag->resolveValue($definition->getArguments())) - ); - $r = new \ReflectionClass($parameterBag->resolveValue($definition->getClass())); - - $object = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments); - - $object->set_notification_manager($this); - - return $object; + return $this->phpbb_container->get($object_name); } } -- cgit v1.2.1 From ffd531e4fd31fee31c6fbd8c94cb6077cd21a82d Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 12 Dec 2012 16:33:30 -0600 Subject: [ticket/11103] Revert changes to constants.php from my IDE Readd a blank line at the end of the file PHPBB3-11103 --- phpBB/includes/constants.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index 5128321618..68af41ab20 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -278,3 +278,4 @@ define('WORDS_TABLE', $table_prefix . 'words'); define('ZEBRA_TABLE', $table_prefix . 'zebra'); // Additional tables + -- cgit v1.2.1 From 249f3c8885d461ae3981dfd7b62093c2175175e3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 13 Dec 2012 19:19:40 -0600 Subject: [ticket/11103] Instantiate $phpbb_notifications as needed https://github.com/phpbb/phpbb3/pull/992#discussion_r2413976 PHPBB3-11103 --- phpBB/includes/functions.php | 22 ++++++++++++++++------ phpBB/includes/functions_admin.php | 10 ++++++---- phpBB/includes/functions_posting.php | 6 ++++-- phpBB/includes/functions_privmsgs.php | 19 ++++++++++++------- phpBB/includes/mcp/mcp_pm_reports.php | 5 +++-- phpBB/includes/mcp/mcp_queue.php | 13 +++++++++---- phpBB/includes/mcp/mcp_reports.php | 12 ++++++++---- phpBB/includes/ucp/ucp_notifications.php | 4 +++- 8 files changed, 61 insertions(+), 30 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 6f619ef51d..9b284c5ca9 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1328,7 +1328,7 @@ function phpbb_timezone_select($user, $default = '', $truncate = false) function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $user_id = 0) { global $db, $user, $config; - global $request, $phpbb_notifications; + global $request, $phpbb_container; $post_time = ($post_time === 0 || $post_time > time()) ? time() : (int) $post_time; @@ -1338,6 +1338,8 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ { // Mark all forums read (index page) + $phpbb_notifications = $phpbb_container->get('notification_manager'); + // Mark all topic notifications read for this user $phpbb_notifications->mark_notifications_read(array( 'topic', @@ -1402,6 +1404,8 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ $forum_id = array($forum_id); } + $phpbb_notifications = $phpbb_container->get('notification_manager'); + $phpbb_notifications->mark_notifications_read_by_parent(array( 'topic', 'approve_topic', @@ -1523,11 +1527,14 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ return; } + $phpbb_notifications = $phpbb_container->get('notification_manager'); + // 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_by_parent(array( 'quote', 'bookmark', @@ -5042,7 +5049,7 @@ function phpbb_build_hidden_fields_for_query_params($request, $exclude = null) function page_header($page_title = '', $display_online_list = true, $item_id = 0, $item = 'forum') { global $db, $config, $template, $SID, $_SID, $_EXTRA_URL, $user, $auth, $phpEx, $phpbb_root_path; - global $phpbb_dispatcher, $request, $phpbb_notifications; + global $phpbb_dispatcher, $request, $phpbb_container; if (defined('HEADER_INC')) { @@ -5230,10 +5237,13 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 { $timezone_name = $user->lang['timezones'][$timezone_name]; } - + // Output the notifications - if ($config['load_notifications']) + $notifications = false; + if ($config['load_notifications'] && $user->data['user_id'] != ANONYMOUS && $user->data['user_type'] != USER_IGNORE) { + $phpbb_notifications = $phpbb_container->get('notification_manager'); + $notifications = $phpbb_notifications->load_notifications(array( 'all_unread' => true, 'limit' => 5, @@ -5264,8 +5274,8 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread, 'HIDDEN_FIELDS_FOR_JUMPBOX' => $hidden_fields_for_jumpbox, - 'UNREAD_NOTIFICATIONS_COUNT' => ($config['load_notifications']) ? $notifications['unread_count'] : '', - 'NOTIFICATIONS_COUNT' => ($config['load_notifications']) ? $user->lang('NOTIFICATIONS_COUNT', $notifications['unread_count']) : '', + 'UNREAD_NOTIFICATIONS_COUNT' => ($notifications !== false) ? $notifications['unread_count'] : '', + 'NOTIFICATIONS_COUNT' => ($notifications !== false) ? $user->lang('NOTIFICATIONS_COUNT', $notifications['unread_count']) : '', 'U_VIEW_ALL_NOTIFICATIONS' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=ucp_notifications'), 'S_NOTIFICATIONS_DISPLAY' => $config['load_notifications'], diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 69ca44861f..9310b218fb 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -618,8 +618,7 @@ function move_posts($post_ids, $topic_id, $auto_sync = true) */ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_sync = true, $call_delete_posts = true) { - global $db, $config; - global $phpbb_notifications; + global $db, $config, $phpbb_container; $approved_topics = 0; $forum_ids = $topic_ids = array(); @@ -716,6 +715,8 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s set_config_count('num_topics', $approved_topics * (-1), true); } + $phpbb_notifications = $phpbb_container->get('notification_manager'); + $phpbb_notifications->delete_notifications(array( 'topic', 'approve_topic', @@ -730,8 +731,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s */ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = true, $post_count_sync = true, $call_delete_topics = true) { - global $db, $config, $phpbb_root_path, $phpEx, $auth, $user; - global $phpbb_notifications; + global $db, $config, $phpbb_root_path, $phpEx, $auth, $user, $phpbb_container; if ($where_type === 'range') { @@ -900,6 +900,8 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = delete_topics('topic_id', $remove_topics, $auto_sync, $post_count_sync, false); } + $phpbb_notifications = $phpbb_container->get('notification_manager'); + $phpbb_notifications->delete_notifications(array( 'quote', 'bookmark', diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 8ba1fed6a7..1648228af5 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1410,8 +1410,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) */ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true, $update_search_index = true) { - global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path; - global $phpbb_notifications; + global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path, $phpbb_container; // We do not handle erasing posts here if ($mode == 'delete') @@ -2231,6 +2230,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u 'post_subject' => $subject, )); + $phpbb_notifications = $phpbb_container->get('notification_manager'); + if ($post_approval) { switch ($mode) @@ -2282,6 +2283,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u case 'edit': case 'edit_last_post': $phpbb_notifications->delete_notifications('topic', $data['topic_id']); + $phpbb_notifications->delete_notifications(array( 'quote', 'bookmark', diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index ae8ffbe90e..14278a2529 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -876,7 +876,9 @@ function update_unread_status($unread, $msg_id, $user_id, $folder_id) return; } - global $db, $user, $phpbb_notifications; + global $db, $user, $phpbb_container; + + $phpbb_notifications = $phpbb_container->get('notification_manager'); $phpbb_notifications->mark_notifications_read('pm', $msg_id, $user_id); @@ -983,8 +985,7 @@ function handle_mark_actions($user_id, $mark_action) */ function delete_pm($user_id, $msg_ids, $folder_id) { - global $db, $user, $phpbb_root_path, $phpEx; - global $phpbb_notifications; + global $db, $user, $phpbb_root_path, $phpEx, $phpbb_container; $user_id = (int) $user_id; $folder_id = (int) $folder_id; @@ -1096,6 +1097,8 @@ function delete_pm($user_id, $msg_ids, $folder_id) $user->data['user_unread_privmsg'] -= $num_unread; } + $phpbb_notifications = $phpbb_container->get('notification_manager'); + $phpbb_notifications->delete_notifications('pm', array_keys($delete_rows)); // Now we have to check which messages we can delete completely @@ -1162,8 +1165,7 @@ function phpbb_delete_user_pms($user_id) */ function phpbb_delete_users_pms($user_ids) { - global $db, $user, $phpbb_root_path, $phpEx; - global $phpbb_notifications; + global $db, $user, $phpbb_root_path, $phpEx, $phpbb_container; $user_id_sql = $db->sql_in_set('user_id', $user_ids); $author_id_sql = $db->sql_in_set('author_id', $user_ids); @@ -1208,6 +1210,8 @@ function phpbb_delete_users_pms($user_ids) $db->sql_transaction('begin'); + $phpbb_notifications = $phpbb_container->get('notification_manager'); + if (!empty($undelivered_msg)) { // A pm is delivered, if for any recipient the message was moved @@ -1571,8 +1575,7 @@ function get_folder_status($folder_id, $folder) */ function submit_pm($mode, $subject, &$data, $put_in_outbox = true) { - global $db, $auth, $config, $phpEx, $template, $user, $phpbb_root_path; - global $phpbb_notifications; + global $db, $auth, $config, $phpEx, $template, $user, $phpbb_root_path, $phpbb_container; // We do not handle erasing pms here if ($mode == 'delete') @@ -1877,6 +1880,8 @@ function submit_pm($mode, $subject, &$data, $put_in_outbox = true) 'recipients' => $recipients, )); + $phpbb_notifications = $phpbb_container->get('notification_manager'); + if ($mode == 'edit') { $phpbb_notifications->update_notifications('pm', $pm_data); diff --git a/phpBB/includes/mcp/mcp_pm_reports.php b/phpBB/includes/mcp/mcp_pm_reports.php index 4ba1b2fd0c..db73506d1d 100644 --- a/phpBB/includes/mcp/mcp_pm_reports.php +++ b/phpBB/includes/mcp/mcp_pm_reports.php @@ -33,8 +33,7 @@ class mcp_pm_reports function main($id, $mode) { global $auth, $db, $user, $template, $cache; - global $config, $phpbb_root_path, $phpEx, $action; - global $phpbb_notifications; + global $config, $phpbb_root_path, $phpEx, $action, $phpbb_container; include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); include_once($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx); @@ -90,6 +89,8 @@ class mcp_pm_reports trigger_error('NO_REPORT'); } + $phpbb_notifications = $phpbb_container->get('notification_manager'); + $phpbb_notifications->mark_notifications_read_by_parent('report_pm', $report_id, $user->data['user_id']); $pm_id = $report['pm_id']; diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 4a3d443006..2a2146db71 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -33,8 +33,7 @@ class mcp_queue function main($id, $mode) { global $auth, $db, $user, $template, $cache; - global $config, $phpbb_root_path, $phpEx, $action; - global $phpbb_notifications; + global $config, $phpbb_root_path, $phpEx, $action, $phpbb_container; include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); @@ -79,6 +78,8 @@ class mcp_queue $post_id = request_var('p', 0); $topic_id = request_var('t', 0); + $phpbb_notifications = $phpbb_container->get('notification_manager'); + if ($topic_id) { $topic_info = get_topic_data(array($topic_id), 'm_approve'); @@ -456,7 +457,7 @@ function approve_post($post_id_list, $id, $mode) { global $db, $template, $user, $config; global $phpEx, $phpbb_root_path; - global $request, $phpbb_notifications; + global $request, $phpbb_container; if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) { @@ -605,6 +606,8 @@ function approve_post($post_id_list, $id, $mode) // Send out normal user notifications $email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']); + $phpbb_notifications = $phpbb_container->get('notification_manager'); + // Handle notifications foreach ($post_info as $post_id => $post_data) { @@ -722,7 +725,7 @@ function disapprove_post($post_id_list, $id, $mode) { global $db, $template, $user, $config; global $phpEx, $phpbb_root_path; - global $request, $phpbb_notifications; + global $request, $phpbb_container; if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) { @@ -855,6 +858,8 @@ function disapprove_post($post_id_list, $id, $mode) } } + $phpbb_notifications = $phpbb_container->get('notification_manager'); + foreach ($post_info as $post_id => $post_data) { if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php index 85723ab3f7..91ff31c51c 100644 --- a/phpBB/includes/mcp/mcp_reports.php +++ b/phpBB/includes/mcp/mcp_reports.php @@ -33,8 +33,7 @@ class mcp_reports function main($id, $mode) { global $auth, $db, $user, $template, $cache; - global $config, $phpbb_root_path, $phpEx, $action; - global $phpbb_notifications; + global $config, $phpbb_root_path, $phpEx, $action, $phpbb_container; include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); @@ -88,6 +87,8 @@ class mcp_reports trigger_error('NO_REPORT'); } + $phpbb_notifications = $phpbb_container->get('notification_manager'); + $phpbb_notifications->mark_notifications_read('report_post', $post_id, $user->data['user_id']); if (!$report_id && $report['report_closed']) @@ -446,8 +447,7 @@ class mcp_reports function close_report($report_id_list, $mode, $action, $pm = false) { global $db, $template, $user, $config, $auth; - global $phpEx, $phpbb_root_path; - global $phpbb_notifications; + global $phpEx, $phpbb_root_path, $phpbb_container; $pm_where = ($pm) ? ' AND r.post_id = 0 ' : ' AND r.pm_id = 0 '; $id_column = ($pm) ? 'pm_id' : 'post_id'; @@ -636,6 +636,8 @@ function close_report($report_id_list, $mode, $action, $pm = false) // Notify reporters if (sizeof($notify_reporters)) { + $phpbb_notifications = $phpbb_container->get('notification_manager'); + foreach ($notify_reporters as $report_id => $reporter) { if ($reporter['user_id'] == ANONYMOUS) @@ -652,6 +654,7 @@ function close_report($report_id_list, $mode, $action, $pm = false) 'closer_id' => $user->data['user_id'], 'from_user_id' => $post_info[$post_id]['author_id'], ))); + $phpbb_notifications->delete_notifications('report_pm', $post_id); } else @@ -660,6 +663,7 @@ function close_report($report_id_list, $mode, $action, $pm = false) 'reporter' => $reporter['user_id'], 'closer_id' => $user->data['user_id'], ))); + $phpbb_notifications->delete_notifications('report_post', $post_id); } } diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php index 76fc411584..338c921e94 100644 --- a/phpBB/includes/ucp/ucp_notifications.php +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -21,7 +21,7 @@ class ucp_notifications public function main($id, $mode) { - global $config, $template, $user, $request, $phpbb_notifications; + global $config, $template, $user, $request, $phpbb_container; global $phpbb_root_path, $phpEx; add_form_key('ucp_notification'); @@ -29,6 +29,8 @@ class ucp_notifications $start = $request->variable('start', 0); $form_time = min($request->variable('form_time', 0), time()); + $phpbb_notifications = $phpbb_container->get('notification_manager'); + switch ($mode) { case 'notification_options': -- cgit v1.2.1 From ddd874ba76366cebe3cc30df6daa1974e29f34d1 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 13 Dec 2012 19:46:32 -0600 Subject: [ticket/11103] dbal -> phpbb_db_driver PHPBB3-11103 --- phpBB/includes/notification/manager.php | 4 ++-- phpBB/includes/notification/method/base.php | 4 ++-- phpBB/includes/notification/type/base.php | 4 ++-- phpBB/includes/user_loader.php | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 22f8f58783..653446ab73 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -33,7 +33,7 @@ class phpbb_notification_manager /** @var phpbb_user_loader */ protected $user_loader = null; - /** @var dbal */ + /** @var phpbb_db_driver */ protected $db = null; /** @var phpbb_user */ @@ -51,7 +51,7 @@ class phpbb_notification_manager /** @var string */ protected $user_notifications_table = null; - public function __construct($notification_types, $notification_methods, $phpbb_container, phpbb_user_loader $user_loader, dbal $db, $user, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) + public function __construct($notification_types, $notification_methods, $phpbb_container, phpbb_user_loader $user_loader, phpbb_db_driver $db, $user, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) { $this->notification_types = $notification_types; $this->notification_methods = $notification_methods; diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index 3f85d62a09..f37e7e7845 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -27,7 +27,7 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth /** @var phpbb_user_loader */ protected $user_loader = null; - /** @var dbal */ + /** @var phpbb_db_driver */ protected $db = null; /** @var phpbb_cache_service */ @@ -61,7 +61,7 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth */ protected $queue = array(); - public function __construct(phpbb_user_loader $user_loader, dbal $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) + public function __construct(phpbb_user_loader $user_loader, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { $this->user_loader = $user_loader; $this->db = $db; diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index d596c06167..31792de04c 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -27,7 +27,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** @var phpbb_user_loader */ protected $user_loader = null; - /** @var dbal */ + /** @var phpbb_db_driver */ protected $db = null; /** @var phpbb_cache_service */ @@ -84,7 +84,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ private $data = array(); - public function __construct(phpbb_user_loader $user_loader, dbal $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) + public function __construct(phpbb_user_loader $user_loader, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) { $this->user_loader = $user_loader; $this->db = $db; diff --git a/phpBB/includes/user_loader.php b/phpBB/includes/user_loader.php index db12854a60..77128d6570 100644 --- a/phpBB/includes/user_loader.php +++ b/phpBB/includes/user_loader.php @@ -24,7 +24,7 @@ if (!defined('IN_PHPBB')) */ class phpbb_user_loader { - /** @var dbal */ + /** @var phpbb_db_driver */ protected $db = null; /** @var string */ @@ -46,12 +46,12 @@ class phpbb_user_loader /** * User loader constructor * - * @param dbal $db A database connection + * @param phpbb_db_driver $db A database connection * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $php_ext php file extension * @param string $users_table The name of the database table (phpbb_users) */ - public function __construct(dbal $db, $phpbb_root_path, $php_ext, $users_table) + public function __construct(phpbb_db_driver $db, $phpbb_root_path, $php_ext, $users_table) { $this->db = $db; -- cgit v1.2.1 From bec05a11f38cd57d7e7a6c7f64ecdb7351e24fc0 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 13 Dec 2012 19:56:39 -0600 Subject: [ticket/11103] Add constants for the tables PHPBB3-11103 --- phpBB/includes/constants.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index 68af41ab20..7a3c73e987 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -239,6 +239,7 @@ define('LOG_TABLE', $table_prefix . 'log'); define('LOGIN_ATTEMPT_TABLE', $table_prefix . 'login_attempts'); define('MODERATOR_CACHE_TABLE', $table_prefix . 'moderator_cache'); define('MODULES_TABLE', $table_prefix . 'modules'); +define('NOTIFICATIONS_TABLE', $table_prefix . 'notifications'); define('POLL_OPTIONS_TABLE', $table_prefix . 'poll_options'); define('POLL_VOTES_TABLE', $table_prefix . 'poll_votes'); define('POSTS_TABLE', $table_prefix . 'posts'); @@ -272,6 +273,7 @@ define('TOPICS_POSTED_TABLE', $table_prefix . 'topics_posted'); define('TOPICS_TRACK_TABLE', $table_prefix . 'topics_track'); define('TOPICS_WATCH_TABLE', $table_prefix . 'topics_watch'); define('USER_GROUP_TABLE', $table_prefix . 'user_group'); +define('USER_NOTIFICATIONS_TABLE', $table_prefix . 'user_notifications'); define('USERS_TABLE', $table_prefix . 'users'); define('WARNINGS_TABLE', $table_prefix . 'warnings'); define('WORDS_TABLE', $table_prefix . 'words'); -- cgit v1.2.1 From 95bd4d73eb41d677470b0bf77c521ae2a9bb731e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Dec 2012 10:33:03 -0600 Subject: [ticket/11103] Mark topic/post subscription notification read when approved PHPBB3-11103 --- phpBB/includes/mcp/mcp_queue.php | 14 +++++++++++++- phpBB/includes/notification/manager.php | 10 ---------- 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 2a2146db71..24afa1f210 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -615,7 +615,13 @@ function approve_post($post_id_list, $id, $mode) { $phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']); - $phpbb_notifications->add_notifications('topic', $post_data); + $phpbb_notifications->add_notifications(array( + 'quote', + 'topic', + ), $post_data); + + $phpbb_notifications->mark_notifications_read('quote', $post_data['post_id'], $user->data['user_id']); + $phpbb_notifications->mark_notifications_read('topic', $post_data['topic_id'], $user->data['user_id']); if ($notify_poster) { @@ -631,6 +637,12 @@ function approve_post($post_id_list, $id, $mode) 'bookmark', 'post', ), $post_data); + + $phpbb_notifications->mark_notifications_read(array( + 'quote', + 'bookmark', + 'post', + ),$post_data['post_id'], $user->data['user_id']); if ($notify_poster) { diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 653446ab73..6bf97a3e71 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -226,16 +226,6 @@ class phpbb_notification_manager */ public function mark_notifications_read($item_type, $item_id, $user_id, $time = false) { - if (is_array($item_type)) - { - foreach ($item_type as $type) - { - $this->mark_notifications_read($type, $item_id, $user_id, $time); - } - - return; - } - $time = ($time !== false) ? $time : time(); $sql = 'UPDATE ' . $this->notifications_table . " -- cgit v1.2.1 From d0375c46f91eb88508cbd8e320c7eda78d4f01dd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Dec 2012 18:25:26 -0600 Subject: [ticket/11103] Purge notifications (to be used when an extension is purged) PHPBB3-11103 --- phpBB/includes/notification/manager.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 653446ab73..fee1d079aa 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -733,6 +733,21 @@ class phpbb_notification_manager $this->db->sql_query($sql); } + /** + * Purge all notifications of a certain type + * + * This should be called when an extension which has notification types + * is purged so that all those notifications are removed + * + * @param string $item_type + */ + public function purge_notifications($item_type) + { + $sql = 'DELETE FROM ' . $this->notifications_table . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "'"; + $this->db->sql_query($sql); + } + /** * Enable all notifications of a certain type * -- cgit v1.2.1 From c6f138ff12f015543f92d07fb5c93c083a246bab Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Dec 2012 18:35:17 -0600 Subject: [ticket/11103] Prune notifications function To delete all notifications before a certain time PHPBB3-11103 --- phpBB/includes/notification/manager.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 90916401c0..a5e1b09754 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -713,7 +713,7 @@ class phpbb_notification_manager * is disabled so that all those notifications are hidden and do not * cause errors * - * @param string $item_type + * @param string $item_type Type identifier of the subscription */ public function disable_notifications($item_type) { @@ -729,7 +729,7 @@ class phpbb_notification_manager * This should be called when an extension which has notification types * is purged so that all those notifications are removed * - * @param string $item_type + * @param string $item_type Type identifier of the subscription */ public function purge_notifications($item_type) { @@ -745,7 +745,7 @@ class phpbb_notification_manager * that was disabled is re-enabled so that all those notifications that * were hidden are shown again * - * @param string $item_type + * @param string $item_type Type identifier of the subscription */ public function enable_notifications($item_type) { @@ -755,6 +755,18 @@ class phpbb_notification_manager $this->db->sql_query($sql); } + /** + * Delete all notifications older than a certain time + * + * @param int $timestamp Unix timestamp to delete all notifications that were created before + */ + public function prune_notifications($timestamp) + { + $sql = 'DELETE FROM ' . $this->notifications_table . ' + WHERE time < ' . (int) $timestamp; + $this->db->sql_query($sql); + } + /** * Helper to get the notifications item type class and set it up */ -- cgit v1.2.1 From f47e51d6dea9d59a36a6babf1f4033104c93a53d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Dec 2012 19:18:26 -0600 Subject: [ticket/11103] Move is_enabled to a separate table for better performance PHPBB3-11103 --- phpBB/includes/constants.php | 1 + phpBB/includes/notification/manager.php | 98 +++++++++++++++++---------- phpBB/includes/notification/type/base.php | 4 -- phpBB/includes/notification/type/bookmark.php | 13 ++-- phpBB/includes/notification/type/post.php | 13 ++-- phpBB/includes/notification/type/quote.php | 24 ++++--- 6 files changed, 92 insertions(+), 61 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index 7a3c73e987..b8bf517d75 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -239,6 +239,7 @@ define('LOG_TABLE', $table_prefix . 'log'); define('LOGIN_ATTEMPT_TABLE', $table_prefix . 'login_attempts'); define('MODERATOR_CACHE_TABLE', $table_prefix . 'moderator_cache'); define('MODULES_TABLE', $table_prefix . 'modules'); +define('NOTIFICATION_TYPES_TABLE', $table_prefix . 'notification_types'); define('NOTIFICATIONS_TABLE', $table_prefix . 'notifications'); define('POLL_OPTIONS_TABLE', $table_prefix . 'poll_options'); define('POLL_VOTES_TABLE', $table_prefix . 'poll_votes'); diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index a5e1b09754..63db3e6e9a 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -45,13 +45,16 @@ class phpbb_notification_manager /** @var string */ protected $php_ext = null; + /** @var string */ + protected $notification_types_table = null; + /** @var string */ protected $notifications_table = null; /** @var string */ protected $user_notifications_table = null; - public function __construct($notification_types, $notification_methods, $phpbb_container, phpbb_user_loader $user_loader, phpbb_db_driver $db, $user, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) + public function __construct($notification_types, $notification_methods, $phpbb_container, phpbb_user_loader $user_loader, phpbb_db_driver $db, $user, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table) { $this->notification_types = $notification_types; $this->notification_methods = $notification_methods; @@ -64,6 +67,7 @@ class phpbb_notification_manager $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; + $this->notification_types_table = $notification_types_table; $this->notifications_table = $notifications_table; $this->user_notifications_table = $user_notifications_table; } @@ -121,11 +125,12 @@ class phpbb_notification_manager if ($options['count_unread']) { // Get the total number of unread notifications - $sql = 'SELECT COUNT(*) AS unread_count - FROM ' . $this->notifications_table . ' - WHERE user_id = ' . (int) $options['user_id'] . ' - AND unread = 1 - AND is_enabled = 1'; + $sql = 'SELECT COUNT(n.notification_id) AS unread_count + FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt + WHERE n.user_id = ' . (int) $options['user_id'] . ' + AND n.unread = 1 + AND nt.notification_type = n.item_type + AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); $unread_count = (int) $this->db->sql_fetchfield('unread_count', $result); $this->db->sql_freeresult($result); @@ -134,10 +139,11 @@ class phpbb_notification_manager if ($options['count_total']) { // Get the total number of notifications - $sql = 'SELECT COUNT(*) AS total_count - FROM ' . $this->notifications_table . ' - WHERE user_id = ' . (int) $options['user_id'] . ' - AND is_enabled = 1'; + $sql = 'SELECT COUNT(n.notification_id) AS total_count + FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt + WHERE n.user_id = ' . (int) $options['user_id'] . ' + AND nt.notification_type = n.item_type + AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); $total_count = (int) $this->db->sql_fetchfield('total_count', $result); $this->db->sql_freeresult($result); @@ -148,12 +154,13 @@ class phpbb_notification_manager $rowset = array(); // Get the main notifications - $sql = 'SELECT * - FROM ' . $this->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']); + $sql = 'SELECT n.* + FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt + WHERE n.user_id = ' . (int) $options['user_id'] . + (($options['notification_id']) ? ((is_array($options['notification_id'])) ? ' AND ' . $this->db->sql_in_set('n.notification_id', $options['notification_id']) : ' AND n.notification_id = ' . (int) $options['notification_id']) : '') . ' + AND nt.notification_type = n.item_type + AND nt.notification_type_enabled = 1 + ORDER BY n.' . $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)) @@ -165,13 +172,14 @@ class phpbb_notification_manager // Get all unread notifications if ($unread_count && $options['all_unread'] && !empty($rowset)) { - $sql = 'SELECT * - FROM ' . $this->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']); + $sql = 'SELECT n.* + FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt + WHERE n.user_id = ' . (int) $options['user_id'] . ' + AND n.unread = 1 + AND ' . $this->db->sql_in_set('n.notification_id', array_keys($rowset), true) . ' + AND nt.notification_type = n.item_type + AND nt.notification_type_enabled = 1 + ORDER BY n.' . $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)) @@ -345,6 +353,23 @@ class phpbb_notification_manager return; } + $sql = 'SELECT notification_type + FROM ' . $this->notification_types_table . " + WHERE notification_type = '" . $this->db->sql_escape($item_type) . "'"; + $result = $this->db->sql_query($sql); + + if ($this->db->sql_fetchrow($result) === false) + { + // Does not exist in the database, must add the item type + $sql = 'INSERT INTO ' . $this->notification_types_table . ' ' . $this->db->sql_build_array('INSERT', array( + 'notification_type' => $item_type, + 'notification_type_enabled' => 1, + )); + $this->db->sql_query($sql); + } + + $this->db->sql_freeresult($result); + $item_id = $this->get_item_type_class($item_type)->get_item_id($data); $user_ids = array(); @@ -356,11 +381,12 @@ class phpbb_notification_manager // Make sure not to send new notifications to users who've already been notified about this item // This may happen when an item was added, but now new users are able to see the item - $sql = 'SELECT user_id - FROM ' . $this->notifications_table . " - WHERE item_type = '" . $this->db->sql_escape($item_type) . "' - AND item_id = " . (int) $item_id . ' - AND is_enabled = 1'; + $sql = 'SELECT n.user_id + FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt + WHERE n.item_type = '" . $this->db->sql_escape($item_type) . "' + AND n.item_id = " . (int) $item_id . ' + AND nt.notification_type = n.item_type + AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { @@ -717,9 +743,9 @@ class phpbb_notification_manager */ public function disable_notifications($item_type) { - $sql = 'UPDATE ' . $this->notifications_table . " - SET is_enabled = 0 - WHERE item_type = '" . $this->db->sql_escape($item_type) . "'"; + $sql = 'UPDATE ' . $this->notification_types_table . " + SET notification_type_enabled = 0 + WHERE notification_type = '" . $this->db->sql_escape($item_type) . "'"; $this->db->sql_query($sql); } @@ -736,6 +762,10 @@ class phpbb_notification_manager $sql = 'DELETE FROM ' . $this->notifications_table . " WHERE item_type = '" . $this->db->sql_escape($item_type) . "'"; $this->db->sql_query($sql); + + $sql = 'DELETE FROM ' . $this->notification_types_table . " + WHERE notification_type = '" . $this->db->sql_escape($item_type) . "'"; + $this->db->sql_query($sql); } /** @@ -749,9 +779,9 @@ class phpbb_notification_manager */ public function enable_notifications($item_type) { - $sql = 'UPDATE ' . $this->notifications_table . " - SET is_enabled = 1 - WHERE item_type = '" . $this->db->sql_escape($item_type) . "'"; + $sql = 'UPDATE ' . $this->notification_types_table . " + SET notification_type_enabled = 1 + WHERE notification_type = '" . $this->db->sql_escape($item_type) . "'"; $this->db->sql_query($sql); } diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 31792de04c..effa57e3a3 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -72,10 +72,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * item_parent_id - Parent item id (ex: for topic => forum_id, for post => topic_id, etc) * user_id * unread - * is_enabled - EXTENSION AUTHORS TAKE NOTE! This is to prevent errors with notifications from extensions! - * - Set is_enabled to 0 for all your notifications when your extension is disabled so they are ignored and do not cause errors. - * - When your extension is enabled again, set is_enabled to 1 and your notifications will be working again. - * * time * data (special serialized field that each notification type can use to store stuff) * diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index a17d8f5db7..750bd3b6cb 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -101,12 +101,13 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); - $sql = 'SELECT * - FROM ' . $this->notifications_table . " - WHERE item_type = '" . $this->get_type() . "' - AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' - AND unread = 1 - AND is_enabled = 1'; + $sql = 'SELECT n.* + FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt + WHERE n.item_type = '" . $this->get_type() . "' + AND n.item_parent_id = " . (int) self::get_item_parent_id($post) . ' + AND n.unread = 1 + AND nt.notification_type = n.item_type + AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 0646282c94..0a42029f18 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -122,12 +122,13 @@ class phpbb_notification_type_post extends phpbb_notification_type_base // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); - $sql = 'SELECT * - FROM ' . $this->notifications_table . " - WHERE item_type = '" . $this->get_type() . "' - AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' - AND unread = 1 - AND is_enabled = 1'; + $sql = 'SELECT n.* + FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt + WHERE n.item_type = '" . $this->get_type() . "' + AND n.item_parent_id = " . (int) self::get_item_parent_id($post) . ' + AND n.unread = 1 + AND nt.notification_type = n.item_type + AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index 1796343a0e..b3a347f98c 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -120,12 +120,13 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications $update_notifications = array(); - $sql = 'SELECT * - FROM ' . $this->notifications_table . " - WHERE item_type = '" . $this->get_type() . "' - AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' - AND unread = 1 - AND is_enabled = 1'; + $sql = 'SELECT n.* + FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt + WHERE n.item_type = '" . $this->get_type() . "' + AND n.item_parent_id = " . (int) self::get_item_parent_id($post) . ' + AND n.unread = 1 + AND nt.notification_type = n.item_type + AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { @@ -151,11 +152,12 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post public function update_notifications($post) { $old_notifications = array(); - $sql = 'SELECT user_id - FROM ' . $this->notifications_table . " - WHERE item_type = '" . $this->get_type() . "' - AND item_id = " . self::get_item_id($post) . ' - AND is_enabled = 1'; + $sql = 'SELECT n.user_id + FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt + WHERE n.item_type = '" . $this->get_type() . "' + AND n.item_id = " . self::get_item_id($post) . ' + AND nt.notification_type = n.item_type + AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { -- cgit v1.2.1 From 47bed3321634d888a51a611e6586c012a27eb1eb Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Dec 2012 21:02:28 -0600 Subject: [ticket/11103] time -> notification_time PHPBB3-11103 --- phpBB/includes/notification/manager.php | 11 +++++------ phpBB/includes/notification/type/approve_post.php | 4 ++-- phpBB/includes/notification/type/approve_topic.php | 2 +- phpBB/includes/notification/type/base.php | 6 +++--- phpBB/includes/notification/type/disapprove_post.php | 2 +- phpBB/includes/notification/type/disapprove_topic.php | 2 +- phpBB/includes/notification/type/post.php | 4 ++-- phpBB/includes/notification/type/post_in_queue.php | 2 +- phpBB/includes/notification/type/report_pm_closed.php | 2 +- phpBB/includes/notification/type/report_post_closed.php | 2 +- phpBB/includes/notification/type/topic.php | 4 ++-- phpBB/includes/notification/type/topic_in_queue.php | 2 +- 12 files changed, 21 insertions(+), 22 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 63db3e6e9a..8276996b94 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -96,7 +96,7 @@ class phpbb_notification_manager $options = array_merge(array( 'notification_id' => false, 'user_id' => $this->user->data['user_id'], - 'order_by' => 'time', + 'order_by' => 'notification_time', 'order_dir' => 'DESC', 'limit' => 0, 'start' => 0, @@ -238,10 +238,9 @@ class phpbb_notification_manager $sql = 'UPDATE ' . $this->notifications_table . " SET unread = 0 - WHERE time <= " . $time . + WHERE notification_time <= " . $time . (($item_type !== false) ? ' AND ' . (is_array($item_type) ? $this->db->sql_in_set('item_type', $item_type) : " item_type = '" . $this->db->sql_escape($item_type) . "'") : '') . (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : '') . - (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); $this->db->sql_query($sql); } @@ -270,7 +269,7 @@ class phpbb_notification_manager $sql = 'UPDATE ' . $this->notifications_table . " SET unread = 0 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' - AND time <= " . $time . + AND notification_time <= " . $time . (($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id) : 'item_parent_id = ' . (int) $item_parent_id) : '') . (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); $this->db->sql_query($sql); @@ -288,7 +287,7 @@ class phpbb_notification_manager $sql = 'UPDATE ' . $this->notifications_table . " SET unread = 0 - WHERE time <= " . $time . ' + WHERE notification_time <= " . $time . ' AND ' . ((is_array($notification_id)) ? $this->db->sql_in_set('notification_id', $notification_id) : 'notification_id = ' . (int) $notification_id); $this->db->sql_query($sql); } @@ -793,7 +792,7 @@ class phpbb_notification_manager public function prune_notifications($timestamp) { $sql = 'DELETE FROM ' . $this->notifications_table . ' - WHERE time < ' . (int) $timestamp; + WHERE notification_time < ' . (int) $timestamp; $this->db->sql_query($sql); } diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php index 38ff3f1d70..1a30781c35 100644 --- a/phpBB/includes/notification/type/approve_post.php +++ b/phpBB/includes/notification/type/approve_post.php @@ -32,7 +32,7 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post { return 'approve_post'; } - + /** * Language key used to output the text * @@ -123,7 +123,7 @@ class phpbb_notification_type_approve_post extends phpbb_notification_type_post $data = parent::create_insert_array($post, $pre_create_data); - $this->time = $data['time'] = time(); + $this->notification_time = $data['notification_time'] = time(); return $data; } diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php index 5b9ea409fe..e728e9ac30 100644 --- a/phpBB/includes/notification/type/approve_topic.php +++ b/phpBB/includes/notification/type/approve_topic.php @@ -121,7 +121,7 @@ class phpbb_notification_type_approve_topic extends phpbb_notification_type_topi { $data = parent::create_insert_array($post, $pre_create_data); - $this->time = $data['time'] = time(); + $this->notification_time = $data['notification_time'] = time(); return $data; } diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index effa57e3a3..45d0e5f60c 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -168,7 +168,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i 'item_type' => $this->get_type(), 'item_parent_id' => static::get_item_parent_id($type_data), - 'time' => time(), + 'notification_time' => time(), 'unread' => true, 'data' => array(), @@ -195,7 +195,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i // Unset data unique to each row unset( - $data['time'], // Also unsetting time, since it always tries to change the time to current (if you actually need to change the time, over-ride this function) + $data['notification_time'], // Also unsetting time, since it always tries to change the time to current (if you actually need to change the time, over-ride this function) $data['notification_id'], $data['unread'], $data['user_id'] @@ -250,7 +250,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i 'FORMATTED_TITLE' => $this->get_title(), 'URL' => $this->get_url(), - 'TIME' => $this->user->format_date($this->time), + 'TIME' => $this->user->format_date($this->notification_time), 'UNREAD' => $this->unread, diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php index d1d56086e7..951c7e0254 100644 --- a/phpBB/includes/notification/type/disapprove_post.php +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -103,7 +103,7 @@ class phpbb_notification_type_disapprove_post extends phpbb_notification_type_ap $data = parent::create_insert_array($post); - $this->time = $data['time'] = time(); + $this->notification_time = $data['notification_time'] = time(); return $data; } diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php index 7affaa8afa..038e528797 100644 --- a/phpBB/includes/notification/type/disapprove_topic.php +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -103,7 +103,7 @@ class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_a $data = parent::create_insert_array($post, $pre_create_data); - $this->time = $data['time'] = time(); + $this->notification_time = $data['notification_time'] = time(); return $data; } diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 0a42029f18..5eced0ca83 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -320,11 +320,11 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $this->set_data('forum_name', $post['forum_name']); - $this->time = $post['post_time']; + $this->notification_time = $post['post_time']; // Topics can be "read" before they are public (while awaiting approval). // Make sure that if the user has read the topic, it's marked as read in the notification - if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->time) + if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->notification_time) { $this->unread = false; } diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php index 3cd9b11283..1c29bee3cd 100644 --- a/phpBB/includes/notification/type/post_in_queue.php +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -120,7 +120,7 @@ class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post { $data = parent::create_insert_array($post, $pre_create_data); - $this->time = $data['time'] = time(); + $this->notification_time = $data['notification_time'] = time(); return $data; } diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index 2d60ae21d4..a735d2a822 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -148,7 +148,7 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p $data = parent::create_insert_array($pm, $pre_create_data); - $this->time = $data['time'] = time(); + $this->notification_time = $data['notification_time'] = time(); return $data; } diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index 3282ba7d8c..8b984fc8ce 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -148,7 +148,7 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type $data = parent::create_insert_array($post, $pre_create_data); - $this->time = $data['time'] = time(); + $this->notification_time = $data['notification_time'] = time(); return $data; } diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 614d644501..6eb78c30bb 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -261,11 +261,11 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base $this->set_data('forum_name', $post['forum_name']); - $this->time = $post['post_time']; + $this->notification_time = $post['post_time']; // Topics can be "read" before they are public (while awaiting approval). // Make sure that if the user has read the topic, it's marked as read in the notification - if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->time) + if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->notification_time) { $this->unread = false; } diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php index 170a98ca1b..dc0b9f9869 100644 --- a/phpBB/includes/notification/type/topic_in_queue.php +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -113,7 +113,7 @@ class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_top { $data = parent::create_insert_array($topic, $pre_create_data); - $this->time = $data['time'] = time(); + $this->notification_time = $data['notification_time'] = time(); return $data; } -- cgit v1.2.1 From fad6bc5a7e58ddd370b88f73712de350b61bca29 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Dec 2012 21:08:26 -0600 Subject: [ticket/11103] unread -> notification_read PHPBB3-11103 --- phpBB/includes/notification/manager.php | 15 +++++++++++---- phpBB/includes/notification/type/base.php | 14 +++++++------- phpBB/includes/notification/type/bookmark.php | 2 +- phpBB/includes/notification/type/post.php | 4 ++-- phpBB/includes/notification/type/quote.php | 2 +- phpBB/includes/notification/type/topic.php | 2 +- 6 files changed, 23 insertions(+), 16 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 8276996b94..fa1fd4b81f 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -128,8 +128,13 @@ class phpbb_notification_manager $sql = 'SELECT COUNT(n.notification_id) AS unread_count FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt WHERE n.user_id = ' . (int) $options['user_id'] . ' +<<<<<<< HEAD AND n.unread = 1 AND nt.notification_type = n.item_type +======= + AND n.notification_read = 0 + AND nt.notification_type = n.notification_type +>>>>>>> 5cedca0... [ticket/11103] unread -> notification_read AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); $unread_count = (int) $this->db->sql_fetchfield('unread_count', $result); @@ -175,7 +180,7 @@ class phpbb_notification_manager $sql = 'SELECT n.* FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt WHERE n.user_id = ' . (int) $options['user_id'] . ' - AND n.unread = 1 + AND n.notification_read = 0 AND ' . $this->db->sql_in_set('n.notification_id', array_keys($rowset), true) . ' AND nt.notification_type = n.item_type AND nt.notification_type_enabled = 1 @@ -237,7 +242,7 @@ class phpbb_notification_manager $time = ($time !== false) ? $time : time(); $sql = 'UPDATE ' . $this->notifications_table . " - SET unread = 0 + SET notification_read = 1 WHERE notification_time <= " . $time . (($item_type !== false) ? ' AND ' . (is_array($item_type) ? $this->db->sql_in_set('item_type', $item_type) : " item_type = '" . $this->db->sql_escape($item_type) . "'") : '') . (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : '') . @@ -267,8 +272,10 @@ class phpbb_notification_manager $time = ($time !== false) ? $time : time(); $sql = 'UPDATE ' . $this->notifications_table . " - SET unread = 0 + SET notification_read = 1 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + SET notification_read = 1 + WHERE notification_type = '" . $this->db->sql_escape($notification_type) . "' AND notification_time <= " . $time . (($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id) : 'item_parent_id = ' . (int) $item_parent_id) : '') . (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); @@ -286,7 +293,7 @@ class phpbb_notification_manager $time = ($time !== false) ? $time : time(); $sql = 'UPDATE ' . $this->notifications_table . " - SET unread = 0 + SET notification_read = 1 WHERE notification_time <= " . $time . ' AND ' . ((is_array($notification_id)) ? $this->db->sql_in_set('notification_id', $notification_id) : 'notification_id = ' . (int) $notification_id); $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 45d0e5f60c..cdca9aa642 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -168,8 +168,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i 'item_type' => $this->get_type(), 'item_parent_id' => static::get_item_parent_id($type_data), - 'notification_time' => time(), - 'unread' => true, + 'notification_time' => time(), + 'notification_read' => false, 'data' => array(), ), $this->data); @@ -197,7 +197,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i unset( $data['notification_time'], // Also unsetting time, since it always tries to change the time to current (if you actually need to change the time, over-ride this function) $data['notification_id'], - $data['unread'], + $data['notification_read'], $data['user_id'] ); @@ -252,9 +252,9 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i 'URL' => $this->get_url(), 'TIME' => $this->user->format_date($this->notification_time), - 'UNREAD' => $this->unread, + 'UNREAD' => !$this->notification_read, - 'U_MARK_READ' => ($this->unread) ? $u_mark_read : '', + 'U_MARK_READ' => (!$this->notification_read) ? $u_mark_read : '', ); } @@ -402,7 +402,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ protected function mark($unread = true, $return = false) { - $this->unread = (bool) $unread; + $this->notification_read = (bool) !$unread; $where = array( "item_type = '" . $this->db->sql_escape($this->item_type) . "'", @@ -417,7 +417,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i } $sql = 'UPDATE ' . $this->notifications_table . ' - SET unread = ' . (int) $this->unread . ' + SET notification_read = ' . (int) $this->notification_read . ' WHERE ' . $where; $this->db->sql_query($sql); } diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php index 750bd3b6cb..4e48a967d0 100644 --- a/phpBB/includes/notification/type/bookmark.php +++ b/phpBB/includes/notification/type/bookmark.php @@ -105,7 +105,7 @@ class phpbb_notification_type_bookmark extends phpbb_notification_type_post FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt WHERE n.item_type = '" . $this->get_type() . "' AND n.item_parent_id = " . (int) self::get_item_parent_id($post) . ' - AND n.unread = 1 + AND n.notification_read = 0 AND nt.notification_type = n.item_type AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index 5eced0ca83..f29372923e 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -126,7 +126,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt WHERE n.item_type = '" . $this->get_type() . "' AND n.item_parent_id = " . (int) self::get_item_parent_id($post) . ' - AND n.unread = 1 + AND n.notification_read = 0 AND nt.notification_type = n.item_type AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); @@ -326,7 +326,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base // Make sure that if the user has read the topic, it's marked as read in the notification if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->notification_time) { - $this->unread = false; + $this->notification_read = true; } return parent::create_insert_array($post, $pre_create_data); diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php index b3a347f98c..5453b267c8 100644 --- a/phpBB/includes/notification/type/quote.php +++ b/phpBB/includes/notification/type/quote.php @@ -124,7 +124,7 @@ class phpbb_notification_type_quote extends phpbb_notification_type_post FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . " nt WHERE n.item_type = '" . $this->get_type() . "' AND n.item_parent_id = " . (int) self::get_item_parent_id($post) . ' - AND n.unread = 1 + AND n.notification_read = 0 AND nt.notification_type = n.item_type AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 6eb78c30bb..4f51ed4cb1 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -267,7 +267,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base // Make sure that if the user has read the topic, it's marked as read in the notification if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->notification_time) { - $this->unread = false; + $this->notification_read = true; } return parent::create_insert_array($post, $pre_create_data); -- cgit v1.2.1 From eeb40181956b578ca98ed0106f3019d8c8299ed3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Dec 2012 21:17:05 -0600 Subject: [ticket/11103] data -> notification_data PHPBB3-11103 --- phpBB/includes/notification/type/base.php | 10 +++++----- phpBB/includes/notification/type/post.php | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index cdca9aa642..c262fbeedb 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -110,7 +110,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i { // The row from the database (unless this is a new notification we're going to add) $this->data = $data; - $this->data['data'] = (isset($this->data['data'])) ? unserialize($this->data['data']) : array(); + $this->data['notification_data'] = (isset($this->data['notification_data'])) ? unserialize($this->data['notification_data']) : array(); } public function __get($name) @@ -137,7 +137,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ protected function get_data($name) { - return ($name === false) ? $this->data['data'] : ((isset($this->data['data'][$name])) ? $this->data['data'][$name] : null); + return ($name === false) ? $this->data['notification_data'] : ((isset($this->data['notification_data'][$name])) ? $this->data['notification_data'][$name] : null); } /** @@ -148,7 +148,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ protected function set_data($name, $value) { - $this->data['data'][$name] = $value; + $this->data['notification_data'][$name] = $value; } /** @@ -171,12 +171,12 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i 'notification_time' => time(), 'notification_read' => false, - 'data' => array(), + 'notification_data' => array(), ), $this->data); $data = $this->data; - $data['data'] = serialize($data['data']); + $data['notification_data'] = serialize($data['notification_data']); return $data; } diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php index f29372923e..ddfa720e5e 100644 --- a/phpBB/includes/notification/type/post.php +++ b/phpBB/includes/notification/type/post.php @@ -342,7 +342,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base // Do not add them as a responder if they were the original poster that created the notification if ($this->get_data('poster_id') == $post['poster_id']) { - return array('data' => serialize($this->get_data(false))); + return array('notification_data' => serialize($this->get_data(false))); } $responders = $this->get_data('responders'); @@ -354,7 +354,7 @@ class phpbb_notification_type_post extends phpbb_notification_type_base // Do not add them as a responder multiple times if ($responder['poster_id'] == $post['poster_id']) { - return array('data' => serialize($this->get_data(false))); + return array('notification_data' => serialize($this->get_data(false))); } } @@ -365,6 +365,6 @@ class phpbb_notification_type_post extends phpbb_notification_type_base $this->set_data('responders', $responders); - return array('data' => serialize($this->get_data(false))); + return array('notification_data' => serialize($this->get_data(false))); } } -- cgit v1.2.1 From 30356efab9503f44c26c6eebe6421911cd70ec64 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Dec 2012 21:54:19 -0600 Subject: [ticket/11103] updating comments PHPBB3-11103 --- phpBB/includes/notification/type/base.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index c262fbeedb..315bcb04c9 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -71,9 +71,9 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * item_id - ID of the item (e.g. post_id, msg_id) * item_parent_id - Parent item id (ex: for topic => forum_id, for post => topic_id, etc) * user_id - * unread - * time - * data (special serialized field that each notification type can use to store stuff) + * notification_read + * notification_time + * notification_data (special serialized field that each notification type can use to store stuff) * * @var array $data Notification row from the database * This must be private, all interaction should use __get(), __set(), get_data(), set_data() -- cgit v1.2.1 From bf93dceb1f69cddc625b7dbbdf588847660070fa Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 26 Dec 2012 11:09:03 -0600 Subject: [ticket/11103] Fix merge conflict PHPBB3-11103 --- phpBB/includes/notification/manager.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index fa1fd4b81f..9858cda898 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -128,13 +128,8 @@ class phpbb_notification_manager $sql = 'SELECT COUNT(n.notification_id) AS unread_count FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt WHERE n.user_id = ' . (int) $options['user_id'] . ' -<<<<<<< HEAD - AND n.unread = 1 - AND nt.notification_type = n.item_type -======= AND n.notification_read = 0 - AND nt.notification_type = n.notification_type ->>>>>>> 5cedca0... [ticket/11103] unread -> notification_read + AND nt.notification_type = n.item_type AND nt.notification_type_enabled = 1'; $result = $this->db->sql_query($sql); $unread_count = (int) $this->db->sql_fetchfield('unread_count', $result); -- cgit v1.2.1 From 5a8520da62a540f140319ecaef011fc49eaba451 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 27 Dec 2012 10:28:57 -0600 Subject: [ticket/11103] Fix some more merging issues PHPBB3-11103 --- phpBB/includes/notification/manager.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 9858cda898..52cfa77388 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -240,7 +240,7 @@ class phpbb_notification_manager SET notification_read = 1 WHERE notification_time <= " . $time . (($item_type !== false) ? ' AND ' . (is_array($item_type) ? $this->db->sql_in_set('item_type', $item_type) : " item_type = '" . $this->db->sql_escape($item_type) . "'") : '') . - (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : '') . + (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : ''); $this->db->sql_query($sql); } @@ -269,8 +269,6 @@ class phpbb_notification_manager $sql = 'UPDATE ' . $this->notifications_table . " SET notification_read = 1 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' - SET notification_read = 1 - WHERE notification_type = '" . $this->db->sql_escape($notification_type) . "' AND notification_time <= " . $time . (($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id) : 'item_parent_id = ' . (int) $item_parent_id) : '') . (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); -- cgit v1.2.1 From 192039a9e070f7ae09397d232d19d33a71e48ed2 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 27 Dec 2012 10:30:21 -0600 Subject: [ticket/11103] Fix sending the user ids to get the username/avatar PHPBB3-11103 --- phpBB/includes/notification/type/pm.php | 2 +- phpBB/includes/notification/type/report_pm.php | 2 +- phpBB/includes/notification/type/report_pm_closed.php | 2 +- phpBB/includes/notification/type/report_post.php | 2 +- phpBB/includes/notification/type/report_post_closed.php | 2 +- phpBB/includes/notification/type/topic.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php index 8d31c87817..b3db7ad5ad 100644 --- a/phpBB/includes/notification/type/pm.php +++ b/phpBB/includes/notification/type/pm.php @@ -161,7 +161,7 @@ class phpbb_notification_type_pm extends phpbb_notification_type_base */ public function users_to_query() { - return array($this->data['from_user_id']); + return array($this->get_data('from_user_id')); } /** diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php index 877e8209e3..3fa73bab41 100644 --- a/phpBB/includes/notification/type/report_pm.php +++ b/phpBB/includes/notification/type/report_pm.php @@ -205,7 +205,7 @@ class phpbb_notification_type_report_pm extends phpbb_notification_type_pm */ public function users_to_query() { - return array($this->data['reporter_id']); + return array($this->get_data('reporter_id')); } /** diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php index a735d2a822..63dfa92064 100644 --- a/phpBB/includes/notification/type/report_pm_closed.php +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -130,7 +130,7 @@ class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_p */ public function users_to_query() { - return array($this->data['closer_id']); + return array($this->get_data('closer_id')); } /** diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index 0334fdb109..1ea532c929 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -172,7 +172,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i */ public function users_to_query() { - return array($this->data['reporter_id']); + return array($this->get_data('reporter_id')); } /** diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php index 8b984fc8ce..3916cd8db7 100644 --- a/phpBB/includes/notification/type/report_post_closed.php +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -130,7 +130,7 @@ class phpbb_notification_type_report_post_closed extends phpbb_notification_type */ public function users_to_query() { - return array($this->data['closer_id']); + return array($this->get_data('closer_id')); } /** diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 4f51ed4cb1..71e074fb50 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -208,7 +208,7 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base */ public function users_to_query() { - return array($this->data['poster_id']); + return array($this->get_data('poster_id')); } /** -- cgit v1.2.1 From 07282a30ae077825ea81a4e26839ac0473dc97b7 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 15 Jan 2013 12:10:07 -0600 Subject: [ticket/11103] Fix some various issues, better comments PHPBB3-11103 --- phpBB/includes/notification/manager.php | 40 +++++++++---- phpBB/includes/notification/method/base.php | 40 +++++++++---- phpBB/includes/notification/type/base.php | 92 +++++++++++++++++++++++------ 3 files changed, 130 insertions(+), 42 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 52cfa77388..a289ec0dfa 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -22,38 +22,54 @@ if (!defined('IN_PHPBB')) class phpbb_notification_manager { /** @var array */ - protected $notification_types = null; + protected $notification_types; /** @var array */ - protected $notification_methods = null; + protected $notification_methods; /** @var ContainerBuilder */ - protected $phpbb_container = null; + protected $phpbb_container; /** @var phpbb_user_loader */ - protected $user_loader = null; + protected $user_loader; /** @var phpbb_db_driver */ - protected $db = null; + protected $db; /** @var phpbb_user */ - protected $user = null; + protected $user; /** @var string */ - protected $phpbb_root_path = null; + protected $phpbb_root_path; /** @var string */ - protected $php_ext = null; + protected $php_ext; /** @var string */ - protected $notification_types_table = null; + protected $notification_types_table; /** @var string */ - protected $notifications_table = null; + protected $notifications_table; /** @var string */ - protected $user_notifications_table = null; + protected $user_notifications_table; + /** + * Notification Constructor + * + * @param array $notification_types + * @param array $notification_methods + * @param ContainerBuilder $phpbb_container + * @param phpbb_user_loader $user_loader + * @param phpbb_db_driver $db + * @param phpbb_user $user + * @param string $phpbb_root_path + * @param string $php_ext + * @param string $notification_types_table + * @param string $notifications_table + * @param string $user_notifications_table + * @return phpbb_notification_manager + */ public function __construct($notification_types, $notification_methods, $phpbb_container, phpbb_user_loader $user_loader, phpbb_db_driver $db, $user, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table) { $this->notification_types = $notification_types; @@ -78,7 +94,7 @@ class phpbb_notification_manager * @param array $options Optional options to control what notifications are loaded * notification_id Notification id to load (or array of notification ids) * user_id User id to load notifications for (Default: $user->data['user_id']) - * order_by Order by (Default: time) + * order_by Order by (Default: notification_time) * order_dir Order direction (Default: DESC) * limit Number of notifications to load (Default: 5) * start Notifications offset (Default: 0) diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index f37e7e7845..c4c0a64ae0 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -22,37 +22,37 @@ if (!defined('IN_PHPBB')) abstract class phpbb_notification_method_base implements phpbb_notification_method_interface { /** @var phpbb_notification_manager */ - protected $notification_manager = null; + protected $notification_manager; /** @var phpbb_user_loader */ - protected $user_loader = null; + protected $user_loader; /** @var phpbb_db_driver */ - protected $db = null; + protected $db; /** @var phpbb_cache_service */ - protected $cache = null; + protected $cache; /** @var phpbb_template */ - protected $template = null; + protected $template; /** @var phpbb_extension_manager */ - protected $extension_manager = null; + protected $extension_manager; /** @var phpbb_user */ - protected $user = null; + protected $user; /** @var phpbb_auth */ - protected $auth = null; + protected $auth; /** @var phpbb_config */ - protected $config = null; + protected $config; /** @var string */ - protected $phpbb_root_path = null; + protected $phpbb_root_path; /** @var string */ - protected $php_ext = null; + protected $php_ext; /** * Queue of messages to be sent @@ -61,6 +61,19 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth */ protected $queue = array(); + /** + * Notification Method Base Constructor + * + * @param phpbb_user_loader $user_loader + * @param phpbb_db_driver $db + * @param phpbb_cache_driver_interface $cache + * @param mixed $user + * @param phpbb_auth $auth + * @param phpbb_config $config + * @param mixed $phpbb_root_path + * @param mixed $php_ext + * @return phpbb_notification_method_base + */ public function __construct(phpbb_user_loader $user_loader, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) { $this->user_loader = $user_loader; @@ -73,6 +86,11 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth $this->php_ext = $php_ext; } + /** + * Set notification manager (required) + * + * @param phpbb_notification_manager $notification_manager + */ public function set_notification_manager(phpbb_notification_manager $notification_manager) { $this->notification_manager = $notification_manager; diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index 315bcb04c9..f52f14c09e 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -22,40 +22,43 @@ if (!defined('IN_PHPBB')) abstract class phpbb_notification_type_base implements phpbb_notification_type_interface { /** @var phpbb_notification_manager */ - protected $notification_manager = null; + protected $notification_manager; /** @var phpbb_user_loader */ - protected $user_loader = null; + protected $user_loader; /** @var phpbb_db_driver */ - protected $db = null; + protected $db; /** @var phpbb_cache_service */ - protected $cache = null; + protected $cache; /** @var phpbb_template */ - protected $template = null; + protected $template; /** @var phpbb_user */ - protected $user = null; + protected $user; /** @var phpbb_auth */ - protected $auth = null; + protected $auth; /** @var phpbb_config */ - protected $config = null; + protected $config; /** @var string */ - protected $phpbb_root_path = null; + protected $phpbb_root_path; /** @var string */ - protected $php_ext = null; + protected $php_ext; /** @var string */ - protected $notifications_table = null; + protected $notification_types_table; /** @var string */ - protected $user_notifications_table = null; + protected $notifications_table; + + /** @var string */ + protected $user_notifications_table; /** * Notification option data (for outputting to the user) @@ -80,7 +83,23 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i */ private $data = array(); - public function __construct(phpbb_user_loader $user_loader, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) + /** + * Notification Type Base Constructor + * + * @param phpbb_user_loader $user_loader + * @param phpbb_db_driver $db + * @param phpbb_cache_driver_interface $cache + * @param phpbb_user $user + * @param phpbb_auth $auth + * @param phpbb_config $config + * @param string $phpbb_root_path + * @param string $php_ext + * @param string $notification_types_table + * @param string $notifications_table + * @param string $user_notifications_table + * @return phpbb_notification_type_base + */ + public function __construct(phpbb_user_loader $user_loader, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notification_types_table, $notifications_table, $user_notifications_table) { $this->user_loader = $user_loader; $this->db = $db; @@ -92,10 +111,16 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; + $this->notification_types_table = $notification_types_table; $this->notifications_table = $notifications_table; $this->user_notifications_table = $user_notifications_table; } + /** + * Set notification manager (required) + * + * @param phpbb_notification_manager $notification_manager + */ public function set_notification_manager(phpbb_notification_manager $notification_manager) { $this->notification_manager = $notification_manager; @@ -113,16 +138,38 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i $this->data['notification_data'] = (isset($this->data['notification_data'])) ? unserialize($this->data['notification_data']) : array(); } + /** + * Magic method to get data from this notification + * + * @param mixed $name + * @return mixed + */ public function __get($name) { return (!isset($this->data[$name])) ? null : $this->data[$name]; } + + /** + * Magic method to set data on this notification + * + * @param mixed $name + * @return mixed + */ public function __set($name, $value) { $this->data[$name] = $value; } + + /** + * Magic method to get a string of this notification + * + * Primarily for testing + * + * @param string $name + * @return mixed + */ public function __toString() { return (!empty($this->data)) ? var_export($this->data, true) : $this->get_type(); @@ -132,7 +179,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * Get special data (only important for the classes that extend this) * * @param string $name Name of the variable to get - * * @return mixed */ protected function get_data($name) @@ -157,7 +203,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * * @param array $type_data Data unique to this notification type * @param array $pre_create_data Data from pre_create_insert_array() - * * @return array Array of data ready to be inserted into the database */ public function create_insert_array($type_data, $pre_create_data = array()) @@ -186,7 +231,6 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * (The service handles insertion) * * @param array $type_data Data unique to this notification type - * * @return array Array of data ready to be updated in the database */ public function create_update_array($type_data) @@ -208,7 +252,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * Mark this item read * * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) - * @return string + * @return string|null If $return is False, nothing will be returned, else the sql code to update this item */ public function mark_read($return = false) { @@ -219,7 +263,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * Mark this item unread * * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) - * @return string + * @return string|null If $return is False, nothing will be returned, else the sql code to update this item */ public function mark_unread($return = false) { @@ -228,6 +272,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Prepare to output the notification to the template + * + * @return array Template variables */ public function prepare_for_display() { @@ -274,6 +320,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Get the user's avatar (fall back) + * + * @return string */ public function get_avatar() { @@ -282,6 +330,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Get the special items to load (fall back) + * + * @return array */ public function get_load_special() { @@ -298,6 +348,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Is available (fall back) + * + * @return bool */ public function is_available() { @@ -306,6 +358,8 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i /** * Pre create insert array function (fall back) + * + * @return array */ public function pre_create_insert_array($type_data, $notify_users) { @@ -398,7 +452,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * * @param bool $unread Unread (True/False) (Default: False) * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) - * @return string + * @return string|null If $return is False, nothing will be returned, else the sql code to update this item */ protected function mark($unread = true, $return = false) { -- cgit v1.2.1 From f089e099fed38b1bdae5316fb09f0c8ed847d495 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 15 Jan 2013 12:29:20 -0600 Subject: [ticket/11103] Including the set call in the declaration throws errors Call the set_notification_manager from the load_object function instead. PHPBB3-11103 --- phpBB/includes/notification/manager.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index a289ec0dfa..5c1016335a 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -841,6 +841,13 @@ class phpbb_notification_manager */ protected function load_object($object_name) { - return $this->phpbb_container->get($object_name); + $object = $this->phpbb_container->get($object_name); + + if (method_exists($object, 'set_notification_manager')) + { + $object->set_notification_manager($this); + } + + return $object; } } -- cgit v1.2.1 From bd499425522a61ddd617e9ac4cfed9a7859bf949 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 15 Jan 2013 12:54:39 -0600 Subject: [ticket/11103] Correcting constructor comments PHPBB3-11103 --- phpBB/includes/notification/method/base.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php index c4c0a64ae0..22418c9be8 100644 --- a/phpBB/includes/notification/method/base.php +++ b/phpBB/includes/notification/method/base.php @@ -67,11 +67,11 @@ abstract class phpbb_notification_method_base implements phpbb_notification_meth * @param phpbb_user_loader $user_loader * @param phpbb_db_driver $db * @param phpbb_cache_driver_interface $cache - * @param mixed $user + * @param phpbb_user $user * @param phpbb_auth $auth * @param phpbb_config $config - * @param mixed $phpbb_root_path - * @param mixed $php_ext + * @param string $phpbb_root_path + * @param string $php_ext * @return phpbb_notification_method_base */ public function __construct(phpbb_user_loader $user_loader, phpbb_db_driver $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) -- cgit v1.2.1 From fb4f7470d481bd73dd505e7ce0522907f67773ef Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 15:34:03 -0600 Subject: [feature/migrations] Rebuilding migrations data on develop So this is easy to merge later. PHPBB3-9737 --- phpBB/includes/db/migration/data/3_0_1.php | 28 ++ phpBB/includes/db/migration/data/3_0_10.php | 28 ++ phpBB/includes/db/migration/data/3_0_10_rc1.php | 30 ++ phpBB/includes/db/migration/data/3_0_10_rc2.php | 28 ++ phpBB/includes/db/migration/data/3_0_10_rc3.php | 28 ++ phpBB/includes/db/migration/data/3_0_11.php | 28 ++ phpBB/includes/db/migration/data/3_0_11_rc1.php | 94 ++++++ phpBB/includes/db/migration/data/3_0_11_rc2.php | 34 ++ phpBB/includes/db/migration/data/3_0_12_rc1.php | 123 +++++++ phpBB/includes/db/migration/data/3_0_1_rc1.php | 102 ++++++ phpBB/includes/db/migration/data/3_0_2.php | 28 ++ phpBB/includes/db/migration/data/3_0_2_rc1.php | 32 ++ phpBB/includes/db/migration/data/3_0_2_rc2.php | 55 +++ phpBB/includes/db/migration/data/3_0_3.php | 28 ++ phpBB/includes/db/migration/data/3_0_3_rc1.php | 63 ++++ phpBB/includes/db/migration/data/3_0_4.php | 49 +++ phpBB/includes/db/migration/data/3_0_4_rc1.php | 107 ++++++ phpBB/includes/db/migration/data/3_0_5.php | 28 ++ phpBB/includes/db/migration/data/3_0_5_rc1.php | 119 +++++++ .../includes/db/migration/data/3_0_5_rc1part2.php | 37 ++ phpBB/includes/db/migration/data/3_0_6.php | 28 ++ phpBB/includes/db/migration/data/3_0_6_rc1.php | 279 +++++++++++++++ phpBB/includes/db/migration/data/3_0_6_rc2.php | 28 ++ phpBB/includes/db/migration/data/3_0_6_rc3.php | 40 +++ phpBB/includes/db/migration/data/3_0_6_rc4.php | 28 ++ phpBB/includes/db/migration/data/3_0_7.php | 28 ++ phpBB/includes/db/migration/data/3_0_7_pl1.php | 28 ++ phpBB/includes/db/migration/data/3_0_7_rc1.php | 53 +++ phpBB/includes/db/migration/data/3_0_7_rc2.php | 72 ++++ phpBB/includes/db/migration/data/3_0_8.php | 28 ++ phpBB/includes/db/migration/data/3_0_8_rc1.php | 221 ++++++++++++ phpBB/includes/db/migration/data/3_0_9.php | 28 ++ phpBB/includes/db/migration/data/3_0_9_rc1.php | 110 ++++++ phpBB/includes/db/migration/data/3_0_9_rc2.php | 28 ++ phpBB/includes/db/migration/data/3_0_9_rc3.php | 28 ++ phpBB/includes/db/migration/data/3_0_9_rc4.php | 28 ++ phpBB/includes/db/migration/data/3_1_0_dev.php | 375 +++++++++++++++++++++ phpBB/includes/db/migration/data/extensions.php | 55 +++ .../includes/db/migration/data/style_update_p1.php | 157 +++++++++ .../includes/db/migration/data/style_update_p2.php | 42 +++ phpBB/includes/db/migration/data/timezone.php | 161 +++++++++ phpBB/includes/update_helpers.php | 112 ------ 42 files changed, 2914 insertions(+), 112 deletions(-) create mode 100644 phpBB/includes/db/migration/data/3_0_1.php create mode 100644 phpBB/includes/db/migration/data/3_0_10.php create mode 100644 phpBB/includes/db/migration/data/3_0_10_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_10_rc2.php create mode 100644 phpBB/includes/db/migration/data/3_0_10_rc3.php create mode 100644 phpBB/includes/db/migration/data/3_0_11.php create mode 100644 phpBB/includes/db/migration/data/3_0_11_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_11_rc2.php create mode 100644 phpBB/includes/db/migration/data/3_0_12_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_1_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_2.php create mode 100644 phpBB/includes/db/migration/data/3_0_2_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_2_rc2.php create mode 100644 phpBB/includes/db/migration/data/3_0_3.php create mode 100644 phpBB/includes/db/migration/data/3_0_3_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_4.php create mode 100644 phpBB/includes/db/migration/data/3_0_4_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_5.php create mode 100644 phpBB/includes/db/migration/data/3_0_5_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_5_rc1part2.php create mode 100644 phpBB/includes/db/migration/data/3_0_6.php create mode 100644 phpBB/includes/db/migration/data/3_0_6_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_6_rc2.php create mode 100644 phpBB/includes/db/migration/data/3_0_6_rc3.php create mode 100644 phpBB/includes/db/migration/data/3_0_6_rc4.php create mode 100644 phpBB/includes/db/migration/data/3_0_7.php create mode 100644 phpBB/includes/db/migration/data/3_0_7_pl1.php create mode 100644 phpBB/includes/db/migration/data/3_0_7_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_7_rc2.php create mode 100644 phpBB/includes/db/migration/data/3_0_8.php create mode 100644 phpBB/includes/db/migration/data/3_0_8_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_9.php create mode 100644 phpBB/includes/db/migration/data/3_0_9_rc1.php create mode 100644 phpBB/includes/db/migration/data/3_0_9_rc2.php create mode 100644 phpBB/includes/db/migration/data/3_0_9_rc3.php create mode 100644 phpBB/includes/db/migration/data/3_0_9_rc4.php create mode 100644 phpBB/includes/db/migration/data/3_1_0_dev.php create mode 100644 phpBB/includes/db/migration/data/extensions.php create mode 100644 phpBB/includes/db/migration/data/style_update_p1.php create mode 100644 phpBB/includes/db/migration/data/style_update_p2.php create mode 100644 phpBB/includes/db/migration/data/timezone.php delete mode 100644 phpBB/includes/update_helpers.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/3_0_1.php b/phpBB/includes/db/migration/data/3_0_1.php new file mode 100644 index 0000000000..a2332c9b59 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_1.php @@ -0,0 +1,28 @@ +sql_query($sql); + + $deactivated_style_ids = array(); + while ($style_id = $this->db->sql_fetchfield('style_id', false, $result)) + { + $deactivated_style_ids[] = (int) $style_id; + } + $this->db->sql_freeresult($result); + + if (!empty($deactivated_style_ids)) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_style = ' . (int) $this->config['default_style'] .' + WHERE ' . $this->db->sql_in_set('user_style', $deactivated_style_ids); + $this->sql_query($sql); + } + } + + function delete_orphan_private_messages() + { + // Delete orphan private messages + $batch_size = 500; + + $sql_array = array( + 'SELECT' => 'p.msg_id', + 'FROM' => array( + PRIVMSGS_TABLE => 'p', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(PRIVMSGS_TO_TABLE => 't'), + 'ON' => 'p.msg_id = t.msg_id', + ), + ), + 'WHERE' => 't.user_id IS NULL', + ); + $sql = $this->db->sql_build_query('SELECT', $sql_array); + + $result = $this->db->sql_query_limit($sql, $batch_size); + + $delete_pms = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $delete_pms[] = (int) $row['msg_id']; + } + $this->db->sql_freeresult($result); + + if (!empty($delete_pms)) + { + $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' + WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms); + $this->sql_query($sql); + + return false; + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_11_rc2.php b/phpBB/includes/db/migration/data/3_0_11_rc2.php new file mode 100644 index 0000000000..f2bed54085 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_11_rc2.php @@ -0,0 +1,34 @@ + array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_novalue' => array('BOOL', 0), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.update', array('version', '3.0.11-rc2')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_12_rc1.php b/phpBB/includes/db/migration/data/3_0_12_rc1.php new file mode 100644 index 0000000000..0d8702f19e --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_12_rc1.php @@ -0,0 +1,123 @@ +db->sql_query($sql); + + $bot_user_ids = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $bot_user_ids[] = (int) $row['user_id']; + } + $this->db->sql_freeresult($result); + + if (!empty($bot_user_ids)) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_allow_pm = 0 + WHERE ' . $this->db->sql_in_set('user_id', $bot_user_ids); + $this->sql_query($sql); + } + } + + public function update_module_auth() + { + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET module_auth = \'acl_u_sig\' + WHERE module_class = \'ucp\' + AND module_basename = \'profile\' + AND module_mode = \'signature\''; + $this->sql_query($sql); + } + + public function update_bots() + { + // Update bots + if (!function_exists('user_delete')) + { + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + } + + $bots_updates = array( + // Bot Deletions + 'NG-Search [Bot]' => false, + 'Nutch/CVS [Bot]' => false, + 'OmniExplorer [Bot]' => false, + 'Seekport [Bot]' => false, + 'Synoo [Bot]' => false, + 'WiseNut [Bot]' => false, + + // Bot Updates + // Bot name to bot user agent map + 'Baidu [Spider]' => 'Baiduspider', + 'Exabot [Bot]' => 'Exabot', + 'Voyager [Bot]' => 'voyager/', + 'W3C [Validator]' => 'W3C_Validator', + ); + + foreach ($bots_updates as $bot_name => $bot_agent) + { + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . ' + WHERE user_type = ' . USER_IGNORE . " + AND username_clean = '" . $this->db->sql_escape(utf8_clean_string($bot_name)) . "'"; + $result = $this->db->sql_query($sql); + $bot_user_id = (int) $this->db->sql_fetchfield('user_id'); + $this->db->sql_freeresult($result); + + if ($bot_user_id) + { + if ($bot_agent === false) + { + $sql = 'DELETE FROM ' . BOTS_TABLE . " + WHERE user_id = $bot_user_id"; + $this->sql_query($sql); + + user_delete('remove', $bot_user_id); + } + else + { + $sql = 'UPDATE ' . BOTS_TABLE . " + SET bot_agent = '" . $this->db->sql_escape($bot_agent) . "' + WHERE user_id = $bot_user_id"; + $this->sql_query($sql); + } + } + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_1_rc1.php b/phpBB/includes/db/migration/data/3_0_1_rc1.php new file mode 100644 index 0000000000..cf067d2e2c --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_1_rc1.php @@ -0,0 +1,102 @@ + array( + $this->table_prefix . 'forums' => array( + 'display_subforum_list' => array('BOOL', 1), + ), + $this->table_prefix . 'sessions' => array( + 'session_forum_id' => array('UINT', 0), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'groups' => array('group_legend'), + ), + 'add_index' => array( + $this->table_prefix . 'sessions' => array( + 'session_forum_id' => array('session_forum_id'), + ), + $this->table_prefix . 'groups' => array( + 'group_legend_name' => array('group_legend', 'group_name'), + ), + ), + ); + } + + function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'forums' => array( + 'display_subforum_list', + ), + $this->table_prefix . 'sessions' => array( + 'session_forum_id', + ), + ), + 'add_index' => array( + $this->table_prefix . 'groups' => array( + 'group_legend' => 'group_legend', + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'sessions' => array('session_forum_id'), + $this->table_prefix . 'groups' => array('group_legend_name'), + ), + ); + } + + function update_data() + { + return array( + array('custom', array(array(&$this, 'fix_unset_last_view_time'))), + array('custom', array(array(&$this, 'reset_smiley_size'))), + + array('config.update', array('version', '3.0.1-rc1')), + ); + } + + function fix_unset_last_view_time() + { + $sql = 'UPDATE ' . $this->table_prefix . "topics + SET topic_last_view_time = topic_last_post_time + WHERE topic_last_view_time = 0"; + $this->sql_query($sql); + } + + function reset_smiley_size() + { + // Update smiley sizes + $smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif'); + + foreach ($smileys as $smiley) + { + if (file_exists($this->phpbb_root_path . 'images/smilies/' . $smiley)) + { + list($width, $height) = getimagesize($this->phpbb_root_path . 'images/smilies/' . $smiley); + + $sql = 'UPDATE ' . SMILIES_TABLE . ' + SET smiley_width = ' . $width . ', smiley_height = ' . $height . " + WHERE smiley_url = '" . $this->db->sql_escape($smiley) . "'"; + + $this->sql_query($sql); + } + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_2.php b/phpBB/includes/db/migration/data/3_0_2.php new file mode 100644 index 0000000000..3469d8d178 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_2.php @@ -0,0 +1,28 @@ + array( + $this->table_prefix . 'drafts' => array( + 'draft_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'forums' => array( + 'forum_last_post_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'posts' => array( + 'post_subject' => array('STEXT_UNI', '', 'true_sort'), + ), + $this->table_prefix . 'privmsgs' => array( + 'message_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'topics' => array( + 'topic_title' => array('STEXT_UNI', '', 'true_sort'), + 'topic_last_post_subject' => array('STEXT_UNI', ''), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'sessions' => array('session_forum_id'), + ), + 'add_index' => array( + $this->table_prefix . 'sessions' => array( + 'session_fid' => array('session_forum_id'), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.update', array('version', '3.0.2-rc2')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_3.php b/phpBB/includes/db/migration/data/3_0_3.php new file mode 100644 index 0000000000..dff375f438 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_3.php @@ -0,0 +1,28 @@ + array( + $this->table_prefix . 'styles_template' => array( + 'template_inherits_id' => array('UINT:4', 0), + 'template_inherit_path' => array('VCHAR', ''), + ), + $this->table_prefix . 'groups' => array( + 'group_max_recipients' => array('UINT', 0), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('enable_queue_trigger', '0')), + array('config.add', array('queue_trigger_posts', '3')), + array('config.add', array('pm_max_recipients', '0')), + array('custom', array(array(&$this, 'set_group_default_max_recipients'))), + array('config.add', array('dbms_version', $this->db->sql_server_info(true))), + array('permission.add', array('u_masspm_group', true, 'u_masspm')), + array('custom', array(array(&$this, 'correct_acp_email_permissions'))), + + array('config.update', array('version', '3.0.3-rc1')), + ); + } + + function correct_acp_email_permissions() + { + $sql = 'UPDATE ' . $this->table_prefix . 'modules + SET module_auth = \'acl_a_email && cfg_email_enable\' + WHERE module_class = \'acp\' + AND module_basename = \'email\''; + $this->sql_query($sql); + } + + function set_group_default_max_recipients() + { + // Set maximum number of recipients for the registered users, bots, guests group + $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5 + WHERE ' . $this->db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS')); + $this->sql_query($sql); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_4.php b/phpBB/includes/db/migration/data/3_0_4.php new file mode 100644 index 0000000000..1af4508331 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_4.php @@ -0,0 +1,49 @@ +db->sql_layer == 'oracle') + { + // log_operation is CLOB - but we can change this later + $sql = 'UPDATE ' . $this->table_prefix . "log + SET log_operation = 'LOG_DELETE_TOPIC' + WHERE log_operation LIKE 'LOG_TOPIC_DELETED'"; + $this->sql_query($sql); + } + else + { + $sql = 'UPDATE ' . $this->table_prefix . "log + SET log_operation = 'LOG_DELETE_TOPIC' + WHERE log_operation = 'LOG_TOPIC_DELETED'"; + $this->sql_query($sql); + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_4_rc1.php b/phpBB/includes/db/migration/data/3_0_4_rc1.php new file mode 100644 index 0000000000..e9bb0e01f5 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_4_rc1.php @@ -0,0 +1,107 @@ + array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_profile' => array('BOOL', 0), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'styles' => array( + 'style_id' => array('UINT', NULL, 'auto_increment'), + 'template_id' => array('UINT', 0), + 'theme_id' => array('UINT', 0), + 'imageset_id' => array('UINT', 0), + ), + $this->table_prefix . 'styles_imageset' => array( + 'imageset_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_imageset_data' => array( + 'image_id' => array('UINT', NULL, 'auto_increment'), + 'imageset_id' => array('UINT', 0), + ), + $this->table_prefix . 'styles_theme' => array( + 'theme_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_template' => array( + 'template_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_template_data' => array( + 'template_id' => array('UINT', 0), + ), + $this->table_prefix . 'forums' => array( + 'forum_style' => array('UINT', 0), + ), + $this->table_prefix . 'users' => array( + 'user_style' => array('UINT', 0), + ), + ), + ); + } + + function update_data() + { + return array( + array('custom', array(array(&$this, 'update_custom_profile_fields'))), + + array('config.update', array('version', '3.0.4-rc1')), + ); + } + + function update_custom_profile_fields() + { + // Update the Custom Profile Fields based on previous settings to the new format + $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide + FROM ' . PROFILE_FIELDS_TABLE; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql_ary = array( + 'field_required' => 0, + 'field_show_on_reg' => 0, + 'field_hide' => 0, + 'field_show_profile'=> 0, + ); + + if ($row['field_required']) + { + $sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; + } + else if ($row['field_show_on_reg']) + { + $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; + } + else if ($row['field_hide']) + { + // Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module + $sql_ary['field_hide'] = 1; + } + else + { + // equivelant to "none", which is the "Display in user control panel" option + $sql_ary['field_show_profile'] = 1; + } + + $this->sql_query('UPDATE ' . $this->table_prefix . 'profile_fields SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary); + } + + $this->db->sql_freeresult($result); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_5.php b/phpBB/includes/db/migration/data/3_0_5.php new file mode 100644 index 0000000000..2f80970781 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_5.php @@ -0,0 +1,28 @@ + array( + $this->table_prefix . 'forums' => array( + 'forum_style' => array('UINT', 0), + ), + ), + ); + } + + function update_data() + { + $search_indexing_state = $this->config['search_indexing_state']; + + return array( + array('config.add', array('captcha_gd_wave', 0)), + array('config.add', array('captcha_gd_3d_noise', 1)), + array('config.add', array('captcha_gd_fonts', 1)), + array('config.add', array('confirm_refresh', 1)), + array('config.add', array('max_num_search_keywords', 10)), + array('config.remove', array('search_indexing_state')), + array('config.add', array('search_indexing_state', $search_indexing_state, true)), + array('custom', array(array(&$this, 'hash_old_passwords'))), + array('custom', array(array(&$this, 'update_ichiro_bot'))), + ); + } + + function hash_old_passwords() + { + $sql = 'SELECT user_id, user_password + FROM ' . $this->table_prefix . 'users + WHERE user_pass_convert = 1'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + if (strlen($row['user_password']) == 32) + { + $sql_ary = array( + 'user_password' => phpbb_hash($row['user_password']), + ); + + $this->sql_query('UPDATE ' . $this->table_prefix . 'users SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id']); + } + } + $this->db->sql_freeresult($result); + } + + function update_ichiro_bot() + { + // Adjust bot entry + $sql = 'UPDATE ' . $this->table_prefix . "bots + SET bot_agent = 'ichiro/' + WHERE bot_agent = 'ichiro/2'"; + $this->sql_query($sql); + } + + function remove_duplicate_auth_options() + { + // Before we are able to add a unique key to auth_option, we need to remove duplicate entries + $sql = 'SELECT auth_option + FROM ' . $this->table_prefix . 'acl_options + GROUP BY auth_option + HAVING COUNT(*) >= 2'; + $result = $this->db->sql_query($sql); + + $auth_options = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $auth_options[] = $row['auth_option']; + } + $this->db->sql_freeresult($result); + + // Remove specific auth options + if (!empty($auth_options)) + { + foreach ($auth_options as $option) + { + // Select auth_option_ids... the largest id will be preserved + $sql = 'SELECT auth_option_id + FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $db->sql_escape($option) . "' + ORDER BY auth_option_id DESC"; + // sql_query_limit not possible here, due to bug in postgresql layer + $result = $this->db->sql_query($sql); + + // Skip first row, this is our original auth option we want to preserve + $row = $this->db->sql_fetchrow($result); + + while ($row = $this->db->sql_fetchrow($result)) + { + // Ok, remove this auth option... + $this->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + } + $this->db->sql_freeresult($result); + } + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php new file mode 100644 index 0000000000..1fab0f8873 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php @@ -0,0 +1,37 @@ + array( + ACL_OPTIONS_TABLE => array('auth_option'), + ), + 'add_unique_index' => array( + ACL_OPTIONS_TABLE => array( + 'auth_option' => array('auth_option'), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.update', array('version', '3.0.5-rc1')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_6.php b/phpBB/includes/db/migration/data/3_0_6.php new file mode 100644 index 0000000000..26176b9437 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_6.php @@ -0,0 +1,28 @@ + array( + $this->table_prefix . 'confirm' => array( + 'attempts' => array('UINT', 0), + ), + $this->table_prefix . 'users' => array( + 'user_new' => array('BOOL', 1), + 'user_reminded' => array('TINT:4', 0), + 'user_reminded_time' => array('TIMESTAMP', 0), + ), + $this->table_prefix . 'groups' => array( + 'group_skip_auth' => array('BOOL', 0, 'after' => 'group_founder_manage'), + ), + $this->table_prefix . 'privmsgs' => array( + 'message_reported' => array('BOOL', 0), + ), + $this->table_prefix . 'reports' => array( + 'pm_id' => array('UINT', 0), + ), + $this->table_prefix . 'profile_fields' => array( + 'field_show_on_vt' => array('BOOL', 0), + ), + $this->table_prefix . 'forums' => array( + 'forum_options' => array('UINT:20', 0), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'users' => array( + 'user_options' => array('UINT:11', 230271), + ), + ), + 'add_index' => array( + $this->table_prefix . 'reports' => array( + 'post_id' => array('post_id'), + 'pm_id' => array('pm_id'), + ), + $this->table_prefix . 'posts' => array( + 'post_username' => array('post_username:255'), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')), + array('if', array( + ($this->config['captcha_gd']), + array('config.update', array('captcha_plugin', 'phpbb_captcha_gd')), + )), + + array('config.add', array('feed_enable', 0)), + array('config.add', array('feed_limit', 10)), + array('config.add', array('feed_overall_forums', 1)), + array('config.add', array('feed_overall_forums_limit', 15)), + array('config.add', array('feed_overall_topics', 0)), + array('config.add', array('feed_overall_topics_limit', 15)), + array('config.add', array('feed_forum', 1)), + array('config.add', array('feed_topic', 1)), + array('config.add', array('feed_item_statistics', 1)), + + array('config.add', array('smilies_per_page', 50)), + array('config.add', array('allow_pm_report', 1)), + array('config.add', array('min_post_chars', 1)), + array('config.add', array('allow_quick_reply', 1)), + array('config.add', array('new_member_post_limit', 0)), + array('config.add', array('new_member_group_default', 0)), + array('config.add', array('delete_time', $this->config['edit_time'])), + + array('config.add', array('allow_avatar', 0)), + array('if', array( + ($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']), + array('config.update', array('allow_avatar', 1)), + )), + array('config.add', array('allow_avatar_remote_upload', 0)), + array('if', array( + ($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']), + array('config.update', array('allow_avatar_remote_upload', 1)), + )), + + array('module.add', array( + 'acp', + 'ACP_BOARD_CONFIGURATION', + array( + 'module_basename' => 'acp_board', + 'modes' => array('feed'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_CAT_USERS', + array( + 'module_basename' => 'acp_users', + 'modes' => array('warnings'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_SERVER_CONFIGURATION', + array( + 'module_basename' => 'acp_send_statistics', + 'modes' => array('send_statistics'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_FORUM_BASED_PERMISSIONS', + array( + 'module_basename' => 'acp_permissions', + 'modes' => array('setting_forum_copy'), + ), + )), + array('module.add', array( + 'mcp', + 'MCP_REPORTS', + array( + 'module_basename' => 'mcp_pm_reports', + 'modes' => array('pm_reports','pm_reports_closed','pm_report_details'), + ), + )), + array('custom', array(array(&$this, 'add_newly_registered_group'))), + array('custom', array(array(&$this, 'set_user_options_default'))), + + array('config.update', array('version', '3.0.6-rc1')), + ); + } + + function set_user_options_default() + { + // 229376 is the added value to enable all three signature options + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376'; + $this->sql_query($sql); + } + + function add_newly_registered_group() + { + // Add newly_registered group... but check if it already exists (we always supported running the updater on any schema) + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . " + WHERE group_name = 'NEWLY_REGISTERED'"; + $result = $this->db->sql_query($sql); + $group_id = (int) $this->db->sql_fetchfield('group_id'); + $this->db->sql_freeresult($result); + + if (!$group_id) + { + $sql = 'INSERT INTO ' . GROUPS_TABLE . " (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5)"; + $this->sql_query($sql); + + $group_id = $this->db->sql_nextid(); + } + + // Insert new user role... at the end of the chain + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = 'ROLE_USER_NEW_MEMBER' + AND role_type = 'u_'"; + $result = $this->db->sql_query($sql); + $u_role = (int) $this->db->sql_fetchfield('role_id'); + $this->db->sql_freeresult($result); + + if (!$u_role) + { + $sql = 'SELECT MAX(role_order) as max_order_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_type = 'u_'"; + $result = $this->db->sql_query($sql); + $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); + $this->db->sql_freeresult($result); + + $next_order_id++; + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_USER_NEW_MEMBER', 'ROLE_DESCRIPTION_USER_NEW_MEMBER', 'u_', $next_order_id)"; + $this->sql_query($sql); + $u_role = $this->db->sql_nextid(); + + // Now add the correct data to the roles... + // The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups + $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')"; + $this->sql_query($sql); + + // Add user role to group + $sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)"; + $this->sql_query($sql); + } + + // Insert new forum role + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = 'ROLE_FORUM_NEW_MEMBER' + AND role_type = 'f_'"; + $result = $this->db->sql_query($sql); + $f_role = (int) $this->db->sql_fetchfield('role_id'); + $this->db->sql_freeresult($result); + + if (!$f_role) + { + $sql = 'SELECT MAX(role_order) as max_order_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_type = 'f_'"; + $result = $this->db->sql_query($sql); + $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); + $this->db->sql_freeresult($result); + + $next_order_id++; + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', $next_order_id)"; + $this->sql_query($sql); + $f_role = $this->db->sql_nextid(); + + $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')"; + $this->sql_query($sql); + } + + // Set every members user_new column to 0 (old users) only if there is no one yet (this makes sure we do not execute this more than once) + $sql = 'SELECT 1 + FROM ' . USERS_TABLE . ' + WHERE user_new = 0'; + $result = $this->db->sql_query_limit($sql, 1); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0'; + $this->sql_query($sql); + } + + // To mimick the old "feature" we will assign the forum role to every forum, regardless of the setting (this makes sure there are no "this does not work!!!! YUO!!!" posts... + // Check if the role is already assigned... + $sql = 'SELECT forum_id + FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id = ' . $f_role; + $result = $this->db->sql_query($sql); + $is_options = (int) $this->db->sql_fetchfield('forum_id'); + $this->db->sql_freeresult($result); + + // Not assigned at all... :/ + if (!$is_options) + { + // Get postable forums + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE forum_type != ' . FORUM_LINK; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)'); + } + $this->db->sql_freeresult($result); + } + + // Clear permissions... + include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext); + $auth_admin = new auth_admin(); + $auth_admin->acl_clear_prefetch(); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_6_rc2.php b/phpBB/includes/db/migration/data/3_0_6_rc2.php new file mode 100644 index 0000000000..4092a5fa61 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_6_rc2.php @@ -0,0 +1,28 @@ +sql_query($sql); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_6_rc4.php b/phpBB/includes/db/migration/data/3_0_6_rc4.php new file mode 100644 index 0000000000..e748c7a4ff --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_6_rc4.php @@ -0,0 +1,28 @@ + array( + $this->table_prefix . 'log' => array('log_time'), + ), + 'add_index' => array( + $this->table_prefix . 'topics_track' => array( + 'topic_id' => array('topic_id'), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('feed_overall', 1)), + array('config.add', array('feed_http_auth', 0)), + array('config.add', array('feed_limit_post', $this->config['feed_limit'])), + array('config.add', array('feed_limit_topic', $this->config['feed_overall_topics_limit'])), + array('config.add', array('feed_topics_new', $this->config['feed_overall_topics'])), + array('config.add', array('feed_topics_active', $this->config['feed_overall_topics'])), + array('custom', array(array(&$this, 'delete_text_templates'))), + + array('config.update', array('version', '3.0.7-rc1')), + ); + } + + function delete_text_templates() + { + // Delete all text-templates from the template_data + $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' + WHERE template_filename ' . $this->db->sql_like_expression($this->db->any_char . '.txt'); + $this->sql_query($sql); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_7_rc2.php b/phpBB/includes/db/migration/data/3_0_7_rc2.php new file mode 100644 index 0000000000..4e380c810d --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_7_rc2.php @@ -0,0 +1,72 @@ + ' . USER_IGNORE . " + AND user_email <> ''"; + $result = $this->db->sql_query_limit($sql, $limit, $start); + + $i = 0; + while ($row = $this->db->sql_fetchrow($result)) + { + $i++; + + // Snapshot of the phpbb_email_hash() function + // We cannot call it directly because the auto updater updates the DB first. :/ + $user_email_hash = sprintf('%u', crc32(strtolower($row['user_email']))) . strlen($row['user_email']); + + if ($user_email_hash != $row['user_email_hash']) + { + $sql_ary = array( + 'user_email_hash' => $user_email_hash, + ); + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE user_id = ' . (int) $row['user_id']; + $this->sql_query($sql); + } + } + $this->db->sql_freeresult($result); + + if ($i < $limit) + { + // Completed + return; + } + + return $start + $limit; + } +} diff --git a/phpBB/includes/db/migration/data/3_0_8.php b/phpBB/includes/db/migration/data/3_0_8.php new file mode 100644 index 0000000000..a5defc8278 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_8.php @@ -0,0 +1,28 @@ + 'acp_board', + 'modes' => array('post'), + ), + )), + array('config.add', array('load_unreads_search', 1)), + array('config.update_if_equals', array(600, 'queue_interval', 60)), + array('config.update_if_equals', array(50, 'email_package_size', 20)), + + array('config.update', array('version', '3.0.8-rc1')), + ); + } + + function update_file_extension_group_names() + { + // Update file extension group names to use language strings. + $sql = 'SELECT lang_dir + FROM ' . LANG_TABLE; + $result = $this->db->sql_query($sql); + + $extension_groups_updated = array(); + while ($lang_dir = $this->db->sql_fetchfield('lang_dir')) + { + $lang_dir = basename($lang_dir); + + // The language strings we need are either in language/.../acp/attachments.php + // in the update package if we're updating to 3.0.8-RC1 or later, + // or they are in language/.../install.php when we're updating from 3.0.7-PL1 or earlier. + // On an already updated board, they can also already be in language/.../acp/attachments.php + // in the board root. + $lang_files = array( + "{$this->phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.{$this->php_ext}", + "{$this->phpbb_root_path}language/$lang_dir/install.{$this->php_ext}", + "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.{$this->php_ext}", + ); + + foreach ($lang_files as $lang_file) + { + if (!file_exists($lang_file)) + { + continue; + } + + $lang = array(); + include($lang_file); + + foreach($lang as $lang_key => $lang_val) + { + if (isset($extension_groups_updated[$lang_key]) || strpos($lang_key, 'EXT_GROUP_') !== 0) + { + continue; + } + + $sql_ary = array( + 'group_name' => substr($lang_key, 10), // Strip off 'EXT_GROUP_' + ); + + $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " + WHERE group_name = '" . $this->db->sql_escape($lang_val) . "'"; + $this->sql_query($sql); + + $extension_groups_updated[$lang_key] = true; + } + } + } + $this->db->sql_freeresult($result); + } + + function update_module_auth() + { + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\' + WHERE module_class = \'ucp\' + AND module_basename = \'profile\' + AND module_mode = \'avatar\''; + $this->sql_query($sql); + } + + function update_bots() + { + $bot_name = 'Bing [Bot]'; + $bot_name_clean = utf8_clean_string($bot_name); + + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . " + WHERE username_clean = '" . $this->db->sql_escape($bot_name_clean) . "'"; + $result = $this->db->sql_query($sql); + $bing_already_added = (bool) $this->db->sql_fetchfield('user_id'); + $this->db->sql_freeresult($result); + + if (!$bing_already_added) + { + $bot_agent = 'bingbot/'; + $bot_ip = ''; + $sql = 'SELECT group_id, group_colour + FROM ' . GROUPS_TABLE . " + WHERE group_name = 'BOTS'"; + $result = $this->db->sql_query($sql); + $group_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$group_row) + { + // default fallback, should never get here + $group_row['group_id'] = 6; + $group_row['group_colour'] = '9E8DA7'; + } + + if (!function_exists('user_add')) + { + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + } + + $user_row = array( + 'user_type' => USER_IGNORE, + 'group_id' => $group_row['group_id'], + 'username' => $bot_name, + 'user_regdate' => time(), + 'user_password' => '', + 'user_colour' => $group_row['group_colour'], + 'user_email' => '', + 'user_lang' => $this->config['default_lang'], + 'user_style' => $this->config['default_style'], + 'user_timezone' => 0, + 'user_dateformat' => $this->config['default_dateformat'], + 'user_allow_massemail' => 0, + ); + + $user_id = user_add($user_row); + + $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( + 'bot_active' => 1, + 'bot_name' => (string) $bot_name, + 'user_id' => (int) $user_id, + 'bot_agent' => (string) $bot_agent, + 'bot_ip' => (string) $bot_ip, + )); + + $this->sql_query($sql); + } + } + + function delete_orphan_shadow_topics() + { + // Delete shadow topics pointing to not existing topics + $batch_size = 500; + + // Set of affected forums we have to resync + $sync_forum_ids = array(); + + $sql_array = array( + 'SELECT' => 't1.topic_id, t1.forum_id', + 'FROM' => array( + TOPICS_TABLE => 't1', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(TOPICS_TABLE => 't2'), + 'ON' => 't1.topic_moved_id = t2.topic_id', + ), + ), + 'WHERE' => 't1.topic_moved_id <> 0 + AND t2.topic_id IS NULL', + ); + $sql = $this->db->sql_build_query('SELECT', $sql_array); + $result = $this->db->sql_query_limit($sql, $batch_size); + + $topic_ids = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $topic_ids[] = (int) $row['topic_id']; + + $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; + } + $this->db->sql_freeresult($result); + + if (!empty($topic_ids)) + { + $sql = 'DELETE FROM ' . TOPICS_TABLE . ' + WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids); + $this->db->sql_query($sql); + + // Sync the forums we have deleted shadow topics from. + sync('forum', 'forum_id', $sync_forum_ids, true, true); + + return false; + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_9.php b/phpBB/includes/db/migration/data/3_0_9.php new file mode 100644 index 0000000000..eb359e2697 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_9.php @@ -0,0 +1,28 @@ + array( + $this->table_prefix . 'login_attempts' => array( + 'COLUMNS' => array( + // this column was removed from the database updater + // after 3.0.9-RC3 was released. It might still exist + // in 3.0.9-RCX installations and has to be dropped in + // 3.0.12 after the db_tools class is capable of properly + // removing a primary key. + // 'attempt_id' => array('UINT', NULL, 'auto_increment'), + 'attempt_ip' => array('VCHAR:40', ''), + 'attempt_browser' => array('VCHAR:150', ''), + 'attempt_forwarded_for' => array('VCHAR:255', ''), + 'attempt_time' => array('TIMESTAMP', 0), + 'user_id' => array('UINT', 0), + 'username' => array('VCHAR_UNI:255', 0), + 'username_clean' => array('VCHAR_CI', 0), + ), + //'PRIMARY_KEY' => 'attempt_id', + 'KEYS' => array( + 'att_ip' => array('INDEX', array('attempt_ip', 'attempt_time')), + 'att_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')), + 'att_time' => array('INDEX', array('attempt_time')), + 'user_id' => array('INDEX', 'user_id'), + ), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'bbcodes' => array( + 'bbcode_id' => array('USINT', 0), + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('ip_login_limit_max', 50)), + array('config.add', array('ip_login_limit_time', 21600)), + array('config.add', array('ip_login_limit_use_forwarded', 0)), + array('custom', array(array(&$this, 'update_file_extension_group_names'))), + array('custom', array(array(&$this, 'fix_firebird_qa_captcha'))), + + array('config.update', array('version', '3.0.9-rc1')), + ); + } + + function update_file_extension_group_names() + { + // Update file extension group names to use language strings, again. + $sql = 'SELECT group_id, group_name + FROM ' . EXTENSION_GROUPS_TABLE . ' + WHERE group_name ' . $this->db->sql_like_expression('EXT_GROUP_' . $this->db->any_char); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql_ary = array( + 'group_name' => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_' + ); + + $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE group_id = ' . $row['group_id']; + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + } + + function fix_firebird_qa_captcha() + { + // Recover from potentially broken Q&A CAPTCHA table on firebird + // Q&A CAPTCHA was uninstallable, so it's safe to remove these + // without data loss + if ($this->db_tools->sql_layer == 'firebird') + { + $tables = array( + $this->table_prefix . 'captcha_questions', + $this->table_prefix . 'captcha_answers', + $this->table_prefix . 'qa_confirm', + ); + foreach ($tables as $table) + { + if ($this->db_tools->sql_table_exists($table)) + { + $this->db_tools->sql_table_drop($table); + } + } + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_9_rc2.php b/phpBB/includes/db/migration/data/3_0_9_rc2.php new file mode 100644 index 0000000000..e3c4716665 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_9_rc2.php @@ -0,0 +1,28 @@ + array( + GROUPS_TABLE => array( + 'group_teampage' => array('UINT', 0, 'after' => 'group_legend'), + ), + PROFILE_FIELDS_TABLE => array( + 'field_show_on_pm' => array('BOOL', 0), + ), + STYLES_TABLE => array( + 'style_path' => array('VCHAR:100', ''), + 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), + 'style_parent_id' => array('UINT:4', 0), + 'style_parent_tree' => array('TEXT', ''), + ), + REPORTS_TABLE => array( + 'reported_post_text' => array('MTEXT_UNI', ''), + 'reported_post_uid' => array('VCHAR:8', ''), + 'reported_post_bitfield' => array('VCHAR:255', ''), + ), + ), + 'change_columns' => array( + GROUPS_TABLE => array( + 'group_legend' => array('UINT', 0), + ), + ), + ); + } + + public function update_data() + { + return array( + array('config.update', array('search_type', 'phpbb_search_' . $this->config['search_type'])), + + array('config.add', array('fulltext_postgres_ts_name', 'simple')), + array('config.add', array('fulltext_postgres_min_word_len', 4)), + array('config.add', array('fulltext_postgres_max_word_len', 254)), + array('config.add', array('fulltext_sphinx_stopwords', 0)), + array('config.add', array('fulltext_sphinx_indexer_mem_limit', 512)), + + array('config.add', array('load_jquery_cdn', 0)), + array('config.add', array('load_jquery_url', '//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js')), + + array('config.add', array('use_system_cron', 0)), + + array('config.add', array('legend_sort_groupname', 0)), + array('config.add', array('teampage_forums', 1)), + array('config.add', array('teampage_memberships', 1)), + + array('config.add', array('load_cpf_pm', 0)), + + array('config.add', array('display_last_subject', 1)), + + array('config.add', array('assets_version', 1)), + + array('config.add', array('site_home_url', '')), + array('config.add', array('site_home_text', '')), + + array('permission.add', array('u_chgprofileinfo', true, 'u_sig')), + + array('module.add', array( + 'acp', + 'ACP_GROUPS', + array( + 'module_basename' => 'acp_groups', + 'modes' => array('position'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_ATTACHMENTS', + array( + 'module_basename' => 'acp_attachments', + 'modes' => array('manage'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_STYLE_MANAGEMENT', + array( + 'module_basename' => 'acp_styles', + 'modes' => array('install', 'cache'), + ), + )), + array('module.add', array( + 'ucp', + 'UCP_PROFILE', + array( + 'module_basename' => 'ucp_profile', + 'modes' => array('autologin_keys'), + ), + )), + // Module will be renamed later + array('module.add', array( + 'acp', + 'ACP_CAT_STYLES', + 'ACP_LANGUAGE' + )), + + array('module.remove', array( + 'acp', + false, + 'ACP_TEMPLATES', + )), + array('module.remove', array( + 'acp', + false, + 'ACP_THEMES', + )), + array('module.remove', array( + 'acp', + false, + 'ACP_IMAGESETS', + )), + + array('custom', array(array($this, 'rename_module_basenames'))), + array('custom', array(array($this, 'rename_styles_module'))), + array('custom', array(array($this, 'add_group_teampage'))), + array('custom', array(array($this, 'update_group_legend'))), + array('custom', array(array($this, 'localise_global_announcements'))), + array('custom', array(array($this, 'update_ucp_pm_basename'))), + array('custom', array(array($this, 'update_ucp_profile_auth'))), + array('custom', array(array($this, 'move_customise_modules'))), + + array('config.update', array('version', '3.1.0-dev')), + ); + } + + public function move_customise_modules() + { + // Move language management to new location in the Customise tab + // First get language module id + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_basename = 'acp_language'"; + $result = $this->db->sql_query($sql); + $language_module_id = $this->db->sql_fetchfield('module_id'); + $this->db->sql_freeresult($result); + // Next get language management module id of the one just created + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = 'ACP_LANGUAGE'"; + $result = $this->db->sql_query($sql); + $language_management_module_id = $this->db->sql_fetchfield('module_id'); + $this->db->sql_freeresult($result); + + if (!class_exists('acp_modules')) + { + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); + } + // acp_modules calls adm_back_link, which is undefined at this point + if (!function_exists('adm_back_link')) + { + include($this->phpbb_root_path . 'includes/functions_acp.' . $this->php_ext); + } + $module_manager = new acp_modules(); + $module_manager->module_class = 'acp'; + $module_manager->move_module($language_module_id, $language_management_module_id); + } + + public function update_ucp_pm_basename() + { + $sql = 'SELECT module_id, module_basename + FROM ' . MODULES_TABLE . " + WHERE module_basename <> 'ucp_pm' AND + module_langname='UCP_PM'"; + $result = $this->db->sql_query_limit($sql, 1); + + if ($row = $this->db->sql_fetchrow($result)) + { + // This update is still not applied. Applying it + + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_basename = 'ucp_pm' + WHERE module_id = " . (int) $row['module_id']; + + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + } + + public function update_ucp_profile_auth() + { + // Update the auth setting for the module + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_auth = 'acl_u_chgprofileinfo' + WHERE module_class = 'ucp' + AND module_basename = 'ucp_profile' + AND module_mode = 'profile_info'"; + $this->sql_query($sql); + } + + public function rename_styles_module() + { + // Rename styles module to Customise + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_langname = 'ACP_CAT_CUSTOMISE' + WHERE module_langname = 'ACP_CAT_STYLES'"; + $this->sql_query($sql); + } + + public function rename_module_basenames() + { + // rename all module basenames to full classname + $sql = 'SELECT module_id, module_basename, module_class + FROM ' . MODULES_TABLE; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $module_id = (int) $row['module_id']; + unset($row['module_id']); + + if (!empty($row['module_basename']) && !empty($row['module_class'])) + { + // all the class names start with class name or with phpbb_ for auto loading + if (strpos($row['module_basename'], $row['module_class'] . '_') !== 0 && + strpos($row['module_basename'], 'phpbb_') !== 0) + { + $row['module_basename'] = $row['module_class'] . '_' . $row['module_basename']; + + $sql_update = $this->db->sql_build_array('UPDATE', $row); + + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET ' . $sql_update . ' + WHERE module_id = ' . $module_id; + $this->sql_query($sql); + } + } + } + + $this->db->sql_freeresult($result); + } + + public function add_group_teampage() + { + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_teampage = 1 + WHERE group_type = ' . GROUP_SPECIAL . " + AND group_name = 'ADMINISTRATORS'"; + $this->sql_query($sql); + + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_teampage = 2 + WHERE group_type = ' . GROUP_SPECIAL . " + AND group_name = 'GLOBAL_MODERATORS'"; + $this->sql_query($sql); + } + + public function update_group_legend() + { + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . ' + WHERE group_legend = 1 + ORDER BY group_name ASC'; + $result = $this->db->sql_query($sql); + + $next_legend = 1; + while ($row = $this->db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_legend = ' . $next_legend . ' + WHERE group_id = ' . (int) $row['group_id']; + $this->sql_query($sql); + + $next_legend++; + } + $this->db->sql_freeresult($result); + } + + public function localise_global_announcements() + { + // Localise Global Announcements + $sql = 'SELECT topic_id, topic_approved, (topic_replies + 1) AS topic_posts, topic_last_post_id, topic_last_post_subject, topic_last_post_time, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour + FROM ' . TOPICS_TABLE . ' + WHERE forum_id = 0 + AND topic_type = ' . POST_GLOBAL; + $result = $this->db->sql_query($sql); + + $global_announcements = $update_lastpost_data = array(); + $update_lastpost_data['forum_last_post_time'] = 0; + $update_forum_data = array( + 'forum_posts' => 0, + 'forum_topics' => 0, + 'forum_topics_real' => 0, + ); + + while ($row = $this->db->sql_fetchrow($result)) + { + $global_announcements[] = (int) $row['topic_id']; + + $update_forum_data['forum_posts'] += (int) $row['topic_posts']; + $update_forum_data['forum_topics_real']++; + if ($row['topic_approved']) + { + $update_forum_data['forum_topics']++; + } + + if ($update_lastpost_data['forum_last_post_time'] < $row['topic_last_post_time']) + { + $update_lastpost_data = array( + 'forum_last_post_id' => (int) $row['topic_last_post_id'], + 'forum_last_post_subject' => $row['topic_last_post_subject'], + 'forum_last_post_time' => (int) $row['topic_last_post_time'], + 'forum_last_poster_id' => (int) $row['topic_last_poster_id'], + 'forum_last_poster_name' => $row['topic_last_poster_name'], + 'forum_last_poster_colour' => $row['topic_last_poster_colour'], + ); + } + } + $this->db->sql_freeresult($result); + + if (!empty($global_announcements)) + { + // Update the post/topic-count for the forum and the last-post if needed + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE forum_type = ' . FORUM_POST; + $result = $this->db->sql_query_limit($sql, 1); + $ga_forum_id = $this->db->sql_fetchfield('forum_id'); + $this->db->sql_freeresult($result); + + $sql = 'SELECT forum_last_post_time + FROM ' . FORUMS_TABLE . ' + WHERE forum_id = ' . $ga_forum_id; + $result = $this->db->sql_query($sql); + $lastpost = (int) $this->db->sql_fetchfield('forum_last_post_time'); + $this->db->sql_freeresult($result); + + $sql_update = 'forum_posts = forum_posts + ' . $update_forum_data['forum_posts'] . ', '; + $sql_update .= 'forum_topics_real = forum_topics_real + ' . $update_forum_data['forum_topics_real'] . ', '; + $sql_update .= 'forum_topics = forum_topics + ' . $update_forum_data['forum_topics']; + if ($lastpost < $update_lastpost_data['forum_last_post_time']) + { + $sql_update .= ', ' . $this->db->sql_build_array('UPDATE', $update_lastpost_data); + } + + $sql = 'UPDATE ' . FORUMS_TABLE . ' + SET ' . $sql_update . ' + WHERE forum_id = ' . $ga_forum_id; + $this->sql_query($sql); + + // Update some forum_ids + $table_ary = array(TOPICS_TABLE, POSTS_TABLE, LOG_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE); + foreach ($table_ary as $table) + { + $sql = "UPDATE $table + SET forum_id = $ga_forum_id + WHERE " . $this->db->sql_in_set('topic_id', $global_announcements); + $this->sql_query($sql); + } + unset($table_ary); + } + } +} diff --git a/phpBB/includes/db/migration/data/extensions.php b/phpBB/includes/db/migration/data/extensions.php new file mode 100644 index 0000000000..b8379483a3 --- /dev/null +++ b/phpBB/includes/db/migration/data/extensions.php @@ -0,0 +1,55 @@ + array( + EXT_TABLE => array( + 'COLUMNS' => array( + 'ext_name' => array('VCHAR', ''), + 'ext_active' => array('BOOL', 0), + 'ext_state' => array('TEXT', ''), + ), + 'KEYS' => array( + 'ext_name' => array('UNIQUE', 'ext_name'), + ), + ), + ), + ); + } + + public function update_data() + { + return array( + // Module will be renamed later + array('module.add', array( + 'acp', + 'ACP_CAT_STYLES', + 'ACP_EXTENSION_MANAGEMENT' + )), + array('module.add', array( + 'acp', + 'ACP_EXTENSION_MANAGEMENT', + array( + 'module_basename' => 'acp_extensions', + 'modes' => array('main'), + ), + )), + array('permission.add', array('a_extensions', true, 'a_styles')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/style_update_p1.php b/phpBB/includes/db/migration/data/style_update_p1.php new file mode 100644 index 0000000000..387b37de8e --- /dev/null +++ b/phpBB/includes/db/migration/data/style_update_p1.php @@ -0,0 +1,157 @@ +phpbb_root_path . 'styles'); + $skip_dirs = array('.', '..', 'prosilver'); + foreach ($iterator as $fileinfo) + { + if ($fileinfo->isDir() && !in_array($fileinfo->getFilename(), $skip_dirs) && file_exists($fileinfo->getPathname() . '/style.cfg')) + { + $style_cfg = parse_cfg_file($fileinfo->getPathname() . '/style.cfg'); + if (isset($style_cfg['phpbb_version']) && version_compare($style_cfg['phpbb_version'], '3.1.0-dev', '>=')) + { + // 3.1 style + $available_styles[] = $fileinfo->getFilename(); + } + } + } + + // Get all installed styles + if ($this->db_tools->sql_table_exists(STYLES_IMAGESET_TABLE)) + { + $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id, i.imageset_path + FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . " i + WHERE t.template_id = s.template_id + AND c.theme_id = s.theme_id + AND i.imageset_id = s.imageset_id"; + } + else + { + $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id + FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . " c + WHERE t.template_id = s.template_id + AND c.theme_id = s.theme_id"; + } + $result = $this->db->sql_query($sql); + + $styles = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $styles[] = $row; + } + $this->db->sql_freeresult($result); + + // Decide which styles to keep, all others will be deleted + $valid_styles = array(); + foreach ($styles as $style_row) + { + if ( + // Delete styles with parent style (not supported yet) + $style_row['template_inherits_id'] == 0 && + // Check if components match + $style_row['template_path'] == $style_row['theme_path'] && (!isset($style_row['imageset_path']) || $style_row['template_path'] == $style_row['imageset_path']) && + // Check if components are valid + in_array($style_row['template_path'], $available_styles) + ) + { + // Valid style. Keep it + $sql_ary = array( + 'style_path' => $style_row['template_path'], + 'bbcode_bitfield' => $style_row['bbcode_bitfield'], + 'style_parent_id' => 0, + 'style_parent_tree' => '', + ); + $this->sql_query('UPDATE ' . STYLES_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE style_id = ' . $style_row['style_id']); + $valid_styles[] = (int) $style_row['style_id']; + } + } + + // Remove old entries from styles table + if (!sizeof($valid_styles)) + { + // No valid styles: remove everything and add prosilver + $this->sql_query('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary); + + $sql_ary = array( + 'style_name' => 'prosilver', + 'style_copyright' => '© phpBB Group', + 'style_active' => 1, + 'style_path' => 'prosilver', + 'bbcode_bitfield' => 'lNg=', + 'style_parent_id' => 0, + 'style_parent_tree' => '', + + // Will be removed in the next step + 'imageset_id' => 0, + 'template_id' => 0, + 'theme_id' => 0, + ); + + $sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->sql_query($sql); + + $sql = 'SELECT style_id + FROM ' . $table . " + WHERE style_name = 'prosilver'"; + $result = $this->sql_query($sql); + $default_style = $this->db->sql_fetchfield($result); + $this->db->sql_freeresult($result); + + set_config('default_style', $default_style); + + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0'; + $this->sql_query($sql); + } + else + { + // There are valid styles in styles table. Remove styles that are outdated + $this->sql_query('DELETE FROM ' . STYLES_TABLE . ' + WHERE ' . $this->db->sql_in_set('style_id', $valid_styles, true)); + + // Change default style + if (!in_array($this->config['default_style'], $valid_styles)) + { + $this->sql_query('UPDATE ' . CONFIG_TABLE . " + SET config_value = '" . $valid_styles[0] . "' + WHERE config_name = 'default_style'"); + } + + // Reset styles for users + $this->sql_query('UPDATE ' . USERS_TABLE . ' + SET user_style = 0 + WHERE ' . $this->db->sql_in_set('user_style', $valid_styles, true)); + } + } +} diff --git a/phpBB/includes/db/migration/data/style_update_p2.php b/phpBB/includes/db/migration/data/style_update_p2.php new file mode 100644 index 0000000000..db4b7f1753 --- /dev/null +++ b/phpBB/includes/db/migration/data/style_update_p2.php @@ -0,0 +1,42 @@ + array( + STYLES_TABLE => array( + 'imageset_id', + 'template_id', + 'theme_id', + ), + ), + + 'drop_tables' => array( + STYLES_IMAGESET_TABLE, + STYLES_IMAGESET_DATA_TABLE, + STYLES_TEMPLATE_TABLE, + STYLES_TEMPLATE_DATA_TABLE, + STYLES_THEME_TABLE, + ), + ); + } + + public function update_data() + { + return array(); + } +} diff --git a/phpBB/includes/db/migration/data/timezone.php b/phpBB/includes/db/migration/data/timezone.php new file mode 100644 index 0000000000..7734ed4b76 --- /dev/null +++ b/phpBB/includes/db/migration/data/timezone.php @@ -0,0 +1,161 @@ + array( + USERS_TABLE => array( + 'user_timezone' => array('VCHAR:100', ''), + ), + ), + ); + } + + public function update_data() + { + return array( + array('custom', array(array($this, 'update_timezones'))), + ); + } + + public function update_timezones() + { + // Update user timezones + $sql = 'SELECT user_dst, user_timezone + FROM ' . USERS_TABLE . ' + GROUP BY user_timezone, user_dst'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_timezone = '" . $this->db->sql_escape($this->convert_phpbb30_timezone($row['user_timezone'], $row['user_dst'])) . "' + WHERE user_timezone = '" . $this->db->sql_escape($row['user_timezone']) . "' + AND user_dst = " . (int) $row['user_dst']; + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + + // Update board default timezone + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET config_value = '" . $this->convert_phpbb30_timezone($this->config['board_timezone'], $this->config['board_dst']) . "' + WHERE config_name = 'board_timezone'"; + $this->sql_query($sql); + + // After we have calculated the timezones we can delete user_dst column from user table. + $this->db_tools->sql_column_remove(USERS_TABLE, 'user_dst'); + } + + /** + * Determine the new timezone for a given phpBB 3.0 timezone and + * "Daylight Saving Time" option + * + * @param $timezone float Users timezone in 3.0 + * @param $dst int Users daylight saving time + * @return string Users new php Timezone which is used since 3.1 + */ + public function convert_phpbb30_timezone($timezone, $dst) + { + $offset = $timezone + $dst; + + switch ($timezone) + { + case '-12': + return 'Etc/GMT+' . abs($offset); //'[UTC - 12] Baker Island Time' + case '-11': + return 'Etc/GMT+' . abs($offset); //'[UTC - 11] Niue Time, Samoa Standard Time' + case '-10': + return 'Etc/GMT+' . abs($offset); //'[UTC - 10] Hawaii-Aleutian Standard Time, Cook Island Time' + case '-9.5': + return 'Pacific/Marquesas'; //'[UTC - 9:30] Marquesas Islands Time' + case '-9': + return 'Etc/GMT+' . abs($offset); //'[UTC - 9] Alaska Standard Time, Gambier Island Time' + case '-8': + return 'Etc/GMT+' . abs($offset); //'[UTC - 8] Pacific Standard Time' + case '-7': + return 'Etc/GMT+' . abs($offset); //'[UTC - 7] Mountain Standard Time' + case '-6': + return 'Etc/GMT+' . abs($offset); //'[UTC - 6] Central Standard Time' + case '-5': + return 'Etc/GMT+' . abs($offset); //'[UTC - 5] Eastern Standard Time' + case '-4.5': + return 'America/Caracas'; //'[UTC - 4:30] Venezuelan Standard Time' + case '-4': + return 'Etc/GMT+' . abs($offset); //'[UTC - 4] Atlantic Standard Time' + case '-3.5': + return 'America/St_Johns'; //'[UTC - 3:30] Newfoundland Standard Time' + case '-3': + return 'Etc/GMT+' . abs($offset); //'[UTC - 3] Amazon Standard Time, Central Greenland Time' + case '-2': + return 'Etc/GMT+' . abs($offset); //'[UTC - 2] Fernando de Noronha Time, South Georgia & the South Sandwich Islands Time' + case '-1': + return 'Etc/GMT+' . abs($offset); //'[UTC - 1] Azores Standard Time, Cape Verde Time, Eastern Greenland Time' + case '0': + return (!$dst) ? 'UTC' : 'Etc/GMT-1'; //'[UTC] Western European Time, Greenwich Mean Time' + case '1': + return 'Etc/GMT-' . $offset; //'[UTC + 1] Central European Time, West African Time' + case '2': + return 'Etc/GMT-' . $offset; //'[UTC + 2] Eastern European Time, Central African Time' + case '3': + return 'Etc/GMT-' . $offset; //'[UTC + 3] Moscow Standard Time, Eastern African Time' + case '3.5': + return 'Asia/Tehran'; //'[UTC + 3:30] Iran Standard Time' + case '4': + return 'Etc/GMT-' . $offset; //'[UTC + 4] Gulf Standard Time, Samara Standard Time' + case '4.5': + return 'Asia/Kabul'; //'[UTC + 4:30] Afghanistan Time' + case '5': + return 'Etc/GMT-' . $offset; //'[UTC + 5] Pakistan Standard Time, Yekaterinburg Standard Time' + case '5.5': + return 'Asia/Kolkata'; //'[UTC + 5:30] Indian Standard Time, Sri Lanka Time' + case '5.75': + return 'Asia/Kathmandu'; //'[UTC + 5:45] Nepal Time' + case '6': + return 'Etc/GMT-' . $offset; //'[UTC + 6] Bangladesh Time, Bhutan Time, Novosibirsk Standard Time' + case '6.5': + return 'Indian/Cocos'; //'[UTC + 6:30] Cocos Islands Time, Myanmar Time' + case '7': + return 'Etc/GMT-' . $offset; //'[UTC + 7] Indochina Time, Krasnoyarsk Standard Time' + case '8': + return 'Etc/GMT-' . $offset; //'[UTC + 8] Chinese Standard Time, Australian Western Standard Time, Irkutsk Standard Time' + case '8.75': + return 'Australia/Eucla'; //'[UTC + 8:45] Southeastern Western Australia Standard Time' + case '9': + return 'Etc/GMT-' . $offset; //'[UTC + 9] Japan Standard Time, Korea Standard Time, Chita Standard Time' + case '9.5': + return 'Australia/ACT'; //'[UTC + 9:30] Australian Central Standard Time' + case '10': + return 'Etc/GMT-' . $offset; //'[UTC + 10] Australian Eastern Standard Time, Vladivostok Standard Time' + case '10.5': + return 'Australia/Lord_Howe'; //'[UTC + 10:30] Lord Howe Standard Time' + case '11': + return 'Etc/GMT-' . $offset; //'[UTC + 11] Solomon Island Time, Magadan Standard Time' + case '11.5': + return 'Pacific/Norfolk'; //'[UTC + 11:30] Norfolk Island Time' + case '12': + return 'Etc/GMT-12'; //'[UTC + 12] New Zealand Time, Fiji Time, Kamchatka Standard Time' + case '12.75': + return 'Pacific/Chatham'; //'[UTC + 12:45] Chatham Islands Time' + case '13': + return 'Pacific/Tongatapu'; //'[UTC + 13] Tonga Time, Phoenix Islands Time' + case '14': + return 'Pacific/Kiritimati'; //'[UTC + 14] Line Island Time' + default: + return 'UTC'; + } + } +} diff --git a/phpBB/includes/update_helpers.php b/phpBB/includes/update_helpers.php deleted file mode 100644 index 69d678b2f8..0000000000 --- a/phpBB/includes/update_helpers.php +++ /dev/null @@ -1,112 +0,0 @@ - Date: Thu, 10 Jan 2013 17:18:12 -0600 Subject: [feature/migrations] Revert schema for migration data PHPBB3-9737 --- phpBB/includes/db/migration/data/3_0_1.php | 5 -- phpBB/includes/db/migration/data/3_0_10.php | 5 -- phpBB/includes/db/migration/data/3_0_10_rc1.php | 5 -- phpBB/includes/db/migration/data/3_0_10_rc2.php | 5 -- phpBB/includes/db/migration/data/3_0_10_rc3.php | 5 -- phpBB/includes/db/migration/data/3_0_11.php | 5 -- phpBB/includes/db/migration/data/3_0_11_rc1.php | 5 -- phpBB/includes/db/migration/data/3_0_11_rc2.php | 11 +++ phpBB/includes/db/migration/data/3_0_12_rc1.php | 5 -- phpBB/includes/db/migration/data/3_0_1_rc1.php | 14 +++- phpBB/includes/db/migration/data/3_0_2.php | 5 -- phpBB/includes/db/migration/data/3_0_2_rc1.php | 5 -- phpBB/includes/db/migration/data/3_0_2_rc2.php | 22 ++++- phpBB/includes/db/migration/data/3_0_3.php | 5 -- phpBB/includes/db/migration/data/3_0_3_rc1.php | 15 ++++ phpBB/includes/db/migration/data/3_0_4.php | 5 -- phpBB/includes/db/migration/data/3_0_4_rc1.php | 11 +++ phpBB/includes/db/migration/data/3_0_5.php | 5 -- .../includes/db/migration/data/3_0_5_rc1part2.php | 4 +- phpBB/includes/db/migration/data/3_0_6.php | 5 -- phpBB/includes/db/migration/data/3_0_6_rc1.php | 40 +++++++++ phpBB/includes/db/migration/data/3_0_6_rc2.php | 5 -- phpBB/includes/db/migration/data/3_0_6_rc3.php | 5 -- phpBB/includes/db/migration/data/3_0_6_rc4.php | 5 -- phpBB/includes/db/migration/data/3_0_7.php | 5 -- phpBB/includes/db/migration/data/3_0_7_pl1.php | 5 -- phpBB/includes/db/migration/data/3_0_7_rc1.php | 20 ++++- phpBB/includes/db/migration/data/3_0_7_rc2.php | 5 -- phpBB/includes/db/migration/data/3_0_8.php | 5 -- phpBB/includes/db/migration/data/3_0_8_rc1.php | 5 -- phpBB/includes/db/migration/data/3_0_9.php | 5 -- phpBB/includes/db/migration/data/3_0_9_rc1.php | 9 ++ phpBB/includes/db/migration/data/3_0_9_rc2.php | 5 -- phpBB/includes/db/migration/data/3_0_9_rc3.php | 5 -- phpBB/includes/db/migration/data/3_0_9_rc4.php | 5 -- phpBB/includes/db/migration/data/3_1_0_dev.php | 37 ++++++-- phpBB/includes/db/migration/data/extensions.php | 11 ++- .../includes/db/migration/data/style_update_p1.php | 11 +-- .../includes/db/migration/data/style_update_p2.php | 98 ++++++++++++++++++++-- phpBB/includes/db/migration/data/timezone.php | 11 +-- phpBB/includes/db/migration/data/timezone_p2.php | 38 +++++++++ 41 files changed, 314 insertions(+), 168 deletions(-) create mode 100644 phpBB/includes/db/migration/data/timezone_p2.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/3_0_1.php b/phpBB/includes/db/migration/data/3_0_1.php index a2332c9b59..d71288c64b 100644 --- a/phpBB/includes/db/migration/data/3_0_1.php +++ b/phpBB/includes/db/migration/data/3_0_1.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_1 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_1_rc1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_10.php b/phpBB/includes/db/migration/data/3_0_10.php index 07410c5ba1..17472562f2 100644 --- a/phpBB/includes/db/migration/data/3_0_10.php +++ b/phpBB/includes/db/migration/data/3_0_10.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_10 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_10_rc3'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_10_rc1.php b/phpBB/includes/db/migration/data/3_0_10_rc1.php index daac50a631..eebee44e39 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc1.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_10_rc1 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_9'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_10_rc2.php b/phpBB/includes/db/migration/data/3_0_10_rc2.php index 234e4c5fc7..b81fde9bcb 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc2.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_10_rc2 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_10_rc1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_10_rc3.php b/phpBB/includes/db/migration/data/3_0_10_rc3.php index 075ce35e3e..d97b0b4aec 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc3.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_10_rc3 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_10_rc2'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_11.php b/phpBB/includes/db/migration/data/3_0_11.php index 0bc9b6c4a5..b149cd374c 100644 --- a/phpBB/includes/db/migration/data/3_0_11.php +++ b/phpBB/includes/db/migration/data/3_0_11.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_11 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_11_rc2'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_11_rc1.php b/phpBB/includes/db/migration/data/3_0_11_rc1.php index 752efd72b2..3d4920bf49 100644 --- a/phpBB/includes/db/migration/data/3_0_11_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_11_rc1.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_11_rc1 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_10'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_11_rc2.php b/phpBB/includes/db/migration/data/3_0_11_rc2.php index f2bed54085..e0638f02d7 100644 --- a/phpBB/includes/db/migration/data/3_0_11_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_11_rc2.php @@ -25,6 +25,17 @@ class phpbb_db_migration_data_3_0_11_rc2 extends phpbb_db_migration ); } + function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_novalue', + ), + ), + ); + } + function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_12_rc1.php b/phpBB/includes/db/migration/data/3_0_12_rc1.php index 0d8702f19e..0b35de2ed5 100644 --- a/phpBB/includes/db/migration/data/3_0_12_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_12_rc1.php @@ -16,11 +16,6 @@ class phpbb_db_migration_data_3_0_12_rc1 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_11'); } - public function update_schema() - { - return array(); - } - public function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_1_rc1.php b/phpBB/includes/db/migration/data/3_0_1_rc1.php index cf067d2e2c..a7af5d052d 100644 --- a/phpBB/includes/db/migration/data/3_0_1_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_1_rc1.php @@ -26,7 +26,9 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration ), ), 'drop_keys' => array( - $this->table_prefix . 'groups' => array('group_legend'), + $this->table_prefix . 'groups' => array( + 'group_legend', + ), ), 'add_index' => array( $this->table_prefix . 'sessions' => array( @@ -52,12 +54,16 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration ), 'add_index' => array( $this->table_prefix . 'groups' => array( - 'group_legend' => 'group_legend', + 'group_legend' => array('group_legend'), ), ), 'drop_keys' => array( - $this->table_prefix . 'sessions' => array('session_forum_id'), - $this->table_prefix . 'groups' => array('group_legend_name'), + $this->table_prefix . 'sessions' => array( + 'session_forum_id', + ), + $this->table_prefix . 'groups' => array( + 'group_legend_name', + ), ), ); } diff --git a/phpBB/includes/db/migration/data/3_0_2.php b/phpBB/includes/db/migration/data/3_0_2.php index 3469d8d178..19e9213262 100644 --- a/phpBB/includes/db/migration/data/3_0_2.php +++ b/phpBB/includes/db/migration/data/3_0_2.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_2 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_2_rc2'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_2_rc1.php b/phpBB/includes/db/migration/data/3_0_2_rc1.php index d3c2200f14..7dd321d83c 100644 --- a/phpBB/includes/db/migration/data/3_0_2_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_2_rc1.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_2_rc1 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_2_rc2.php b/phpBB/includes/db/migration/data/3_0_2_rc2.php index 67fd1faec6..d73f9587c3 100644 --- a/phpBB/includes/db/migration/data/3_0_2_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_2_rc2.php @@ -36,7 +36,9 @@ class phpbb_db_migration_data_3_0_2_rc2 extends phpbb_db_migration ), ), 'drop_keys' => array( - $this->table_prefix . 'sessions' => array('session_forum_id'), + $this->table_prefix . 'sessions' => array( + 'session_forum_id', + ), ), 'add_index' => array( $this->table_prefix . 'sessions' => array( @@ -46,6 +48,24 @@ class phpbb_db_migration_data_3_0_2_rc2 extends phpbb_db_migration ); } + function revert_schema() + { + return array( + 'add_index' => array( + $this->table_prefix . 'sessions' => array( + 'session_forum_id' => array( + 'session_forum_id', + ), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'sessions' => array( + 'session_fid', + ), + ), + ); + } + function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_3.php b/phpBB/includes/db/migration/data/3_0_3.php index dff375f438..d671b0cac3 100644 --- a/phpBB/includes/db/migration/data/3_0_3.php +++ b/phpBB/includes/db/migration/data/3_0_3.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_3 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_3_rc1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_3_rc1.php b/phpBB/includes/db/migration/data/3_0_3_rc1.php index 2320c4ac4b..9cce80be74 100644 --- a/phpBB/includes/db/migration/data/3_0_3_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_3_rc1.php @@ -29,6 +29,21 @@ class phpbb_db_migration_data_3_0_3_rc1 extends phpbb_db_migration ); } + function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'styles_template' => array( + 'template_inherits_id', + 'template_inherit_path', + ), + $this->table_prefix . 'groups' => array( + 'group_max_recipients', + ), + ), + ); + } + function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_4.php b/phpBB/includes/db/migration/data/3_0_4.php index 1af4508331..e734814530 100644 --- a/phpBB/includes/db/migration/data/3_0_4.php +++ b/phpBB/includes/db/migration/data/3_0_4.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_4 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_4_rc1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_4_rc1.php b/phpBB/includes/db/migration/data/3_0_4_rc1.php index e9bb0e01f5..eb2fcb8d0e 100644 --- a/phpBB/includes/db/migration/data/3_0_4_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_4_rc1.php @@ -55,6 +55,17 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration ); } + function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_profile', + ), + ), + ); + } + function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_5.php b/phpBB/includes/db/migration/data/3_0_5.php index 2f80970781..6d61793d08 100644 --- a/phpBB/includes/db/migration/data/3_0_5.php +++ b/phpBB/includes/db/migration/data/3_0_5.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_5 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_5_rc1part2'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php index 1fab0f8873..354de748c8 100644 --- a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php +++ b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php @@ -18,10 +18,10 @@ class phpbb_db_migration_data_3_0_5_rc1part2 extends phpbb_db_migration { return array( 'drop_keys' => array( - ACL_OPTIONS_TABLE => array('auth_option'), + $this->table_prefix . 'acl_options' => array('auth_option'), ), 'add_unique_index' => array( - ACL_OPTIONS_TABLE => array( + $this->table_prefix . 'acl_options' => array( 'auth_option' => array('auth_option'), ), ), diff --git a/phpBB/includes/db/migration/data/3_0_6.php b/phpBB/includes/db/migration/data/3_0_6.php index 26176b9437..cc6fccaae2 100644 --- a/phpBB/includes/db/migration/data/3_0_6.php +++ b/phpBB/includes/db/migration/data/3_0_6.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_6 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_6_rc4'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_6_rc1.php b/phpBB/includes/db/migration/data/3_0_6_rc1.php index 35adcf52be..b520bda6d0 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc1.php @@ -59,6 +59,46 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration ); } + function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'confirm' => array( + 'attempts', + ), + $this->table_prefix . 'users' => array( + 'user_new', + 'user_reminded', + 'user_reminded_time', + ), + $this->table_prefix . 'groups' => array( + 'group_skip_auth', + ), + $this->table_prefix . 'privmsgs' => array( + 'message_reported', + ), + $this->table_prefix . 'reports' => array( + 'pm_id', + ), + $this->table_prefix . 'profile_fields' => array( + 'field_show_on_vt', + ), + $this->table_prefix . 'forums' => array( + 'forum_options', + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'reports' => array( + 'post_id', + 'pm_id', + ), + $this->table_prefix . 'posts' => array( + 'post_username', + ), + ), + ); + } + function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_6_rc2.php b/phpBB/includes/db/migration/data/3_0_6_rc2.php index 4092a5fa61..d61c296445 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc2.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_6_rc2 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_6_rc1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_6_rc3.php b/phpBB/includes/db/migration/data/3_0_6_rc3.php index ec22d1da77..a3f0dcacdf 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc3.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_6_rc3 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_6_rc2'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_6_rc4.php b/phpBB/includes/db/migration/data/3_0_6_rc4.php index e748c7a4ff..3855b85551 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc4.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc4.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_6_rc4 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_6_rc3'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_7.php b/phpBB/includes/db/migration/data/3_0_7.php index f27b56f778..59779c9cb0 100644 --- a/phpBB/includes/db/migration/data/3_0_7.php +++ b/phpBB/includes/db/migration/data/3_0_7.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_7 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_7_rc2'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_7_pl1.php b/phpBB/includes/db/migration/data/3_0_7_pl1.php index 5543d6437a..5570a5dc06 100644 --- a/phpBB/includes/db/migration/data/3_0_7_pl1.php +++ b/phpBB/includes/db/migration/data/3_0_7_pl1.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_7_pl1 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_7'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_7_rc1.php b/phpBB/includes/db/migration/data/3_0_7_rc1.php index 71584382e8..84b8f798a8 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc1.php @@ -18,7 +18,9 @@ class phpbb_db_migration_data_3_0_7_rc1 extends phpbb_db_migration { return array( 'drop_keys' => array( - $this->table_prefix . 'log' => array('log_time'), + $this->table_prefix . 'log' => array( + 'log_time', + ), ), 'add_index' => array( $this->table_prefix . 'topics_track' => array( @@ -28,6 +30,22 @@ class phpbb_db_migration_data_3_0_7_rc1 extends phpbb_db_migration ); } + function revert_schema() + { + return array( + 'add_index' => array( + $this->table_prefix . 'log' => array( + 'log_time' => array('log_time'), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'topics_track' => array( + 'topic_id', + ), + ), + ); + } + function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_7_rc2.php b/phpBB/includes/db/migration/data/3_0_7_rc2.php index 4e380c810d..48aa818ba3 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc2.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_7_rc2 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_7_rc1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_8.php b/phpBB/includes/db/migration/data/3_0_8.php index a5defc8278..d94fe869fb 100644 --- a/phpBB/includes/db/migration/data/3_0_8.php +++ b/phpBB/includes/db/migration/data/3_0_8.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_8 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_8_rc1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_8_rc1.php b/phpBB/includes/db/migration/data/3_0_8_rc1.php index 78db06b512..eb4cc5bd1a 100644 --- a/phpBB/includes/db/migration/data/3_0_8_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_8_rc1.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_7_pl1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_9.php b/phpBB/includes/db/migration/data/3_0_9.php index eb359e2697..d19a24b45e 100644 --- a/phpBB/includes/db/migration/data/3_0_9.php +++ b/phpBB/includes/db/migration/data/3_0_9.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_9 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_9_rc4'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_9_rc1.php b/phpBB/includes/db/migration/data/3_0_9_rc1.php index ea49cdbba9..4ed48061a4 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc1.php @@ -51,6 +51,15 @@ class phpbb_db_migration_data_3_0_9_rc1 extends phpbb_db_migration ); } + function revert_schema() + { + return array( + 'drop_tables' => array( + $this->table_prefix . 'login_attempts', + ), + ); + } + function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_9_rc2.php b/phpBB/includes/db/migration/data/3_0_9_rc2.php index e3c4716665..98ef232cb4 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc2.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_9_rc2 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_9_rc1'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_9_rc3.php b/phpBB/includes/db/migration/data/3_0_9_rc3.php index 3cdecb96ae..b84d61031e 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc3.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_9_rc3 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_9_rc2'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_9_rc4.php b/phpBB/includes/db/migration/data/3_0_9_rc4.php index c2a92e618a..2a00bba843 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc4.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc4.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_3_0_9_rc4 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_9_rc3'); } - function update_schema() - { - return array(); - } - function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/3_1_0_dev.php b/phpBB/includes/db/migration/data/3_1_0_dev.php index 2771d82d83..4f7ed07158 100644 --- a/phpBB/includes/db/migration/data/3_1_0_dev.php +++ b/phpBB/includes/db/migration/data/3_1_0_dev.php @@ -15,7 +15,7 @@ class phpbb_db_migration_data_3_1_0_dev extends phpbb_db_migration 'phpbb_db_migration_data_3_0_11', 'phpbb_db_migration_data_extensions', 'phpbb_db_migration_data_style_update_p2', - 'phpbb_db_migration_data_timezone', + 'phpbb_db_migration_data_timezone_p2', ); } @@ -23,32 +23,57 @@ class phpbb_db_migration_data_3_1_0_dev extends phpbb_db_migration { return array( 'add_columns' => array( - GROUPS_TABLE => array( + $this->table_prefix . 'groups' => array( 'group_teampage' => array('UINT', 0, 'after' => 'group_legend'), ), - PROFILE_FIELDS_TABLE => array( + $this->table_prefix . 'profile_fields' => array( 'field_show_on_pm' => array('BOOL', 0), ), - STYLES_TABLE => array( + $this->table_prefix . 'styles' => array( 'style_path' => array('VCHAR:100', ''), 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), 'style_parent_id' => array('UINT:4', 0), 'style_parent_tree' => array('TEXT', ''), ), - REPORTS_TABLE => array( + $this->table_prefix . 'reports' => array( 'reported_post_text' => array('MTEXT_UNI', ''), 'reported_post_uid' => array('VCHAR:8', ''), 'reported_post_bitfield' => array('VCHAR:255', ''), ), ), 'change_columns' => array( - GROUPS_TABLE => array( + $this->table_prefix . 'groups' => array( 'group_legend' => array('UINT', 0), ), ), ); } + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'groups' => array( + 'group_teampage', + ), + $this->table_prefix . 'profile_fields' => array( + 'field_show_on_pm', + ), + $this->table_prefix . 'styles' => array( + 'style_path', + 'bbcode_bitfield', + 'style_parent_id', + 'style_parent_tree', + ), + $this->table_prefix . 'reports' => array( + 'reported_post_text', + 'reported_post_uid', + 'reported_post_bitfield', + ), + ), + ); + } + public function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/extensions.php b/phpBB/includes/db/migration/data/extensions.php index b8379483a3..b5f5b792cf 100644 --- a/phpBB/includes/db/migration/data/extensions.php +++ b/phpBB/includes/db/migration/data/extensions.php @@ -18,7 +18,7 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration { return array( 'add_tables' => array( - EXT_TABLE => array( + $this->table_prefix . 'ext' => array( 'COLUMNS' => array( 'ext_name' => array('VCHAR', ''), 'ext_active' => array('BOOL', 0), @@ -32,6 +32,15 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration ); } + public function revert_schema() + { + return array( + 'drop_tables' => array( + $this->table_prefix . 'ext', + ), + ); + } + public function update_data() { return array( diff --git a/phpBB/includes/db/migration/data/style_update_p1.php b/phpBB/includes/db/migration/data/style_update_p1.php index 387b37de8e..f1b26f525a 100644 --- a/phpBB/includes/db/migration/data/style_update_p1.php +++ b/phpBB/includes/db/migration/data/style_update_p1.php @@ -14,11 +14,6 @@ class phpbb_db_migration_data_style_update_p1 extends phpbb_db_migration return array('phpbb_db_migration_data_3_0_11'); } - public function update_schema() - { - return array(); - } - public function update_data() { return array( @@ -47,10 +42,10 @@ class phpbb_db_migration_data_style_update_p1 extends phpbb_db_migration } // Get all installed styles - if ($this->db_tools->sql_table_exists(STYLES_IMAGESET_TABLE)) + if ($this->db_tools->sql_table_exists($this->table_prefix . 'styles_imageset')) { $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id, i.imageset_path - FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . " i + FROM ' . STYLES_TABLE . ' s, ' . $this->table_prefix . 'styles_template t, ' . $this->table_prefix . 'styles_theme c, ' . $this->table_prefix . "styles_imageset i WHERE t.template_id = s.template_id AND c.theme_id = s.theme_id AND i.imageset_id = s.imageset_id"; @@ -58,7 +53,7 @@ class phpbb_db_migration_data_style_update_p1 extends phpbb_db_migration else { $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id - FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . " c + FROM ' . STYLES_TABLE . ' s, ' . $this->table_prefix . 'styles_template t, ' . $this->table_prefix . "stles_theme c WHERE t.template_id = s.template_id AND c.theme_id = s.theme_id"; } diff --git a/phpBB/includes/db/migration/data/style_update_p2.php b/phpBB/includes/db/migration/data/style_update_p2.php index db4b7f1753..361eb5a389 100644 --- a/phpBB/includes/db/migration/data/style_update_p2.php +++ b/phpBB/includes/db/migration/data/style_update_p2.php @@ -18,7 +18,7 @@ class phpbb_db_migration_data_style_update_p2 extends phpbb_db_migration { return array( 'drop_columns' => array( - STYLES_TABLE => array( + $this->table_prefix . 'styles' => array( 'imageset_id', 'template_id', 'theme_id', @@ -26,17 +26,99 @@ class phpbb_db_migration_data_style_update_p2 extends phpbb_db_migration ), 'drop_tables' => array( - STYLES_IMAGESET_TABLE, - STYLES_IMAGESET_DATA_TABLE, - STYLES_TEMPLATE_TABLE, - STYLES_TEMPLATE_DATA_TABLE, - STYLES_THEME_TABLE, + $this->table_prefix . 'styles_imageset', + $this->table_prefix . 'styles_imageset_data', + $this->table_prefix . 'styles_template', + $this->table_prefix . 'styles_template_data', + $this->table_prefix . 'styles_theme', ), ); } - public function update_data() + public function revert_schema() { - return array(); + return array( + 'add_columns' => array( + $this->table_prefix . 'styles' => array( + 'imageset_id' => array('UINT', 0), + 'template_id' => array('UINT', 0), + 'theme_id' => array('UINT', 0), + ), + ), + + 'add_tables' => array( + $this->table_prefix . 'styles_imageset' => array( + 'COLUMNS' => array( + 'imageset_id' => array('UINT', NULL, 'auto_increment'), + 'imageset_name' => array('VCHAR_UNI:255', ''), + 'imageset_copyright' => array('VCHAR_UNI', ''), + 'imageset_path' => array('VCHAR:100', ''), + ), + 'PRIMARY_KEY' => 'imageset_id', + 'KEYS' => array( + 'imgset_nm' => array('UNIQUE', 'imageset_name'), + ), + ), + $this->table_prefix . 'styles_imageset_data' => array( + 'COLUMNS' => array( + 'image_id' => array('UINT', NULL, 'auto_increment'), + 'image_name' => array('VCHAR:200', ''), + 'image_filename' => array('VCHAR:200', ''), + 'image_lang' => array('VCHAR:30', ''), + 'image_height' => array('USINT', 0), + 'image_width' => array('USINT', 0), + 'imageset_id' => array('UINT', 0), + ), + 'PRIMARY_KEY' => 'image_id', + 'KEYS' => array( + 'i_d' => array('INDEX', 'imageset_id'), + ), + ), + $this->table_prefix . 'styles_template' => array( + 'COLUMNS' => array( + 'template_id' => array('UINT', NULL, 'auto_increment'), + 'template_name' => array('VCHAR_UNI:255', ''), + 'template_copyright' => array('VCHAR_UNI', ''), + 'template_path' => array('VCHAR:100', ''), + 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), + 'template_storedb' => array('BOOL', 0), + 'template_inherits_id' => array('UINT:4', 0), + 'template_inherit_path' => array('VCHAR', ''), + ), + 'PRIMARY_KEY' => 'template_id', + 'KEYS' => array( + 'tmplte_nm' => array('UNIQUE', 'template_name'), + ), + ), + $this->table_prefix . 'styles_template_data' => array( + 'COLUMNS' => array( + 'template_id' => array('UINT', 0), + 'template_filename' => array('VCHAR:100', ''), + 'template_included' => array('TEXT', ''), + 'template_mtime' => array('TIMESTAMP', 0), + 'template_data' => array('MTEXT_UNI', ''), + ), + 'KEYS' => array( + 'tid' => array('INDEX', 'template_id'), + 'tfn' => array('INDEX', 'template_filename'), + ), + ), + $this->table_prefix . 'styles_theme' => array( + 'COLUMNS' => array( + 'theme_id' => array('UINT', NULL, 'auto_increment'), + 'theme_name' => array('VCHAR_UNI:255', ''), + 'theme_copyright' => array('VCHAR_UNI', ''), + 'theme_path' => array('VCHAR:100', ''), + 'theme_storedb' => array('BOOL', 0), + 'theme_mtime' => array('TIMESTAMP', 0), + 'theme_data' => array('MTEXT_UNI', ''), + ), + 'PRIMARY_KEY' => 'theme_id', + 'KEYS' => array( + 'theme_name' => array('UNIQUE', 'theme_name'), + ), + ), + ), + ); } } diff --git a/phpBB/includes/db/migration/data/timezone.php b/phpBB/includes/db/migration/data/timezone.php index 7734ed4b76..1a7dfe1e19 100644 --- a/phpBB/includes/db/migration/data/timezone.php +++ b/phpBB/includes/db/migration/data/timezone.php @@ -18,7 +18,7 @@ class phpbb_db_migration_data_timezone extends phpbb_db_migration { return array( 'change_columns' => array( - USERS_TABLE => array( + $this->table_prefix . 'users' => array( 'user_timezone' => array('VCHAR:100', ''), ), ), @@ -36,13 +36,13 @@ class phpbb_db_migration_data_timezone extends phpbb_db_migration { // Update user timezones $sql = 'SELECT user_dst, user_timezone - FROM ' . USERS_TABLE . ' + FROM ' . $this->table_prefix . 'users GROUP BY user_timezone, user_dst'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - $sql = 'UPDATE ' . USERS_TABLE . " + $sql = 'UPDATE ' . $this->table_prefix . "users SET user_timezone = '" . $this->db->sql_escape($this->convert_phpbb30_timezone($row['user_timezone'], $row['user_dst'])) . "' WHERE user_timezone = '" . $this->db->sql_escape($row['user_timezone']) . "' AND user_dst = " . (int) $row['user_dst']; @@ -51,13 +51,10 @@ class phpbb_db_migration_data_timezone extends phpbb_db_migration $this->db->sql_freeresult($result); // Update board default timezone - $sql = 'UPDATE ' . CONFIG_TABLE . " + $sql = 'UPDATE ' . $this->table_prefix . "config SET config_value = '" . $this->convert_phpbb30_timezone($this->config['board_timezone'], $this->config['board_dst']) . "' WHERE config_name = 'board_timezone'"; $this->sql_query($sql); - - // After we have calculated the timezones we can delete user_dst column from user table. - $this->db_tools->sql_column_remove(USERS_TABLE, 'user_dst'); } /** diff --git a/phpBB/includes/db/migration/data/timezone_p2.php b/phpBB/includes/db/migration/data/timezone_p2.php new file mode 100644 index 0000000000..85c1cf9456 --- /dev/null +++ b/phpBB/includes/db/migration/data/timezone_p2.php @@ -0,0 +1,38 @@ + array( + $this->table_prefix . 'users' => array( + 'user_dst', + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'users' => array( + 'user_dst' => array('BOOL', 0), + ), + ), + ); + } +} -- cgit v1.2.1 From 74f4397451dae0ab83d977d97d96ed9549bf3ab9 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 22:28:48 -0600 Subject: [feature/migrations] Make depends_on static to call it without dependencies Move installing migrations to migration/install.php and handle figuring out what migrations have been installed based on phpBB version. PHPBB3-11318 --- phpBB/includes/db/migration/data/3_0_1.php | 4 +- phpBB/includes/db/migration/data/3_0_10.php | 4 +- phpBB/includes/db/migration/data/3_0_10_rc1.php | 4 +- phpBB/includes/db/migration/data/3_0_10_rc2.php | 4 +- phpBB/includes/db/migration/data/3_0_10_rc3.php | 4 +- phpBB/includes/db/migration/data/3_0_11.php | 4 +- phpBB/includes/db/migration/data/3_0_11_rc1.php | 8 +- phpBB/includes/db/migration/data/3_0_11_rc2.php | 8 +- phpBB/includes/db/migration/data/3_0_12_rc1.php | 2 +- phpBB/includes/db/migration/data/3_0_1_rc1.php | 15 +-- phpBB/includes/db/migration/data/3_0_2.php | 4 +- phpBB/includes/db/migration/data/3_0_2_rc1.php | 4 +- phpBB/includes/db/migration/data/3_0_2_rc2.php | 8 +- phpBB/includes/db/migration/data/3_0_3.php | 4 +- phpBB/includes/db/migration/data/3_0_3_rc1.php | 12 +- phpBB/includes/db/migration/data/3_0_4.php | 6 +- phpBB/includes/db/migration/data/3_0_4_rc1.php | 10 +- phpBB/includes/db/migration/data/3_0_5.php | 4 +- phpBB/includes/db/migration/data/3_0_5_rc1.php | 12 +- .../includes/db/migration/data/3_0_5_rc1part2.php | 6 +- phpBB/includes/db/migration/data/3_0_6.php | 4 +- phpBB/includes/db/migration/data/3_0_6_rc1.php | 12 +- phpBB/includes/db/migration/data/3_0_6_rc2.php | 4 +- phpBB/includes/db/migration/data/3_0_6_rc3.php | 6 +- phpBB/includes/db/migration/data/3_0_6_rc4.php | 4 +- phpBB/includes/db/migration/data/3_0_7.php | 4 +- phpBB/includes/db/migration/data/3_0_7_pl1.php | 4 +- phpBB/includes/db/migration/data/3_0_7_rc1.php | 10 +- phpBB/includes/db/migration/data/3_0_7_rc2.php | 6 +- phpBB/includes/db/migration/data/3_0_8.php | 4 +- phpBB/includes/db/migration/data/3_0_8_rc1.php | 12 +- phpBB/includes/db/migration/data/3_0_9.php | 4 +- phpBB/includes/db/migration/data/3_0_9_rc1.php | 12 +- phpBB/includes/db/migration/data/3_0_9_rc2.php | 4 +- phpBB/includes/db/migration/data/3_0_9_rc3.php | 4 +- phpBB/includes/db/migration/data/3_0_9_rc4.php | 4 +- phpBB/includes/db/migration/data/3_1_0_dev.php | 2 +- phpBB/includes/db/migration/data/extensions.php | 2 +- .../includes/db/migration/data/style_update_p1.php | 2 +- .../includes/db/migration/data/style_update_p2.php | 2 +- phpBB/includes/db/migration/data/timezone.php | 2 +- phpBB/includes/db/migration/data/timezone_p2.php | 2 +- phpBB/includes/db/migration/install.php | 129 +++++++++++++++++++++ 43 files changed, 245 insertions(+), 121 deletions(-) create mode 100644 phpBB/includes/db/migration/install.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/3_0_1.php b/phpBB/includes/db/migration/data/3_0_1.php index d71288c64b..a9eac6f110 100644 --- a/phpBB/includes/db/migration/data/3_0_1.php +++ b/phpBB/includes/db/migration/data/3_0_1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_1_rc1'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.1')), diff --git a/phpBB/includes/db/migration/data/3_0_10.php b/phpBB/includes/db/migration/data/3_0_10.php index 17472562f2..89afb8a432 100644 --- a/phpBB/includes/db/migration/data/3_0_10.php +++ b/phpBB/includes/db/migration/data/3_0_10.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_10 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_10_rc3'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.10')), diff --git a/phpBB/includes/db/migration/data/3_0_10_rc1.php b/phpBB/includes/db/migration/data/3_0_10_rc1.php index eebee44e39..ca8fadec61 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_10_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9'); } - function update_data() + public function update_data() { return array( array('config.add', array('email_max_chunk_size', 50)), diff --git a/phpBB/includes/db/migration/data/3_0_10_rc2.php b/phpBB/includes/db/migration/data/3_0_10_rc2.php index b81fde9bcb..1f39ea48e0 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc2.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_10_rc2 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_10_rc1'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.10-rc2')), diff --git a/phpBB/includes/db/migration/data/3_0_10_rc3.php b/phpBB/includes/db/migration/data/3_0_10_rc3.php index d97b0b4aec..cd82bb573e 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc3.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_10_rc3 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_10_rc2'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.10-rc3')), diff --git a/phpBB/includes/db/migration/data/3_0_11.php b/phpBB/includes/db/migration/data/3_0_11.php index b149cd374c..9f25f0e489 100644 --- a/phpBB/includes/db/migration/data/3_0_11.php +++ b/phpBB/includes/db/migration/data/3_0_11.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_11 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11_rc2'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.11')), diff --git a/phpBB/includes/db/migration/data/3_0_11_rc1.php b/phpBB/includes/db/migration/data/3_0_11_rc1.php index 3d4920bf49..676e6baa87 100644 --- a/phpBB/includes/db/migration/data/3_0_11_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_11_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_11_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_10'); } - function update_data() + public function update_data() { return array( array('custom', array(array(&$this, 'cleanup_deactivated_styles'))), @@ -24,7 +24,7 @@ class phpbb_db_migration_data_3_0_11_rc1 extends phpbb_db_migration ); } - function cleanup_deactivated_styles() + public function cleanup_deactivated_styles() { // Updates users having current style a deactivated one $sql = 'SELECT style_id @@ -48,7 +48,7 @@ class phpbb_db_migration_data_3_0_11_rc1 extends phpbb_db_migration } } - function delete_orphan_private_messages() + public function delete_orphan_private_messages() { // Delete orphan private messages $batch_size = 500; diff --git a/phpBB/includes/db/migration/data/3_0_11_rc2.php b/phpBB/includes/db/migration/data/3_0_11_rc2.php index e0638f02d7..e5bb3e44a6 100644 --- a/phpBB/includes/db/migration/data/3_0_11_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_11_rc2.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_11_rc2 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11_rc1'); } - function update_schema() + public function update_schema() { return array( 'add_columns' => array( @@ -25,7 +25,7 @@ class phpbb_db_migration_data_3_0_11_rc2 extends phpbb_db_migration ); } - function revert_schema() + public function revert_schema() { return array( 'drop_columns' => array( @@ -36,7 +36,7 @@ class phpbb_db_migration_data_3_0_11_rc2 extends phpbb_db_migration ); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.11-rc2')), diff --git a/phpBB/includes/db/migration/data/3_0_12_rc1.php b/phpBB/includes/db/migration/data/3_0_12_rc1.php index 0b35de2ed5..4fe0828716 100644 --- a/phpBB/includes/db/migration/data/3_0_12_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_12_rc1.php @@ -11,7 +11,7 @@ class phpbb_db_migration_data_3_0_12_rc1 extends phpbb_db_migration { - public function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11'); } diff --git a/phpBB/includes/db/migration/data/3_0_1_rc1.php b/phpBB/includes/db/migration/data/3_0_1_rc1.php index a7af5d052d..9f1c04809d 100644 --- a/phpBB/includes/db/migration/data/3_0_1_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_1_rc1.php @@ -9,12 +9,7 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration { - function depends_on() - { - return array(); - } - - function update_schema() + public function update_schema() { return array( 'add_columns' => array( @@ -41,7 +36,7 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration ); } - function revert_schema() + public function revert_schema() { return array( 'drop_columns' => array( @@ -68,7 +63,7 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration ); } - function update_data() + public function update_data() { return array( array('custom', array(array(&$this, 'fix_unset_last_view_time'))), @@ -78,7 +73,7 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration ); } - function fix_unset_last_view_time() + public function fix_unset_last_view_time() { $sql = 'UPDATE ' . $this->table_prefix . "topics SET topic_last_view_time = topic_last_post_time @@ -86,7 +81,7 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration $this->sql_query($sql); } - function reset_smiley_size() + public function reset_smiley_size() { // Update smiley sizes $smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif'); diff --git a/phpBB/includes/db/migration/data/3_0_2.php b/phpBB/includes/db/migration/data/3_0_2.php index 19e9213262..8661578281 100644 --- a/phpBB/includes/db/migration/data/3_0_2.php +++ b/phpBB/includes/db/migration/data/3_0_2.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_2 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_2_rc2'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.2')), diff --git a/phpBB/includes/db/migration/data/3_0_2_rc1.php b/phpBB/includes/db/migration/data/3_0_2_rc1.php index 7dd321d83c..851060c3b5 100644 --- a/phpBB/includes/db/migration/data/3_0_2_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_2_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_2_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_1'); } - function update_data() + public function update_data() { return array( array('config.add', array('referer_validation', '1')), diff --git a/phpBB/includes/db/migration/data/3_0_2_rc2.php b/phpBB/includes/db/migration/data/3_0_2_rc2.php index d73f9587c3..c255e55aef 100644 --- a/phpBB/includes/db/migration/data/3_0_2_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_2_rc2.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_2_rc2 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_2_rc1'); } - function update_schema() + public function update_schema() { return array( 'change_columns' => array( @@ -48,7 +48,7 @@ class phpbb_db_migration_data_3_0_2_rc2 extends phpbb_db_migration ); } - function revert_schema() + public function revert_schema() { return array( 'add_index' => array( @@ -66,7 +66,7 @@ class phpbb_db_migration_data_3_0_2_rc2 extends phpbb_db_migration ); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.2-rc2')), diff --git a/phpBB/includes/db/migration/data/3_0_3.php b/phpBB/includes/db/migration/data/3_0_3.php index d671b0cac3..2873c798fd 100644 --- a/phpBB/includes/db/migration/data/3_0_3.php +++ b/phpBB/includes/db/migration/data/3_0_3.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_3 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_3_rc1'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.3')), diff --git a/phpBB/includes/db/migration/data/3_0_3_rc1.php b/phpBB/includes/db/migration/data/3_0_3_rc1.php index 9cce80be74..49e4170c3f 100644 --- a/phpBB/includes/db/migration/data/3_0_3_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_3_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_3_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_2'); } - function update_schema() + public function update_schema() { return array( 'add_columns' => array( @@ -29,7 +29,7 @@ class phpbb_db_migration_data_3_0_3_rc1 extends phpbb_db_migration ); } - function revert_schema() + public function revert_schema() { return array( 'drop_columns' => array( @@ -44,7 +44,7 @@ class phpbb_db_migration_data_3_0_3_rc1 extends phpbb_db_migration ); } - function update_data() + public function update_data() { return array( array('config.add', array('enable_queue_trigger', '0')), @@ -59,7 +59,7 @@ class phpbb_db_migration_data_3_0_3_rc1 extends phpbb_db_migration ); } - function correct_acp_email_permissions() + public function correct_acp_email_permissions() { $sql = 'UPDATE ' . $this->table_prefix . 'modules SET module_auth = \'acl_a_email && cfg_email_enable\' @@ -68,7 +68,7 @@ class phpbb_db_migration_data_3_0_3_rc1 extends phpbb_db_migration $this->sql_query($sql); } - function set_group_default_max_recipients() + public function set_group_default_max_recipients() { // Set maximum number of recipients for the registered users, bots, guests group $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5 diff --git a/phpBB/includes/db/migration/data/3_0_4.php b/phpBB/includes/db/migration/data/3_0_4.php index e734814530..590ae3c69f 100644 --- a/phpBB/includes/db/migration/data/3_0_4.php +++ b/phpBB/includes/db/migration/data/3_0_4.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_4 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_4_rc1'); } - function update_data() + public function update_data() { return array( array('custom', array(array(&$this, 'rename_log_delete_topic'))), @@ -23,7 +23,7 @@ class phpbb_db_migration_data_3_0_4 extends phpbb_db_migration ); } - function rename_log_delete_topic() + public function rename_log_delete_topic() { if ($this->db->sql_layer == 'oracle') { diff --git a/phpBB/includes/db/migration/data/3_0_4_rc1.php b/phpBB/includes/db/migration/data/3_0_4_rc1.php index eb2fcb8d0e..8f44baf046 100644 --- a/phpBB/includes/db/migration/data/3_0_4_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_4_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_3'); } - function update_schema() + public function update_schema() { return array( 'add_columns' => array( @@ -55,7 +55,7 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration ); } - function revert_schema() + public function revert_schema() { return array( 'drop_columns' => array( @@ -66,7 +66,7 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration ); } - function update_data() + public function update_data() { return array( array('custom', array(array(&$this, 'update_custom_profile_fields'))), @@ -75,7 +75,7 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration ); } - function update_custom_profile_fields() + public function update_custom_profile_fields() { // Update the Custom Profile Fields based on previous settings to the new format $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide diff --git a/phpBB/includes/db/migration/data/3_0_5.php b/phpBB/includes/db/migration/data/3_0_5.php index 6d61793d08..65b292207e 100644 --- a/phpBB/includes/db/migration/data/3_0_5.php +++ b/phpBB/includes/db/migration/data/3_0_5.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_5 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_5_rc1part2'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.5')), diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1.php b/phpBB/includes/db/migration/data/3_0_5_rc1.php index cbf28c0be6..a0893a0dbb 100644 --- a/phpBB/includes/db/migration/data/3_0_5_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_5_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_4'); } - function update_schema() + public function update_schema() { return array( 'change_columns' => array( @@ -25,7 +25,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration ); } - function update_data() + public function update_data() { $search_indexing_state = $this->config['search_indexing_state']; @@ -42,7 +42,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration ); } - function hash_old_passwords() + public function hash_old_passwords() { $sql = 'SELECT user_id, user_password FROM ' . $this->table_prefix . 'users @@ -63,7 +63,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration $this->db->sql_freeresult($result); } - function update_ichiro_bot() + public function update_ichiro_bot() { // Adjust bot entry $sql = 'UPDATE ' . $this->table_prefix . "bots @@ -72,7 +72,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration $this->sql_query($sql); } - function remove_duplicate_auth_options() + public function remove_duplicate_auth_options() { // Before we are able to add a unique key to auth_option, we need to remove duplicate entries $sql = 'SELECT auth_option diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php index 354de748c8..0597fc0ff8 100644 --- a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php +++ b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_5_rc1part2 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_5_rc1'); } - function update_schema() + public function update_schema() { return array( 'drop_keys' => array( @@ -28,7 +28,7 @@ class phpbb_db_migration_data_3_0_5_rc1part2 extends phpbb_db_migration ); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.5-rc1')), diff --git a/phpBB/includes/db/migration/data/3_0_6.php b/phpBB/includes/db/migration/data/3_0_6.php index cc6fccaae2..a7b88e510a 100644 --- a/phpBB/includes/db/migration/data/3_0_6.php +++ b/phpBB/includes/db/migration/data/3_0_6.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_6 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6_rc4'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.6')), diff --git a/phpBB/includes/db/migration/data/3_0_6_rc1.php b/phpBB/includes/db/migration/data/3_0_6_rc1.php index b520bda6d0..5ebeceeed7 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_5'); } - function update_schema() + public function update_schema() { return array( 'add_columns' => array( @@ -59,7 +59,7 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration ); } - function revert_schema() + public function revert_schema() { return array( 'drop_columns' => array( @@ -99,7 +99,7 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration ); } - function update_data() + public function update_data() { return array( array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')), @@ -184,14 +184,14 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration ); } - function set_user_options_default() + public function set_user_options_default() { // 229376 is the added value to enable all three signature options $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376'; $this->sql_query($sql); } - function add_newly_registered_group() + public function add_newly_registered_group() { // Add newly_registered group... but check if it already exists (we always supported running the updater on any schema) $sql = 'SELECT group_id diff --git a/phpBB/includes/db/migration/data/3_0_6_rc2.php b/phpBB/includes/db/migration/data/3_0_6_rc2.php index d61c296445..7cbda4c616 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc2.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_6_rc2 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6_rc1'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.6-rc2')), diff --git a/phpBB/includes/db/migration/data/3_0_6_rc3.php b/phpBB/includes/db/migration/data/3_0_6_rc3.php index a3f0dcacdf..209057ec70 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc3.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_6_rc3 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6_rc2'); } - function update_data() + public function update_data() { return array( array('custom', array(array(&$this, 'update_cp_fields'))), @@ -23,7 +23,7 @@ class phpbb_db_migration_data_3_0_6_rc3 extends phpbb_db_migration ); } - function update_cp_fields() + public function update_cp_fields() { // Update the Custom Profile Fields based on previous settings to the new format $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . ' diff --git a/phpBB/includes/db/migration/data/3_0_6_rc4.php b/phpBB/includes/db/migration/data/3_0_6_rc4.php index 3855b85551..62f0e91a7d 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc4.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc4.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_6_rc4 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6_rc3'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.6-rc4')), diff --git a/phpBB/includes/db/migration/data/3_0_7.php b/phpBB/includes/db/migration/data/3_0_7.php index 59779c9cb0..3e215ff905 100644 --- a/phpBB/includes/db/migration/data/3_0_7.php +++ b/phpBB/includes/db/migration/data/3_0_7.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_7 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_7_rc2'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.7')), diff --git a/phpBB/includes/db/migration/data/3_0_7_pl1.php b/phpBB/includes/db/migration/data/3_0_7_pl1.php index 5570a5dc06..ffe0836d02 100644 --- a/phpBB/includes/db/migration/data/3_0_7_pl1.php +++ b/phpBB/includes/db/migration/data/3_0_7_pl1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_7_pl1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_7'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.7-pl1')), diff --git a/phpBB/includes/db/migration/data/3_0_7_rc1.php b/phpBB/includes/db/migration/data/3_0_7_rc1.php index 84b8f798a8..b30830c21d 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_7_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6'); } - function update_schema() + public function update_schema() { return array( 'drop_keys' => array( @@ -30,7 +30,7 @@ class phpbb_db_migration_data_3_0_7_rc1 extends phpbb_db_migration ); } - function revert_schema() + public function revert_schema() { return array( 'add_index' => array( @@ -46,7 +46,7 @@ class phpbb_db_migration_data_3_0_7_rc1 extends phpbb_db_migration ); } - function update_data() + public function update_data() { return array( array('config.add', array('feed_overall', 1)), @@ -61,7 +61,7 @@ class phpbb_db_migration_data_3_0_7_rc1 extends phpbb_db_migration ); } - function delete_text_templates() + public function delete_text_templates() { // Delete all text-templates from the template_data $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' diff --git a/phpBB/includes/db/migration/data/3_0_7_rc2.php b/phpBB/includes/db/migration/data/3_0_7_rc2.php index 48aa818ba3..e986be23bf 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc2.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_7_rc2 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_7_rc1'); } - function update_data() + public function update_data() { return array( array('custom', array(array(&$this, 'update_email_hash'))), @@ -23,7 +23,7 @@ class phpbb_db_migration_data_3_0_7_rc2 extends phpbb_db_migration ); } - function update_email_hash($start = 0) + public function update_email_hash($start = 0) { $limit = 1000; diff --git a/phpBB/includes/db/migration/data/3_0_8.php b/phpBB/includes/db/migration/data/3_0_8.php index d94fe869fb..8043b934b0 100644 --- a/phpBB/includes/db/migration/data/3_0_8.php +++ b/phpBB/includes/db/migration/data/3_0_8.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_8 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_8_rc1'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.8')), diff --git a/phpBB/includes/db/migration/data/3_0_8_rc1.php b/phpBB/includes/db/migration/data/3_0_8_rc1.php index eb4cc5bd1a..8214f44f17 100644 --- a/phpBB/includes/db/migration/data/3_0_8_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_8_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_7_pl1'); } - function update_data() + public function update_data() { return array( array('custom', array(array(&$this, 'update_file_extension_group_names'))), @@ -37,7 +37,7 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration ); } - function update_file_extension_group_names() + public function update_file_extension_group_names() { // Update file extension group names to use language strings. $sql = 'SELECT lang_dir @@ -93,7 +93,7 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration $this->db->sql_freeresult($result); } - function update_module_auth() + public function update_module_auth() { $sql = 'UPDATE ' . MODULES_TABLE . ' SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\' @@ -103,7 +103,7 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration $this->sql_query($sql); } - function update_bots() + public function update_bots() { $bot_name = 'Bing [Bot]'; $bot_name_clean = utf8_clean_string($bot_name); @@ -167,7 +167,7 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration } } - function delete_orphan_shadow_topics() + public function delete_orphan_shadow_topics() { // Delete shadow topics pointing to not existing topics $batch_size = 500; diff --git a/phpBB/includes/db/migration/data/3_0_9.php b/phpBB/includes/db/migration/data/3_0_9.php index d19a24b45e..c562f1f2cf 100644 --- a/phpBB/includes/db/migration/data/3_0_9.php +++ b/phpBB/includes/db/migration/data/3_0_9.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_9 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9_rc4'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.9')), diff --git a/phpBB/includes/db/migration/data/3_0_9_rc1.php b/phpBB/includes/db/migration/data/3_0_9_rc1.php index 4ed48061a4..367bb25734 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc1.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_9_rc1 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_8'); } - function update_schema() + public function update_schema() { return array( 'add_tables' => array( @@ -51,7 +51,7 @@ class phpbb_db_migration_data_3_0_9_rc1 extends phpbb_db_migration ); } - function revert_schema() + public function revert_schema() { return array( 'drop_tables' => array( @@ -60,7 +60,7 @@ class phpbb_db_migration_data_3_0_9_rc1 extends phpbb_db_migration ); } - function update_data() + public function update_data() { return array( array('config.add', array('ip_login_limit_max', 50)), @@ -73,7 +73,7 @@ class phpbb_db_migration_data_3_0_9_rc1 extends phpbb_db_migration ); } - function update_file_extension_group_names() + public function update_file_extension_group_names() { // Update file extension group names to use language strings, again. $sql = 'SELECT group_id, group_name @@ -95,7 +95,7 @@ class phpbb_db_migration_data_3_0_9_rc1 extends phpbb_db_migration $this->db->sql_freeresult($result); } - function fix_firebird_qa_captcha() + public function fix_firebird_qa_captcha() { // Recover from potentially broken Q&A CAPTCHA table on firebird // Q&A CAPTCHA was uninstallable, so it's safe to remove these diff --git a/phpBB/includes/db/migration/data/3_0_9_rc2.php b/phpBB/includes/db/migration/data/3_0_9_rc2.php index 98ef232cb4..c8566d54a5 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc2.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_9_rc2 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9_rc1'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.9-rc2')), diff --git a/phpBB/includes/db/migration/data/3_0_9_rc3.php b/phpBB/includes/db/migration/data/3_0_9_rc3.php index b84d61031e..da977e9666 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc3.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_9_rc3 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9_rc2'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.9-rc3')), diff --git a/phpBB/includes/db/migration/data/3_0_9_rc4.php b/phpBB/includes/db/migration/data/3_0_9_rc4.php index 2a00bba843..0bfe26985c 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc4.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc4.php @@ -9,12 +9,12 @@ class phpbb_db_migration_data_3_0_9_rc4 extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9_rc3'); } - function update_data() + public function update_data() { return array( array('config.update', array('version', '3.0.9-rc4')), diff --git a/phpBB/includes/db/migration/data/3_1_0_dev.php b/phpBB/includes/db/migration/data/3_1_0_dev.php index 4f7ed07158..14953591d1 100644 --- a/phpBB/includes/db/migration/data/3_1_0_dev.php +++ b/phpBB/includes/db/migration/data/3_1_0_dev.php @@ -9,7 +9,7 @@ class phpbb_db_migration_data_3_1_0_dev extends phpbb_db_migration { - public function depends_on() + static public function depends_on() { return array( 'phpbb_db_migration_data_3_0_11', diff --git a/phpBB/includes/db/migration/data/extensions.php b/phpBB/includes/db/migration/data/extensions.php index b5f5b792cf..ff54d0d933 100644 --- a/phpBB/includes/db/migration/data/extensions.php +++ b/phpBB/includes/db/migration/data/extensions.php @@ -9,7 +9,7 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration { - public function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11'); } diff --git a/phpBB/includes/db/migration/data/style_update_p1.php b/phpBB/includes/db/migration/data/style_update_p1.php index f1b26f525a..701afc0d78 100644 --- a/phpBB/includes/db/migration/data/style_update_p1.php +++ b/phpBB/includes/db/migration/data/style_update_p1.php @@ -9,7 +9,7 @@ class phpbb_db_migration_data_style_update_p1 extends phpbb_db_migration { - public function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11'); } diff --git a/phpBB/includes/db/migration/data/style_update_p2.php b/phpBB/includes/db/migration/data/style_update_p2.php index 361eb5a389..1a8cc9da58 100644 --- a/phpBB/includes/db/migration/data/style_update_p2.php +++ b/phpBB/includes/db/migration/data/style_update_p2.php @@ -9,7 +9,7 @@ class phpbb_db_migration_data_style_update_p2 extends phpbb_db_migration { - public function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_style_update_p1'); } diff --git a/phpBB/includes/db/migration/data/timezone.php b/phpBB/includes/db/migration/data/timezone.php index 1a7dfe1e19..3658120629 100644 --- a/phpBB/includes/db/migration/data/timezone.php +++ b/phpBB/includes/db/migration/data/timezone.php @@ -9,7 +9,7 @@ class phpbb_db_migration_data_timezone extends phpbb_db_migration { - public function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11'); } diff --git a/phpBB/includes/db/migration/data/timezone_p2.php b/phpBB/includes/db/migration/data/timezone_p2.php index 85c1cf9456..15f1a3e414 100644 --- a/phpBB/includes/db/migration/data/timezone_p2.php +++ b/phpBB/includes/db/migration/data/timezone_p2.php @@ -9,7 +9,7 @@ class phpbb_db_migration_data_timezone_p2 extends phpbb_db_migration { - public function depends_on() + static public function depends_on() { return array('phpbb_db_migration_data_timezone'); } diff --git a/phpBB/includes/db/migration/install.php b/phpBB/includes/db/migration/install.php new file mode 100644 index 0000000000..af2ba392b1 --- /dev/null +++ b/phpBB/includes/db/migration/install.php @@ -0,0 +1,129 @@ + 'phpbb_db_migration_data_3_0_1_rc1', + '3.0.1' => 'phpbb_db_migration_data_3_0_1', + '3.0.2-rc1' => 'phpbb_db_migration_data_3_0_2_rc1', + '3.0.2-rc2' => 'phpbb_db_migration_data_3_0_2_rc2', + '3.0.2' => 'phpbb_db_migration_data_3_0_2', + '3.0.3-rc1' => 'phpbb_db_migration_data_3_0_3_rc1', + '3.0.3' => 'phpbb_db_migration_data_3_0_3', + '3.0.4-rc1' => 'phpbb_db_migration_data_3_0_4_rc1', + '3.0.4' => 'phpbb_db_migration_data_3_0_4', + '3.0.5-rc1' => array( + 'phpbb_db_migration_data_3_0_5_rc1', + 'phpbb_db_migration_data_3_0_5_rc1part2', + ), + '3.0.5' => 'phpbb_db_migration_data_3_0_5', + '3.0.6-rc1' => 'phpbb_db_migration_data_3_0_6_rc1', + '3.0.6-rc2' => 'phpbb_db_migration_data_3_0_6_rc2', + '3.0.6-rc3' => 'phpbb_db_migration_data_3_0_6_rc3', + '3.0.6-rc4' => 'phpbb_db_migration_data_3_0_6_rc4', + '3.0.6' => 'phpbb_db_migration_data_3_0_6', + '3.0.7-rc1' => 'phpbb_db_migration_data_3_0_7_rc1', + '3.0.7-rc2' => 'phpbb_db_migration_data_3_0_7_rc2', + '3.0.7' => 'phpbb_db_migration_data_3_0_7', + '3.0.7-pl1' => 'phpbb_db_migration_data_3_0_7_pl1', + '3.0.8-rc1' => 'phpbb_db_migration_data_3_0_8_rc1', + '3.0.8' => 'phpbb_db_migration_data_3_0_8', + '3.0.9-rc1' => 'phpbb_db_migration_data_3_0_9_rc1', + '3.0.9-rc2' => 'phpbb_db_migration_data_3_0_9_rc2', + '3.0.9-rc3' => 'phpbb_db_migration_data_3_0_9_rc3', + '3.0.9-rc4' => 'phpbb_db_migration_data_3_0_9_rc4', + '3.0.9' => 'phpbb_db_migration_data_3_0_9', + '3.0.10-rc1' => 'phpbb_db_migration_data_3_0_10_rc1', + '3.0.10-rc2' => 'phpbb_db_migration_data_3_0_10_rc2', + '3.0.10-rc3' => 'phpbb_db_migration_data_3_0_10_rc3', + '3.0.10' => 'phpbb_db_migration_data_3_0_10', + '3.0.11-rc1' => 'phpbb_db_migration_data_3_0_11_rc1', + '3.0.11-rc2' => 'phpbb_db_migration_data_3_0_11_rc2', + '3.0.11' => 'phpbb_db_migration_data_3_0_11', + '3.0.12-rc1' => 'phpbb_db_migration_data_3_0_12_rc1', + '3.1.0-dev' => array( + 'phpbb_db_migration_data_style_update_p1', + 'phpbb_db_migration_data_style_update_p2', + 'phpbb_db_migration_data_timezone', + 'phpbb_db_migration_data_timezone_p2', + 'phpbb_db_migration_data_extensions', + 'phpbb_db_migration_data_3_1_0_dev', + ), + ); + + public function install(phpbb_db_driver $db, phpbb_db_tools $db_tools, $table_prefix, $version) + { + $this->create_table($db_tools); + + $this->guess_installed_migrations($db, $table_prefix, $version); + } + + protected function create_table(phpbb_db_tools $db_tools) + { + if (!$db_tools->sql_table_exists(MIGRATIONS_TABLE)) + { + $db_tools->sql_create_table(MIGRATIONS_TABLE, array( + 'COLUMNS' => array( + 'migration_name' => array('VCHAR', ''), + 'migration_depends_on' => array('TEXT', ''), + 'migration_schema_done' => array('BOOL', 0), + 'migration_data_done' => array('BOOL', 0), + 'migration_data_state' => array('TEXT', ''), + 'migration_start_time' => array('TIMESTAMP', 0), + 'migration_end_time' => array('TIMESTAMP', 0), + ), + 'PRIMARY_KEY' => 'migration_name', + )); + } + } + + /** + * Guess what migrations have been installed based on phpBB version + * + * @param mixed $version + */ + protected function guess_installed_migrations(phpbb_db_driver $db, $table_prefix, $version) + { + $installed = array(); + foreach ($this->version_to_migration as $compare => $migration_list) + { + if (version_compare($version, $compare, '<=')) + { + // The migration should have effectively been installed already + if (!is_array($migration_list)) + { + $migration_list = array($migration_list); + } + + foreach ($migration_list as $migration_name) + { + $sql_ary = array( + 'migration_name' => $migration_name, + 'migration_depends_on' => $migration_name::depends_on(), + 'migration_schema_done' => 1, + 'migration_data_done' => 1, + 'migration_data_state' => '', + 'migration_start_time' => 0, + 'migration_end_time' => 0, + ); + $sql = 'INSERT INTO ' . $table_prefix . 'migrations ' . + $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + } + } + } + } +} -- cgit v1.2.1 From 8baceacc36f06c2c14d4a4c08cecb3c80b3c76d3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 22:45:26 -0600 Subject: [feature/migrations] Fix migrations installer, schema for schema_data.sql PHPBB3-11318 --- phpBB/includes/db/migration/install.php | 43 ++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/install.php b/phpBB/includes/db/migration/install.php index af2ba392b1..95f3a3b994 100644 --- a/phpBB/includes/db/migration/install.php +++ b/phpBB/includes/db/migration/install.php @@ -66,16 +66,16 @@ class phpbb_db_migration_install public function install(phpbb_db_driver $db, phpbb_db_tools $db_tools, $table_prefix, $version) { - $this->create_table($db_tools); + $this->create_table($db_tools, $table_prefix); $this->guess_installed_migrations($db, $table_prefix, $version); } - protected function create_table(phpbb_db_tools $db_tools) + protected function create_table(phpbb_db_tools $db_tools, $table_prefix) { - if (!$db_tools->sql_table_exists(MIGRATIONS_TABLE)) + if (!$db_tools->sql_table_exists($table_prefix . 'migrations')) { - $db_tools->sql_create_table(MIGRATIONS_TABLE, array( + $db_tools->sql_create_table($table_prefix . 'migrations', array( 'COLUMNS' => array( 'migration_name' => array('VCHAR', ''), 'migration_depends_on' => array('TEXT', ''), @@ -100,7 +100,7 @@ class phpbb_db_migration_install $installed = array(); foreach ($this->version_to_migration as $compare => $migration_list) { - if (version_compare($version, $compare, '<=')) + if (version_compare($version, $compare, '>=')) { // The migration should have effectively been installed already if (!is_array($migration_list)) @@ -110,18 +110,27 @@ class phpbb_db_migration_install foreach ($migration_list as $migration_name) { - $sql_ary = array( - 'migration_name' => $migration_name, - 'migration_depends_on' => $migration_name::depends_on(), - 'migration_schema_done' => 1, - 'migration_data_done' => 1, - 'migration_data_state' => '', - 'migration_start_time' => 0, - 'migration_end_time' => 0, - ); - $sql = 'INSERT INTO ' . $table_prefix . 'migrations ' . - $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); + $sql = 'SELECT 1 FROM ' . $table_prefix . "migrations + WHERE migration_name = '" . $db->sql_escape($migration_name) . "'"; + $result = $db->sql_query($sql); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (!$row) + { + $sql_ary = array( + 'migration_name' => $migration_name, + 'migration_depends_on' => serialize($migration_name::depends_on()), + 'migration_schema_done' => 1, + 'migration_data_done' => 1, + 'migration_data_state' => '', + 'migration_start_time' => 0, + 'migration_end_time' => 0, + ); + $sql = 'INSERT INTO ' . $table_prefix . 'migrations ' . + $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + } } } } -- cgit v1.2.1 From dfcf9966e95fce074a5ed6eb4036393f5b62de7c Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 12 Jan 2013 19:45:20 -0600 Subject: [feature/migrations] Comments for the return in the custom functions PHPBB3-11318 --- phpBB/includes/db/migration/data/3_0_11_rc1.php | 1 + phpBB/includes/db/migration/data/3_0_7_rc2.php | 1 + 2 files changed, 2 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/3_0_11_rc1.php b/phpBB/includes/db/migration/data/3_0_11_rc1.php index 676e6baa87..43e0156760 100644 --- a/phpBB/includes/db/migration/data/3_0_11_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_11_rc1.php @@ -83,6 +83,7 @@ class phpbb_db_migration_data_3_0_11_rc1 extends phpbb_db_migration WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms); $this->sql_query($sql); + // Return false to have the Migrator call this function again return false; } } diff --git a/phpBB/includes/db/migration/data/3_0_7_rc2.php b/phpBB/includes/db/migration/data/3_0_7_rc2.php index e986be23bf..c2720b532f 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc2.php @@ -62,6 +62,7 @@ class phpbb_db_migration_data_3_0_7_rc2 extends phpbb_db_migration return; } + // Return the next start, will be sent to $start when this function is called again return $start + $limit; } } -- cgit v1.2.1 From 5e69e1a7612a4dbe24620cc5cad33720cb0c2885 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 13 Jan 2013 13:23:02 -0600 Subject: [feature/migrations] effectively installed check for migration data PHPBB3-9737 --- phpBB/includes/db/migration/data/3_0_1.php | 5 + phpBB/includes/db/migration/data/3_0_10.php | 5 + phpBB/includes/db/migration/data/3_0_10_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_10_rc2.php | 5 + phpBB/includes/db/migration/data/3_0_10_rc3.php | 5 + phpBB/includes/db/migration/data/3_0_11.php | 5 + phpBB/includes/db/migration/data/3_0_11_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_11_rc2.php | 5 + phpBB/includes/db/migration/data/3_0_12_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_1_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_2.php | 5 + phpBB/includes/db/migration/data/3_0_2_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_2_rc2.php | 5 + phpBB/includes/db/migration/data/3_0_3.php | 5 + phpBB/includes/db/migration/data/3_0_3_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_4.php | 5 + phpBB/includes/db/migration/data/3_0_4_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_5.php | 5 + phpBB/includes/db/migration/data/3_0_5_rc1.php | 5 + .../includes/db/migration/data/3_0_5_rc1part2.php | 5 + phpBB/includes/db/migration/data/3_0_6.php | 5 + phpBB/includes/db/migration/data/3_0_6_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_6_rc2.php | 5 + phpBB/includes/db/migration/data/3_0_6_rc3.php | 5 + phpBB/includes/db/migration/data/3_0_6_rc4.php | 5 + phpBB/includes/db/migration/data/3_0_7.php | 5 + phpBB/includes/db/migration/data/3_0_7_pl1.php | 5 + phpBB/includes/db/migration/data/3_0_7_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_7_rc2.php | 5 + phpBB/includes/db/migration/data/3_0_8.php | 5 + phpBB/includes/db/migration/data/3_0_8_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_9.php | 5 + phpBB/includes/db/migration/data/3_0_9_rc1.php | 5 + phpBB/includes/db/migration/data/3_0_9_rc2.php | 5 + phpBB/includes/db/migration/data/3_0_9_rc3.php | 5 + phpBB/includes/db/migration/data/3_0_9_rc4.php | 5 + phpBB/includes/db/migration/data/3_1_0_dev.php | 5 + phpBB/includes/db/migration/data/extensions.php | 5 + .../includes/db/migration/data/style_update_p1.php | 5 + .../includes/db/migration/data/style_update_p2.php | 5 + phpBB/includes/db/migration/data/timezone.php | 5 + phpBB/includes/db/migration/data/timezone_p2.php | 5 + phpBB/includes/db/migration/install.php | 138 --------------------- 43 files changed, 210 insertions(+), 138 deletions(-) delete mode 100644 phpBB/includes/db/migration/install.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/3_0_1.php b/phpBB/includes/db/migration/data/3_0_1.php index a9eac6f110..8b7c6f0f7c 100644 --- a/phpBB/includes/db/migration/data/3_0_1.php +++ b/phpBB/includes/db/migration/data/3_0_1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_1_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_10.php b/phpBB/includes/db/migration/data/3_0_10.php index 89afb8a432..b24a876bac 100644 --- a/phpBB/includes/db/migration/data/3_0_10.php +++ b/phpBB/includes/db/migration/data/3_0_10.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_10 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.10', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_10_rc3'); diff --git a/phpBB/includes/db/migration/data/3_0_10_rc1.php b/phpBB/includes/db/migration/data/3_0_10_rc1.php index ca8fadec61..46b7db4e59 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_10_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.10-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9'); diff --git a/phpBB/includes/db/migration/data/3_0_10_rc2.php b/phpBB/includes/db/migration/data/3_0_10_rc2.php index 1f39ea48e0..5e85467202 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_10_rc2 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.10-rc2', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_10_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_10_rc3.php b/phpBB/includes/db/migration/data/3_0_10_rc3.php index cd82bb573e..6ff81f7776 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc3.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_10_rc3 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.10-rc3', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_10_rc2'); diff --git a/phpBB/includes/db/migration/data/3_0_11.php b/phpBB/includes/db/migration/data/3_0_11.php index 9f25f0e489..1a63508593 100644 --- a/phpBB/includes/db/migration/data/3_0_11.php +++ b/phpBB/includes/db/migration/data/3_0_11.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_11 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.11', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11_rc2'); diff --git a/phpBB/includes/db/migration/data/3_0_11_rc1.php b/phpBB/includes/db/migration/data/3_0_11_rc1.php index 43e0156760..19703bcc35 100644 --- a/phpBB/includes/db/migration/data/3_0_11_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_11_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_11_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.11-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_10'); diff --git a/phpBB/includes/db/migration/data/3_0_11_rc2.php b/phpBB/includes/db/migration/data/3_0_11_rc2.php index e5bb3e44a6..219d44c4e0 100644 --- a/phpBB/includes/db/migration/data/3_0_11_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_11_rc2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_11_rc2 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.11-rc2', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_12_rc1.php b/phpBB/includes/db/migration/data/3_0_12_rc1.php index 4fe0828716..c23e8b24b8 100644 --- a/phpBB/includes/db/migration/data/3_0_12_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_12_rc1.php @@ -11,6 +11,11 @@ class phpbb_db_migration_data_3_0_12_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.12-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11'); diff --git a/phpBB/includes/db/migration/data/3_0_1_rc1.php b/phpBB/includes/db/migration/data/3_0_1_rc1.php index 9f1c04809d..2fc2849d04 100644 --- a/phpBB/includes/db/migration/data/3_0_1_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_1_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.1-rc1', '>='); + } + public function update_schema() { return array( diff --git a/phpBB/includes/db/migration/data/3_0_2.php b/phpBB/includes/db/migration/data/3_0_2.php index 8661578281..8aa975f779 100644 --- a/phpBB/includes/db/migration/data/3_0_2.php +++ b/phpBB/includes/db/migration/data/3_0_2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_2 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.2', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_2_rc2'); diff --git a/phpBB/includes/db/migration/data/3_0_2_rc1.php b/phpBB/includes/db/migration/data/3_0_2_rc1.php index 851060c3b5..6081cd682c 100644 --- a/phpBB/includes/db/migration/data/3_0_2_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_2_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_2_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.2-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_1'); diff --git a/phpBB/includes/db/migration/data/3_0_2_rc2.php b/phpBB/includes/db/migration/data/3_0_2_rc2.php index c255e55aef..bb76c270d7 100644 --- a/phpBB/includes/db/migration/data/3_0_2_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_2_rc2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_2_rc2 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.2-rc2', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_2_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_3.php b/phpBB/includes/db/migration/data/3_0_3.php index 2873c798fd..82039a109b 100644 --- a/phpBB/includes/db/migration/data/3_0_3.php +++ b/phpBB/includes/db/migration/data/3_0_3.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_3 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.3', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_3_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_3_rc1.php b/phpBB/includes/db/migration/data/3_0_3_rc1.php index 49e4170c3f..5e300962b7 100644 --- a/phpBB/includes/db/migration/data/3_0_3_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_3_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_3_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.3-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_2'); diff --git a/phpBB/includes/db/migration/data/3_0_4.php b/phpBB/includes/db/migration/data/3_0_4.php index 590ae3c69f..34af9fa4ae 100644 --- a/phpBB/includes/db/migration/data/3_0_4.php +++ b/phpBB/includes/db/migration/data/3_0_4.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_4 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.4', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_4_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_4_rc1.php b/phpBB/includes/db/migration/data/3_0_4_rc1.php index 8f44baf046..f63bebcf75 100644 --- a/phpBB/includes/db/migration/data/3_0_4_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_4_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.4-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_3'); diff --git a/phpBB/includes/db/migration/data/3_0_5.php b/phpBB/includes/db/migration/data/3_0_5.php index 65b292207e..077ed251d2 100644 --- a/phpBB/includes/db/migration/data/3_0_5.php +++ b/phpBB/includes/db/migration/data/3_0_5.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_5 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.5', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_5_rc1part2'); diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1.php b/phpBB/includes/db/migration/data/3_0_5_rc1.php index a0893a0dbb..df85ee4f7d 100644 --- a/phpBB/includes/db/migration/data/3_0_5_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_5_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.5-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_4'); diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php index 0597fc0ff8..d2fad7a7f8 100644 --- a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php +++ b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_5_rc1part2 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.5-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_5_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_6.php b/phpBB/includes/db/migration/data/3_0_6.php index a7b88e510a..1b0cbb1435 100644 --- a/phpBB/includes/db/migration/data/3_0_6.php +++ b/phpBB/includes/db/migration/data/3_0_6.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_6 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.6', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6_rc4'); diff --git a/phpBB/includes/db/migration/data/3_0_6_rc1.php b/phpBB/includes/db/migration/data/3_0_6_rc1.php index 5ebeceeed7..0f85084e65 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.6-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_5'); diff --git a/phpBB/includes/db/migration/data/3_0_6_rc2.php b/phpBB/includes/db/migration/data/3_0_6_rc2.php index 7cbda4c616..a9c497b3cd 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_6_rc2 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.6-rc2', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_6_rc3.php b/phpBB/includes/db/migration/data/3_0_6_rc3.php index 209057ec70..eca19fc2ff 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc3.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_6_rc3 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.6-rc3', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6_rc2'); diff --git a/phpBB/includes/db/migration/data/3_0_6_rc4.php b/phpBB/includes/db/migration/data/3_0_6_rc4.php index 62f0e91a7d..19611d3c56 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc4.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc4.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_6_rc4 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.6-rc4', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6_rc3'); diff --git a/phpBB/includes/db/migration/data/3_0_7.php b/phpBB/includes/db/migration/data/3_0_7.php index 3e215ff905..97cdf4e3f1 100644 --- a/phpBB/includes/db/migration/data/3_0_7.php +++ b/phpBB/includes/db/migration/data/3_0_7.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_7 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.7', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_7_rc2'); diff --git a/phpBB/includes/db/migration/data/3_0_7_pl1.php b/phpBB/includes/db/migration/data/3_0_7_pl1.php index ffe0836d02..176854a8a6 100644 --- a/phpBB/includes/db/migration/data/3_0_7_pl1.php +++ b/phpBB/includes/db/migration/data/3_0_7_pl1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_7_pl1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.7-pl1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_7'); diff --git a/phpBB/includes/db/migration/data/3_0_7_rc1.php b/phpBB/includes/db/migration/data/3_0_7_rc1.php index b30830c21d..daf52213b9 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_7_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.7-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_6'); diff --git a/phpBB/includes/db/migration/data/3_0_7_rc2.php b/phpBB/includes/db/migration/data/3_0_7_rc2.php index c2720b532f..8167d8fa40 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_7_rc2 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.7-rc2', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_7_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_8.php b/phpBB/includes/db/migration/data/3_0_8.php index 8043b934b0..25baaf0f07 100644 --- a/phpBB/includes/db/migration/data/3_0_8.php +++ b/phpBB/includes/db/migration/data/3_0_8.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_8 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.8', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_8_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_8_rc1.php b/phpBB/includes/db/migration/data/3_0_8_rc1.php index 8214f44f17..13e68a7953 100644 --- a/phpBB/includes/db/migration/data/3_0_8_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_8_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.8-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_7_pl1'); diff --git a/phpBB/includes/db/migration/data/3_0_9.php b/phpBB/includes/db/migration/data/3_0_9.php index c562f1f2cf..b35350dbb5 100644 --- a/phpBB/includes/db/migration/data/3_0_9.php +++ b/phpBB/includes/db/migration/data/3_0_9.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_9 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.9', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9_rc4'); diff --git a/phpBB/includes/db/migration/data/3_0_9_rc1.php b/phpBB/includes/db/migration/data/3_0_9_rc1.php index 367bb25734..be6ced2566 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_9_rc1 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.9-rc1', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_8'); diff --git a/phpBB/includes/db/migration/data/3_0_9_rc2.php b/phpBB/includes/db/migration/data/3_0_9_rc2.php index c8566d54a5..0bec42a8de 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_9_rc2 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.9-rc2', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9_rc1'); diff --git a/phpBB/includes/db/migration/data/3_0_9_rc3.php b/phpBB/includes/db/migration/data/3_0_9_rc3.php index da977e9666..a339670932 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc3.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_9_rc3 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.9-rc3', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9_rc2'); diff --git a/phpBB/includes/db/migration/data/3_0_9_rc4.php b/phpBB/includes/db/migration/data/3_0_9_rc4.php index 0bfe26985c..ab5c302611 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc4.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc4.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_0_9_rc4 extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.0.9-rc4', '>='); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_9_rc3'); diff --git a/phpBB/includes/db/migration/data/3_1_0_dev.php b/phpBB/includes/db/migration/data/3_1_0_dev.php index 14953591d1..ac8882cb3a 100644 --- a/phpBB/includes/db/migration/data/3_1_0_dev.php +++ b/phpBB/includes/db/migration/data/3_1_0_dev.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_3_1_0_dev extends phpbb_db_migration { + public function effectively_installed() + { + return version_compare($this->config['version'], '3.1.0-dev', '>='); + } + static public function depends_on() { return array( diff --git a/phpBB/includes/db/migration/data/extensions.php b/phpBB/includes/db/migration/data/extensions.php index ff54d0d933..f077741883 100644 --- a/phpBB/includes/db/migration/data/extensions.php +++ b/phpBB/includes/db/migration/data/extensions.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration { + public function effectively_installed() + { + return $this->db_tools->sql_table_exists($this->table_prefix . 'ext'); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11'); diff --git a/phpBB/includes/db/migration/data/style_update_p1.php b/phpBB/includes/db/migration/data/style_update_p1.php index 701afc0d78..7506b7c49b 100644 --- a/phpBB/includes/db/migration/data/style_update_p1.php +++ b/phpBB/includes/db/migration/data/style_update_p1.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_style_update_p1 extends phpbb_db_migration { + public function effectively_installed() + { + return !$this->db_tools->sql_table_exists($this->table_prefix . 'styles_imageset'); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11'); diff --git a/phpBB/includes/db/migration/data/style_update_p2.php b/phpBB/includes/db/migration/data/style_update_p2.php index 1a8cc9da58..ef13f45d9b 100644 --- a/phpBB/includes/db/migration/data/style_update_p2.php +++ b/phpBB/includes/db/migration/data/style_update_p2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_style_update_p2 extends phpbb_db_migration { + public function effectively_installed() + { + return !$this->db_tools->sql_table_exists($this->table_prefix . 'styles_imageset'); + } + static public function depends_on() { return array('phpbb_db_migration_data_style_update_p1'); diff --git a/phpBB/includes/db/migration/data/timezone.php b/phpBB/includes/db/migration/data/timezone.php index 3658120629..66085b8872 100644 --- a/phpBB/includes/db/migration/data/timezone.php +++ b/phpBB/includes/db/migration/data/timezone.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_timezone extends phpbb_db_migration { + public function effectively_installed() + { + return !$this->db_tools->sql_column_exists($this->table_prefix . 'users', 'user_dst'); + } + static public function depends_on() { return array('phpbb_db_migration_data_3_0_11'); diff --git a/phpBB/includes/db/migration/data/timezone_p2.php b/phpBB/includes/db/migration/data/timezone_p2.php index 15f1a3e414..38347a0c63 100644 --- a/phpBB/includes/db/migration/data/timezone_p2.php +++ b/phpBB/includes/db/migration/data/timezone_p2.php @@ -9,6 +9,11 @@ class phpbb_db_migration_data_timezone_p2 extends phpbb_db_migration { + public function effectively_installed() + { + return !$this->db_tools->sql_column_exists($this->table_prefix . 'users', 'user_dst'); + } + static public function depends_on() { return array('phpbb_db_migration_data_timezone'); diff --git a/phpBB/includes/db/migration/install.php b/phpBB/includes/db/migration/install.php deleted file mode 100644 index 95f3a3b994..0000000000 --- a/phpBB/includes/db/migration/install.php +++ /dev/null @@ -1,138 +0,0 @@ - 'phpbb_db_migration_data_3_0_1_rc1', - '3.0.1' => 'phpbb_db_migration_data_3_0_1', - '3.0.2-rc1' => 'phpbb_db_migration_data_3_0_2_rc1', - '3.0.2-rc2' => 'phpbb_db_migration_data_3_0_2_rc2', - '3.0.2' => 'phpbb_db_migration_data_3_0_2', - '3.0.3-rc1' => 'phpbb_db_migration_data_3_0_3_rc1', - '3.0.3' => 'phpbb_db_migration_data_3_0_3', - '3.0.4-rc1' => 'phpbb_db_migration_data_3_0_4_rc1', - '3.0.4' => 'phpbb_db_migration_data_3_0_4', - '3.0.5-rc1' => array( - 'phpbb_db_migration_data_3_0_5_rc1', - 'phpbb_db_migration_data_3_0_5_rc1part2', - ), - '3.0.5' => 'phpbb_db_migration_data_3_0_5', - '3.0.6-rc1' => 'phpbb_db_migration_data_3_0_6_rc1', - '3.0.6-rc2' => 'phpbb_db_migration_data_3_0_6_rc2', - '3.0.6-rc3' => 'phpbb_db_migration_data_3_0_6_rc3', - '3.0.6-rc4' => 'phpbb_db_migration_data_3_0_6_rc4', - '3.0.6' => 'phpbb_db_migration_data_3_0_6', - '3.0.7-rc1' => 'phpbb_db_migration_data_3_0_7_rc1', - '3.0.7-rc2' => 'phpbb_db_migration_data_3_0_7_rc2', - '3.0.7' => 'phpbb_db_migration_data_3_0_7', - '3.0.7-pl1' => 'phpbb_db_migration_data_3_0_7_pl1', - '3.0.8-rc1' => 'phpbb_db_migration_data_3_0_8_rc1', - '3.0.8' => 'phpbb_db_migration_data_3_0_8', - '3.0.9-rc1' => 'phpbb_db_migration_data_3_0_9_rc1', - '3.0.9-rc2' => 'phpbb_db_migration_data_3_0_9_rc2', - '3.0.9-rc3' => 'phpbb_db_migration_data_3_0_9_rc3', - '3.0.9-rc4' => 'phpbb_db_migration_data_3_0_9_rc4', - '3.0.9' => 'phpbb_db_migration_data_3_0_9', - '3.0.10-rc1' => 'phpbb_db_migration_data_3_0_10_rc1', - '3.0.10-rc2' => 'phpbb_db_migration_data_3_0_10_rc2', - '3.0.10-rc3' => 'phpbb_db_migration_data_3_0_10_rc3', - '3.0.10' => 'phpbb_db_migration_data_3_0_10', - '3.0.11-rc1' => 'phpbb_db_migration_data_3_0_11_rc1', - '3.0.11-rc2' => 'phpbb_db_migration_data_3_0_11_rc2', - '3.0.11' => 'phpbb_db_migration_data_3_0_11', - '3.0.12-rc1' => 'phpbb_db_migration_data_3_0_12_rc1', - '3.1.0-dev' => array( - 'phpbb_db_migration_data_style_update_p1', - 'phpbb_db_migration_data_style_update_p2', - 'phpbb_db_migration_data_timezone', - 'phpbb_db_migration_data_timezone_p2', - 'phpbb_db_migration_data_extensions', - 'phpbb_db_migration_data_3_1_0_dev', - ), - ); - - public function install(phpbb_db_driver $db, phpbb_db_tools $db_tools, $table_prefix, $version) - { - $this->create_table($db_tools, $table_prefix); - - $this->guess_installed_migrations($db, $table_prefix, $version); - } - - protected function create_table(phpbb_db_tools $db_tools, $table_prefix) - { - if (!$db_tools->sql_table_exists($table_prefix . 'migrations')) - { - $db_tools->sql_create_table($table_prefix . 'migrations', array( - 'COLUMNS' => array( - 'migration_name' => array('VCHAR', ''), - 'migration_depends_on' => array('TEXT', ''), - 'migration_schema_done' => array('BOOL', 0), - 'migration_data_done' => array('BOOL', 0), - 'migration_data_state' => array('TEXT', ''), - 'migration_start_time' => array('TIMESTAMP', 0), - 'migration_end_time' => array('TIMESTAMP', 0), - ), - 'PRIMARY_KEY' => 'migration_name', - )); - } - } - - /** - * Guess what migrations have been installed based on phpBB version - * - * @param mixed $version - */ - protected function guess_installed_migrations(phpbb_db_driver $db, $table_prefix, $version) - { - $installed = array(); - foreach ($this->version_to_migration as $compare => $migration_list) - { - if (version_compare($version, $compare, '>=')) - { - // The migration should have effectively been installed already - if (!is_array($migration_list)) - { - $migration_list = array($migration_list); - } - - foreach ($migration_list as $migration_name) - { - $sql = 'SELECT 1 FROM ' . $table_prefix . "migrations - WHERE migration_name = '" . $db->sql_escape($migration_name) . "'"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$row) - { - $sql_ary = array( - 'migration_name' => $migration_name, - 'migration_depends_on' => serialize($migration_name::depends_on()), - 'migration_schema_done' => 1, - 'migration_data_done' => 1, - 'migration_data_state' => '', - 'migration_start_time' => 0, - 'migration_end_time' => 0, - ); - $sql = 'INSERT INTO ' . $table_prefix . 'migrations ' . - $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - } - } - } - } - } -} -- cgit v1.2.1 From 747e51491859507ad2f1891df5df4e563c23dd57 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 14 Jan 2013 12:38:14 -0600 Subject: [feature/migrations] Reports table schema changes in recent develop PHPBB3-9737 --- phpBB/includes/db/migration/data/3_1_0_dev.php | 1 + .../db/migration/data/reported_posts_display.php | 42 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 phpBB/includes/db/migration/data/reported_posts_display.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/3_1_0_dev.php b/phpBB/includes/db/migration/data/3_1_0_dev.php index ac8882cb3a..8b437104e0 100644 --- a/phpBB/includes/db/migration/data/3_1_0_dev.php +++ b/phpBB/includes/db/migration/data/3_1_0_dev.php @@ -21,6 +21,7 @@ class phpbb_db_migration_data_3_1_0_dev extends phpbb_db_migration 'phpbb_db_migration_data_extensions', 'phpbb_db_migration_data_style_update_p2', 'phpbb_db_migration_data_timezone_p2', + 'phpbb_db_migration_data_reported_posts_display', ); } diff --git a/phpBB/includes/db/migration/data/reported_posts_display.php b/phpBB/includes/db/migration/data/reported_posts_display.php new file mode 100644 index 0000000000..fa605e28e5 --- /dev/null +++ b/phpBB/includes/db/migration/data/reported_posts_display.php @@ -0,0 +1,42 @@ +db_tools->sql_column_exists($this->table_prefix . 'reports', 'reported_post_enable_bbcode'); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'reports' => array( + 'reported_post_enable_bbcode' => array('BOOL', 1), + 'reported_post_enable_smilies' => array('BOOL', 1), + 'reported_post_enable_magic_url' => array('BOOL', 1), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'reports' => array( + 'reported_post_enable_bbcode', + 'reported_post_enable_smilies', + 'reported_post_enable_magic_url', + ), + ), + ); + } +} -- cgit v1.2.1 From 58507f250bf11dda6a138d5f66057ec413750e03 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 14 Jan 2013 12:45:01 -0600 Subject: [feature/migrations] Subdirectories for migration data Organization will set you free PHPBB3-9737 --- phpBB/includes/db/migration/data/30x/3_0_1.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_10.php | 28 ++ .../includes/db/migration/data/30x/3_0_10_rc1.php | 30 ++ .../includes/db/migration/data/30x/3_0_10_rc2.php | 28 ++ .../includes/db/migration/data/30x/3_0_10_rc3.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_11.php | 28 ++ .../includes/db/migration/data/30x/3_0_11_rc1.php | 95 +++++ .../includes/db/migration/data/30x/3_0_11_rc2.php | 50 +++ .../includes/db/migration/data/30x/3_0_12_rc1.php | 123 +++++++ phpBB/includes/db/migration/data/30x/3_0_1_rc1.php | 108 ++++++ phpBB/includes/db/migration/data/30x/3_0_2.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_2_rc1.php | 32 ++ phpBB/includes/db/migration/data/30x/3_0_2_rc2.php | 80 ++++ phpBB/includes/db/migration/data/30x/3_0_3.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_3_rc1.php | 83 +++++ phpBB/includes/db/migration/data/30x/3_0_4.php | 49 +++ phpBB/includes/db/migration/data/30x/3_0_4_rc1.php | 123 +++++++ phpBB/includes/db/migration/data/30x/3_0_5.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_5_rc1.php | 124 +++++++ .../db/migration/data/30x/3_0_5_rc1part2.php | 42 +++ phpBB/includes/db/migration/data/30x/3_0_6.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_6_rc1.php | 324 ++++++++++++++++ phpBB/includes/db/migration/data/30x/3_0_6_rc2.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_6_rc3.php | 40 ++ phpBB/includes/db/migration/data/30x/3_0_6_rc4.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_7.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_7_pl1.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_7_rc1.php | 76 ++++ phpBB/includes/db/migration/data/30x/3_0_7_rc2.php | 73 ++++ phpBB/includes/db/migration/data/30x/3_0_8.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_8_rc1.php | 221 +++++++++++ phpBB/includes/db/migration/data/30x/3_0_9.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_9_rc1.php | 124 +++++++ phpBB/includes/db/migration/data/30x/3_0_9_rc2.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_9_rc3.php | 28 ++ phpBB/includes/db/migration/data/30x/3_0_9_rc4.php | 28 ++ phpBB/includes/db/migration/data/310/dev.php | 406 +++++++++++++++++++++ .../includes/db/migration/data/310/extensions.php | 69 ++++ .../migration/data/310/reported_posts_display.php | 42 +++ .../db/migration/data/310/style_update_p1.php | 157 ++++++++ .../db/migration/data/310/style_update_p2.php | 129 +++++++ phpBB/includes/db/migration/data/310/timezone.php | 163 +++++++++ .../includes/db/migration/data/310/timezone_p2.php | 43 +++ phpBB/includes/db/migration/data/3_0_1.php | 28 -- phpBB/includes/db/migration/data/3_0_10.php | 28 -- phpBB/includes/db/migration/data/3_0_10_rc1.php | 30 -- phpBB/includes/db/migration/data/3_0_10_rc2.php | 28 -- phpBB/includes/db/migration/data/3_0_10_rc3.php | 28 -- phpBB/includes/db/migration/data/3_0_11.php | 28 -- phpBB/includes/db/migration/data/3_0_11_rc1.php | 95 ----- phpBB/includes/db/migration/data/3_0_11_rc2.php | 50 --- phpBB/includes/db/migration/data/3_0_12_rc1.php | 123 ------- phpBB/includes/db/migration/data/3_0_1_rc1.php | 108 ------ phpBB/includes/db/migration/data/3_0_2.php | 28 -- phpBB/includes/db/migration/data/3_0_2_rc1.php | 32 -- phpBB/includes/db/migration/data/3_0_2_rc2.php | 80 ---- phpBB/includes/db/migration/data/3_0_3.php | 28 -- phpBB/includes/db/migration/data/3_0_3_rc1.php | 83 ----- phpBB/includes/db/migration/data/3_0_4.php | 49 --- phpBB/includes/db/migration/data/3_0_4_rc1.php | 123 ------- phpBB/includes/db/migration/data/3_0_5.php | 28 -- phpBB/includes/db/migration/data/3_0_5_rc1.php | 124 ------- .../includes/db/migration/data/3_0_5_rc1part2.php | 42 --- phpBB/includes/db/migration/data/3_0_6.php | 28 -- phpBB/includes/db/migration/data/3_0_6_rc1.php | 324 ---------------- phpBB/includes/db/migration/data/3_0_6_rc2.php | 28 -- phpBB/includes/db/migration/data/3_0_6_rc3.php | 40 -- phpBB/includes/db/migration/data/3_0_6_rc4.php | 28 -- phpBB/includes/db/migration/data/3_0_7.php | 28 -- phpBB/includes/db/migration/data/3_0_7_pl1.php | 28 -- phpBB/includes/db/migration/data/3_0_7_rc1.php | 76 ---- phpBB/includes/db/migration/data/3_0_7_rc2.php | 73 ---- phpBB/includes/db/migration/data/3_0_8.php | 28 -- phpBB/includes/db/migration/data/3_0_8_rc1.php | 221 ----------- phpBB/includes/db/migration/data/3_0_9.php | 28 -- phpBB/includes/db/migration/data/3_0_9_rc1.php | 124 ------- phpBB/includes/db/migration/data/3_0_9_rc2.php | 28 -- phpBB/includes/db/migration/data/3_0_9_rc3.php | 28 -- phpBB/includes/db/migration/data/3_0_9_rc4.php | 28 -- phpBB/includes/db/migration/data/3_1_0_dev.php | 406 --------------------- phpBB/includes/db/migration/data/extensions.php | 69 ---- .../db/migration/data/reported_posts_display.php | 42 --- .../includes/db/migration/data/style_update_p1.php | 157 -------- .../includes/db/migration/data/style_update_p2.php | 129 ------- phpBB/includes/db/migration/data/timezone.php | 163 --------- phpBB/includes/db/migration/data/timezone_p2.php | 43 --- 86 files changed, 3310 insertions(+), 3310 deletions(-) create mode 100644 phpBB/includes/db/migration/data/30x/3_0_1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_10.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_10_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_10_rc2.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_10_rc3.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_11.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_11_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_11_rc2.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_12_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_1_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_2.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_2_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_2_rc2.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_3.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_3_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_4.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_4_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_5.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_5_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_5_rc1part2.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_6.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_6_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_6_rc2.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_6_rc3.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_6_rc4.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_7.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_7_pl1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_7_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_7_rc2.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_8.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_8_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_9.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_9_rc1.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_9_rc2.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_9_rc3.php create mode 100644 phpBB/includes/db/migration/data/30x/3_0_9_rc4.php create mode 100644 phpBB/includes/db/migration/data/310/dev.php create mode 100644 phpBB/includes/db/migration/data/310/extensions.php create mode 100644 phpBB/includes/db/migration/data/310/reported_posts_display.php create mode 100644 phpBB/includes/db/migration/data/310/style_update_p1.php create mode 100644 phpBB/includes/db/migration/data/310/style_update_p2.php create mode 100644 phpBB/includes/db/migration/data/310/timezone.php create mode 100644 phpBB/includes/db/migration/data/310/timezone_p2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_10.php delete mode 100644 phpBB/includes/db/migration/data/3_0_10_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_10_rc2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_10_rc3.php delete mode 100644 phpBB/includes/db/migration/data/3_0_11.php delete mode 100644 phpBB/includes/db/migration/data/3_0_11_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_11_rc2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_12_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_1_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_2_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_2_rc2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_3.php delete mode 100644 phpBB/includes/db/migration/data/3_0_3_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_4.php delete mode 100644 phpBB/includes/db/migration/data/3_0_4_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_5.php delete mode 100644 phpBB/includes/db/migration/data/3_0_5_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_5_rc1part2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_6.php delete mode 100644 phpBB/includes/db/migration/data/3_0_6_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_6_rc2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_6_rc3.php delete mode 100644 phpBB/includes/db/migration/data/3_0_6_rc4.php delete mode 100644 phpBB/includes/db/migration/data/3_0_7.php delete mode 100644 phpBB/includes/db/migration/data/3_0_7_pl1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_7_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_7_rc2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_8.php delete mode 100644 phpBB/includes/db/migration/data/3_0_8_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_9.php delete mode 100644 phpBB/includes/db/migration/data/3_0_9_rc1.php delete mode 100644 phpBB/includes/db/migration/data/3_0_9_rc2.php delete mode 100644 phpBB/includes/db/migration/data/3_0_9_rc3.php delete mode 100644 phpBB/includes/db/migration/data/3_0_9_rc4.php delete mode 100644 phpBB/includes/db/migration/data/3_1_0_dev.php delete mode 100644 phpBB/includes/db/migration/data/extensions.php delete mode 100644 phpBB/includes/db/migration/data/reported_posts_display.php delete mode 100644 phpBB/includes/db/migration/data/style_update_p1.php delete mode 100644 phpBB/includes/db/migration/data/style_update_p2.php delete mode 100644 phpBB/includes/db/migration/data/timezone.php delete mode 100644 phpBB/includes/db/migration/data/timezone_p2.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/30x/3_0_1.php b/phpBB/includes/db/migration/data/30x/3_0_1.php new file mode 100644 index 0000000000..c996a0138a --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_1.php @@ -0,0 +1,28 @@ +config['version'], '3.0.1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_1_rc1'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.1')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_10.php b/phpBB/includes/db/migration/data/30x/3_0_10.php new file mode 100644 index 0000000000..122f93d6b4 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_10.php @@ -0,0 +1,28 @@ +config['version'], '3.0.10', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_10_rc3'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.10')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_10_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_10_rc1.php new file mode 100644 index 0000000000..0ed05812dc --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_10_rc1.php @@ -0,0 +1,30 @@ +config['version'], '3.0.10-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_9'); + } + + public function update_data() + { + return array( + array('config.add', array('email_max_chunk_size', 50)), + + array('config.update', array('version', '3.0.10-rc1')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_10_rc2.php b/phpBB/includes/db/migration/data/30x/3_0_10_rc2.php new file mode 100644 index 0000000000..b14b3b00aa --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_10_rc2.php @@ -0,0 +1,28 @@ +config['version'], '3.0.10-rc2', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_10_rc1'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.10-rc2')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_10_rc3.php b/phpBB/includes/db/migration/data/30x/3_0_10_rc3.php new file mode 100644 index 0000000000..473057d65d --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_10_rc3.php @@ -0,0 +1,28 @@ +config['version'], '3.0.10-rc3', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_10_rc2'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.10-rc3')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_11.php b/phpBB/includes/db/migration/data/30x/3_0_11.php new file mode 100644 index 0000000000..e063c699cc --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_11.php @@ -0,0 +1,28 @@ +config['version'], '3.0.11', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_11_rc2'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.11')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_11_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_11_rc1.php new file mode 100644 index 0000000000..dddfc0e0e7 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_11_rc1.php @@ -0,0 +1,95 @@ +config['version'], '3.0.11-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_10'); + } + + public function update_data() + { + return array( + array('custom', array(array(&$this, 'cleanup_deactivated_styles'))), + array('custom', array(array(&$this, 'delete_orphan_private_messages'))), + + array('config.update', array('version', '3.0.11-rc1')), + ); + } + + public function cleanup_deactivated_styles() + { + // Updates users having current style a deactivated one + $sql = 'SELECT style_id + FROM ' . STYLES_TABLE . ' + WHERE style_active = 0'; + $result = $this->sql_query($sql); + + $deactivated_style_ids = array(); + while ($style_id = $this->db->sql_fetchfield('style_id', false, $result)) + { + $deactivated_style_ids[] = (int) $style_id; + } + $this->db->sql_freeresult($result); + + if (!empty($deactivated_style_ids)) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_style = ' . (int) $this->config['default_style'] .' + WHERE ' . $this->db->sql_in_set('user_style', $deactivated_style_ids); + $this->sql_query($sql); + } + } + + public function delete_orphan_private_messages() + { + // Delete orphan private messages + $batch_size = 500; + + $sql_array = array( + 'SELECT' => 'p.msg_id', + 'FROM' => array( + PRIVMSGS_TABLE => 'p', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(PRIVMSGS_TO_TABLE => 't'), + 'ON' => 'p.msg_id = t.msg_id', + ), + ), + 'WHERE' => 't.user_id IS NULL', + ); + $sql = $this->db->sql_build_query('SELECT', $sql_array); + + $result = $this->db->sql_query_limit($sql, $batch_size); + + $delete_pms = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $delete_pms[] = (int) $row['msg_id']; + } + $this->db->sql_freeresult($result); + + if (!empty($delete_pms)) + { + $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' + WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms); + $this->sql_query($sql); + + // Return false to have the Migrator call this function again + return false; + } + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_11_rc2.php b/phpBB/includes/db/migration/data/30x/3_0_11_rc2.php new file mode 100644 index 0000000000..fac8523e8c --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_11_rc2.php @@ -0,0 +1,50 @@ +config['version'], '3.0.11-rc2', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_11_rc1'); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_novalue' => array('BOOL', 0), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_novalue', + ), + ), + ); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.11-rc2')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_12_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_12_rc1.php new file mode 100644 index 0000000000..6a31a51201 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_12_rc1.php @@ -0,0 +1,123 @@ +config['version'], '3.0.12-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_11'); + } + + public function update_data() + { + return array( + array('custom', array(array(&$this, 'update_module_auth'))), + array('custom', array(array(&$this, 'update_bots'))), + array('custom', array(array(&$this, 'disable_bots_from_receiving_pms'))), + + array('config.update', array('version', '3.0.12-rc1')), + ); + } + + public function disable_bots_from_receiving_pms() + { + // Disable receiving pms for bots + $sql = 'SELECT user_id + FROM ' . BOTS_TABLE; + $result = $this->db->sql_query($sql); + + $bot_user_ids = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $bot_user_ids[] = (int) $row['user_id']; + } + $this->db->sql_freeresult($result); + + if (!empty($bot_user_ids)) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_allow_pm = 0 + WHERE ' . $this->db->sql_in_set('user_id', $bot_user_ids); + $this->sql_query($sql); + } + } + + public function update_module_auth() + { + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET module_auth = \'acl_u_sig\' + WHERE module_class = \'ucp\' + AND module_basename = \'profile\' + AND module_mode = \'signature\''; + $this->sql_query($sql); + } + + public function update_bots() + { + // Update bots + if (!function_exists('user_delete')) + { + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + } + + $bots_updates = array( + // Bot Deletions + 'NG-Search [Bot]' => false, + 'Nutch/CVS [Bot]' => false, + 'OmniExplorer [Bot]' => false, + 'Seekport [Bot]' => false, + 'Synoo [Bot]' => false, + 'WiseNut [Bot]' => false, + + // Bot Updates + // Bot name to bot user agent map + 'Baidu [Spider]' => 'Baiduspider', + 'Exabot [Bot]' => 'Exabot', + 'Voyager [Bot]' => 'voyager/', + 'W3C [Validator]' => 'W3C_Validator', + ); + + foreach ($bots_updates as $bot_name => $bot_agent) + { + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . ' + WHERE user_type = ' . USER_IGNORE . " + AND username_clean = '" . $this->db->sql_escape(utf8_clean_string($bot_name)) . "'"; + $result = $this->db->sql_query($sql); + $bot_user_id = (int) $this->db->sql_fetchfield('user_id'); + $this->db->sql_freeresult($result); + + if ($bot_user_id) + { + if ($bot_agent === false) + { + $sql = 'DELETE FROM ' . BOTS_TABLE . " + WHERE user_id = $bot_user_id"; + $this->sql_query($sql); + + user_delete('remove', $bot_user_id); + } + else + { + $sql = 'UPDATE ' . BOTS_TABLE . " + SET bot_agent = '" . $this->db->sql_escape($bot_agent) . "' + WHERE user_id = $bot_user_id"; + $this->sql_query($sql); + } + } + } + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_1_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_1_rc1.php new file mode 100644 index 0000000000..562ccf077c --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_1_rc1.php @@ -0,0 +1,108 @@ +config['version'], '3.0.1-rc1', '>='); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'forums' => array( + 'display_subforum_list' => array('BOOL', 1), + ), + $this->table_prefix . 'sessions' => array( + 'session_forum_id' => array('UINT', 0), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'groups' => array( + 'group_legend', + ), + ), + 'add_index' => array( + $this->table_prefix . 'sessions' => array( + 'session_forum_id' => array('session_forum_id'), + ), + $this->table_prefix . 'groups' => array( + 'group_legend_name' => array('group_legend', 'group_name'), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'forums' => array( + 'display_subforum_list', + ), + $this->table_prefix . 'sessions' => array( + 'session_forum_id', + ), + ), + 'add_index' => array( + $this->table_prefix . 'groups' => array( + 'group_legend' => array('group_legend'), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'sessions' => array( + 'session_forum_id', + ), + $this->table_prefix . 'groups' => array( + 'group_legend_name', + ), + ), + ); + } + + public function update_data() + { + return array( + array('custom', array(array(&$this, 'fix_unset_last_view_time'))), + array('custom', array(array(&$this, 'reset_smiley_size'))), + + array('config.update', array('version', '3.0.1-rc1')), + ); + } + + public function fix_unset_last_view_time() + { + $sql = 'UPDATE ' . $this->table_prefix . "topics + SET topic_last_view_time = topic_last_post_time + WHERE topic_last_view_time = 0"; + $this->sql_query($sql); + } + + public function reset_smiley_size() + { + // Update smiley sizes + $smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif'); + + foreach ($smileys as $smiley) + { + if (file_exists($this->phpbb_root_path . 'images/smilies/' . $smiley)) + { + list($width, $height) = getimagesize($this->phpbb_root_path . 'images/smilies/' . $smiley); + + $sql = 'UPDATE ' . SMILIES_TABLE . ' + SET smiley_width = ' . $width . ', smiley_height = ' . $height . " + WHERE smiley_url = '" . $this->db->sql_escape($smiley) . "'"; + + $this->sql_query($sql); + } + } + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_2.php b/phpBB/includes/db/migration/data/30x/3_0_2.php new file mode 100644 index 0000000000..eed5acef82 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_2.php @@ -0,0 +1,28 @@ +config['version'], '3.0.2', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_2_rc2'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.2')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_2_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_2_rc1.php new file mode 100644 index 0000000000..a960e90765 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_2_rc1.php @@ -0,0 +1,32 @@ +config['version'], '3.0.2-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_1'); + } + + public function update_data() + { + return array( + array('config.add', array('referer_validation', '1')), + array('config.add', array('check_attachment_content', '1')), + array('config.add', array('mime_triggers', 'body|head|html|img|plaintext|a href|pre|script|table|title')), + + array('config.update', array('version', '3.0.2-rc1')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_2_rc2.php b/phpBB/includes/db/migration/data/30x/3_0_2_rc2.php new file mode 100644 index 0000000000..8917dfea77 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_2_rc2.php @@ -0,0 +1,80 @@ +config['version'], '3.0.2-rc2', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_2_rc1'); + } + + public function update_schema() + { + return array( + 'change_columns' => array( + $this->table_prefix . 'drafts' => array( + 'draft_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'forums' => array( + 'forum_last_post_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'posts' => array( + 'post_subject' => array('STEXT_UNI', '', 'true_sort'), + ), + $this->table_prefix . 'privmsgs' => array( + 'message_subject' => array('STEXT_UNI', ''), + ), + $this->table_prefix . 'topics' => array( + 'topic_title' => array('STEXT_UNI', '', 'true_sort'), + 'topic_last_post_subject' => array('STEXT_UNI', ''), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'sessions' => array( + 'session_forum_id', + ), + ), + 'add_index' => array( + $this->table_prefix . 'sessions' => array( + 'session_fid' => array('session_forum_id'), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'add_index' => array( + $this->table_prefix . 'sessions' => array( + 'session_forum_id' => array( + 'session_forum_id', + ), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'sessions' => array( + 'session_fid', + ), + ), + ); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.2-rc2')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_3.php b/phpBB/includes/db/migration/data/30x/3_0_3.php new file mode 100644 index 0000000000..8984cf7b76 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_3.php @@ -0,0 +1,28 @@ +config['version'], '3.0.3', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_3_rc1'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.3')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_3_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_3_rc1.php new file mode 100644 index 0000000000..4b102e1a2e --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_3_rc1.php @@ -0,0 +1,83 @@ +config['version'], '3.0.3-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_2'); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'styles_template' => array( + 'template_inherits_id' => array('UINT:4', 0), + 'template_inherit_path' => array('VCHAR', ''), + ), + $this->table_prefix . 'groups' => array( + 'group_max_recipients' => array('UINT', 0), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'styles_template' => array( + 'template_inherits_id', + 'template_inherit_path', + ), + $this->table_prefix . 'groups' => array( + 'group_max_recipients', + ), + ), + ); + } + + public function update_data() + { + return array( + array('config.add', array('enable_queue_trigger', '0')), + array('config.add', array('queue_trigger_posts', '3')), + array('config.add', array('pm_max_recipients', '0')), + array('custom', array(array(&$this, 'set_group_default_max_recipients'))), + array('config.add', array('dbms_version', $this->db->sql_server_info(true))), + array('permission.add', array('u_masspm_group', true, 'u_masspm')), + array('custom', array(array(&$this, 'correct_acp_email_permissions'))), + + array('config.update', array('version', '3.0.3-rc1')), + ); + } + + public function correct_acp_email_permissions() + { + $sql = 'UPDATE ' . $this->table_prefix . 'modules + SET module_auth = \'acl_a_email && cfg_email_enable\' + WHERE module_class = \'acp\' + AND module_basename = \'email\''; + $this->sql_query($sql); + } + + public function set_group_default_max_recipients() + { + // Set maximum number of recipients for the registered users, bots, guests group + $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5 + WHERE ' . $this->db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS')); + $this->sql_query($sql); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_4.php b/phpBB/includes/db/migration/data/30x/3_0_4.php new file mode 100644 index 0000000000..9a0c132e78 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_4.php @@ -0,0 +1,49 @@ +config['version'], '3.0.4', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_4_rc1'); + } + + public function update_data() + { + return array( + array('custom', array(array(&$this, 'rename_log_delete_topic'))), + + array('config.update', array('version', '3.0.4')), + ); + } + + public function rename_log_delete_topic() + { + if ($this->db->sql_layer == 'oracle') + { + // log_operation is CLOB - but we can change this later + $sql = 'UPDATE ' . $this->table_prefix . "log + SET log_operation = 'LOG_DELETE_TOPIC' + WHERE log_operation LIKE 'LOG_TOPIC_DELETED'"; + $this->sql_query($sql); + } + else + { + $sql = 'UPDATE ' . $this->table_prefix . "log + SET log_operation = 'LOG_DELETE_TOPIC' + WHERE log_operation = 'LOG_TOPIC_DELETED'"; + $this->sql_query($sql); + } + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_4_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_4_rc1.php new file mode 100644 index 0000000000..8ad75a557b --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_4_rc1.php @@ -0,0 +1,123 @@ +config['version'], '3.0.4-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_3'); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_profile' => array('BOOL', 0), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'styles' => array( + 'style_id' => array('UINT', NULL, 'auto_increment'), + 'template_id' => array('UINT', 0), + 'theme_id' => array('UINT', 0), + 'imageset_id' => array('UINT', 0), + ), + $this->table_prefix . 'styles_imageset' => array( + 'imageset_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_imageset_data' => array( + 'image_id' => array('UINT', NULL, 'auto_increment'), + 'imageset_id' => array('UINT', 0), + ), + $this->table_prefix . 'styles_theme' => array( + 'theme_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_template' => array( + 'template_id' => array('UINT', NULL, 'auto_increment'), + ), + $this->table_prefix . 'styles_template_data' => array( + 'template_id' => array('UINT', 0), + ), + $this->table_prefix . 'forums' => array( + 'forum_style' => array('UINT', 0), + ), + $this->table_prefix . 'users' => array( + 'user_style' => array('UINT', 0), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_profile', + ), + ), + ); + } + + public function update_data() + { + return array( + array('custom', array(array(&$this, 'update_custom_profile_fields'))), + + array('config.update', array('version', '3.0.4-rc1')), + ); + } + + public function update_custom_profile_fields() + { + // Update the Custom Profile Fields based on previous settings to the new format + $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide + FROM ' . PROFILE_FIELDS_TABLE; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql_ary = array( + 'field_required' => 0, + 'field_show_on_reg' => 0, + 'field_hide' => 0, + 'field_show_profile'=> 0, + ); + + if ($row['field_required']) + { + $sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; + } + else if ($row['field_show_on_reg']) + { + $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; + } + else if ($row['field_hide']) + { + // Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module + $sql_ary['field_hide'] = 1; + } + else + { + // equivelant to "none", which is the "Display in user control panel" option + $sql_ary['field_show_profile'] = 1; + } + + $this->sql_query('UPDATE ' . $this->table_prefix . 'profile_fields SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary); + } + + $this->db->sql_freeresult($result); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_5.php b/phpBB/includes/db/migration/data/30x/3_0_5.php new file mode 100644 index 0000000000..16d2dee457 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_5.php @@ -0,0 +1,28 @@ +config['version'], '3.0.5', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_5_rc1part2'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.5')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_5_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_5_rc1.php new file mode 100644 index 0000000000..ea17cc1e31 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_5_rc1.php @@ -0,0 +1,124 @@ +config['version'], '3.0.5-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_4'); + } + + public function update_schema() + { + return array( + 'change_columns' => array( + $this->table_prefix . 'forums' => array( + 'forum_style' => array('UINT', 0), + ), + ), + ); + } + + public function update_data() + { + $search_indexing_state = $this->config['search_indexing_state']; + + return array( + array('config.add', array('captcha_gd_wave', 0)), + array('config.add', array('captcha_gd_3d_noise', 1)), + array('config.add', array('captcha_gd_fonts', 1)), + array('config.add', array('confirm_refresh', 1)), + array('config.add', array('max_num_search_keywords', 10)), + array('config.remove', array('search_indexing_state')), + array('config.add', array('search_indexing_state', $search_indexing_state, true)), + array('custom', array(array(&$this, 'hash_old_passwords'))), + array('custom', array(array(&$this, 'update_ichiro_bot'))), + ); + } + + public function hash_old_passwords() + { + $sql = 'SELECT user_id, user_password + FROM ' . $this->table_prefix . 'users + WHERE user_pass_convert = 1'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + if (strlen($row['user_password']) == 32) + { + $sql_ary = array( + 'user_password' => phpbb_hash($row['user_password']), + ); + + $this->sql_query('UPDATE ' . $this->table_prefix . 'users SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id']); + } + } + $this->db->sql_freeresult($result); + } + + public function update_ichiro_bot() + { + // Adjust bot entry + $sql = 'UPDATE ' . $this->table_prefix . "bots + SET bot_agent = 'ichiro/' + WHERE bot_agent = 'ichiro/2'"; + $this->sql_query($sql); + } + + public function remove_duplicate_auth_options() + { + // Before we are able to add a unique key to auth_option, we need to remove duplicate entries + $sql = 'SELECT auth_option + FROM ' . $this->table_prefix . 'acl_options + GROUP BY auth_option + HAVING COUNT(*) >= 2'; + $result = $this->db->sql_query($sql); + + $auth_options = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $auth_options[] = $row['auth_option']; + } + $this->db->sql_freeresult($result); + + // Remove specific auth options + if (!empty($auth_options)) + { + foreach ($auth_options as $option) + { + // Select auth_option_ids... the largest id will be preserved + $sql = 'SELECT auth_option_id + FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $db->sql_escape($option) . "' + ORDER BY auth_option_id DESC"; + // sql_query_limit not possible here, due to bug in postgresql layer + $result = $this->db->sql_query($sql); + + // Skip first row, this is our original auth option we want to preserve + $row = $this->db->sql_fetchrow($result); + + while ($row = $this->db->sql_fetchrow($result)) + { + // Ok, remove this auth option... + $this->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + $this->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); + } + $this->db->sql_freeresult($result); + } + } + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_5_rc1part2.php b/phpBB/includes/db/migration/data/30x/3_0_5_rc1part2.php new file mode 100644 index 0000000000..8538347b1a --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_5_rc1part2.php @@ -0,0 +1,42 @@ +config['version'], '3.0.5-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_5_rc1'); + } + + public function update_schema() + { + return array( + 'drop_keys' => array( + $this->table_prefix . 'acl_options' => array('auth_option'), + ), + 'add_unique_index' => array( + $this->table_prefix . 'acl_options' => array( + 'auth_option' => array('auth_option'), + ), + ), + ); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.5-rc1')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_6.php b/phpBB/includes/db/migration/data/30x/3_0_6.php new file mode 100644 index 0000000000..bb651dc7cd --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_6.php @@ -0,0 +1,28 @@ +config['version'], '3.0.6', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_6_rc4'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.6')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_6_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_6_rc1.php new file mode 100644 index 0000000000..38c282ebf0 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_6_rc1.php @@ -0,0 +1,324 @@ +config['version'], '3.0.6-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_5'); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'confirm' => array( + 'attempts' => array('UINT', 0), + ), + $this->table_prefix . 'users' => array( + 'user_new' => array('BOOL', 1), + 'user_reminded' => array('TINT:4', 0), + 'user_reminded_time' => array('TIMESTAMP', 0), + ), + $this->table_prefix . 'groups' => array( + 'group_skip_auth' => array('BOOL', 0, 'after' => 'group_founder_manage'), + ), + $this->table_prefix . 'privmsgs' => array( + 'message_reported' => array('BOOL', 0), + ), + $this->table_prefix . 'reports' => array( + 'pm_id' => array('UINT', 0), + ), + $this->table_prefix . 'profile_fields' => array( + 'field_show_on_vt' => array('BOOL', 0), + ), + $this->table_prefix . 'forums' => array( + 'forum_options' => array('UINT:20', 0), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'users' => array( + 'user_options' => array('UINT:11', 230271), + ), + ), + 'add_index' => array( + $this->table_prefix . 'reports' => array( + 'post_id' => array('post_id'), + 'pm_id' => array('pm_id'), + ), + $this->table_prefix . 'posts' => array( + 'post_username' => array('post_username:255'), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'confirm' => array( + 'attempts', + ), + $this->table_prefix . 'users' => array( + 'user_new', + 'user_reminded', + 'user_reminded_time', + ), + $this->table_prefix . 'groups' => array( + 'group_skip_auth', + ), + $this->table_prefix . 'privmsgs' => array( + 'message_reported', + ), + $this->table_prefix . 'reports' => array( + 'pm_id', + ), + $this->table_prefix . 'profile_fields' => array( + 'field_show_on_vt', + ), + $this->table_prefix . 'forums' => array( + 'forum_options', + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'reports' => array( + 'post_id', + 'pm_id', + ), + $this->table_prefix . 'posts' => array( + 'post_username', + ), + ), + ); + } + + public function update_data() + { + return array( + array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')), + array('if', array( + ($this->config['captcha_gd']), + array('config.update', array('captcha_plugin', 'phpbb_captcha_gd')), + )), + + array('config.add', array('feed_enable', 0)), + array('config.add', array('feed_limit', 10)), + array('config.add', array('feed_overall_forums', 1)), + array('config.add', array('feed_overall_forums_limit', 15)), + array('config.add', array('feed_overall_topics', 0)), + array('config.add', array('feed_overall_topics_limit', 15)), + array('config.add', array('feed_forum', 1)), + array('config.add', array('feed_topic', 1)), + array('config.add', array('feed_item_statistics', 1)), + + array('config.add', array('smilies_per_page', 50)), + array('config.add', array('allow_pm_report', 1)), + array('config.add', array('min_post_chars', 1)), + array('config.add', array('allow_quick_reply', 1)), + array('config.add', array('new_member_post_limit', 0)), + array('config.add', array('new_member_group_default', 0)), + array('config.add', array('delete_time', $this->config['edit_time'])), + + array('config.add', array('allow_avatar', 0)), + array('if', array( + ($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']), + array('config.update', array('allow_avatar', 1)), + )), + array('config.add', array('allow_avatar_remote_upload', 0)), + array('if', array( + ($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']), + array('config.update', array('allow_avatar_remote_upload', 1)), + )), + + array('module.add', array( + 'acp', + 'ACP_BOARD_CONFIGURATION', + array( + 'module_basename' => 'acp_board', + 'modes' => array('feed'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_CAT_USERS', + array( + 'module_basename' => 'acp_users', + 'modes' => array('warnings'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_SERVER_CONFIGURATION', + array( + 'module_basename' => 'acp_send_statistics', + 'modes' => array('send_statistics'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_FORUM_BASED_PERMISSIONS', + array( + 'module_basename' => 'acp_permissions', + 'modes' => array('setting_forum_copy'), + ), + )), + array('module.add', array( + 'mcp', + 'MCP_REPORTS', + array( + 'module_basename' => 'mcp_pm_reports', + 'modes' => array('pm_reports','pm_reports_closed','pm_report_details'), + ), + )), + array('custom', array(array(&$this, 'add_newly_registered_group'))), + array('custom', array(array(&$this, 'set_user_options_default'))), + + array('config.update', array('version', '3.0.6-rc1')), + ); + } + + public function set_user_options_default() + { + // 229376 is the added value to enable all three signature options + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376'; + $this->sql_query($sql); + } + + public function add_newly_registered_group() + { + // Add newly_registered group... but check if it already exists (we always supported running the updater on any schema) + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . " + WHERE group_name = 'NEWLY_REGISTERED'"; + $result = $this->db->sql_query($sql); + $group_id = (int) $this->db->sql_fetchfield('group_id'); + $this->db->sql_freeresult($result); + + if (!$group_id) + { + $sql = 'INSERT INTO ' . GROUPS_TABLE . " (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5)"; + $this->sql_query($sql); + + $group_id = $this->db->sql_nextid(); + } + + // Insert new user role... at the end of the chain + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = 'ROLE_USER_NEW_MEMBER' + AND role_type = 'u_'"; + $result = $this->db->sql_query($sql); + $u_role = (int) $this->db->sql_fetchfield('role_id'); + $this->db->sql_freeresult($result); + + if (!$u_role) + { + $sql = 'SELECT MAX(role_order) as max_order_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_type = 'u_'"; + $result = $this->db->sql_query($sql); + $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); + $this->db->sql_freeresult($result); + + $next_order_id++; + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_USER_NEW_MEMBER', 'ROLE_DESCRIPTION_USER_NEW_MEMBER', 'u_', $next_order_id)"; + $this->sql_query($sql); + $u_role = $this->db->sql_nextid(); + + // Now add the correct data to the roles... + // The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups + $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')"; + $this->sql_query($sql); + + // Add user role to group + $sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)"; + $this->sql_query($sql); + } + + // Insert new forum role + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = 'ROLE_FORUM_NEW_MEMBER' + AND role_type = 'f_'"; + $result = $this->db->sql_query($sql); + $f_role = (int) $this->db->sql_fetchfield('role_id'); + $this->db->sql_freeresult($result); + + if (!$f_role) + { + $sql = 'SELECT MAX(role_order) as max_order_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_type = 'f_'"; + $result = $this->db->sql_query($sql); + $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); + $this->db->sql_freeresult($result); + + $next_order_id++; + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', $next_order_id)"; + $this->sql_query($sql); + $f_role = $this->db->sql_nextid(); + + $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')"; + $this->sql_query($sql); + } + + // Set every members user_new column to 0 (old users) only if there is no one yet (this makes sure we do not execute this more than once) + $sql = 'SELECT 1 + FROM ' . USERS_TABLE . ' + WHERE user_new = 0'; + $result = $this->db->sql_query_limit($sql, 1); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0'; + $this->sql_query($sql); + } + + // To mimick the old "feature" we will assign the forum role to every forum, regardless of the setting (this makes sure there are no "this does not work!!!! YUO!!!" posts... + // Check if the role is already assigned... + $sql = 'SELECT forum_id + FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id = ' . $f_role; + $result = $this->db->sql_query($sql); + $is_options = (int) $this->db->sql_fetchfield('forum_id'); + $this->db->sql_freeresult($result); + + // Not assigned at all... :/ + if (!$is_options) + { + // Get postable forums + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE forum_type != ' . FORUM_LINK; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)'); + } + $this->db->sql_freeresult($result); + } + + // Clear permissions... + include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext); + $auth_admin = new auth_admin(); + $auth_admin->acl_clear_prefetch(); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_6_rc2.php b/phpBB/includes/db/migration/data/30x/3_0_6_rc2.php new file mode 100644 index 0000000000..a939dbd489 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_6_rc2.php @@ -0,0 +1,28 @@ +config['version'], '3.0.6-rc2', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_6_rc1'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.6-rc2')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_6_rc3.php b/phpBB/includes/db/migration/data/30x/3_0_6_rc3.php new file mode 100644 index 0000000000..b3f09d8ab8 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_6_rc3.php @@ -0,0 +1,40 @@ +config['version'], '3.0.6-rc3', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_6_rc2'); + } + + public function update_data() + { + return array( + array('custom', array(array(&$this, 'update_cp_fields'))), + + array('config.update', array('version', '3.0.6-rc3')), + ); + } + + public function update_cp_fields() + { + // Update the Custom Profile Fields based on previous settings to the new format + $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . ' + SET field_show_on_vt = 1 + WHERE field_hide = 0 + AND (field_required = 1 OR field_show_on_reg = 1 OR field_show_profile = 1)'; + $this->sql_query($sql); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_6_rc4.php b/phpBB/includes/db/migration/data/30x/3_0_6_rc4.php new file mode 100644 index 0000000000..fc2923f99b --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_6_rc4.php @@ -0,0 +1,28 @@ +config['version'], '3.0.6-rc4', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_6_rc3'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.6-rc4')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_7.php b/phpBB/includes/db/migration/data/30x/3_0_7.php new file mode 100644 index 0000000000..9ff2e9e4ab --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_7.php @@ -0,0 +1,28 @@ +config['version'], '3.0.7', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_7_rc2'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.7')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_7_pl1.php b/phpBB/includes/db/migration/data/30x/3_0_7_pl1.php new file mode 100644 index 0000000000..c9cc9d19ac --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_7_pl1.php @@ -0,0 +1,28 @@ +config['version'], '3.0.7-pl1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_7'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.7-pl1')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_7_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_7_rc1.php new file mode 100644 index 0000000000..ffebf66f2d --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_7_rc1.php @@ -0,0 +1,76 @@ +config['version'], '3.0.7-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_6'); + } + + public function update_schema() + { + return array( + 'drop_keys' => array( + $this->table_prefix . 'log' => array( + 'log_time', + ), + ), + 'add_index' => array( + $this->table_prefix . 'topics_track' => array( + 'topic_id' => array('topic_id'), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'add_index' => array( + $this->table_prefix . 'log' => array( + 'log_time' => array('log_time'), + ), + ), + 'drop_keys' => array( + $this->table_prefix . 'topics_track' => array( + 'topic_id', + ), + ), + ); + } + + public function update_data() + { + return array( + array('config.add', array('feed_overall', 1)), + array('config.add', array('feed_http_auth', 0)), + array('config.add', array('feed_limit_post', $this->config['feed_limit'])), + array('config.add', array('feed_limit_topic', $this->config['feed_overall_topics_limit'])), + array('config.add', array('feed_topics_new', $this->config['feed_overall_topics'])), + array('config.add', array('feed_topics_active', $this->config['feed_overall_topics'])), + array('custom', array(array(&$this, 'delete_text_templates'))), + + array('config.update', array('version', '3.0.7-rc1')), + ); + } + + public function delete_text_templates() + { + // Delete all text-templates from the template_data + $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' + WHERE template_filename ' . $this->db->sql_like_expression($this->db->any_char . '.txt'); + $this->sql_query($sql); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_7_rc2.php b/phpBB/includes/db/migration/data/30x/3_0_7_rc2.php new file mode 100644 index 0000000000..55bc2bc679 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_7_rc2.php @@ -0,0 +1,73 @@ +config['version'], '3.0.7-rc2', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_7_rc1'); + } + + public function update_data() + { + return array( + array('custom', array(array(&$this, 'update_email_hash'))), + + array('config.update', array('version', '3.0.7-rc2')), + ); + } + + public function update_email_hash($start = 0) + { + $limit = 1000; + + $sql = 'SELECT user_id, user_email, user_email_hash + FROM ' . USERS_TABLE . ' + WHERE user_type <> ' . USER_IGNORE . " + AND user_email <> ''"; + $result = $this->db->sql_query_limit($sql, $limit, $start); + + $i = 0; + while ($row = $this->db->sql_fetchrow($result)) + { + $i++; + + // Snapshot of the phpbb_email_hash() function + // We cannot call it directly because the auto updater updates the DB first. :/ + $user_email_hash = sprintf('%u', crc32(strtolower($row['user_email']))) . strlen($row['user_email']); + + if ($user_email_hash != $row['user_email_hash']) + { + $sql_ary = array( + 'user_email_hash' => $user_email_hash, + ); + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE user_id = ' . (int) $row['user_id']; + $this->sql_query($sql); + } + } + $this->db->sql_freeresult($result); + + if ($i < $limit) + { + // Completed + return; + } + + // Return the next start, will be sent to $start when this function is called again + return $start + $limit; + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_8.php b/phpBB/includes/db/migration/data/30x/3_0_8.php new file mode 100644 index 0000000000..8998ef9627 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_8.php @@ -0,0 +1,28 @@ +config['version'], '3.0.8', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_8_rc1'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.8')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_8_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_8_rc1.php new file mode 100644 index 0000000000..aeff35333e --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_8_rc1.php @@ -0,0 +1,221 @@ +config['version'], '3.0.8-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_7_pl1'); + } + + public function update_data() + { + return array( + array('custom', array(array(&$this, 'update_file_extension_group_names'))), + array('custom', array(array(&$this, 'update_module_auth'))), + array('custom', array(array(&$this, 'update_bots'))), + array('custom', array(array(&$this, 'delete_orphan_shadow_topics'))), + array('module.add', array( + 'acp', + 'ACP_MESSAGES', + array( + 'module_basename' => 'acp_board', + 'modes' => array('post'), + ), + )), + array('config.add', array('load_unreads_search', 1)), + array('config.update_if_equals', array(600, 'queue_interval', 60)), + array('config.update_if_equals', array(50, 'email_package_size', 20)), + + array('config.update', array('version', '3.0.8-rc1')), + ); + } + + public function update_file_extension_group_names() + { + // Update file extension group names to use language strings. + $sql = 'SELECT lang_dir + FROM ' . LANG_TABLE; + $result = $this->db->sql_query($sql); + + $extension_groups_updated = array(); + while ($lang_dir = $this->db->sql_fetchfield('lang_dir')) + { + $lang_dir = basename($lang_dir); + + // The language strings we need are either in language/.../acp/attachments.php + // in the update package if we're updating to 3.0.8-RC1 or later, + // or they are in language/.../install.php when we're updating from 3.0.7-PL1 or earlier. + // On an already updated board, they can also already be in language/.../acp/attachments.php + // in the board root. + $lang_files = array( + "{$this->phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.{$this->php_ext}", + "{$this->phpbb_root_path}language/$lang_dir/install.{$this->php_ext}", + "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.{$this->php_ext}", + ); + + foreach ($lang_files as $lang_file) + { + if (!file_exists($lang_file)) + { + continue; + } + + $lang = array(); + include($lang_file); + + foreach($lang as $lang_key => $lang_val) + { + if (isset($extension_groups_updated[$lang_key]) || strpos($lang_key, 'EXT_GROUP_') !== 0) + { + continue; + } + + $sql_ary = array( + 'group_name' => substr($lang_key, 10), // Strip off 'EXT_GROUP_' + ); + + $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " + WHERE group_name = '" . $this->db->sql_escape($lang_val) . "'"; + $this->sql_query($sql); + + $extension_groups_updated[$lang_key] = true; + } + } + } + $this->db->sql_freeresult($result); + } + + public function update_module_auth() + { + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\' + WHERE module_class = \'ucp\' + AND module_basename = \'profile\' + AND module_mode = \'avatar\''; + $this->sql_query($sql); + } + + public function update_bots() + { + $bot_name = 'Bing [Bot]'; + $bot_name_clean = utf8_clean_string($bot_name); + + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . " + WHERE username_clean = '" . $this->db->sql_escape($bot_name_clean) . "'"; + $result = $this->db->sql_query($sql); + $bing_already_added = (bool) $this->db->sql_fetchfield('user_id'); + $this->db->sql_freeresult($result); + + if (!$bing_already_added) + { + $bot_agent = 'bingbot/'; + $bot_ip = ''; + $sql = 'SELECT group_id, group_colour + FROM ' . GROUPS_TABLE . " + WHERE group_name = 'BOTS'"; + $result = $this->db->sql_query($sql); + $group_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$group_row) + { + // default fallback, should never get here + $group_row['group_id'] = 6; + $group_row['group_colour'] = '9E8DA7'; + } + + if (!function_exists('user_add')) + { + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + } + + $user_row = array( + 'user_type' => USER_IGNORE, + 'group_id' => $group_row['group_id'], + 'username' => $bot_name, + 'user_regdate' => time(), + 'user_password' => '', + 'user_colour' => $group_row['group_colour'], + 'user_email' => '', + 'user_lang' => $this->config['default_lang'], + 'user_style' => $this->config['default_style'], + 'user_timezone' => 0, + 'user_dateformat' => $this->config['default_dateformat'], + 'user_allow_massemail' => 0, + ); + + $user_id = user_add($user_row); + + $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( + 'bot_active' => 1, + 'bot_name' => (string) $bot_name, + 'user_id' => (int) $user_id, + 'bot_agent' => (string) $bot_agent, + 'bot_ip' => (string) $bot_ip, + )); + + $this->sql_query($sql); + } + } + + public function delete_orphan_shadow_topics() + { + // Delete shadow topics pointing to not existing topics + $batch_size = 500; + + // Set of affected forums we have to resync + $sync_forum_ids = array(); + + $sql_array = array( + 'SELECT' => 't1.topic_id, t1.forum_id', + 'FROM' => array( + TOPICS_TABLE => 't1', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array(TOPICS_TABLE => 't2'), + 'ON' => 't1.topic_moved_id = t2.topic_id', + ), + ), + 'WHERE' => 't1.topic_moved_id <> 0 + AND t2.topic_id IS NULL', + ); + $sql = $this->db->sql_build_query('SELECT', $sql_array); + $result = $this->db->sql_query_limit($sql, $batch_size); + + $topic_ids = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $topic_ids[] = (int) $row['topic_id']; + + $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; + } + $this->db->sql_freeresult($result); + + if (!empty($topic_ids)) + { + $sql = 'DELETE FROM ' . TOPICS_TABLE . ' + WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids); + $this->db->sql_query($sql); + + // Sync the forums we have deleted shadow topics from. + sync('forum', 'forum_id', $sync_forum_ids, true, true); + + return false; + } + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_9.php b/phpBB/includes/db/migration/data/30x/3_0_9.php new file mode 100644 index 0000000000..d5269ea6f0 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_9.php @@ -0,0 +1,28 @@ +config['version'], '3.0.9', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_9_rc4'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.9')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_9_rc1.php b/phpBB/includes/db/migration/data/30x/3_0_9_rc1.php new file mode 100644 index 0000000000..1f8622798e --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_9_rc1.php @@ -0,0 +1,124 @@ +config['version'], '3.0.9-rc1', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_8'); + } + + public function update_schema() + { + return array( + 'add_tables' => array( + $this->table_prefix . 'login_attempts' => array( + 'COLUMNS' => array( + // this column was removed from the database updater + // after 3.0.9-RC3 was released. It might still exist + // in 3.0.9-RCX installations and has to be dropped in + // 3.0.12 after the db_tools class is capable of properly + // removing a primary key. + // 'attempt_id' => array('UINT', NULL, 'auto_increment'), + 'attempt_ip' => array('VCHAR:40', ''), + 'attempt_browser' => array('VCHAR:150', ''), + 'attempt_forwarded_for' => array('VCHAR:255', ''), + 'attempt_time' => array('TIMESTAMP', 0), + 'user_id' => array('UINT', 0), + 'username' => array('VCHAR_UNI:255', 0), + 'username_clean' => array('VCHAR_CI', 0), + ), + //'PRIMARY_KEY' => 'attempt_id', + 'KEYS' => array( + 'att_ip' => array('INDEX', array('attempt_ip', 'attempt_time')), + 'att_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')), + 'att_time' => array('INDEX', array('attempt_time')), + 'user_id' => array('INDEX', 'user_id'), + ), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'bbcodes' => array( + 'bbcode_id' => array('USINT', 0), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_tables' => array( + $this->table_prefix . 'login_attempts', + ), + ); + } + + public function update_data() + { + return array( + array('config.add', array('ip_login_limit_max', 50)), + array('config.add', array('ip_login_limit_time', 21600)), + array('config.add', array('ip_login_limit_use_forwarded', 0)), + array('custom', array(array(&$this, 'update_file_extension_group_names'))), + array('custom', array(array(&$this, 'fix_firebird_qa_captcha'))), + + array('config.update', array('version', '3.0.9-rc1')), + ); + } + + public function update_file_extension_group_names() + { + // Update file extension group names to use language strings, again. + $sql = 'SELECT group_id, group_name + FROM ' . EXTENSION_GROUPS_TABLE . ' + WHERE group_name ' . $this->db->sql_like_expression('EXT_GROUP_' . $this->db->any_char); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql_ary = array( + 'group_name' => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_' + ); + + $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE group_id = ' . $row['group_id']; + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + } + + public function fix_firebird_qa_captcha() + { + // Recover from potentially broken Q&A CAPTCHA table on firebird + // Q&A CAPTCHA was uninstallable, so it's safe to remove these + // without data loss + if ($this->db_tools->sql_layer == 'firebird') + { + $tables = array( + $this->table_prefix . 'captcha_questions', + $this->table_prefix . 'captcha_answers', + $this->table_prefix . 'qa_confirm', + ); + foreach ($tables as $table) + { + if ($this->db_tools->sql_table_exists($table)) + { + $this->db_tools->sql_table_drop($table); + } + } + } + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_9_rc2.php b/phpBB/includes/db/migration/data/30x/3_0_9_rc2.php new file mode 100644 index 0000000000..c0e662aa45 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_9_rc2.php @@ -0,0 +1,28 @@ +config['version'], '3.0.9-rc2', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_9_rc1'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.9-rc2')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_9_rc3.php b/phpBB/includes/db/migration/data/30x/3_0_9_rc3.php new file mode 100644 index 0000000000..d6d1f14b2e --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_9_rc3.php @@ -0,0 +1,28 @@ +config['version'], '3.0.9-rc3', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_9_rc2'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.9-rc3')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/30x/3_0_9_rc4.php b/phpBB/includes/db/migration/data/30x/3_0_9_rc4.php new file mode 100644 index 0000000000..e673249343 --- /dev/null +++ b/phpBB/includes/db/migration/data/30x/3_0_9_rc4.php @@ -0,0 +1,28 @@ +config['version'], '3.0.9-rc4', '>='); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_9_rc3'); + } + + public function update_data() + { + return array( + array('config.update', array('version', '3.0.9-rc4')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/310/dev.php b/phpBB/includes/db/migration/data/310/dev.php new file mode 100644 index 0000000000..f41750e327 --- /dev/null +++ b/phpBB/includes/db/migration/data/310/dev.php @@ -0,0 +1,406 @@ +config['version'], '3.1.0-dev', '>='); + } + + static public function depends_on() + { + return array( + 'phpbb_db_migration_data_30x_11', + 'phpbb_db_migration_data_310_extensions', + 'phpbb_db_migration_data_310_style_update_p2', + 'phpbb_db_migration_data_310_timezone_p2', + 'phpbb_db_migration_data_310_reported_posts_display', + ); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'groups' => array( + 'group_teampage' => array('UINT', 0, 'after' => 'group_legend'), + ), + $this->table_prefix . 'profile_fields' => array( + 'field_show_on_pm' => array('BOOL', 0), + ), + $this->table_prefix . 'styles' => array( + 'style_path' => array('VCHAR:100', ''), + 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), + 'style_parent_id' => array('UINT:4', 0), + 'style_parent_tree' => array('TEXT', ''), + ), + $this->table_prefix . 'reports' => array( + 'reported_post_text' => array('MTEXT_UNI', ''), + 'reported_post_uid' => array('VCHAR:8', ''), + 'reported_post_bitfield' => array('VCHAR:255', ''), + ), + ), + 'change_columns' => array( + $this->table_prefix . 'groups' => array( + 'group_legend' => array('UINT', 0), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'groups' => array( + 'group_teampage', + ), + $this->table_prefix . 'profile_fields' => array( + 'field_show_on_pm', + ), + $this->table_prefix . 'styles' => array( + 'style_path', + 'bbcode_bitfield', + 'style_parent_id', + 'style_parent_tree', + ), + $this->table_prefix . 'reports' => array( + 'reported_post_text', + 'reported_post_uid', + 'reported_post_bitfield', + ), + ), + ); + } + + public function update_data() + { + return array( + array('config.update', array('search_type', 'phpbb_search_' . $this->config['search_type'])), + + array('config.add', array('fulltext_postgres_ts_name', 'simple')), + array('config.add', array('fulltext_postgres_min_word_len', 4)), + array('config.add', array('fulltext_postgres_max_word_len', 254)), + array('config.add', array('fulltext_sphinx_stopwords', 0)), + array('config.add', array('fulltext_sphinx_indexer_mem_limit', 512)), + + array('config.add', array('load_jquery_cdn', 0)), + array('config.add', array('load_jquery_url', '//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js')), + + array('config.add', array('use_system_cron', 0)), + + array('config.add', array('legend_sort_groupname', 0)), + array('config.add', array('teampage_forums', 1)), + array('config.add', array('teampage_memberships', 1)), + + array('config.add', array('load_cpf_pm', 0)), + + array('config.add', array('display_last_subject', 1)), + + array('config.add', array('assets_version', 1)), + + array('config.add', array('site_home_url', '')), + array('config.add', array('site_home_text', '')), + + array('permission.add', array('u_chgprofileinfo', true, 'u_sig')), + + array('module.add', array( + 'acp', + 'ACP_GROUPS', + array( + 'module_basename' => 'acp_groups', + 'modes' => array('position'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_ATTACHMENTS', + array( + 'module_basename' => 'acp_attachments', + 'modes' => array('manage'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_STYLE_MANAGEMENT', + array( + 'module_basename' => 'acp_styles', + 'modes' => array('install', 'cache'), + ), + )), + array('module.add', array( + 'ucp', + 'UCP_PROFILE', + array( + 'module_basename' => 'ucp_profile', + 'modes' => array('autologin_keys'), + ), + )), + // Module will be renamed later + array('module.add', array( + 'acp', + 'ACP_CAT_STYLES', + 'ACP_LANGUAGE' + )), + + array('module.remove', array( + 'acp', + false, + 'ACP_TEMPLATES', + )), + array('module.remove', array( + 'acp', + false, + 'ACP_THEMES', + )), + array('module.remove', array( + 'acp', + false, + 'ACP_IMAGESETS', + )), + + array('custom', array(array($this, 'rename_module_basenames'))), + array('custom', array(array($this, 'rename_styles_module'))), + array('custom', array(array($this, 'add_group_teampage'))), + array('custom', array(array($this, 'update_group_legend'))), + array('custom', array(array($this, 'localise_global_announcements'))), + array('custom', array(array($this, 'update_ucp_pm_basename'))), + array('custom', array(array($this, 'update_ucp_profile_auth'))), + array('custom', array(array($this, 'move_customise_modules'))), + + array('config.update', array('version', '3.1.0-dev')), + ); + } + + public function move_customise_modules() + { + // Move language management to new location in the Customise tab + // First get language module id + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_basename = 'acp_language'"; + $result = $this->db->sql_query($sql); + $language_module_id = $this->db->sql_fetchfield('module_id'); + $this->db->sql_freeresult($result); + // Next get language management module id of the one just created + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = 'ACP_LANGUAGE'"; + $result = $this->db->sql_query($sql); + $language_management_module_id = $this->db->sql_fetchfield('module_id'); + $this->db->sql_freeresult($result); + + if (!class_exists('acp_modules')) + { + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); + } + // acp_modules calls adm_back_link, which is undefined at this point + if (!function_exists('adm_back_link')) + { + include($this->phpbb_root_path . 'includes/functions_acp.' . $this->php_ext); + } + $module_manager = new acp_modules(); + $module_manager->module_class = 'acp'; + $module_manager->move_module($language_module_id, $language_management_module_id); + } + + public function update_ucp_pm_basename() + { + $sql = 'SELECT module_id, module_basename + FROM ' . MODULES_TABLE . " + WHERE module_basename <> 'ucp_pm' AND + module_langname='UCP_PM'"; + $result = $this->db->sql_query_limit($sql, 1); + + if ($row = $this->db->sql_fetchrow($result)) + { + // This update is still not applied. Applying it + + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_basename = 'ucp_pm' + WHERE module_id = " . (int) $row['module_id']; + + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + } + + public function update_ucp_profile_auth() + { + // Update the auth setting for the module + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_auth = 'acl_u_chgprofileinfo' + WHERE module_class = 'ucp' + AND module_basename = 'ucp_profile' + AND module_mode = 'profile_info'"; + $this->sql_query($sql); + } + + public function rename_styles_module() + { + // Rename styles module to Customise + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_langname = 'ACP_CAT_CUSTOMISE' + WHERE module_langname = 'ACP_CAT_STYLES'"; + $this->sql_query($sql); + } + + public function rename_module_basenames() + { + // rename all module basenames to full classname + $sql = 'SELECT module_id, module_basename, module_class + FROM ' . MODULES_TABLE; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $module_id = (int) $row['module_id']; + unset($row['module_id']); + + if (!empty($row['module_basename']) && !empty($row['module_class'])) + { + // all the class names start with class name or with phpbb_ for auto loading + if (strpos($row['module_basename'], $row['module_class'] . '_') !== 0 && + strpos($row['module_basename'], 'phpbb_') !== 0) + { + $row['module_basename'] = $row['module_class'] . '_' . $row['module_basename']; + + $sql_update = $this->db->sql_build_array('UPDATE', $row); + + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET ' . $sql_update . ' + WHERE module_id = ' . $module_id; + $this->sql_query($sql); + } + } + } + + $this->db->sql_freeresult($result); + } + + public function add_group_teampage() + { + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_teampage = 1 + WHERE group_type = ' . GROUP_SPECIAL . " + AND group_name = 'ADMINISTRATORS'"; + $this->sql_query($sql); + + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_teampage = 2 + WHERE group_type = ' . GROUP_SPECIAL . " + AND group_name = 'GLOBAL_MODERATORS'"; + $this->sql_query($sql); + } + + public function update_group_legend() + { + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . ' + WHERE group_legend = 1 + ORDER BY group_name ASC'; + $result = $this->db->sql_query($sql); + + $next_legend = 1; + while ($row = $this->db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_legend = ' . $next_legend . ' + WHERE group_id = ' . (int) $row['group_id']; + $this->sql_query($sql); + + $next_legend++; + } + $this->db->sql_freeresult($result); + } + + public function localise_global_announcements() + { + // Localise Global Announcements + $sql = 'SELECT topic_id, topic_approved, (topic_replies + 1) AS topic_posts, topic_last_post_id, topic_last_post_subject, topic_last_post_time, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour + FROM ' . TOPICS_TABLE . ' + WHERE forum_id = 0 + AND topic_type = ' . POST_GLOBAL; + $result = $this->db->sql_query($sql); + + $global_announcements = $update_lastpost_data = array(); + $update_lastpost_data['forum_last_post_time'] = 0; + $update_forum_data = array( + 'forum_posts' => 0, + 'forum_topics' => 0, + 'forum_topics_real' => 0, + ); + + while ($row = $this->db->sql_fetchrow($result)) + { + $global_announcements[] = (int) $row['topic_id']; + + $update_forum_data['forum_posts'] += (int) $row['topic_posts']; + $update_forum_data['forum_topics_real']++; + if ($row['topic_approved']) + { + $update_forum_data['forum_topics']++; + } + + if ($update_lastpost_data['forum_last_post_time'] < $row['topic_last_post_time']) + { + $update_lastpost_data = array( + 'forum_last_post_id' => (int) $row['topic_last_post_id'], + 'forum_last_post_subject' => $row['topic_last_post_subject'], + 'forum_last_post_time' => (int) $row['topic_last_post_time'], + 'forum_last_poster_id' => (int) $row['topic_last_poster_id'], + 'forum_last_poster_name' => $row['topic_last_poster_name'], + 'forum_last_poster_colour' => $row['topic_last_poster_colour'], + ); + } + } + $this->db->sql_freeresult($result); + + if (!empty($global_announcements)) + { + // Update the post/topic-count for the forum and the last-post if needed + $sql = 'SELECT forum_id + FROM ' . FORUMS_TABLE . ' + WHERE forum_type = ' . FORUM_POST; + $result = $this->db->sql_query_limit($sql, 1); + $ga_forum_id = $this->db->sql_fetchfield('forum_id'); + $this->db->sql_freeresult($result); + + $sql = 'SELECT forum_last_post_time + FROM ' . FORUMS_TABLE . ' + WHERE forum_id = ' . $ga_forum_id; + $result = $this->db->sql_query($sql); + $lastpost = (int) $this->db->sql_fetchfield('forum_last_post_time'); + $this->db->sql_freeresult($result); + + $sql_update = 'forum_posts = forum_posts + ' . $update_forum_data['forum_posts'] . ', '; + $sql_update .= 'forum_topics_real = forum_topics_real + ' . $update_forum_data['forum_topics_real'] . ', '; + $sql_update .= 'forum_topics = forum_topics + ' . $update_forum_data['forum_topics']; + if ($lastpost < $update_lastpost_data['forum_last_post_time']) + { + $sql_update .= ', ' . $this->db->sql_build_array('UPDATE', $update_lastpost_data); + } + + $sql = 'UPDATE ' . FORUMS_TABLE . ' + SET ' . $sql_update . ' + WHERE forum_id = ' . $ga_forum_id; + $this->sql_query($sql); + + // Update some forum_ids + $table_ary = array(TOPICS_TABLE, POSTS_TABLE, LOG_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE); + foreach ($table_ary as $table) + { + $sql = "UPDATE $table + SET forum_id = $ga_forum_id + WHERE " . $this->db->sql_in_set('topic_id', $global_announcements); + $this->sql_query($sql); + } + unset($table_ary); + } + } +} diff --git a/phpBB/includes/db/migration/data/310/extensions.php b/phpBB/includes/db/migration/data/310/extensions.php new file mode 100644 index 0000000000..925fa29384 --- /dev/null +++ b/phpBB/includes/db/migration/data/310/extensions.php @@ -0,0 +1,69 @@ +db_tools->sql_table_exists($this->table_prefix . 'ext'); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_11'); + } + + public function update_schema() + { + return array( + 'add_tables' => array( + $this->table_prefix . 'ext' => array( + 'COLUMNS' => array( + 'ext_name' => array('VCHAR', ''), + 'ext_active' => array('BOOL', 0), + 'ext_state' => array('TEXT', ''), + ), + 'KEYS' => array( + 'ext_name' => array('UNIQUE', 'ext_name'), + ), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_tables' => array( + $this->table_prefix . 'ext', + ), + ); + } + + public function update_data() + { + return array( + // Module will be renamed later + array('module.add', array( + 'acp', + 'ACP_CAT_STYLES', + 'ACP_EXTENSION_MANAGEMENT' + )), + array('module.add', array( + 'acp', + 'ACP_EXTENSION_MANAGEMENT', + array( + 'module_basename' => 'acp_extensions', + 'modes' => array('main'), + ), + )), + array('permission.add', array('a_extensions', true, 'a_styles')), + ); + } +} diff --git a/phpBB/includes/db/migration/data/310/reported_posts_display.php b/phpBB/includes/db/migration/data/310/reported_posts_display.php new file mode 100644 index 0000000000..64f0f1aaec --- /dev/null +++ b/phpBB/includes/db/migration/data/310/reported_posts_display.php @@ -0,0 +1,42 @@ +db_tools->sql_column_exists($this->table_prefix . 'reports', 'reported_post_enable_bbcode'); + } + + public function update_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'reports' => array( + 'reported_post_enable_bbcode' => array('BOOL', 1), + 'reported_post_enable_smilies' => array('BOOL', 1), + 'reported_post_enable_magic_url' => array('BOOL', 1), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'reports' => array( + 'reported_post_enable_bbcode', + 'reported_post_enable_smilies', + 'reported_post_enable_magic_url', + ), + ), + ); + } +} diff --git a/phpBB/includes/db/migration/data/310/style_update_p1.php b/phpBB/includes/db/migration/data/310/style_update_p1.php new file mode 100644 index 0000000000..d19ccc37cf --- /dev/null +++ b/phpBB/includes/db/migration/data/310/style_update_p1.php @@ -0,0 +1,157 @@ +db_tools->sql_table_exists($this->table_prefix . 'styles_imageset'); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_11'); + } + + public function update_data() + { + return array( + array('custom', array(array($this, 'styles_update'))), + ); + } + + public function styles_update() + { + // Get list of valid 3.1 styles + $available_styles = array('prosilver'); + + $iterator = new DirectoryIterator($this->phpbb_root_path . 'styles'); + $skip_dirs = array('.', '..', 'prosilver'); + foreach ($iterator as $fileinfo) + { + if ($fileinfo->isDir() && !in_array($fileinfo->getFilename(), $skip_dirs) && file_exists($fileinfo->getPathname() . '/style.cfg')) + { + $style_cfg = parse_cfg_file($fileinfo->getPathname() . '/style.cfg'); + if (isset($style_cfg['phpbb_version']) && version_compare($style_cfg['phpbb_version'], '3.1.0-dev', '>=')) + { + // 3.1 style + $available_styles[] = $fileinfo->getFilename(); + } + } + } + + // Get all installed styles + if ($this->db_tools->sql_table_exists($this->table_prefix . 'styles_imageset')) + { + $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id, i.imageset_path + FROM ' . STYLES_TABLE . ' s, ' . $this->table_prefix . 'styles_template t, ' . $this->table_prefix . 'styles_theme c, ' . $this->table_prefix . "styles_imageset i + WHERE t.template_id = s.template_id + AND c.theme_id = s.theme_id + AND i.imageset_id = s.imageset_id"; + } + else + { + $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id + FROM ' . STYLES_TABLE . ' s, ' . $this->table_prefix . 'styles_template t, ' . $this->table_prefix . "stles_theme c + WHERE t.template_id = s.template_id + AND c.theme_id = s.theme_id"; + } + $result = $this->db->sql_query($sql); + + $styles = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $styles[] = $row; + } + $this->db->sql_freeresult($result); + + // Decide which styles to keep, all others will be deleted + $valid_styles = array(); + foreach ($styles as $style_row) + { + if ( + // Delete styles with parent style (not supported yet) + $style_row['template_inherits_id'] == 0 && + // Check if components match + $style_row['template_path'] == $style_row['theme_path'] && (!isset($style_row['imageset_path']) || $style_row['template_path'] == $style_row['imageset_path']) && + // Check if components are valid + in_array($style_row['template_path'], $available_styles) + ) + { + // Valid style. Keep it + $sql_ary = array( + 'style_path' => $style_row['template_path'], + 'bbcode_bitfield' => $style_row['bbcode_bitfield'], + 'style_parent_id' => 0, + 'style_parent_tree' => '', + ); + $this->sql_query('UPDATE ' . STYLES_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE style_id = ' . $style_row['style_id']); + $valid_styles[] = (int) $style_row['style_id']; + } + } + + // Remove old entries from styles table + if (!sizeof($valid_styles)) + { + // No valid styles: remove everything and add prosilver + $this->sql_query('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary); + + $sql_ary = array( + 'style_name' => 'prosilver', + 'style_copyright' => '© phpBB Group', + 'style_active' => 1, + 'style_path' => 'prosilver', + 'bbcode_bitfield' => 'lNg=', + 'style_parent_id' => 0, + 'style_parent_tree' => '', + + // Will be removed in the next step + 'imageset_id' => 0, + 'template_id' => 0, + 'theme_id' => 0, + ); + + $sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->sql_query($sql); + + $sql = 'SELECT style_id + FROM ' . $table . " + WHERE style_name = 'prosilver'"; + $result = $this->sql_query($sql); + $default_style = $this->db->sql_fetchfield($result); + $this->db->sql_freeresult($result); + + set_config('default_style', $default_style); + + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0'; + $this->sql_query($sql); + } + else + { + // There are valid styles in styles table. Remove styles that are outdated + $this->sql_query('DELETE FROM ' . STYLES_TABLE . ' + WHERE ' . $this->db->sql_in_set('style_id', $valid_styles, true)); + + // Change default style + if (!in_array($this->config['default_style'], $valid_styles)) + { + $this->sql_query('UPDATE ' . CONFIG_TABLE . " + SET config_value = '" . $valid_styles[0] . "' + WHERE config_name = 'default_style'"); + } + + // Reset styles for users + $this->sql_query('UPDATE ' . USERS_TABLE . ' + SET user_style = 0 + WHERE ' . $this->db->sql_in_set('user_style', $valid_styles, true)); + } + } +} diff --git a/phpBB/includes/db/migration/data/310/style_update_p2.php b/phpBB/includes/db/migration/data/310/style_update_p2.php new file mode 100644 index 0000000000..7b10518a66 --- /dev/null +++ b/phpBB/includes/db/migration/data/310/style_update_p2.php @@ -0,0 +1,129 @@ +db_tools->sql_table_exists($this->table_prefix . 'styles_imageset'); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_310_style_update_p1'); + } + + public function update_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'styles' => array( + 'imageset_id', + 'template_id', + 'theme_id', + ), + ), + + 'drop_tables' => array( + $this->table_prefix . 'styles_imageset', + $this->table_prefix . 'styles_imageset_data', + $this->table_prefix . 'styles_template', + $this->table_prefix . 'styles_template_data', + $this->table_prefix . 'styles_theme', + ), + ); + } + + public function revert_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'styles' => array( + 'imageset_id' => array('UINT', 0), + 'template_id' => array('UINT', 0), + 'theme_id' => array('UINT', 0), + ), + ), + + 'add_tables' => array( + $this->table_prefix . 'styles_imageset' => array( + 'COLUMNS' => array( + 'imageset_id' => array('UINT', NULL, 'auto_increment'), + 'imageset_name' => array('VCHAR_UNI:255', ''), + 'imageset_copyright' => array('VCHAR_UNI', ''), + 'imageset_path' => array('VCHAR:100', ''), + ), + 'PRIMARY_KEY' => 'imageset_id', + 'KEYS' => array( + 'imgset_nm' => array('UNIQUE', 'imageset_name'), + ), + ), + $this->table_prefix . 'styles_imageset_data' => array( + 'COLUMNS' => array( + 'image_id' => array('UINT', NULL, 'auto_increment'), + 'image_name' => array('VCHAR:200', ''), + 'image_filename' => array('VCHAR:200', ''), + 'image_lang' => array('VCHAR:30', ''), + 'image_height' => array('USINT', 0), + 'image_width' => array('USINT', 0), + 'imageset_id' => array('UINT', 0), + ), + 'PRIMARY_KEY' => 'image_id', + 'KEYS' => array( + 'i_d' => array('INDEX', 'imageset_id'), + ), + ), + $this->table_prefix . 'styles_template' => array( + 'COLUMNS' => array( + 'template_id' => array('UINT', NULL, 'auto_increment'), + 'template_name' => array('VCHAR_UNI:255', ''), + 'template_copyright' => array('VCHAR_UNI', ''), + 'template_path' => array('VCHAR:100', ''), + 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), + 'template_storedb' => array('BOOL', 0), + 'template_inherits_id' => array('UINT:4', 0), + 'template_inherit_path' => array('VCHAR', ''), + ), + 'PRIMARY_KEY' => 'template_id', + 'KEYS' => array( + 'tmplte_nm' => array('UNIQUE', 'template_name'), + ), + ), + $this->table_prefix . 'styles_template_data' => array( + 'COLUMNS' => array( + 'template_id' => array('UINT', 0), + 'template_filename' => array('VCHAR:100', ''), + 'template_included' => array('TEXT', ''), + 'template_mtime' => array('TIMESTAMP', 0), + 'template_data' => array('MTEXT_UNI', ''), + ), + 'KEYS' => array( + 'tid' => array('INDEX', 'template_id'), + 'tfn' => array('INDEX', 'template_filename'), + ), + ), + $this->table_prefix . 'styles_theme' => array( + 'COLUMNS' => array( + 'theme_id' => array('UINT', NULL, 'auto_increment'), + 'theme_name' => array('VCHAR_UNI:255', ''), + 'theme_copyright' => array('VCHAR_UNI', ''), + 'theme_path' => array('VCHAR:100', ''), + 'theme_storedb' => array('BOOL', 0), + 'theme_mtime' => array('TIMESTAMP', 0), + 'theme_data' => array('MTEXT_UNI', ''), + ), + 'PRIMARY_KEY' => 'theme_id', + 'KEYS' => array( + 'theme_name' => array('UNIQUE', 'theme_name'), + ), + ), + ), + ); + } +} diff --git a/phpBB/includes/db/migration/data/310/timezone.php b/phpBB/includes/db/migration/data/310/timezone.php new file mode 100644 index 0000000000..7a6a9bce05 --- /dev/null +++ b/phpBB/includes/db/migration/data/310/timezone.php @@ -0,0 +1,163 @@ +db_tools->sql_column_exists($this->table_prefix . 'users', 'user_dst'); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_11'); + } + + public function update_schema() + { + return array( + 'change_columns' => array( + $this->table_prefix . 'users' => array( + 'user_timezone' => array('VCHAR:100', ''), + ), + ), + ); + } + + public function update_data() + { + return array( + array('custom', array(array($this, 'update_timezones'))), + ); + } + + public function update_timezones() + { + // Update user timezones + $sql = 'SELECT user_dst, user_timezone + FROM ' . $this->table_prefix . 'users + GROUP BY user_timezone, user_dst'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . $this->table_prefix . "users + SET user_timezone = '" . $this->db->sql_escape($this->convert_phpbb30_timezone($row['user_timezone'], $row['user_dst'])) . "' + WHERE user_timezone = '" . $this->db->sql_escape($row['user_timezone']) . "' + AND user_dst = " . (int) $row['user_dst']; + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + + // Update board default timezone + $sql = 'UPDATE ' . $this->table_prefix . "config + SET config_value = '" . $this->convert_phpbb30_timezone($this->config['board_timezone'], $this->config['board_dst']) . "' + WHERE config_name = 'board_timezone'"; + $this->sql_query($sql); + } + + /** + * Determine the new timezone for a given phpBB 3.0 timezone and + * "Daylight Saving Time" option + * + * @param $timezone float Users timezone in 3.0 + * @param $dst int Users daylight saving time + * @return string Users new php Timezone which is used since 3.1 + */ + public function convert_phpbb30_timezone($timezone, $dst) + { + $offset = $timezone + $dst; + + switch ($timezone) + { + case '-12': + return 'Etc/GMT+' . abs($offset); //'[UTC - 12] Baker Island Time' + case '-11': + return 'Etc/GMT+' . abs($offset); //'[UTC - 11] Niue Time, Samoa Standard Time' + case '-10': + return 'Etc/GMT+' . abs($offset); //'[UTC - 10] Hawaii-Aleutian Standard Time, Cook Island Time' + case '-9.5': + return 'Pacific/Marquesas'; //'[UTC - 9:30] Marquesas Islands Time' + case '-9': + return 'Etc/GMT+' . abs($offset); //'[UTC - 9] Alaska Standard Time, Gambier Island Time' + case '-8': + return 'Etc/GMT+' . abs($offset); //'[UTC - 8] Pacific Standard Time' + case '-7': + return 'Etc/GMT+' . abs($offset); //'[UTC - 7] Mountain Standard Time' + case '-6': + return 'Etc/GMT+' . abs($offset); //'[UTC - 6] Central Standard Time' + case '-5': + return 'Etc/GMT+' . abs($offset); //'[UTC - 5] Eastern Standard Time' + case '-4.5': + return 'America/Caracas'; //'[UTC - 4:30] Venezuelan Standard Time' + case '-4': + return 'Etc/GMT+' . abs($offset); //'[UTC - 4] Atlantic Standard Time' + case '-3.5': + return 'America/St_Johns'; //'[UTC - 3:30] Newfoundland Standard Time' + case '-3': + return 'Etc/GMT+' . abs($offset); //'[UTC - 3] Amazon Standard Time, Central Greenland Time' + case '-2': + return 'Etc/GMT+' . abs($offset); //'[UTC - 2] Fernando de Noronha Time, South Georgia & the South Sandwich Islands Time' + case '-1': + return 'Etc/GMT+' . abs($offset); //'[UTC - 1] Azores Standard Time, Cape Verde Time, Eastern Greenland Time' + case '0': + return (!$dst) ? 'UTC' : 'Etc/GMT-1'; //'[UTC] Western European Time, Greenwich Mean Time' + case '1': + return 'Etc/GMT-' . $offset; //'[UTC + 1] Central European Time, West African Time' + case '2': + return 'Etc/GMT-' . $offset; //'[UTC + 2] Eastern European Time, Central African Time' + case '3': + return 'Etc/GMT-' . $offset; //'[UTC + 3] Moscow Standard Time, Eastern African Time' + case '3.5': + return 'Asia/Tehran'; //'[UTC + 3:30] Iran Standard Time' + case '4': + return 'Etc/GMT-' . $offset; //'[UTC + 4] Gulf Standard Time, Samara Standard Time' + case '4.5': + return 'Asia/Kabul'; //'[UTC + 4:30] Afghanistan Time' + case '5': + return 'Etc/GMT-' . $offset; //'[UTC + 5] Pakistan Standard Time, Yekaterinburg Standard Time' + case '5.5': + return 'Asia/Kolkata'; //'[UTC + 5:30] Indian Standard Time, Sri Lanka Time' + case '5.75': + return 'Asia/Kathmandu'; //'[UTC + 5:45] Nepal Time' + case '6': + return 'Etc/GMT-' . $offset; //'[UTC + 6] Bangladesh Time, Bhutan Time, Novosibirsk Standard Time' + case '6.5': + return 'Indian/Cocos'; //'[UTC + 6:30] Cocos Islands Time, Myanmar Time' + case '7': + return 'Etc/GMT-' . $offset; //'[UTC + 7] Indochina Time, Krasnoyarsk Standard Time' + case '8': + return 'Etc/GMT-' . $offset; //'[UTC + 8] Chinese Standard Time, Australian Western Standard Time, Irkutsk Standard Time' + case '8.75': + return 'Australia/Eucla'; //'[UTC + 8:45] Southeastern Western Australia Standard Time' + case '9': + return 'Etc/GMT-' . $offset; //'[UTC + 9] Japan Standard Time, Korea Standard Time, Chita Standard Time' + case '9.5': + return 'Australia/ACT'; //'[UTC + 9:30] Australian Central Standard Time' + case '10': + return 'Etc/GMT-' . $offset; //'[UTC + 10] Australian Eastern Standard Time, Vladivostok Standard Time' + case '10.5': + return 'Australia/Lord_Howe'; //'[UTC + 10:30] Lord Howe Standard Time' + case '11': + return 'Etc/GMT-' . $offset; //'[UTC + 11] Solomon Island Time, Magadan Standard Time' + case '11.5': + return 'Pacific/Norfolk'; //'[UTC + 11:30] Norfolk Island Time' + case '12': + return 'Etc/GMT-12'; //'[UTC + 12] New Zealand Time, Fiji Time, Kamchatka Standard Time' + case '12.75': + return 'Pacific/Chatham'; //'[UTC + 12:45] Chatham Islands Time' + case '13': + return 'Pacific/Tongatapu'; //'[UTC + 13] Tonga Time, Phoenix Islands Time' + case '14': + return 'Pacific/Kiritimati'; //'[UTC + 14] Line Island Time' + default: + return 'UTC'; + } + } +} diff --git a/phpBB/includes/db/migration/data/310/timezone_p2.php b/phpBB/includes/db/migration/data/310/timezone_p2.php new file mode 100644 index 0000000000..113b979e4f --- /dev/null +++ b/phpBB/includes/db/migration/data/310/timezone_p2.php @@ -0,0 +1,43 @@ +db_tools->sql_column_exists($this->table_prefix . 'users', 'user_dst'); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_310_timezone'); + } + + public function update_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'users' => array( + 'user_dst', + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'users' => array( + 'user_dst' => array('BOOL', 0), + ), + ), + ); + } +} diff --git a/phpBB/includes/db/migration/data/3_0_1.php b/phpBB/includes/db/migration/data/3_0_1.php deleted file mode 100644 index 8b7c6f0f7c..0000000000 --- a/phpBB/includes/db/migration/data/3_0_1.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_1_rc1'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.1')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_10.php b/phpBB/includes/db/migration/data/3_0_10.php deleted file mode 100644 index b24a876bac..0000000000 --- a/phpBB/includes/db/migration/data/3_0_10.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.10', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_10_rc3'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.10')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_10_rc1.php b/phpBB/includes/db/migration/data/3_0_10_rc1.php deleted file mode 100644 index 46b7db4e59..0000000000 --- a/phpBB/includes/db/migration/data/3_0_10_rc1.php +++ /dev/null @@ -1,30 +0,0 @@ -config['version'], '3.0.10-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_9'); - } - - public function update_data() - { - return array( - array('config.add', array('email_max_chunk_size', 50)), - - array('config.update', array('version', '3.0.10-rc1')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_10_rc2.php b/phpBB/includes/db/migration/data/3_0_10_rc2.php deleted file mode 100644 index 5e85467202..0000000000 --- a/phpBB/includes/db/migration/data/3_0_10_rc2.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.10-rc2', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_10_rc1'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.10-rc2')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_10_rc3.php b/phpBB/includes/db/migration/data/3_0_10_rc3.php deleted file mode 100644 index 6ff81f7776..0000000000 --- a/phpBB/includes/db/migration/data/3_0_10_rc3.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.10-rc3', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_10_rc2'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.10-rc3')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_11.php b/phpBB/includes/db/migration/data/3_0_11.php deleted file mode 100644 index 1a63508593..0000000000 --- a/phpBB/includes/db/migration/data/3_0_11.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.11', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_11_rc2'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.11')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_11_rc1.php b/phpBB/includes/db/migration/data/3_0_11_rc1.php deleted file mode 100644 index 19703bcc35..0000000000 --- a/phpBB/includes/db/migration/data/3_0_11_rc1.php +++ /dev/null @@ -1,95 +0,0 @@ -config['version'], '3.0.11-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_10'); - } - - public function update_data() - { - return array( - array('custom', array(array(&$this, 'cleanup_deactivated_styles'))), - array('custom', array(array(&$this, 'delete_orphan_private_messages'))), - - array('config.update', array('version', '3.0.11-rc1')), - ); - } - - public function cleanup_deactivated_styles() - { - // Updates users having current style a deactivated one - $sql = 'SELECT style_id - FROM ' . STYLES_TABLE . ' - WHERE style_active = 0'; - $result = $this->sql_query($sql); - - $deactivated_style_ids = array(); - while ($style_id = $this->db->sql_fetchfield('style_id', false, $result)) - { - $deactivated_style_ids[] = (int) $style_id; - } - $this->db->sql_freeresult($result); - - if (!empty($deactivated_style_ids)) - { - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_style = ' . (int) $this->config['default_style'] .' - WHERE ' . $this->db->sql_in_set('user_style', $deactivated_style_ids); - $this->sql_query($sql); - } - } - - public function delete_orphan_private_messages() - { - // Delete orphan private messages - $batch_size = 500; - - $sql_array = array( - 'SELECT' => 'p.msg_id', - 'FROM' => array( - PRIVMSGS_TABLE => 'p', - ), - 'LEFT_JOIN' => array( - array( - 'FROM' => array(PRIVMSGS_TO_TABLE => 't'), - 'ON' => 'p.msg_id = t.msg_id', - ), - ), - 'WHERE' => 't.user_id IS NULL', - ); - $sql = $this->db->sql_build_query('SELECT', $sql_array); - - $result = $this->db->sql_query_limit($sql, $batch_size); - - $delete_pms = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $delete_pms[] = (int) $row['msg_id']; - } - $this->db->sql_freeresult($result); - - if (!empty($delete_pms)) - { - $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' - WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms); - $this->sql_query($sql); - - // Return false to have the Migrator call this function again - return false; - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_11_rc2.php b/phpBB/includes/db/migration/data/3_0_11_rc2.php deleted file mode 100644 index 219d44c4e0..0000000000 --- a/phpBB/includes/db/migration/data/3_0_11_rc2.php +++ /dev/null @@ -1,50 +0,0 @@ -config['version'], '3.0.11-rc2', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_11_rc1'); - } - - public function update_schema() - { - return array( - 'add_columns' => array( - $this->table_prefix . 'profile_fields' => array( - 'field_show_novalue' => array('BOOL', 0), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_columns' => array( - $this->table_prefix . 'profile_fields' => array( - 'field_show_novalue', - ), - ), - ); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.11-rc2')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_12_rc1.php b/phpBB/includes/db/migration/data/3_0_12_rc1.php deleted file mode 100644 index c23e8b24b8..0000000000 --- a/phpBB/includes/db/migration/data/3_0_12_rc1.php +++ /dev/null @@ -1,123 +0,0 @@ -config['version'], '3.0.12-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_11'); - } - - public function update_data() - { - return array( - array('custom', array(array(&$this, 'update_module_auth'))), - array('custom', array(array(&$this, 'update_bots'))), - array('custom', array(array(&$this, 'disable_bots_from_receiving_pms'))), - - array('config.update', array('version', '3.0.12-rc1')), - ); - } - - public function disable_bots_from_receiving_pms() - { - // Disable receiving pms for bots - $sql = 'SELECT user_id - FROM ' . BOTS_TABLE; - $result = $this->db->sql_query($sql); - - $bot_user_ids = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $bot_user_ids[] = (int) $row['user_id']; - } - $this->db->sql_freeresult($result); - - if (!empty($bot_user_ids)) - { - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_allow_pm = 0 - WHERE ' . $this->db->sql_in_set('user_id', $bot_user_ids); - $this->sql_query($sql); - } - } - - public function update_module_auth() - { - $sql = 'UPDATE ' . MODULES_TABLE . ' - SET module_auth = \'acl_u_sig\' - WHERE module_class = \'ucp\' - AND module_basename = \'profile\' - AND module_mode = \'signature\''; - $this->sql_query($sql); - } - - public function update_bots() - { - // Update bots - if (!function_exists('user_delete')) - { - include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); - } - - $bots_updates = array( - // Bot Deletions - 'NG-Search [Bot]' => false, - 'Nutch/CVS [Bot]' => false, - 'OmniExplorer [Bot]' => false, - 'Seekport [Bot]' => false, - 'Synoo [Bot]' => false, - 'WiseNut [Bot]' => false, - - // Bot Updates - // Bot name to bot user agent map - 'Baidu [Spider]' => 'Baiduspider', - 'Exabot [Bot]' => 'Exabot', - 'Voyager [Bot]' => 'voyager/', - 'W3C [Validator]' => 'W3C_Validator', - ); - - foreach ($bots_updates as $bot_name => $bot_agent) - { - $sql = 'SELECT user_id - FROM ' . USERS_TABLE . ' - WHERE user_type = ' . USER_IGNORE . " - AND username_clean = '" . $this->db->sql_escape(utf8_clean_string($bot_name)) . "'"; - $result = $this->db->sql_query($sql); - $bot_user_id = (int) $this->db->sql_fetchfield('user_id'); - $this->db->sql_freeresult($result); - - if ($bot_user_id) - { - if ($bot_agent === false) - { - $sql = 'DELETE FROM ' . BOTS_TABLE . " - WHERE user_id = $bot_user_id"; - $this->sql_query($sql); - - user_delete('remove', $bot_user_id); - } - else - { - $sql = 'UPDATE ' . BOTS_TABLE . " - SET bot_agent = '" . $this->db->sql_escape($bot_agent) . "' - WHERE user_id = $bot_user_id"; - $this->sql_query($sql); - } - } - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_1_rc1.php b/phpBB/includes/db/migration/data/3_0_1_rc1.php deleted file mode 100644 index 2fc2849d04..0000000000 --- a/phpBB/includes/db/migration/data/3_0_1_rc1.php +++ /dev/null @@ -1,108 +0,0 @@ -config['version'], '3.0.1-rc1', '>='); - } - - public function update_schema() - { - return array( - 'add_columns' => array( - $this->table_prefix . 'forums' => array( - 'display_subforum_list' => array('BOOL', 1), - ), - $this->table_prefix . 'sessions' => array( - 'session_forum_id' => array('UINT', 0), - ), - ), - 'drop_keys' => array( - $this->table_prefix . 'groups' => array( - 'group_legend', - ), - ), - 'add_index' => array( - $this->table_prefix . 'sessions' => array( - 'session_forum_id' => array('session_forum_id'), - ), - $this->table_prefix . 'groups' => array( - 'group_legend_name' => array('group_legend', 'group_name'), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_columns' => array( - $this->table_prefix . 'forums' => array( - 'display_subforum_list', - ), - $this->table_prefix . 'sessions' => array( - 'session_forum_id', - ), - ), - 'add_index' => array( - $this->table_prefix . 'groups' => array( - 'group_legend' => array('group_legend'), - ), - ), - 'drop_keys' => array( - $this->table_prefix . 'sessions' => array( - 'session_forum_id', - ), - $this->table_prefix . 'groups' => array( - 'group_legend_name', - ), - ), - ); - } - - public function update_data() - { - return array( - array('custom', array(array(&$this, 'fix_unset_last_view_time'))), - array('custom', array(array(&$this, 'reset_smiley_size'))), - - array('config.update', array('version', '3.0.1-rc1')), - ); - } - - public function fix_unset_last_view_time() - { - $sql = 'UPDATE ' . $this->table_prefix . "topics - SET topic_last_view_time = topic_last_post_time - WHERE topic_last_view_time = 0"; - $this->sql_query($sql); - } - - public function reset_smiley_size() - { - // Update smiley sizes - $smileys = array('icon_e_surprised.gif', 'icon_eek.gif', 'icon_cool.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_cry.gif', 'icon_evil.gif', 'icon_twisted.gif', 'icon_rolleyes.gif', 'icon_exclaim.gif', 'icon_question.gif', 'icon_idea.gif', 'icon_arrow.gif', 'icon_neutral.gif', 'icon_mrgreen.gif', 'icon_e_ugeek.gif'); - - foreach ($smileys as $smiley) - { - if (file_exists($this->phpbb_root_path . 'images/smilies/' . $smiley)) - { - list($width, $height) = getimagesize($this->phpbb_root_path . 'images/smilies/' . $smiley); - - $sql = 'UPDATE ' . SMILIES_TABLE . ' - SET smiley_width = ' . $width . ', smiley_height = ' . $height . " - WHERE smiley_url = '" . $this->db->sql_escape($smiley) . "'"; - - $this->sql_query($sql); - } - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_2.php b/phpBB/includes/db/migration/data/3_0_2.php deleted file mode 100644 index 8aa975f779..0000000000 --- a/phpBB/includes/db/migration/data/3_0_2.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.2', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_2_rc2'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.2')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_2_rc1.php b/phpBB/includes/db/migration/data/3_0_2_rc1.php deleted file mode 100644 index 6081cd682c..0000000000 --- a/phpBB/includes/db/migration/data/3_0_2_rc1.php +++ /dev/null @@ -1,32 +0,0 @@ -config['version'], '3.0.2-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_1'); - } - - public function update_data() - { - return array( - array('config.add', array('referer_validation', '1')), - array('config.add', array('check_attachment_content', '1')), - array('config.add', array('mime_triggers', 'body|head|html|img|plaintext|a href|pre|script|table|title')), - - array('config.update', array('version', '3.0.2-rc1')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_2_rc2.php b/phpBB/includes/db/migration/data/3_0_2_rc2.php deleted file mode 100644 index bb76c270d7..0000000000 --- a/phpBB/includes/db/migration/data/3_0_2_rc2.php +++ /dev/null @@ -1,80 +0,0 @@ -config['version'], '3.0.2-rc2', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_2_rc1'); - } - - public function update_schema() - { - return array( - 'change_columns' => array( - $this->table_prefix . 'drafts' => array( - 'draft_subject' => array('STEXT_UNI', ''), - ), - $this->table_prefix . 'forums' => array( - 'forum_last_post_subject' => array('STEXT_UNI', ''), - ), - $this->table_prefix . 'posts' => array( - 'post_subject' => array('STEXT_UNI', '', 'true_sort'), - ), - $this->table_prefix . 'privmsgs' => array( - 'message_subject' => array('STEXT_UNI', ''), - ), - $this->table_prefix . 'topics' => array( - 'topic_title' => array('STEXT_UNI', '', 'true_sort'), - 'topic_last_post_subject' => array('STEXT_UNI', ''), - ), - ), - 'drop_keys' => array( - $this->table_prefix . 'sessions' => array( - 'session_forum_id', - ), - ), - 'add_index' => array( - $this->table_prefix . 'sessions' => array( - 'session_fid' => array('session_forum_id'), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'add_index' => array( - $this->table_prefix . 'sessions' => array( - 'session_forum_id' => array( - 'session_forum_id', - ), - ), - ), - 'drop_keys' => array( - $this->table_prefix . 'sessions' => array( - 'session_fid', - ), - ), - ); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.2-rc2')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_3.php b/phpBB/includes/db/migration/data/3_0_3.php deleted file mode 100644 index 82039a109b..0000000000 --- a/phpBB/includes/db/migration/data/3_0_3.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.3', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_3_rc1'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.3')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_3_rc1.php b/phpBB/includes/db/migration/data/3_0_3_rc1.php deleted file mode 100644 index 5e300962b7..0000000000 --- a/phpBB/includes/db/migration/data/3_0_3_rc1.php +++ /dev/null @@ -1,83 +0,0 @@ -config['version'], '3.0.3-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_2'); - } - - public function update_schema() - { - return array( - 'add_columns' => array( - $this->table_prefix . 'styles_template' => array( - 'template_inherits_id' => array('UINT:4', 0), - 'template_inherit_path' => array('VCHAR', ''), - ), - $this->table_prefix . 'groups' => array( - 'group_max_recipients' => array('UINT', 0), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_columns' => array( - $this->table_prefix . 'styles_template' => array( - 'template_inherits_id', - 'template_inherit_path', - ), - $this->table_prefix . 'groups' => array( - 'group_max_recipients', - ), - ), - ); - } - - public function update_data() - { - return array( - array('config.add', array('enable_queue_trigger', '0')), - array('config.add', array('queue_trigger_posts', '3')), - array('config.add', array('pm_max_recipients', '0')), - array('custom', array(array(&$this, 'set_group_default_max_recipients'))), - array('config.add', array('dbms_version', $this->db->sql_server_info(true))), - array('permission.add', array('u_masspm_group', true, 'u_masspm')), - array('custom', array(array(&$this, 'correct_acp_email_permissions'))), - - array('config.update', array('version', '3.0.3-rc1')), - ); - } - - public function correct_acp_email_permissions() - { - $sql = 'UPDATE ' . $this->table_prefix . 'modules - SET module_auth = \'acl_a_email && cfg_email_enable\' - WHERE module_class = \'acp\' - AND module_basename = \'email\''; - $this->sql_query($sql); - } - - public function set_group_default_max_recipients() - { - // Set maximum number of recipients for the registered users, bots, guests group - $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_max_recipients = 5 - WHERE ' . $this->db->sql_in_set('group_name', array('GUESTS', 'REGISTERED', 'REGISTERED_COPPA', 'BOTS')); - $this->sql_query($sql); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_4.php b/phpBB/includes/db/migration/data/3_0_4.php deleted file mode 100644 index 34af9fa4ae..0000000000 --- a/phpBB/includes/db/migration/data/3_0_4.php +++ /dev/null @@ -1,49 +0,0 @@ -config['version'], '3.0.4', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_4_rc1'); - } - - public function update_data() - { - return array( - array('custom', array(array(&$this, 'rename_log_delete_topic'))), - - array('config.update', array('version', '3.0.4')), - ); - } - - public function rename_log_delete_topic() - { - if ($this->db->sql_layer == 'oracle') - { - // log_operation is CLOB - but we can change this later - $sql = 'UPDATE ' . $this->table_prefix . "log - SET log_operation = 'LOG_DELETE_TOPIC' - WHERE log_operation LIKE 'LOG_TOPIC_DELETED'"; - $this->sql_query($sql); - } - else - { - $sql = 'UPDATE ' . $this->table_prefix . "log - SET log_operation = 'LOG_DELETE_TOPIC' - WHERE log_operation = 'LOG_TOPIC_DELETED'"; - $this->sql_query($sql); - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_4_rc1.php b/phpBB/includes/db/migration/data/3_0_4_rc1.php deleted file mode 100644 index f63bebcf75..0000000000 --- a/phpBB/includes/db/migration/data/3_0_4_rc1.php +++ /dev/null @@ -1,123 +0,0 @@ -config['version'], '3.0.4-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_3'); - } - - public function update_schema() - { - return array( - 'add_columns' => array( - $this->table_prefix . 'profile_fields' => array( - 'field_show_profile' => array('BOOL', 0), - ), - ), - 'change_columns' => array( - $this->table_prefix . 'styles' => array( - 'style_id' => array('UINT', NULL, 'auto_increment'), - 'template_id' => array('UINT', 0), - 'theme_id' => array('UINT', 0), - 'imageset_id' => array('UINT', 0), - ), - $this->table_prefix . 'styles_imageset' => array( - 'imageset_id' => array('UINT', NULL, 'auto_increment'), - ), - $this->table_prefix . 'styles_imageset_data' => array( - 'image_id' => array('UINT', NULL, 'auto_increment'), - 'imageset_id' => array('UINT', 0), - ), - $this->table_prefix . 'styles_theme' => array( - 'theme_id' => array('UINT', NULL, 'auto_increment'), - ), - $this->table_prefix . 'styles_template' => array( - 'template_id' => array('UINT', NULL, 'auto_increment'), - ), - $this->table_prefix . 'styles_template_data' => array( - 'template_id' => array('UINT', 0), - ), - $this->table_prefix . 'forums' => array( - 'forum_style' => array('UINT', 0), - ), - $this->table_prefix . 'users' => array( - 'user_style' => array('UINT', 0), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_columns' => array( - $this->table_prefix . 'profile_fields' => array( - 'field_show_profile', - ), - ), - ); - } - - public function update_data() - { - return array( - array('custom', array(array(&$this, 'update_custom_profile_fields'))), - - array('config.update', array('version', '3.0.4-rc1')), - ); - } - - public function update_custom_profile_fields() - { - // Update the Custom Profile Fields based on previous settings to the new format - $sql = 'SELECT field_id, field_required, field_show_on_reg, field_hide - FROM ' . PROFILE_FIELDS_TABLE; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $sql_ary = array( - 'field_required' => 0, - 'field_show_on_reg' => 0, - 'field_hide' => 0, - 'field_show_profile'=> 0, - ); - - if ($row['field_required']) - { - $sql_ary['field_required'] = $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; - } - else if ($row['field_show_on_reg']) - { - $sql_ary['field_show_on_reg'] = $sql_ary['field_show_profile'] = 1; - } - else if ($row['field_hide']) - { - // Only administrators and moderators can see this CPF, if the view is enabled, they can see it, otherwise just admins in the acp_users module - $sql_ary['field_hide'] = 1; - } - else - { - // equivelant to "none", which is the "Display in user control panel" option - $sql_ary['field_show_profile'] = 1; - } - - $this->sql_query('UPDATE ' . $this->table_prefix . 'profile_fields SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary); - } - - $this->db->sql_freeresult($result); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_5.php b/phpBB/includes/db/migration/data/3_0_5.php deleted file mode 100644 index 077ed251d2..0000000000 --- a/phpBB/includes/db/migration/data/3_0_5.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.5', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_5_rc1part2'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.5')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1.php b/phpBB/includes/db/migration/data/3_0_5_rc1.php deleted file mode 100644 index df85ee4f7d..0000000000 --- a/phpBB/includes/db/migration/data/3_0_5_rc1.php +++ /dev/null @@ -1,124 +0,0 @@ -config['version'], '3.0.5-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_4'); - } - - public function update_schema() - { - return array( - 'change_columns' => array( - $this->table_prefix . 'forums' => array( - 'forum_style' => array('UINT', 0), - ), - ), - ); - } - - public function update_data() - { - $search_indexing_state = $this->config['search_indexing_state']; - - return array( - array('config.add', array('captcha_gd_wave', 0)), - array('config.add', array('captcha_gd_3d_noise', 1)), - array('config.add', array('captcha_gd_fonts', 1)), - array('config.add', array('confirm_refresh', 1)), - array('config.add', array('max_num_search_keywords', 10)), - array('config.remove', array('search_indexing_state')), - array('config.add', array('search_indexing_state', $search_indexing_state, true)), - array('custom', array(array(&$this, 'hash_old_passwords'))), - array('custom', array(array(&$this, 'update_ichiro_bot'))), - ); - } - - public function hash_old_passwords() - { - $sql = 'SELECT user_id, user_password - FROM ' . $this->table_prefix . 'users - WHERE user_pass_convert = 1'; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - if (strlen($row['user_password']) == 32) - { - $sql_ary = array( - 'user_password' => phpbb_hash($row['user_password']), - ); - - $this->sql_query('UPDATE ' . $this->table_prefix . 'users SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id']); - } - } - $this->db->sql_freeresult($result); - } - - public function update_ichiro_bot() - { - // Adjust bot entry - $sql = 'UPDATE ' . $this->table_prefix . "bots - SET bot_agent = 'ichiro/' - WHERE bot_agent = 'ichiro/2'"; - $this->sql_query($sql); - } - - public function remove_duplicate_auth_options() - { - // Before we are able to add a unique key to auth_option, we need to remove duplicate entries - $sql = 'SELECT auth_option - FROM ' . $this->table_prefix . 'acl_options - GROUP BY auth_option - HAVING COUNT(*) >= 2'; - $result = $this->db->sql_query($sql); - - $auth_options = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $auth_options[] = $row['auth_option']; - } - $this->db->sql_freeresult($result); - - // Remove specific auth options - if (!empty($auth_options)) - { - foreach ($auth_options as $option) - { - // Select auth_option_ids... the largest id will be preserved - $sql = 'SELECT auth_option_id - FROM ' . ACL_OPTIONS_TABLE . " - WHERE auth_option = '" . $db->sql_escape($option) . "' - ORDER BY auth_option_id DESC"; - // sql_query_limit not possible here, due to bug in postgresql layer - $result = $this->db->sql_query($sql); - - // Skip first row, this is our original auth option we want to preserve - $row = $this->db->sql_fetchrow($result); - - while ($row = $this->db->sql_fetchrow($result)) - { - // Ok, remove this auth option... - $this->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - $this->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - $this->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - $this->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id']); - } - $this->db->sql_freeresult($result); - } - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php deleted file mode 100644 index d2fad7a7f8..0000000000 --- a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php +++ /dev/null @@ -1,42 +0,0 @@ -config['version'], '3.0.5-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_5_rc1'); - } - - public function update_schema() - { - return array( - 'drop_keys' => array( - $this->table_prefix . 'acl_options' => array('auth_option'), - ), - 'add_unique_index' => array( - $this->table_prefix . 'acl_options' => array( - 'auth_option' => array('auth_option'), - ), - ), - ); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.5-rc1')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_6.php b/phpBB/includes/db/migration/data/3_0_6.php deleted file mode 100644 index 1b0cbb1435..0000000000 --- a/phpBB/includes/db/migration/data/3_0_6.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.6', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_6_rc4'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.6')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_6_rc1.php b/phpBB/includes/db/migration/data/3_0_6_rc1.php deleted file mode 100644 index 0f85084e65..0000000000 --- a/phpBB/includes/db/migration/data/3_0_6_rc1.php +++ /dev/null @@ -1,324 +0,0 @@ -config['version'], '3.0.6-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_5'); - } - - public function update_schema() - { - return array( - 'add_columns' => array( - $this->table_prefix . 'confirm' => array( - 'attempts' => array('UINT', 0), - ), - $this->table_prefix . 'users' => array( - 'user_new' => array('BOOL', 1), - 'user_reminded' => array('TINT:4', 0), - 'user_reminded_time' => array('TIMESTAMP', 0), - ), - $this->table_prefix . 'groups' => array( - 'group_skip_auth' => array('BOOL', 0, 'after' => 'group_founder_manage'), - ), - $this->table_prefix . 'privmsgs' => array( - 'message_reported' => array('BOOL', 0), - ), - $this->table_prefix . 'reports' => array( - 'pm_id' => array('UINT', 0), - ), - $this->table_prefix . 'profile_fields' => array( - 'field_show_on_vt' => array('BOOL', 0), - ), - $this->table_prefix . 'forums' => array( - 'forum_options' => array('UINT:20', 0), - ), - ), - 'change_columns' => array( - $this->table_prefix . 'users' => array( - 'user_options' => array('UINT:11', 230271), - ), - ), - 'add_index' => array( - $this->table_prefix . 'reports' => array( - 'post_id' => array('post_id'), - 'pm_id' => array('pm_id'), - ), - $this->table_prefix . 'posts' => array( - 'post_username' => array('post_username:255'), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_columns' => array( - $this->table_prefix . 'confirm' => array( - 'attempts', - ), - $this->table_prefix . 'users' => array( - 'user_new', - 'user_reminded', - 'user_reminded_time', - ), - $this->table_prefix . 'groups' => array( - 'group_skip_auth', - ), - $this->table_prefix . 'privmsgs' => array( - 'message_reported', - ), - $this->table_prefix . 'reports' => array( - 'pm_id', - ), - $this->table_prefix . 'profile_fields' => array( - 'field_show_on_vt', - ), - $this->table_prefix . 'forums' => array( - 'forum_options', - ), - ), - 'drop_keys' => array( - $this->table_prefix . 'reports' => array( - 'post_id', - 'pm_id', - ), - $this->table_prefix . 'posts' => array( - 'post_username', - ), - ), - ); - } - - public function update_data() - { - return array( - array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')), - array('if', array( - ($this->config['captcha_gd']), - array('config.update', array('captcha_plugin', 'phpbb_captcha_gd')), - )), - - array('config.add', array('feed_enable', 0)), - array('config.add', array('feed_limit', 10)), - array('config.add', array('feed_overall_forums', 1)), - array('config.add', array('feed_overall_forums_limit', 15)), - array('config.add', array('feed_overall_topics', 0)), - array('config.add', array('feed_overall_topics_limit', 15)), - array('config.add', array('feed_forum', 1)), - array('config.add', array('feed_topic', 1)), - array('config.add', array('feed_item_statistics', 1)), - - array('config.add', array('smilies_per_page', 50)), - array('config.add', array('allow_pm_report', 1)), - array('config.add', array('min_post_chars', 1)), - array('config.add', array('allow_quick_reply', 1)), - array('config.add', array('new_member_post_limit', 0)), - array('config.add', array('new_member_group_default', 0)), - array('config.add', array('delete_time', $this->config['edit_time'])), - - array('config.add', array('allow_avatar', 0)), - array('if', array( - ($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']), - array('config.update', array('allow_avatar', 1)), - )), - array('config.add', array('allow_avatar_remote_upload', 0)), - array('if', array( - ($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']), - array('config.update', array('allow_avatar_remote_upload', 1)), - )), - - array('module.add', array( - 'acp', - 'ACP_BOARD_CONFIGURATION', - array( - 'module_basename' => 'acp_board', - 'modes' => array('feed'), - ), - )), - array('module.add', array( - 'acp', - 'ACP_CAT_USERS', - array( - 'module_basename' => 'acp_users', - 'modes' => array('warnings'), - ), - )), - array('module.add', array( - 'acp', - 'ACP_SERVER_CONFIGURATION', - array( - 'module_basename' => 'acp_send_statistics', - 'modes' => array('send_statistics'), - ), - )), - array('module.add', array( - 'acp', - 'ACP_FORUM_BASED_PERMISSIONS', - array( - 'module_basename' => 'acp_permissions', - 'modes' => array('setting_forum_copy'), - ), - )), - array('module.add', array( - 'mcp', - 'MCP_REPORTS', - array( - 'module_basename' => 'mcp_pm_reports', - 'modes' => array('pm_reports','pm_reports_closed','pm_report_details'), - ), - )), - array('custom', array(array(&$this, 'add_newly_registered_group'))), - array('custom', array(array(&$this, 'set_user_options_default'))), - - array('config.update', array('version', '3.0.6-rc1')), - ); - } - - public function set_user_options_default() - { - // 229376 is the added value to enable all three signature options - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376'; - $this->sql_query($sql); - } - - public function add_newly_registered_group() - { - // Add newly_registered group... but check if it already exists (we always supported running the updater on any schema) - $sql = 'SELECT group_id - FROM ' . GROUPS_TABLE . " - WHERE group_name = 'NEWLY_REGISTERED'"; - $result = $this->db->sql_query($sql); - $group_id = (int) $this->db->sql_fetchfield('group_id'); - $this->db->sql_freeresult($result); - - if (!$group_id) - { - $sql = 'INSERT INTO ' . GROUPS_TABLE . " (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5)"; - $this->sql_query($sql); - - $group_id = $this->db->sql_nextid(); - } - - // Insert new user role... at the end of the chain - $sql = 'SELECT role_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_name = 'ROLE_USER_NEW_MEMBER' - AND role_type = 'u_'"; - $result = $this->db->sql_query($sql); - $u_role = (int) $this->db->sql_fetchfield('role_id'); - $this->db->sql_freeresult($result); - - if (!$u_role) - { - $sql = 'SELECT MAX(role_order) as max_order_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_type = 'u_'"; - $result = $this->db->sql_query($sql); - $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); - $this->db->sql_freeresult($result); - - $next_order_id++; - - $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_USER_NEW_MEMBER', 'ROLE_DESCRIPTION_USER_NEW_MEMBER', 'u_', $next_order_id)"; - $this->sql_query($sql); - $u_role = $this->db->sql_nextid(); - - // Now add the correct data to the roles... - // The standard role says that new users are not able to send a PM, Mass PM, are not able to PM groups - $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $u_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group')"; - $this->sql_query($sql); - - // Add user role to group - $sql = 'INSERT INTO ' . ACL_GROUPS_TABLE . " (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES ($group_id, 0, 0, $u_role, 0)"; - $this->sql_query($sql); - } - - // Insert new forum role - $sql = 'SELECT role_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_name = 'ROLE_FORUM_NEW_MEMBER' - AND role_type = 'f_'"; - $result = $this->db->sql_query($sql); - $f_role = (int) $this->db->sql_fetchfield('role_id'); - $this->db->sql_freeresult($result); - - if (!$f_role) - { - $sql = 'SELECT MAX(role_order) as max_order_id - FROM ' . ACL_ROLES_TABLE . " - WHERE role_type = 'f_'"; - $result = $this->db->sql_query($sql); - $next_order_id = (int) $this->db->sql_fetchfield('max_order_id'); - $this->db->sql_freeresult($result); - - $next_order_id++; - - $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . " (role_name, role_description, role_type, role_order) VALUES ('ROLE_FORUM_NEW_MEMBER', 'ROLE_DESCRIPTION_FORUM_NEW_MEMBER', 'f_', $next_order_id)"; - $this->sql_query($sql); - $f_role = $this->db->sql_nextid(); - - $sql = 'INSERT INTO ' . ACL_ROLES_DATA_TABLE . " (role_id, auth_option_id, auth_setting) SELECT $f_role, auth_option_id, 0 FROM " . ACL_OPTIONS_TABLE . " WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove')"; - $this->sql_query($sql); - } - - // Set every members user_new column to 0 (old users) only if there is no one yet (this makes sure we do not execute this more than once) - $sql = 'SELECT 1 - FROM ' . USERS_TABLE . ' - WHERE user_new = 0'; - $result = $this->db->sql_query_limit($sql, 1); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$row) - { - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0'; - $this->sql_query($sql); - } - - // To mimick the old "feature" we will assign the forum role to every forum, regardless of the setting (this makes sure there are no "this does not work!!!! YUO!!!" posts... - // Check if the role is already assigned... - $sql = 'SELECT forum_id - FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id . ' - AND auth_role_id = ' . $f_role; - $result = $this->db->sql_query($sql); - $is_options = (int) $this->db->sql_fetchfield('forum_id'); - $this->db->sql_freeresult($result); - - // Not assigned at all... :/ - if (!$is_options) - { - // Get postable forums - $sql = 'SELECT forum_id - FROM ' . FORUMS_TABLE . ' - WHERE forum_type != ' . FORUM_LINK; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $this->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' (group_id, forum_id, auth_option_id, auth_role_id, auth_setting) VALUES (' . $group_id . ', ' . (int) $row['forum_id'] . ', 0, ' . $f_role . ', 0)'); - } - $this->db->sql_freeresult($result); - } - - // Clear permissions... - include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext); - $auth_admin = new auth_admin(); - $auth_admin->acl_clear_prefetch(); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_6_rc2.php b/phpBB/includes/db/migration/data/3_0_6_rc2.php deleted file mode 100644 index a9c497b3cd..0000000000 --- a/phpBB/includes/db/migration/data/3_0_6_rc2.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.6-rc2', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_6_rc1'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.6-rc2')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_6_rc3.php b/phpBB/includes/db/migration/data/3_0_6_rc3.php deleted file mode 100644 index eca19fc2ff..0000000000 --- a/phpBB/includes/db/migration/data/3_0_6_rc3.php +++ /dev/null @@ -1,40 +0,0 @@ -config['version'], '3.0.6-rc3', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_6_rc2'); - } - - public function update_data() - { - return array( - array('custom', array(array(&$this, 'update_cp_fields'))), - - array('config.update', array('version', '3.0.6-rc3')), - ); - } - - public function update_cp_fields() - { - // Update the Custom Profile Fields based on previous settings to the new format - $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . ' - SET field_show_on_vt = 1 - WHERE field_hide = 0 - AND (field_required = 1 OR field_show_on_reg = 1 OR field_show_profile = 1)'; - $this->sql_query($sql); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_6_rc4.php b/phpBB/includes/db/migration/data/3_0_6_rc4.php deleted file mode 100644 index 19611d3c56..0000000000 --- a/phpBB/includes/db/migration/data/3_0_6_rc4.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.6-rc4', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_6_rc3'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.6-rc4')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_7.php b/phpBB/includes/db/migration/data/3_0_7.php deleted file mode 100644 index 97cdf4e3f1..0000000000 --- a/phpBB/includes/db/migration/data/3_0_7.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.7', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_7_rc2'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.7')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_7_pl1.php b/phpBB/includes/db/migration/data/3_0_7_pl1.php deleted file mode 100644 index 176854a8a6..0000000000 --- a/phpBB/includes/db/migration/data/3_0_7_pl1.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.7-pl1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_7'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.7-pl1')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_7_rc1.php b/phpBB/includes/db/migration/data/3_0_7_rc1.php deleted file mode 100644 index daf52213b9..0000000000 --- a/phpBB/includes/db/migration/data/3_0_7_rc1.php +++ /dev/null @@ -1,76 +0,0 @@ -config['version'], '3.0.7-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_6'); - } - - public function update_schema() - { - return array( - 'drop_keys' => array( - $this->table_prefix . 'log' => array( - 'log_time', - ), - ), - 'add_index' => array( - $this->table_prefix . 'topics_track' => array( - 'topic_id' => array('topic_id'), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'add_index' => array( - $this->table_prefix . 'log' => array( - 'log_time' => array('log_time'), - ), - ), - 'drop_keys' => array( - $this->table_prefix . 'topics_track' => array( - 'topic_id', - ), - ), - ); - } - - public function update_data() - { - return array( - array('config.add', array('feed_overall', 1)), - array('config.add', array('feed_http_auth', 0)), - array('config.add', array('feed_limit_post', $this->config['feed_limit'])), - array('config.add', array('feed_limit_topic', $this->config['feed_overall_topics_limit'])), - array('config.add', array('feed_topics_new', $this->config['feed_overall_topics'])), - array('config.add', array('feed_topics_active', $this->config['feed_overall_topics'])), - array('custom', array(array(&$this, 'delete_text_templates'))), - - array('config.update', array('version', '3.0.7-rc1')), - ); - } - - public function delete_text_templates() - { - // Delete all text-templates from the template_data - $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' - WHERE template_filename ' . $this->db->sql_like_expression($this->db->any_char . '.txt'); - $this->sql_query($sql); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_7_rc2.php b/phpBB/includes/db/migration/data/3_0_7_rc2.php deleted file mode 100644 index 8167d8fa40..0000000000 --- a/phpBB/includes/db/migration/data/3_0_7_rc2.php +++ /dev/null @@ -1,73 +0,0 @@ -config['version'], '3.0.7-rc2', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_7_rc1'); - } - - public function update_data() - { - return array( - array('custom', array(array(&$this, 'update_email_hash'))), - - array('config.update', array('version', '3.0.7-rc2')), - ); - } - - public function update_email_hash($start = 0) - { - $limit = 1000; - - $sql = 'SELECT user_id, user_email, user_email_hash - FROM ' . USERS_TABLE . ' - WHERE user_type <> ' . USER_IGNORE . " - AND user_email <> ''"; - $result = $this->db->sql_query_limit($sql, $limit, $start); - - $i = 0; - while ($row = $this->db->sql_fetchrow($result)) - { - $i++; - - // Snapshot of the phpbb_email_hash() function - // We cannot call it directly because the auto updater updates the DB first. :/ - $user_email_hash = sprintf('%u', crc32(strtolower($row['user_email']))) . strlen($row['user_email']); - - if ($user_email_hash != $row['user_email_hash']) - { - $sql_ary = array( - 'user_email_hash' => $user_email_hash, - ); - - $sql = 'UPDATE ' . USERS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE user_id = ' . (int) $row['user_id']; - $this->sql_query($sql); - } - } - $this->db->sql_freeresult($result); - - if ($i < $limit) - { - // Completed - return; - } - - // Return the next start, will be sent to $start when this function is called again - return $start + $limit; - } -} diff --git a/phpBB/includes/db/migration/data/3_0_8.php b/phpBB/includes/db/migration/data/3_0_8.php deleted file mode 100644 index 25baaf0f07..0000000000 --- a/phpBB/includes/db/migration/data/3_0_8.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.8', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_8_rc1'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.8')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_8_rc1.php b/phpBB/includes/db/migration/data/3_0_8_rc1.php deleted file mode 100644 index 13e68a7953..0000000000 --- a/phpBB/includes/db/migration/data/3_0_8_rc1.php +++ /dev/null @@ -1,221 +0,0 @@ -config['version'], '3.0.8-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_7_pl1'); - } - - public function update_data() - { - return array( - array('custom', array(array(&$this, 'update_file_extension_group_names'))), - array('custom', array(array(&$this, 'update_module_auth'))), - array('custom', array(array(&$this, 'update_bots'))), - array('custom', array(array(&$this, 'delete_orphan_shadow_topics'))), - array('module.add', array( - 'acp', - 'ACP_MESSAGES', - array( - 'module_basename' => 'acp_board', - 'modes' => array('post'), - ), - )), - array('config.add', array('load_unreads_search', 1)), - array('config.update_if_equals', array(600, 'queue_interval', 60)), - array('config.update_if_equals', array(50, 'email_package_size', 20)), - - array('config.update', array('version', '3.0.8-rc1')), - ); - } - - public function update_file_extension_group_names() - { - // Update file extension group names to use language strings. - $sql = 'SELECT lang_dir - FROM ' . LANG_TABLE; - $result = $this->db->sql_query($sql); - - $extension_groups_updated = array(); - while ($lang_dir = $this->db->sql_fetchfield('lang_dir')) - { - $lang_dir = basename($lang_dir); - - // The language strings we need are either in language/.../acp/attachments.php - // in the update package if we're updating to 3.0.8-RC1 or later, - // or they are in language/.../install.php when we're updating from 3.0.7-PL1 or earlier. - // On an already updated board, they can also already be in language/.../acp/attachments.php - // in the board root. - $lang_files = array( - "{$this->phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.{$this->php_ext}", - "{$this->phpbb_root_path}language/$lang_dir/install.{$this->php_ext}", - "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.{$this->php_ext}", - ); - - foreach ($lang_files as $lang_file) - { - if (!file_exists($lang_file)) - { - continue; - } - - $lang = array(); - include($lang_file); - - foreach($lang as $lang_key => $lang_val) - { - if (isset($extension_groups_updated[$lang_key]) || strpos($lang_key, 'EXT_GROUP_') !== 0) - { - continue; - } - - $sql_ary = array( - 'group_name' => substr($lang_key, 10), // Strip off 'EXT_GROUP_' - ); - - $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " - WHERE group_name = '" . $this->db->sql_escape($lang_val) . "'"; - $this->sql_query($sql); - - $extension_groups_updated[$lang_key] = true; - } - } - } - $this->db->sql_freeresult($result); - } - - public function update_module_auth() - { - $sql = 'UPDATE ' . MODULES_TABLE . ' - SET module_auth = \'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)\' - WHERE module_class = \'ucp\' - AND module_basename = \'profile\' - AND module_mode = \'avatar\''; - $this->sql_query($sql); - } - - public function update_bots() - { - $bot_name = 'Bing [Bot]'; - $bot_name_clean = utf8_clean_string($bot_name); - - $sql = 'SELECT user_id - FROM ' . USERS_TABLE . " - WHERE username_clean = '" . $this->db->sql_escape($bot_name_clean) . "'"; - $result = $this->db->sql_query($sql); - $bing_already_added = (bool) $this->db->sql_fetchfield('user_id'); - $this->db->sql_freeresult($result); - - if (!$bing_already_added) - { - $bot_agent = 'bingbot/'; - $bot_ip = ''; - $sql = 'SELECT group_id, group_colour - FROM ' . GROUPS_TABLE . " - WHERE group_name = 'BOTS'"; - $result = $this->db->sql_query($sql); - $group_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$group_row) - { - // default fallback, should never get here - $group_row['group_id'] = 6; - $group_row['group_colour'] = '9E8DA7'; - } - - if (!function_exists('user_add')) - { - include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); - } - - $user_row = array( - 'user_type' => USER_IGNORE, - 'group_id' => $group_row['group_id'], - 'username' => $bot_name, - 'user_regdate' => time(), - 'user_password' => '', - 'user_colour' => $group_row['group_colour'], - 'user_email' => '', - 'user_lang' => $this->config['default_lang'], - 'user_style' => $this->config['default_style'], - 'user_timezone' => 0, - 'user_dateformat' => $this->config['default_dateformat'], - 'user_allow_massemail' => 0, - ); - - $user_id = user_add($user_row); - - $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( - 'bot_active' => 1, - 'bot_name' => (string) $bot_name, - 'user_id' => (int) $user_id, - 'bot_agent' => (string) $bot_agent, - 'bot_ip' => (string) $bot_ip, - )); - - $this->sql_query($sql); - } - } - - public function delete_orphan_shadow_topics() - { - // Delete shadow topics pointing to not existing topics - $batch_size = 500; - - // Set of affected forums we have to resync - $sync_forum_ids = array(); - - $sql_array = array( - 'SELECT' => 't1.topic_id, t1.forum_id', - 'FROM' => array( - TOPICS_TABLE => 't1', - ), - 'LEFT_JOIN' => array( - array( - 'FROM' => array(TOPICS_TABLE => 't2'), - 'ON' => 't1.topic_moved_id = t2.topic_id', - ), - ), - 'WHERE' => 't1.topic_moved_id <> 0 - AND t2.topic_id IS NULL', - ); - $sql = $this->db->sql_build_query('SELECT', $sql_array); - $result = $this->db->sql_query_limit($sql, $batch_size); - - $topic_ids = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $topic_ids[] = (int) $row['topic_id']; - - $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; - } - $this->db->sql_freeresult($result); - - if (!empty($topic_ids)) - { - $sql = 'DELETE FROM ' . TOPICS_TABLE . ' - WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids); - $this->db->sql_query($sql); - - // Sync the forums we have deleted shadow topics from. - sync('forum', 'forum_id', $sync_forum_ids, true, true); - - return false; - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_9.php b/phpBB/includes/db/migration/data/3_0_9.php deleted file mode 100644 index b35350dbb5..0000000000 --- a/phpBB/includes/db/migration/data/3_0_9.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.9', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_9_rc4'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.9')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_9_rc1.php b/phpBB/includes/db/migration/data/3_0_9_rc1.php deleted file mode 100644 index be6ced2566..0000000000 --- a/phpBB/includes/db/migration/data/3_0_9_rc1.php +++ /dev/null @@ -1,124 +0,0 @@ -config['version'], '3.0.9-rc1', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_8'); - } - - public function update_schema() - { - return array( - 'add_tables' => array( - $this->table_prefix . 'login_attempts' => array( - 'COLUMNS' => array( - // this column was removed from the database updater - // after 3.0.9-RC3 was released. It might still exist - // in 3.0.9-RCX installations and has to be dropped in - // 3.0.12 after the db_tools class is capable of properly - // removing a primary key. - // 'attempt_id' => array('UINT', NULL, 'auto_increment'), - 'attempt_ip' => array('VCHAR:40', ''), - 'attempt_browser' => array('VCHAR:150', ''), - 'attempt_forwarded_for' => array('VCHAR:255', ''), - 'attempt_time' => array('TIMESTAMP', 0), - 'user_id' => array('UINT', 0), - 'username' => array('VCHAR_UNI:255', 0), - 'username_clean' => array('VCHAR_CI', 0), - ), - //'PRIMARY_KEY' => 'attempt_id', - 'KEYS' => array( - 'att_ip' => array('INDEX', array('attempt_ip', 'attempt_time')), - 'att_for' => array('INDEX', array('attempt_forwarded_for', 'attempt_time')), - 'att_time' => array('INDEX', array('attempt_time')), - 'user_id' => array('INDEX', 'user_id'), - ), - ), - ), - 'change_columns' => array( - $this->table_prefix . 'bbcodes' => array( - 'bbcode_id' => array('USINT', 0), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_tables' => array( - $this->table_prefix . 'login_attempts', - ), - ); - } - - public function update_data() - { - return array( - array('config.add', array('ip_login_limit_max', 50)), - array('config.add', array('ip_login_limit_time', 21600)), - array('config.add', array('ip_login_limit_use_forwarded', 0)), - array('custom', array(array(&$this, 'update_file_extension_group_names'))), - array('custom', array(array(&$this, 'fix_firebird_qa_captcha'))), - - array('config.update', array('version', '3.0.9-rc1')), - ); - } - - public function update_file_extension_group_names() - { - // Update file extension group names to use language strings, again. - $sql = 'SELECT group_id, group_name - FROM ' . EXTENSION_GROUPS_TABLE . ' - WHERE group_name ' . $this->db->sql_like_expression('EXT_GROUP_' . $this->db->any_char); - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $sql_ary = array( - 'group_name' => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_' - ); - - $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE group_id = ' . $row['group_id']; - $this->sql_query($sql); - } - $this->db->sql_freeresult($result); - } - - public function fix_firebird_qa_captcha() - { - // Recover from potentially broken Q&A CAPTCHA table on firebird - // Q&A CAPTCHA was uninstallable, so it's safe to remove these - // without data loss - if ($this->db_tools->sql_layer == 'firebird') - { - $tables = array( - $this->table_prefix . 'captcha_questions', - $this->table_prefix . 'captcha_answers', - $this->table_prefix . 'qa_confirm', - ); - foreach ($tables as $table) - { - if ($this->db_tools->sql_table_exists($table)) - { - $this->db_tools->sql_table_drop($table); - } - } - } - } -} diff --git a/phpBB/includes/db/migration/data/3_0_9_rc2.php b/phpBB/includes/db/migration/data/3_0_9_rc2.php deleted file mode 100644 index 0bec42a8de..0000000000 --- a/phpBB/includes/db/migration/data/3_0_9_rc2.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.9-rc2', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_9_rc1'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.9-rc2')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_9_rc3.php b/phpBB/includes/db/migration/data/3_0_9_rc3.php deleted file mode 100644 index a339670932..0000000000 --- a/phpBB/includes/db/migration/data/3_0_9_rc3.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.9-rc3', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_9_rc2'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.9-rc3')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_0_9_rc4.php b/phpBB/includes/db/migration/data/3_0_9_rc4.php deleted file mode 100644 index ab5c302611..0000000000 --- a/phpBB/includes/db/migration/data/3_0_9_rc4.php +++ /dev/null @@ -1,28 +0,0 @@ -config['version'], '3.0.9-rc4', '>='); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_9_rc3'); - } - - public function update_data() - { - return array( - array('config.update', array('version', '3.0.9-rc4')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/3_1_0_dev.php b/phpBB/includes/db/migration/data/3_1_0_dev.php deleted file mode 100644 index 8b437104e0..0000000000 --- a/phpBB/includes/db/migration/data/3_1_0_dev.php +++ /dev/null @@ -1,406 +0,0 @@ -config['version'], '3.1.0-dev', '>='); - } - - static public function depends_on() - { - return array( - 'phpbb_db_migration_data_3_0_11', - 'phpbb_db_migration_data_extensions', - 'phpbb_db_migration_data_style_update_p2', - 'phpbb_db_migration_data_timezone_p2', - 'phpbb_db_migration_data_reported_posts_display', - ); - } - - public function update_schema() - { - return array( - 'add_columns' => array( - $this->table_prefix . 'groups' => array( - 'group_teampage' => array('UINT', 0, 'after' => 'group_legend'), - ), - $this->table_prefix . 'profile_fields' => array( - 'field_show_on_pm' => array('BOOL', 0), - ), - $this->table_prefix . 'styles' => array( - 'style_path' => array('VCHAR:100', ''), - 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), - 'style_parent_id' => array('UINT:4', 0), - 'style_parent_tree' => array('TEXT', ''), - ), - $this->table_prefix . 'reports' => array( - 'reported_post_text' => array('MTEXT_UNI', ''), - 'reported_post_uid' => array('VCHAR:8', ''), - 'reported_post_bitfield' => array('VCHAR:255', ''), - ), - ), - 'change_columns' => array( - $this->table_prefix . 'groups' => array( - 'group_legend' => array('UINT', 0), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_columns' => array( - $this->table_prefix . 'groups' => array( - 'group_teampage', - ), - $this->table_prefix . 'profile_fields' => array( - 'field_show_on_pm', - ), - $this->table_prefix . 'styles' => array( - 'style_path', - 'bbcode_bitfield', - 'style_parent_id', - 'style_parent_tree', - ), - $this->table_prefix . 'reports' => array( - 'reported_post_text', - 'reported_post_uid', - 'reported_post_bitfield', - ), - ), - ); - } - - public function update_data() - { - return array( - array('config.update', array('search_type', 'phpbb_search_' . $this->config['search_type'])), - - array('config.add', array('fulltext_postgres_ts_name', 'simple')), - array('config.add', array('fulltext_postgres_min_word_len', 4)), - array('config.add', array('fulltext_postgres_max_word_len', 254)), - array('config.add', array('fulltext_sphinx_stopwords', 0)), - array('config.add', array('fulltext_sphinx_indexer_mem_limit', 512)), - - array('config.add', array('load_jquery_cdn', 0)), - array('config.add', array('load_jquery_url', '//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js')), - - array('config.add', array('use_system_cron', 0)), - - array('config.add', array('legend_sort_groupname', 0)), - array('config.add', array('teampage_forums', 1)), - array('config.add', array('teampage_memberships', 1)), - - array('config.add', array('load_cpf_pm', 0)), - - array('config.add', array('display_last_subject', 1)), - - array('config.add', array('assets_version', 1)), - - array('config.add', array('site_home_url', '')), - array('config.add', array('site_home_text', '')), - - array('permission.add', array('u_chgprofileinfo', true, 'u_sig')), - - array('module.add', array( - 'acp', - 'ACP_GROUPS', - array( - 'module_basename' => 'acp_groups', - 'modes' => array('position'), - ), - )), - array('module.add', array( - 'acp', - 'ACP_ATTACHMENTS', - array( - 'module_basename' => 'acp_attachments', - 'modes' => array('manage'), - ), - )), - array('module.add', array( - 'acp', - 'ACP_STYLE_MANAGEMENT', - array( - 'module_basename' => 'acp_styles', - 'modes' => array('install', 'cache'), - ), - )), - array('module.add', array( - 'ucp', - 'UCP_PROFILE', - array( - 'module_basename' => 'ucp_profile', - 'modes' => array('autologin_keys'), - ), - )), - // Module will be renamed later - array('module.add', array( - 'acp', - 'ACP_CAT_STYLES', - 'ACP_LANGUAGE' - )), - - array('module.remove', array( - 'acp', - false, - 'ACP_TEMPLATES', - )), - array('module.remove', array( - 'acp', - false, - 'ACP_THEMES', - )), - array('module.remove', array( - 'acp', - false, - 'ACP_IMAGESETS', - )), - - array('custom', array(array($this, 'rename_module_basenames'))), - array('custom', array(array($this, 'rename_styles_module'))), - array('custom', array(array($this, 'add_group_teampage'))), - array('custom', array(array($this, 'update_group_legend'))), - array('custom', array(array($this, 'localise_global_announcements'))), - array('custom', array(array($this, 'update_ucp_pm_basename'))), - array('custom', array(array($this, 'update_ucp_profile_auth'))), - array('custom', array(array($this, 'move_customise_modules'))), - - array('config.update', array('version', '3.1.0-dev')), - ); - } - - public function move_customise_modules() - { - // Move language management to new location in the Customise tab - // First get language module id - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_basename = 'acp_language'"; - $result = $this->db->sql_query($sql); - $language_module_id = $this->db->sql_fetchfield('module_id'); - $this->db->sql_freeresult($result); - // Next get language management module id of the one just created - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = 'ACP_LANGUAGE'"; - $result = $this->db->sql_query($sql); - $language_management_module_id = $this->db->sql_fetchfield('module_id'); - $this->db->sql_freeresult($result); - - if (!class_exists('acp_modules')) - { - include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); - } - // acp_modules calls adm_back_link, which is undefined at this point - if (!function_exists('adm_back_link')) - { - include($this->phpbb_root_path . 'includes/functions_acp.' . $this->php_ext); - } - $module_manager = new acp_modules(); - $module_manager->module_class = 'acp'; - $module_manager->move_module($language_module_id, $language_management_module_id); - } - - public function update_ucp_pm_basename() - { - $sql = 'SELECT module_id, module_basename - FROM ' . MODULES_TABLE . " - WHERE module_basename <> 'ucp_pm' AND - module_langname='UCP_PM'"; - $result = $this->db->sql_query_limit($sql, 1); - - if ($row = $this->db->sql_fetchrow($result)) - { - // This update is still not applied. Applying it - - $sql = 'UPDATE ' . MODULES_TABLE . " - SET module_basename = 'ucp_pm' - WHERE module_id = " . (int) $row['module_id']; - - $this->sql_query($sql); - } - $this->db->sql_freeresult($result); - } - - public function update_ucp_profile_auth() - { - // Update the auth setting for the module - $sql = 'UPDATE ' . MODULES_TABLE . " - SET module_auth = 'acl_u_chgprofileinfo' - WHERE module_class = 'ucp' - AND module_basename = 'ucp_profile' - AND module_mode = 'profile_info'"; - $this->sql_query($sql); - } - - public function rename_styles_module() - { - // Rename styles module to Customise - $sql = 'UPDATE ' . MODULES_TABLE . " - SET module_langname = 'ACP_CAT_CUSTOMISE' - WHERE module_langname = 'ACP_CAT_STYLES'"; - $this->sql_query($sql); - } - - public function rename_module_basenames() - { - // rename all module basenames to full classname - $sql = 'SELECT module_id, module_basename, module_class - FROM ' . MODULES_TABLE; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $module_id = (int) $row['module_id']; - unset($row['module_id']); - - if (!empty($row['module_basename']) && !empty($row['module_class'])) - { - // all the class names start with class name or with phpbb_ for auto loading - if (strpos($row['module_basename'], $row['module_class'] . '_') !== 0 && - strpos($row['module_basename'], 'phpbb_') !== 0) - { - $row['module_basename'] = $row['module_class'] . '_' . $row['module_basename']; - - $sql_update = $this->db->sql_build_array('UPDATE', $row); - - $sql = 'UPDATE ' . MODULES_TABLE . ' - SET ' . $sql_update . ' - WHERE module_id = ' . $module_id; - $this->sql_query($sql); - } - } - } - - $this->db->sql_freeresult($result); - } - - public function add_group_teampage() - { - $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_teampage = 1 - WHERE group_type = ' . GROUP_SPECIAL . " - AND group_name = 'ADMINISTRATORS'"; - $this->sql_query($sql); - - $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_teampage = 2 - WHERE group_type = ' . GROUP_SPECIAL . " - AND group_name = 'GLOBAL_MODERATORS'"; - $this->sql_query($sql); - } - - public function update_group_legend() - { - $sql = 'SELECT group_id - FROM ' . GROUPS_TABLE . ' - WHERE group_legend = 1 - ORDER BY group_name ASC'; - $result = $this->db->sql_query($sql); - - $next_legend = 1; - while ($row = $this->db->sql_fetchrow($result)) - { - $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_legend = ' . $next_legend . ' - WHERE group_id = ' . (int) $row['group_id']; - $this->sql_query($sql); - - $next_legend++; - } - $this->db->sql_freeresult($result); - } - - public function localise_global_announcements() - { - // Localise Global Announcements - $sql = 'SELECT topic_id, topic_approved, (topic_replies + 1) AS topic_posts, topic_last_post_id, topic_last_post_subject, topic_last_post_time, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour - FROM ' . TOPICS_TABLE . ' - WHERE forum_id = 0 - AND topic_type = ' . POST_GLOBAL; - $result = $this->db->sql_query($sql); - - $global_announcements = $update_lastpost_data = array(); - $update_lastpost_data['forum_last_post_time'] = 0; - $update_forum_data = array( - 'forum_posts' => 0, - 'forum_topics' => 0, - 'forum_topics_real' => 0, - ); - - while ($row = $this->db->sql_fetchrow($result)) - { - $global_announcements[] = (int) $row['topic_id']; - - $update_forum_data['forum_posts'] += (int) $row['topic_posts']; - $update_forum_data['forum_topics_real']++; - if ($row['topic_approved']) - { - $update_forum_data['forum_topics']++; - } - - if ($update_lastpost_data['forum_last_post_time'] < $row['topic_last_post_time']) - { - $update_lastpost_data = array( - 'forum_last_post_id' => (int) $row['topic_last_post_id'], - 'forum_last_post_subject' => $row['topic_last_post_subject'], - 'forum_last_post_time' => (int) $row['topic_last_post_time'], - 'forum_last_poster_id' => (int) $row['topic_last_poster_id'], - 'forum_last_poster_name' => $row['topic_last_poster_name'], - 'forum_last_poster_colour' => $row['topic_last_poster_colour'], - ); - } - } - $this->db->sql_freeresult($result); - - if (!empty($global_announcements)) - { - // Update the post/topic-count for the forum and the last-post if needed - $sql = 'SELECT forum_id - FROM ' . FORUMS_TABLE . ' - WHERE forum_type = ' . FORUM_POST; - $result = $this->db->sql_query_limit($sql, 1); - $ga_forum_id = $this->db->sql_fetchfield('forum_id'); - $this->db->sql_freeresult($result); - - $sql = 'SELECT forum_last_post_time - FROM ' . FORUMS_TABLE . ' - WHERE forum_id = ' . $ga_forum_id; - $result = $this->db->sql_query($sql); - $lastpost = (int) $this->db->sql_fetchfield('forum_last_post_time'); - $this->db->sql_freeresult($result); - - $sql_update = 'forum_posts = forum_posts + ' . $update_forum_data['forum_posts'] . ', '; - $sql_update .= 'forum_topics_real = forum_topics_real + ' . $update_forum_data['forum_topics_real'] . ', '; - $sql_update .= 'forum_topics = forum_topics + ' . $update_forum_data['forum_topics']; - if ($lastpost < $update_lastpost_data['forum_last_post_time']) - { - $sql_update .= ', ' . $this->db->sql_build_array('UPDATE', $update_lastpost_data); - } - - $sql = 'UPDATE ' . FORUMS_TABLE . ' - SET ' . $sql_update . ' - WHERE forum_id = ' . $ga_forum_id; - $this->sql_query($sql); - - // Update some forum_ids - $table_ary = array(TOPICS_TABLE, POSTS_TABLE, LOG_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE); - foreach ($table_ary as $table) - { - $sql = "UPDATE $table - SET forum_id = $ga_forum_id - WHERE " . $this->db->sql_in_set('topic_id', $global_announcements); - $this->sql_query($sql); - } - unset($table_ary); - } - } -} diff --git a/phpBB/includes/db/migration/data/extensions.php b/phpBB/includes/db/migration/data/extensions.php deleted file mode 100644 index f077741883..0000000000 --- a/phpBB/includes/db/migration/data/extensions.php +++ /dev/null @@ -1,69 +0,0 @@ -db_tools->sql_table_exists($this->table_prefix . 'ext'); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_11'); - } - - public function update_schema() - { - return array( - 'add_tables' => array( - $this->table_prefix . 'ext' => array( - 'COLUMNS' => array( - 'ext_name' => array('VCHAR', ''), - 'ext_active' => array('BOOL', 0), - 'ext_state' => array('TEXT', ''), - ), - 'KEYS' => array( - 'ext_name' => array('UNIQUE', 'ext_name'), - ), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_tables' => array( - $this->table_prefix . 'ext', - ), - ); - } - - public function update_data() - { - return array( - // Module will be renamed later - array('module.add', array( - 'acp', - 'ACP_CAT_STYLES', - 'ACP_EXTENSION_MANAGEMENT' - )), - array('module.add', array( - 'acp', - 'ACP_EXTENSION_MANAGEMENT', - array( - 'module_basename' => 'acp_extensions', - 'modes' => array('main'), - ), - )), - array('permission.add', array('a_extensions', true, 'a_styles')), - ); - } -} diff --git a/phpBB/includes/db/migration/data/reported_posts_display.php b/phpBB/includes/db/migration/data/reported_posts_display.php deleted file mode 100644 index fa605e28e5..0000000000 --- a/phpBB/includes/db/migration/data/reported_posts_display.php +++ /dev/null @@ -1,42 +0,0 @@ -db_tools->sql_column_exists($this->table_prefix . 'reports', 'reported_post_enable_bbcode'); - } - - public function update_schema() - { - return array( - 'add_columns' => array( - $this->table_prefix . 'reports' => array( - 'reported_post_enable_bbcode' => array('BOOL', 1), - 'reported_post_enable_smilies' => array('BOOL', 1), - 'reported_post_enable_magic_url' => array('BOOL', 1), - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'drop_columns' => array( - $this->table_prefix . 'reports' => array( - 'reported_post_enable_bbcode', - 'reported_post_enable_smilies', - 'reported_post_enable_magic_url', - ), - ), - ); - } -} diff --git a/phpBB/includes/db/migration/data/style_update_p1.php b/phpBB/includes/db/migration/data/style_update_p1.php deleted file mode 100644 index 7506b7c49b..0000000000 --- a/phpBB/includes/db/migration/data/style_update_p1.php +++ /dev/null @@ -1,157 +0,0 @@ -db_tools->sql_table_exists($this->table_prefix . 'styles_imageset'); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_11'); - } - - public function update_data() - { - return array( - array('custom', array(array($this, 'styles_update'))), - ); - } - - public function styles_update() - { - // Get list of valid 3.1 styles - $available_styles = array('prosilver'); - - $iterator = new DirectoryIterator($this->phpbb_root_path . 'styles'); - $skip_dirs = array('.', '..', 'prosilver'); - foreach ($iterator as $fileinfo) - { - if ($fileinfo->isDir() && !in_array($fileinfo->getFilename(), $skip_dirs) && file_exists($fileinfo->getPathname() . '/style.cfg')) - { - $style_cfg = parse_cfg_file($fileinfo->getPathname() . '/style.cfg'); - if (isset($style_cfg['phpbb_version']) && version_compare($style_cfg['phpbb_version'], '3.1.0-dev', '>=')) - { - // 3.1 style - $available_styles[] = $fileinfo->getFilename(); - } - } - } - - // Get all installed styles - if ($this->db_tools->sql_table_exists($this->table_prefix . 'styles_imageset')) - { - $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id, i.imageset_path - FROM ' . STYLES_TABLE . ' s, ' . $this->table_prefix . 'styles_template t, ' . $this->table_prefix . 'styles_theme c, ' . $this->table_prefix . "styles_imageset i - WHERE t.template_id = s.template_id - AND c.theme_id = s.theme_id - AND i.imageset_id = s.imageset_id"; - } - else - { - $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_id - FROM ' . STYLES_TABLE . ' s, ' . $this->table_prefix . 'styles_template t, ' . $this->table_prefix . "stles_theme c - WHERE t.template_id = s.template_id - AND c.theme_id = s.theme_id"; - } - $result = $this->db->sql_query($sql); - - $styles = array(); - while ($row = $this->db->sql_fetchrow($result)) - { - $styles[] = $row; - } - $this->db->sql_freeresult($result); - - // Decide which styles to keep, all others will be deleted - $valid_styles = array(); - foreach ($styles as $style_row) - { - if ( - // Delete styles with parent style (not supported yet) - $style_row['template_inherits_id'] == 0 && - // Check if components match - $style_row['template_path'] == $style_row['theme_path'] && (!isset($style_row['imageset_path']) || $style_row['template_path'] == $style_row['imageset_path']) && - // Check if components are valid - in_array($style_row['template_path'], $available_styles) - ) - { - // Valid style. Keep it - $sql_ary = array( - 'style_path' => $style_row['template_path'], - 'bbcode_bitfield' => $style_row['bbcode_bitfield'], - 'style_parent_id' => 0, - 'style_parent_tree' => '', - ); - $this->sql_query('UPDATE ' . STYLES_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE style_id = ' . $style_row['style_id']); - $valid_styles[] = (int) $style_row['style_id']; - } - } - - // Remove old entries from styles table - if (!sizeof($valid_styles)) - { - // No valid styles: remove everything and add prosilver - $this->sql_query('DELETE FROM ' . STYLES_TABLE, $errored, $error_ary); - - $sql_ary = array( - 'style_name' => 'prosilver', - 'style_copyright' => '© phpBB Group', - 'style_active' => 1, - 'style_path' => 'prosilver', - 'bbcode_bitfield' => 'lNg=', - 'style_parent_id' => 0, - 'style_parent_tree' => '', - - // Will be removed in the next step - 'imageset_id' => 0, - 'template_id' => 0, - 'theme_id' => 0, - ); - - $sql = 'INSERT INTO ' . STYLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); - $this->sql_query($sql); - - $sql = 'SELECT style_id - FROM ' . $table . " - WHERE style_name = 'prosilver'"; - $result = $this->sql_query($sql); - $default_style = $this->db->sql_fetchfield($result); - $this->db->sql_freeresult($result); - - set_config('default_style', $default_style); - - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0'; - $this->sql_query($sql); - } - else - { - // There are valid styles in styles table. Remove styles that are outdated - $this->sql_query('DELETE FROM ' . STYLES_TABLE . ' - WHERE ' . $this->db->sql_in_set('style_id', $valid_styles, true)); - - // Change default style - if (!in_array($this->config['default_style'], $valid_styles)) - { - $this->sql_query('UPDATE ' . CONFIG_TABLE . " - SET config_value = '" . $valid_styles[0] . "' - WHERE config_name = 'default_style'"); - } - - // Reset styles for users - $this->sql_query('UPDATE ' . USERS_TABLE . ' - SET user_style = 0 - WHERE ' . $this->db->sql_in_set('user_style', $valid_styles, true)); - } - } -} diff --git a/phpBB/includes/db/migration/data/style_update_p2.php b/phpBB/includes/db/migration/data/style_update_p2.php deleted file mode 100644 index ef13f45d9b..0000000000 --- a/phpBB/includes/db/migration/data/style_update_p2.php +++ /dev/null @@ -1,129 +0,0 @@ -db_tools->sql_table_exists($this->table_prefix . 'styles_imageset'); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_style_update_p1'); - } - - public function update_schema() - { - return array( - 'drop_columns' => array( - $this->table_prefix . 'styles' => array( - 'imageset_id', - 'template_id', - 'theme_id', - ), - ), - - 'drop_tables' => array( - $this->table_prefix . 'styles_imageset', - $this->table_prefix . 'styles_imageset_data', - $this->table_prefix . 'styles_template', - $this->table_prefix . 'styles_template_data', - $this->table_prefix . 'styles_theme', - ), - ); - } - - public function revert_schema() - { - return array( - 'add_columns' => array( - $this->table_prefix . 'styles' => array( - 'imageset_id' => array('UINT', 0), - 'template_id' => array('UINT', 0), - 'theme_id' => array('UINT', 0), - ), - ), - - 'add_tables' => array( - $this->table_prefix . 'styles_imageset' => array( - 'COLUMNS' => array( - 'imageset_id' => array('UINT', NULL, 'auto_increment'), - 'imageset_name' => array('VCHAR_UNI:255', ''), - 'imageset_copyright' => array('VCHAR_UNI', ''), - 'imageset_path' => array('VCHAR:100', ''), - ), - 'PRIMARY_KEY' => 'imageset_id', - 'KEYS' => array( - 'imgset_nm' => array('UNIQUE', 'imageset_name'), - ), - ), - $this->table_prefix . 'styles_imageset_data' => array( - 'COLUMNS' => array( - 'image_id' => array('UINT', NULL, 'auto_increment'), - 'image_name' => array('VCHAR:200', ''), - 'image_filename' => array('VCHAR:200', ''), - 'image_lang' => array('VCHAR:30', ''), - 'image_height' => array('USINT', 0), - 'image_width' => array('USINT', 0), - 'imageset_id' => array('UINT', 0), - ), - 'PRIMARY_KEY' => 'image_id', - 'KEYS' => array( - 'i_d' => array('INDEX', 'imageset_id'), - ), - ), - $this->table_prefix . 'styles_template' => array( - 'COLUMNS' => array( - 'template_id' => array('UINT', NULL, 'auto_increment'), - 'template_name' => array('VCHAR_UNI:255', ''), - 'template_copyright' => array('VCHAR_UNI', ''), - 'template_path' => array('VCHAR:100', ''), - 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), - 'template_storedb' => array('BOOL', 0), - 'template_inherits_id' => array('UINT:4', 0), - 'template_inherit_path' => array('VCHAR', ''), - ), - 'PRIMARY_KEY' => 'template_id', - 'KEYS' => array( - 'tmplte_nm' => array('UNIQUE', 'template_name'), - ), - ), - $this->table_prefix . 'styles_template_data' => array( - 'COLUMNS' => array( - 'template_id' => array('UINT', 0), - 'template_filename' => array('VCHAR:100', ''), - 'template_included' => array('TEXT', ''), - 'template_mtime' => array('TIMESTAMP', 0), - 'template_data' => array('MTEXT_UNI', ''), - ), - 'KEYS' => array( - 'tid' => array('INDEX', 'template_id'), - 'tfn' => array('INDEX', 'template_filename'), - ), - ), - $this->table_prefix . 'styles_theme' => array( - 'COLUMNS' => array( - 'theme_id' => array('UINT', NULL, 'auto_increment'), - 'theme_name' => array('VCHAR_UNI:255', ''), - 'theme_copyright' => array('VCHAR_UNI', ''), - 'theme_path' => array('VCHAR:100', ''), - 'theme_storedb' => array('BOOL', 0), - 'theme_mtime' => array('TIMESTAMP', 0), - 'theme_data' => array('MTEXT_UNI', ''), - ), - 'PRIMARY_KEY' => 'theme_id', - 'KEYS' => array( - 'theme_name' => array('UNIQUE', 'theme_name'), - ), - ), - ), - ); - } -} diff --git a/phpBB/includes/db/migration/data/timezone.php b/phpBB/includes/db/migration/data/timezone.php deleted file mode 100644 index 66085b8872..0000000000 --- a/phpBB/includes/db/migration/data/timezone.php +++ /dev/null @@ -1,163 +0,0 @@ -db_tools->sql_column_exists($this->table_prefix . 'users', 'user_dst'); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_3_0_11'); - } - - public function update_schema() - { - return array( - 'change_columns' => array( - $this->table_prefix . 'users' => array( - 'user_timezone' => array('VCHAR:100', ''), - ), - ), - ); - } - - public function update_data() - { - return array( - array('custom', array(array($this, 'update_timezones'))), - ); - } - - public function update_timezones() - { - // Update user timezones - $sql = 'SELECT user_dst, user_timezone - FROM ' . $this->table_prefix . 'users - GROUP BY user_timezone, user_dst'; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - $sql = 'UPDATE ' . $this->table_prefix . "users - SET user_timezone = '" . $this->db->sql_escape($this->convert_phpbb30_timezone($row['user_timezone'], $row['user_dst'])) . "' - WHERE user_timezone = '" . $this->db->sql_escape($row['user_timezone']) . "' - AND user_dst = " . (int) $row['user_dst']; - $this->sql_query($sql); - } - $this->db->sql_freeresult($result); - - // Update board default timezone - $sql = 'UPDATE ' . $this->table_prefix . "config - SET config_value = '" . $this->convert_phpbb30_timezone($this->config['board_timezone'], $this->config['board_dst']) . "' - WHERE config_name = 'board_timezone'"; - $this->sql_query($sql); - } - - /** - * Determine the new timezone for a given phpBB 3.0 timezone and - * "Daylight Saving Time" option - * - * @param $timezone float Users timezone in 3.0 - * @param $dst int Users daylight saving time - * @return string Users new php Timezone which is used since 3.1 - */ - public function convert_phpbb30_timezone($timezone, $dst) - { - $offset = $timezone + $dst; - - switch ($timezone) - { - case '-12': - return 'Etc/GMT+' . abs($offset); //'[UTC - 12] Baker Island Time' - case '-11': - return 'Etc/GMT+' . abs($offset); //'[UTC - 11] Niue Time, Samoa Standard Time' - case '-10': - return 'Etc/GMT+' . abs($offset); //'[UTC - 10] Hawaii-Aleutian Standard Time, Cook Island Time' - case '-9.5': - return 'Pacific/Marquesas'; //'[UTC - 9:30] Marquesas Islands Time' - case '-9': - return 'Etc/GMT+' . abs($offset); //'[UTC - 9] Alaska Standard Time, Gambier Island Time' - case '-8': - return 'Etc/GMT+' . abs($offset); //'[UTC - 8] Pacific Standard Time' - case '-7': - return 'Etc/GMT+' . abs($offset); //'[UTC - 7] Mountain Standard Time' - case '-6': - return 'Etc/GMT+' . abs($offset); //'[UTC - 6] Central Standard Time' - case '-5': - return 'Etc/GMT+' . abs($offset); //'[UTC - 5] Eastern Standard Time' - case '-4.5': - return 'America/Caracas'; //'[UTC - 4:30] Venezuelan Standard Time' - case '-4': - return 'Etc/GMT+' . abs($offset); //'[UTC - 4] Atlantic Standard Time' - case '-3.5': - return 'America/St_Johns'; //'[UTC - 3:30] Newfoundland Standard Time' - case '-3': - return 'Etc/GMT+' . abs($offset); //'[UTC - 3] Amazon Standard Time, Central Greenland Time' - case '-2': - return 'Etc/GMT+' . abs($offset); //'[UTC - 2] Fernando de Noronha Time, South Georgia & the South Sandwich Islands Time' - case '-1': - return 'Etc/GMT+' . abs($offset); //'[UTC - 1] Azores Standard Time, Cape Verde Time, Eastern Greenland Time' - case '0': - return (!$dst) ? 'UTC' : 'Etc/GMT-1'; //'[UTC] Western European Time, Greenwich Mean Time' - case '1': - return 'Etc/GMT-' . $offset; //'[UTC + 1] Central European Time, West African Time' - case '2': - return 'Etc/GMT-' . $offset; //'[UTC + 2] Eastern European Time, Central African Time' - case '3': - return 'Etc/GMT-' . $offset; //'[UTC + 3] Moscow Standard Time, Eastern African Time' - case '3.5': - return 'Asia/Tehran'; //'[UTC + 3:30] Iran Standard Time' - case '4': - return 'Etc/GMT-' . $offset; //'[UTC + 4] Gulf Standard Time, Samara Standard Time' - case '4.5': - return 'Asia/Kabul'; //'[UTC + 4:30] Afghanistan Time' - case '5': - return 'Etc/GMT-' . $offset; //'[UTC + 5] Pakistan Standard Time, Yekaterinburg Standard Time' - case '5.5': - return 'Asia/Kolkata'; //'[UTC + 5:30] Indian Standard Time, Sri Lanka Time' - case '5.75': - return 'Asia/Kathmandu'; //'[UTC + 5:45] Nepal Time' - case '6': - return 'Etc/GMT-' . $offset; //'[UTC + 6] Bangladesh Time, Bhutan Time, Novosibirsk Standard Time' - case '6.5': - return 'Indian/Cocos'; //'[UTC + 6:30] Cocos Islands Time, Myanmar Time' - case '7': - return 'Etc/GMT-' . $offset; //'[UTC + 7] Indochina Time, Krasnoyarsk Standard Time' - case '8': - return 'Etc/GMT-' . $offset; //'[UTC + 8] Chinese Standard Time, Australian Western Standard Time, Irkutsk Standard Time' - case '8.75': - return 'Australia/Eucla'; //'[UTC + 8:45] Southeastern Western Australia Standard Time' - case '9': - return 'Etc/GMT-' . $offset; //'[UTC + 9] Japan Standard Time, Korea Standard Time, Chita Standard Time' - case '9.5': - return 'Australia/ACT'; //'[UTC + 9:30] Australian Central Standard Time' - case '10': - return 'Etc/GMT-' . $offset; //'[UTC + 10] Australian Eastern Standard Time, Vladivostok Standard Time' - case '10.5': - return 'Australia/Lord_Howe'; //'[UTC + 10:30] Lord Howe Standard Time' - case '11': - return 'Etc/GMT-' . $offset; //'[UTC + 11] Solomon Island Time, Magadan Standard Time' - case '11.5': - return 'Pacific/Norfolk'; //'[UTC + 11:30] Norfolk Island Time' - case '12': - return 'Etc/GMT-12'; //'[UTC + 12] New Zealand Time, Fiji Time, Kamchatka Standard Time' - case '12.75': - return 'Pacific/Chatham'; //'[UTC + 12:45] Chatham Islands Time' - case '13': - return 'Pacific/Tongatapu'; //'[UTC + 13] Tonga Time, Phoenix Islands Time' - case '14': - return 'Pacific/Kiritimati'; //'[UTC + 14] Line Island Time' - default: - return 'UTC'; - } - } -} diff --git a/phpBB/includes/db/migration/data/timezone_p2.php b/phpBB/includes/db/migration/data/timezone_p2.php deleted file mode 100644 index 38347a0c63..0000000000 --- a/phpBB/includes/db/migration/data/timezone_p2.php +++ /dev/null @@ -1,43 +0,0 @@ -db_tools->sql_column_exists($this->table_prefix . 'users', 'user_dst'); - } - - static public function depends_on() - { - return array('phpbb_db_migration_data_timezone'); - } - - public function update_schema() - { - return array( - 'drop_columns' => array( - $this->table_prefix . 'users' => array( - 'user_dst', - ), - ), - ); - } - - public function revert_schema() - { - return array( - 'add_columns' => array( - $this->table_prefix . 'users' => array( - 'user_dst' => array('BOOL', 0), - ), - ), - ); - } -} -- cgit v1.2.1 From e4afb68dc35131918a6b91ae9874ade97f448475 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 14 Jan 2013 12:50:13 -0600 Subject: [feature/migrations] Correct depends_on PHPBB3-9737 --- phpBB/includes/db/migration/data/310/dev.php | 1 - phpBB/includes/db/migration/data/310/extensions.php | 2 +- phpBB/includes/db/migration/data/310/reported_posts_display.php | 5 +++++ phpBB/includes/db/migration/data/310/style_update_p1.php | 2 +- phpBB/includes/db/migration/data/310/timezone.php | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/310/dev.php b/phpBB/includes/db/migration/data/310/dev.php index f41750e327..13b36bbf30 100644 --- a/phpBB/includes/db/migration/data/310/dev.php +++ b/phpBB/includes/db/migration/data/310/dev.php @@ -17,7 +17,6 @@ class phpbb_db_migration_data_310_dev extends phpbb_db_migration static public function depends_on() { return array( - 'phpbb_db_migration_data_30x_11', 'phpbb_db_migration_data_310_extensions', 'phpbb_db_migration_data_310_style_update_p2', 'phpbb_db_migration_data_310_timezone_p2', diff --git a/phpBB/includes/db/migration/data/310/extensions.php b/phpBB/includes/db/migration/data/310/extensions.php index 925fa29384..6a9caa1cfc 100644 --- a/phpBB/includes/db/migration/data/310/extensions.php +++ b/phpBB/includes/db/migration/data/310/extensions.php @@ -16,7 +16,7 @@ class phpbb_db_migration_data_310_extensions extends phpbb_db_migration static public function depends_on() { - return array('phpbb_db_migration_data_30x_11'); + return array('phpbb_db_migration_data_30x_3_0_11'); } public function update_schema() diff --git a/phpBB/includes/db/migration/data/310/reported_posts_display.php b/phpBB/includes/db/migration/data/310/reported_posts_display.php index 64f0f1aaec..80a0a0e43f 100644 --- a/phpBB/includes/db/migration/data/310/reported_posts_display.php +++ b/phpBB/includes/db/migration/data/310/reported_posts_display.php @@ -14,6 +14,11 @@ class phpbb_db_migration_data_310_reported_posts_display extends phpbb_db_migrat return $this->db_tools->sql_column_exists($this->table_prefix . 'reports', 'reported_post_enable_bbcode'); } + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_11'); + } + public function update_schema() { return array( diff --git a/phpBB/includes/db/migration/data/310/style_update_p1.php b/phpBB/includes/db/migration/data/310/style_update_p1.php index d19ccc37cf..e324ce7f24 100644 --- a/phpBB/includes/db/migration/data/310/style_update_p1.php +++ b/phpBB/includes/db/migration/data/310/style_update_p1.php @@ -16,7 +16,7 @@ class phpbb_db_migration_data_310_style_update_p1 extends phpbb_db_migration static public function depends_on() { - return array('phpbb_db_migration_data_30x_11'); + return array('phpbb_db_migration_data_30x_3_0_11'); } public function update_data() diff --git a/phpBB/includes/db/migration/data/310/timezone.php b/phpBB/includes/db/migration/data/310/timezone.php index 7a6a9bce05..6e50cbe45f 100644 --- a/phpBB/includes/db/migration/data/310/timezone.php +++ b/phpBB/includes/db/migration/data/310/timezone.php @@ -16,7 +16,7 @@ class phpbb_db_migration_data_310_timezone extends phpbb_db_migration static public function depends_on() { - return array('phpbb_db_migration_data_30x_11'); + return array('phpbb_db_migration_data_30x_3_0_11'); } public function update_schema() -- cgit v1.2.1 From a665ad5c2e44922fbd9790597913091c68311533 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 15 Jan 2013 18:58:19 -0600 Subject: [feature/migrations] Remove user_msnm migration PHPBB3-9737 --- phpBB/includes/db/migration/data/310/dev.php | 1 + .../includes/db/migration/data/310/remove_msnm.php | 43 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 phpBB/includes/db/migration/data/310/remove_msnm.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/310/dev.php b/phpBB/includes/db/migration/data/310/dev.php index 13b36bbf30..34f081bf62 100644 --- a/phpBB/includes/db/migration/data/310/dev.php +++ b/phpBB/includes/db/migration/data/310/dev.php @@ -21,6 +21,7 @@ class phpbb_db_migration_data_310_dev extends phpbb_db_migration 'phpbb_db_migration_data_310_style_update_p2', 'phpbb_db_migration_data_310_timezone_p2', 'phpbb_db_migration_data_310_reported_posts_display', + 'phpbb_db_migration_data_310_remove_msnm', ); } diff --git a/phpBB/includes/db/migration/data/310/remove_msnm.php b/phpBB/includes/db/migration/data/310/remove_msnm.php new file mode 100644 index 0000000000..521161df6b --- /dev/null +++ b/phpBB/includes/db/migration/data/310/remove_msnm.php @@ -0,0 +1,43 @@ +db_tools->sql_column_exists($this->table_prefix . 'users', 'user_msnm'); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_30x_3_0_11'); + } + + public function update_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'users' => array( + 'user_msnm', + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'add_columns' => array( + $this->table_prefix . 'users' => array( + 'user_msnm' => array('VCHAR_UNI', ''), + ), + ), + ); + } +} -- cgit v1.2.1 From 7ad577a86afa379d67812ed184b7a59a32c64e9e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 15 Feb 2013 16:02:33 -0600 Subject: [ticket/11103] Add Notification Settings link in flyout menu PHPBB3-11103 --- phpBB/includes/functions.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 0c514e7205..8ba7b2c24b 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5277,6 +5277,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'UNREAD_NOTIFICATIONS_COUNT' => ($notifications !== false) ? $notifications['unread_count'] : '', 'NOTIFICATIONS_COUNT' => ($notifications !== false) ? $user->lang('NOTIFICATIONS_COUNT', $notifications['unread_count']) : '', 'U_VIEW_ALL_NOTIFICATIONS' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=ucp_notifications'), + 'U_NOTIFICATION_SETTINGS' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=ucp_notifications&mode=notification_options'), 'S_NOTIFICATIONS_DISPLAY' => $config['load_notifications'], 'S_USER_NEW_PRIVMSG' => $user->data['user_new_privmsg'], -- cgit v1.2.1 From 4bf64b5e38efd194b6ab41fcc5d62ee0cc6fad5a Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 23 Feb 2013 15:10:21 -0600 Subject: [feature/migrations] Fully revert the removal of the user_msnm field PHBB3-9737 --- phpBB/includes/db/migration/data/310/dev.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/310/dev.php b/phpBB/includes/db/migration/data/310/dev.php index 34f081bf62..13b36bbf30 100644 --- a/phpBB/includes/db/migration/data/310/dev.php +++ b/phpBB/includes/db/migration/data/310/dev.php @@ -21,7 +21,6 @@ class phpbb_db_migration_data_310_dev extends phpbb_db_migration 'phpbb_db_migration_data_310_style_update_p2', 'phpbb_db_migration_data_310_timezone_p2', 'phpbb_db_migration_data_310_reported_posts_display', - 'phpbb_db_migration_data_310_remove_msnm', ); } -- cgit v1.2.1 From 6045aa7aa2fb63358e3f736504b17533b1085712 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Mon, 25 Feb 2013 19:16:29 -0600 Subject: [ticket/11367] Migrator throws error if migrations table does not exist Force load_migration_state to not throw errors if the table does not exist. PHPBB3-11367 --- phpBB/includes/db/migrator.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 41d996b1e3..ea5de3372f 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -99,18 +99,26 @@ class phpbb_db_migrator { $this->migration_state = array(); + // prevent errors in case the table does not exist yet + $this->db->sql_return_on_error(true); + $sql = "SELECT * FROM " . $this->migrations_table; $result = $this->db->sql_query($sql); - while ($migration = $this->db->sql_fetchrow($result)) + if (!$this->db->sql_error_triggered) { - $this->migration_state[$migration['migration_name']] = $migration; + while ($migration = $this->db->sql_fetchrow($result)) + { + $this->migration_state[$migration['migration_name']] = $migration; + + $this->migration_state[$migration['migration_name']]['migration_depends_on'] = unserialize($migration['migration_depends_on']); + } - $this->migration_state[$migration['migration_name']]['migration_depends_on'] = unserialize($migration['migration_depends_on']); + $this->db->sql_freeresult($result); } - $this->db->sql_freeresult($result); + $this->db->sql_return_on_error(false); } /** -- cgit v1.2.1 From 9a319fefb2ffed58da1d3339d59e53de09521e03 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 26 Feb 2013 10:22:13 -0600 Subject: [ticket/11367] Always freeresult PHPBB3-11367 --- phpBB/includes/db/migrator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index ea5de3372f..74f71775f3 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -114,10 +114,10 @@ class phpbb_db_migrator $this->migration_state[$migration['migration_name']]['migration_depends_on'] = unserialize($migration['migration_depends_on']); } - - $this->db->sql_freeresult($result); } + $this->db->sql_freeresult($result); + $this->db->sql_return_on_error(false); } -- cgit v1.2.1 From f9cbf5b4c7ea4f4eb1438d98ccc1cb71b0fea2af Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 26 Feb 2013 19:25:51 -0600 Subject: [ticket/11369] Reverting migration throws error String is attempted to be unserialized PHPBB3-11369 --- phpBB/includes/db/migrator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 74f71775f3..d6bcae6ca6 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -434,7 +434,7 @@ class phpbb_db_migrator } else { - $result = $this->process_data_step($migration->revert_data(), $state['migration_data_state'], false); + $result = $this->process_data_step($migration->revert_data(), '', false); $state['migration_data_state'] = ($result === true) ? '' : $result; $state['migration_data_done'] = ($result === true) ? false : true; -- cgit v1.2.1 From 51651b3d9f8622a195d877bbcf106acd413aee03 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 26 Feb 2013 19:44:03 -0600 Subject: [ticket/11370] Effectively installed migrations not inserted into table insert_migration() function now handles inserting/updating Move all insert/update code to insert_migration() function to prevent this from occurring again. PHPBB3-11370 --- phpBB/includes/db/migrator.php | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 74f71775f3..691285d477 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -332,7 +332,6 @@ class phpbb_db_migrator if (!isset($this->migration_state[$name])) { $state['migration_start_time'] = time(); - $this->insert_migration($name, $state); } } @@ -361,14 +360,7 @@ class phpbb_db_migrator } } - $insert = $state; - $insert['migration_depends_on'] = serialize($state['migration_depends_on']); - $sql = 'UPDATE ' . $this->migrations_table . ' - SET ' . $this->db->sql_build_array('UPDATE', $insert) . " - WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; - $this->db->sql_query($sql); - - $this->migration_state[$name] = $state; + $this->insert_migration($name, $state); return true; } @@ -440,14 +432,7 @@ class phpbb_db_migrator $state['migration_data_done'] = ($result === true) ? false : true; } - $insert = $state; - $insert['migration_depends_on'] = serialize($state['migration_depends_on']); - $sql = 'UPDATE ' . $this->migrations_table . ' - SET ' . $this->db->sql_build_array('UPDATE', $insert) . " - WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; - $this->db->sql_query($sql); - - $this->migration_state[$name] = $state; + $this->insert_migration($name, $state); } else { @@ -660,7 +645,7 @@ class phpbb_db_migrator } /** - * Insert migration row into the database + * Insert/Update migration row into the database * * @param string $name Name of the migration * @param array $state @@ -669,12 +654,22 @@ class phpbb_db_migrator protected function insert_migration($name, $state) { $migration_row = $state; - $migration_row['migration_name'] = $name; $migration_row['migration_depends_on'] = serialize($state['migration_depends_on']); - $sql = 'INSERT INTO ' . $this->migrations_table . ' - ' . $this->db->sql_build_array('INSERT', $migration_row); - $this->db->sql_query($sql); + if (isset($this->migration_state[$name])) + { + $sql = 'UPDATE ' . $this->migrations_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $migration_row) . " + WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + } + else + { + $migration_row['migration_name'] = $name; + $sql = 'INSERT INTO ' . $this->migrations_table . ' + ' . $this->db->sql_build_array('INSERT', $migration_row); + $this->db->sql_query($sql); + } $this->migration_state[$name] = $state; } -- cgit v1.2.1 From c6aabab03961cbfc3d96ef12e91fb65dbc367c16 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 26 Feb 2013 19:54:47 -0600 Subject: [ticket/11103] Notifications Migration file PHPBB3-11103 --- .../db/migration/data/310/notifications.php | 160 +++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 phpBB/includes/db/migration/data/310/notifications.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/310/notifications.php b/phpBB/includes/db/migration/data/310/notifications.php new file mode 100644 index 0000000000..6299ede7f7 --- /dev/null +++ b/phpBB/includes/db/migration/data/310/notifications.php @@ -0,0 +1,160 @@ +db_tools->sql_table_exists($this->table_prefix . 'notifications'); + } + + static public function depends_on() + { + return array('phpbb_db_migration_data_310_dev'); + } + + public function update_schema() + { + return array( + 'add_tables' => array( + $this->table_prefix . 'notification_types' => array( + 'COLUMNS' => array( + 'notification_type' => array('VCHAR:255', ''), + 'notification_type_enabled' => array('BOOL', 1), + ), + 'PRIMARY_KEY' => array('notification_type', 'notification_type_enabled'), + ), + $this->table_prefix . 'notifications' => array( + 'COLUMNS' => array( + 'notification_id' => array('UINT', NULL, 'auto_increment'), + 'item_type' => array('VCHAR:255', ''), + 'item_id' => array('UINT', 0), + 'item_parent_id' => array('UINT', 0), + 'user_id' => array('UINT', 0), + 'notification_read' => array('BOOL', 0), + 'notification_time' => array('TIMESTAMP', 1), + 'notification_data' => array('TEXT_UNI', ''), + ), + 'PRIMARY_KEY' => 'notification_id', + 'KEYS' => array( + 'item_ident' => array('INDEX', array('item_type', 'item_id')), + 'user' => array('INDEX', array('user_id', 'notification_read')), + ), + ), + $this->table_prefix . 'user_notifications' => array( + 'COLUMNS' => array( + 'item_type' => array('VCHAR:255', ''), + 'item_id' => array('UINT', 0), + 'user_id' => array('UINT', 0), + 'method' => array('VCHAR:255', ''), + 'notify' => array('BOOL', 1), + ), + ), + ), + ); + } + + public function revert_schema() + { + return array( + 'drop_tables' => array( + $this->table_prefix . 'notification_types', + $this->table_prefix . 'notifications', + $this->table_prefix . 'user_notifications', + ), + ); + } + + public function update_data() + { + return array( + array('module.add', array( + 'ucp', + 'UCP_MAIN', + array( + 'module_basename' => 'ucp_notifications', + 'modes' => array('notification_list'), + ), + )), + array('module.add', array( + 'ucp', + 'UCP_PREFS', + array( + 'module_basename' => 'ucp_notifications', + 'modes' => array('notification_options'), + ), + )), + array('config.add', array('load_notifications', 1)), + array('custom', array(array($this, 'convert_notifications'))), + ); + } + + public function convert_notifications() + { + $convert_notifications = array( + array( + 'check' => ($this->config['allow_topic_notify']), + 'item_type' => 'post', + ), + array( + 'check' => ($this->config['allow_forum_notify']), + 'item_type' => 'topic', + ), + array( + 'check' => ($this->config['allow_bookmarks']), + 'item_type' => 'bookmark', + ), + array( + 'check' => ($this->config['allow_privmsg']), + 'item_type' => 'pm', + ), + ); + + foreach ($convert_notifications as $convert_data) + { + if ($convert_data['check']) + { + $sql = 'SELECT user_id, user_notify_type + FROM ' . USERS_TABLE . ' + WHERE user_notify = 1'; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $this->sql_query('INSERT INTO ' . $this->table_prefix . 'user_notifications ' . $this->db->sql_build_array('INSERT', array( + 'item_type' => $convert_data['item_type'], + 'item_id' => 0, + 'user_id' => $row['user_id'], + 'method' => '', + ))); + + if ($row['user_notify_type'] == NOTIFY_EMAIL || $row['user_notify_type'] == NOTIFY_BOTH) + { + $this->sql_query('INSERT INTO ' . $this->table_prefix . 'user_notifications ' . $this->db->sql_build_array('INSERT', array( + 'item_type' => $convert_data['item_type'], + 'item_id' => 0, + 'user_id' => $row['user_id'], + 'method' => 'email', + ))); + } + + if ($row['user_notify_type'] == NOTIFY_IM || $row['user_notify_type'] == NOTIFY_BOTH) + { + $this->sql_query('INSERT INTO ' . $this->table_prefix . 'user_notifications ' . $this->db->sql_build_array('INSERT', array( + 'item_type' => $convert_data['item_type'], + 'item_id' => 0, + 'user_id' => $row['user_id'], + 'method' => 'jabber', + ))); + } + } + $this->db->sql_freeresult($result); + } + } + } +} -- cgit v1.2.1 From d296e809d5e44eec0005ed8229d5a173cd4f6edb Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 27 Feb 2013 11:12:18 -0600 Subject: [ticket/11363] Load module info files for extensions too Use the acp_modules::get_module_infos function instead of our own include code PHPBB3-11363 --- phpBB/includes/db/migration/tool/module.php | 45 +++++++---------------------- 1 file changed, 11 insertions(+), 34 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/tool/module.php b/phpBB/includes/db/migration/tool/module.php index 4d7fae2bb0..994768598c 100644 --- a/phpBB/includes/db/migration/tool/module.php +++ b/phpBB/includes/db/migration/tool/module.php @@ -183,25 +183,13 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac $basename = str_replace(array('/', '\\'), '', $basename); $class = str_replace(array('/', '\\'), '', $class); - $include_path = ($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path; - $info_file = "$class/info/$basename.{$this->php_ext}"; - - // The manual and automatic ways both failed... - if (!file_exists($include_path . $info_file)) - { - throw new phpbb_db_migration_exception('MODULE_INFO_FILE_NOT_EXIST', $class, $info_file); - } - - $classname = "{$basename}_info"; - - if (!class_exists($classname)) + if (!class_exists('acp_modules')) { - include($include_path . $info_file); + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); } - - $info = new $classname; - $module = $info->module(); - unset($info); + $acp_modules = new acp_modules(); + $module = $acp_modules->get_module_infos($basename, $class); + unset($acp_modules); $result = ''; foreach ($module['modes'] as $mode => $module_info) @@ -373,30 +361,19 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac $basename = str_replace(array('/', '\\'), '', $module['module_basename']); $class = str_replace(array('/', '\\'), '', $class); - $include_path = ($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path; - $info_file = "$class/info/$basename.{$this->php_ext}"; - - if (!file_exists($include_path . $info_file)) - { - throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', $info_file); - } - - $classname = "{$basename}_info"; - - if (!class_exists($classname)) + if (!class_exists('acp_modules')) { - include($include_path . $info_file); + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); } - - $info = new $classname; - $module_info = $info->module(); - unset($info); + $acp_modules = new acp_modules(); + $module_info = $acp_modules->get_module_infos($basename, $class); + unset($acp_modules); foreach ($module_info['modes'] as $mode => $info) { if (!isset($module['modes']) || in_array($mode, $module['modes'])) { - $this->remove($class, $parent, $info['title']) . '
'; + $this->remove($class, $parent, $info['title']); } } } -- cgit v1.2.1 From 9b554fbf3c9d1cb720fbd340bba552328790967f Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 27 Feb 2013 13:52:45 -0600 Subject: [ticket/11372] Migrator should only check if effectively installed if not installed at all PHPBB3-11372 --- phpBB/includes/db/migrator.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 74f71775f3..1ba65d71a6 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -316,20 +316,20 @@ class phpbb_db_migrator 'class' => $migration, ); - if ($migration->effectively_installed()) + if (!isset($this->migration_state[$name])) { - $state = array( - 'migration_depends_on' => $migration->depends_on(), - 'migration_schema_done' => true, - 'migration_data_done' => true, - 'migration_data_state' => '', - 'migration_start_time' => 0, - 'migration_end_time' => 0, - ); - } - else - { - if (!isset($this->migration_state[$name])) + if ($migration->effectively_installed()) + { + $state = array( + 'migration_depends_on' => $migration->depends_on(), + 'migration_schema_done' => true, + 'migration_data_done' => true, + 'migration_data_state' => '', + 'migration_start_time' => 0, + 'migration_end_time' => 0, + ); + } + else { $state['migration_start_time'] = time(); $this->insert_migration($name, $state); -- cgit v1.2.1 From c3434dec4020e1053f40382cdec729316f901728 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 27 Feb 2013 14:09:27 -0600 Subject: [ticket/11363] Fix a couple bugs and throw errors if the file not found PHPBB3-11363 --- phpBB/includes/db/migration/tool/module.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/tool/module.php b/phpBB/includes/db/migration/tool/module.php index 994768598c..8744866a16 100644 --- a/phpBB/includes/db/migration/tool/module.php +++ b/phpBB/includes/db/migration/tool/module.php @@ -189,8 +189,14 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac } $acp_modules = new acp_modules(); $module = $acp_modules->get_module_infos($basename, $class); + $module = $module[$basename]; unset($acp_modules); + if (empty($module)) + { + throw new phpbb_db_migration_exception('MODULE_INFO_FILE_NOT_EXIST', $class, $basename); + } + $result = ''; foreach ($module['modes'] as $mode => $module_info) { @@ -367,8 +373,14 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac } $acp_modules = new acp_modules(); $module_info = $acp_modules->get_module_infos($basename, $class); + $module_info = $module_info[$basename]; unset($acp_modules); + if (empty($module_info)) + { + throw new phpbb_db_migration_exception('MODULE_INFO_FILE_NOT_EXIST', $class, $basename); + } + foreach ($module_info['modes'] as $mode => $info) { if (!isset($module['modes']) || in_array($mode, $module['modes'])) -- cgit v1.2.1 From 247ecdf11bd404f4842a93afbf9c5dae9d541f55 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 28 Feb 2013 15:06:52 -0600 Subject: [ticket/11103] Fix effectively installed check PHPBB3-11103 --- phpBB/includes/db/migration/data/310/notifications.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/data/310/notifications.php b/phpBB/includes/db/migration/data/310/notifications.php index 6299ede7f7..82bfd4cb2d 100644 --- a/phpBB/includes/db/migration/data/310/notifications.php +++ b/phpBB/includes/db/migration/data/310/notifications.php @@ -11,7 +11,7 @@ class phpbb_db_migration_data_310_notifications extends phpbb_db_migration { public function effectively_installed() { - return false;//!$this->db_tools->sql_table_exists($this->table_prefix . 'notifications'); + return $this->db_tools->sql_table_exists($this->table_prefix . 'notifications'); } static public function depends_on() -- cgit v1.2.1 From b41b1a36d1ee85abc05c22b443db7b10af077f7e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 28 Feb 2013 15:25:18 -0600 Subject: [ticket/11103] Case time in queries as an int PHPBB3-11103 --- phpBB/includes/notification/manager.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php index 5c1016335a..ff83d4bb37 100644 --- a/phpBB/includes/notification/manager.php +++ b/phpBB/includes/notification/manager.php @@ -254,7 +254,7 @@ class phpbb_notification_manager $sql = 'UPDATE ' . $this->notifications_table . " SET notification_read = 1 - WHERE notification_time <= " . $time . + WHERE notification_time <= " . (int) $time . (($item_type !== false) ? ' AND ' . (is_array($item_type) ? $this->db->sql_in_set('item_type', $item_type) : " item_type = '" . $this->db->sql_escape($item_type) . "'") : '') . (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : ''); $this->db->sql_query($sql); @@ -285,7 +285,7 @@ class phpbb_notification_manager $sql = 'UPDATE ' . $this->notifications_table . " SET notification_read = 1 WHERE item_type = '" . $this->db->sql_escape($item_type) . "' - AND notification_time <= " . $time . + AND notification_time <= " . (int) $time . (($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id) : 'item_parent_id = ' . (int) $item_parent_id) : '') . (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); $this->db->sql_query($sql); @@ -303,7 +303,7 @@ class phpbb_notification_manager $sql = 'UPDATE ' . $this->notifications_table . " SET notification_read = 1 - WHERE notification_time <= " . $time . ' + WHERE notification_time <= " . (int) $time . ' AND ' . ((is_array($notification_id)) ? $this->db->sql_in_set('notification_id', $notification_id) : 'notification_id = ' . (int) $notification_id); $this->db->sql_query($sql); } -- cgit v1.2.1 From ee264e723566eb96ab9d068d3da671778f49a4f2 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 28 Feb 2013 17:25:39 -0600 Subject: [ticket/11103] Don't call generate_board_url many times Fix a URL and some comments PHPBB3-11103 --- phpBB/includes/notification/type/base.php | 3 ++- phpBB/includes/notification/type/report_post.php | 2 +- phpBB/includes/notification/type/topic.php | 10 ++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php index f52f14c09e..600ef7c965 100644 --- a/phpBB/includes/notification/type/base.php +++ b/phpBB/includes/notification/type/base.php @@ -154,7 +154,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * Magic method to set data on this notification * * @param mixed $name - * @return mixed + * @return null */ public function __set($name, $value) { @@ -191,6 +191,7 @@ abstract class phpbb_notification_type_base implements phpbb_notification_type_i * * @param string $name Name of the variable to set * @param mixed $value Value to set to the variable + * @return mixed */ protected function set_data($name, $value) { diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php index 1ea532c929..de5c54a291 100644 --- a/phpBB/includes/notification/type/report_post.php +++ b/phpBB/includes/notification/type/report_post.php @@ -99,7 +99,7 @@ class phpbb_notification_type_report_post extends phpbb_notification_type_post_i 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), - 'U_VIEW_REPORT' => "{$board_url}mcp.{$this->php_ext}?f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports", + 'U_VIEW_REPORT' => "{$board_url}/mcp.{$this->php_ext}?f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports", 'U_VIEW_POST' => "{$board_url}/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", 'U_NEWEST_POST' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&view=unread#unread", 'U_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php index 71e074fb50..2549b29409 100644 --- a/phpBB/includes/notification/type/topic.php +++ b/phpBB/includes/notification/type/topic.php @@ -170,6 +170,8 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base */ public function get_email_template_variables() { + $board_url = generate_board_url(); + if ($this->get_data('post_username')) { $username = $this->get_data('post_username'); @@ -184,10 +186,10 @@ class phpbb_notification_type_topic extends phpbb_notification_type_base 'FORUM_NAME' => htmlspecialchars_decode($this->get_data('forum_name')), 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), - 'U_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}", - 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}", - 'U_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->item_parent_id}", - 'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?uid={$this->user_id}&f={$this->item_parent_id}&unwatch=forum", + 'U_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}", + 'U_VIEW_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}", + 'U_FORUM' => "{$board_url}/viewforum.{$this->php_ext}?f={$this->item_parent_id}", + 'U_STOP_WATCHING_FORUM' => "{$board_url}/viewforum.{$this->php_ext}?uid={$this->user_id}&f={$this->item_parent_id}&unwatch=forum", ); } -- cgit v1.2.1 From e34f6a5269d7bd15b6b1357dc192893af8ec02e5 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 1 Mar 2013 11:37:24 -0600 Subject: [ticket/11381] Make finder able to search in all available extensions PHPBB3-11381 --- phpBB/includes/extension/finder.php | 37 +++++++++++++++++------- phpBB/includes/style/extension_path_provider.php | 2 +- 2 files changed, 28 insertions(+), 11 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index fb19b98429..af31478337 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -247,14 +247,16 @@ class phpbb_extension_finder * phpBB naming rules an incorrect class name will be returned. * * @param bool $cache Whether the result should be cached + * @param bool $use_all_available Use all available instead of just all + * enabled extensions * @return array An array of found class names */ - public function get_classes($cache = true) + public function get_classes($cache = true, $use_all_available = false) { $this->query['extension_suffix'] .= $this->php_ext; $this->query['core_suffix'] .= $this->php_ext; - $files = $this->find($cache, false); + $files = $this->find($cache, false, $use_all_available); $classes = array(); foreach ($files as $file => $ext_name) @@ -270,23 +272,27 @@ class phpbb_extension_finder * Finds all directories matching the configured options * * @param bool $cache Whether the result should be cached + * @param bool $use_all_available Use all available instead of just all + * enabled extensions * @param bool $extension_keys Whether the result should have extension name as array key * @return array An array of paths to found directories */ - public function get_directories($cache = true, $extension_keys = false) + public function get_directories($cache = true, $use_all_available = false, $extension_keys = false) { - return $this->find_with_root_path($cache, true, $extension_keys); + return $this->find_with_root_path($cache, true, $use_all_available, $extension_keys); } /** * Finds all files matching the configured options. * * @param bool $cache Whether the result should be cached + * @param bool $use_all_available Use all available instead of just all + * enabled extensions * @return array An array of paths to found files */ - public function get_files($cache = true) + public function get_files($cache = true, $use_all_available = false) { - return $this->find_with_root_path($cache, false); + return $this->find_with_root_path($cache, false, $use_all_available); } /** @@ -295,13 +301,15 @@ class phpbb_extension_finder * @param bool $cache Whether the result should be cached * @param bool $is_dir Directories will be returned when true, only files * otherwise + * @param bool $use_all_available Use all available instead of just all + * enabled extensions * @param bool $extension_keys If true, result will be associative array * with extension name as key * @return array An array of paths to found items */ - protected function find_with_root_path($cache = true, $is_dir = false, $extension_keys = false) + protected function find_with_root_path($cache = true, $is_dir = false, $use_all_available = false, $extension_keys = false) { - $items = $this->find($cache, $is_dir); + $items = $this->find($cache, $is_dir, $use_all_available); $result = array(); foreach ($items as $item => $ext_name) @@ -325,9 +333,11 @@ class phpbb_extension_finder * @param bool $cache Whether the result should be cached * @param bool $is_dir Directories will be returned when true, only files * otherwise + * @param bool $use_all_available Use all available instead of just all + * enabled extensions * @return array An array of paths to found items */ - public function find($cache = true, $is_dir = false) + public function find($cache = true, $is_dir = false, $use_all_available = false) { $this->query['is_dir'] = $is_dir; $query = md5(serialize($this->query)); @@ -339,7 +349,14 @@ class phpbb_extension_finder $files = array(); - $extensions = $this->extension_manager->all_enabled(); + if ($use_all_available) + { + $extensions = $this->extension_manager->all_available(); + } + else + { + $extensions = $this->extension_manager->all_enabled(); + } if ($this->query['core_path']) { diff --git a/phpBB/includes/style/extension_path_provider.php b/phpBB/includes/style/extension_path_provider.php index 4eac300424..6976a45ed0 100644 --- a/phpBB/includes/style/extension_path_provider.php +++ b/phpBB/includes/style/extension_path_provider.php @@ -92,7 +92,7 @@ class phpbb_style_extension_path_provider extends phpbb_extension_provider imple if ($path && !phpbb_is_absolute($path)) { $result = $finder->directory('/' . $this->ext_dir_prefix . $path) - ->get_directories(true, true); + ->get_directories(true, false, true); foreach ($result as $ext => $ext_path) { $directories[$ext][] = $ext_path; -- cgit v1.2.1 From e483e3f4591b584aeea32aa5bb2a7be322086287 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 1 Mar 2013 12:05:08 -0600 Subject: [ticket/11363] Fix to make get_module_infos get from all extensions Depends on 11381 PHPBB3-11363 --- phpBB/includes/acp/acp_modules.php | 10 ++++-- phpBB/includes/db/migration/tool/module.php | 52 ++++++++++++++--------------- 2 files changed, 34 insertions(+), 28 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_modules.php b/phpBB/includes/acp/acp_modules.php index 52a82004e8..fce26bf45f 100644 --- a/phpBB/includes/acp/acp_modules.php +++ b/phpBB/includes/acp/acp_modules.php @@ -535,8 +535,14 @@ class acp_modules /** * Get available module information from module files + * + * @param string $module + * @param bool|string $module_class + * @param bool $use_all_available Use all available instead of just all + * enabled extensions + * @return array */ - function get_module_infos($module = '', $module_class = false) + function get_module_infos($module = '', $module_class = false, $use_all_available = false) { global $phpbb_root_path, $phpEx; @@ -556,7 +562,7 @@ class acp_modules ->extension_directory("/$module_class") ->core_path("includes/$module_class/info/") ->core_prefix($module_class . '_') - ->get_classes(); + ->get_classes(true, $use_all_available); foreach ($modules as $module) { diff --git a/phpBB/includes/db/migration/tool/module.php b/phpBB/includes/db/migration/tool/module.php index 8744866a16..6ffb073543 100644 --- a/phpBB/includes/db/migration/tool/module.php +++ b/phpBB/includes/db/migration/tool/module.php @@ -183,19 +183,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac $basename = str_replace(array('/', '\\'), '', $basename); $class = str_replace(array('/', '\\'), '', $class); - if (!class_exists('acp_modules')) - { - include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); - } - $acp_modules = new acp_modules(); - $module = $acp_modules->get_module_infos($basename, $class); - $module = $module[$basename]; - unset($acp_modules); - - if (empty($module)) - { - throw new phpbb_db_migration_exception('MODULE_INFO_FILE_NOT_EXIST', $class, $basename); - } + $module = $this->get_module_info($class, $basename); $result = ''; foreach ($module['modes'] as $mode => $module_info) @@ -367,19 +355,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac $basename = str_replace(array('/', '\\'), '', $module['module_basename']); $class = str_replace(array('/', '\\'), '', $class); - if (!class_exists('acp_modules')) - { - include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); - } - $acp_modules = new acp_modules(); - $module_info = $acp_modules->get_module_infos($basename, $class); - $module_info = $module_info[$basename]; - unset($acp_modules); - - if (empty($module_info)) - { - throw new phpbb_db_migration_exception('MODULE_INFO_FILE_NOT_EXIST', $class, $basename); - } + $module_info = $this->get_module_info($class, $basename); foreach ($module_info['modes'] as $mode => $info) { @@ -499,4 +475,28 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac return call_user_func_array(array(&$this, $call), $arguments); } } + + /** + * Wrapper for acp_modules::get_module_infos() + * + * @param string $class Module Class + * @param string $basename Module Basename + * @return array Module Information + */ + protected function get_module_info($class, $basename) + { + if (!class_exists('acp_modules')) + { + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); + } + $acp_modules = new acp_modules(); + $module = $acp_modules->get_module_infos($basename, $class, true); + + if (empty($module)); + { + throw new phpbb_db_migration_exception('MODULE_INFO_FILE_NOT_EXIST', $class, $basename); + } + + return array_pop($module); + } } -- cgit v1.2.1 From 39ca212e17e80d14dbbd20cf5542ab37f27bd217 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 2 Mar 2013 11:02:53 -0600 Subject: [ticket/11386] Use finder to find migration files PHPBB3-11386 --- phpBB/includes/db/migrator.php | 53 ++++++--------------- phpBB/includes/extension/finder.php | 91 +++++++++++++++++++++++++++++------- phpBB/includes/extension/manager.php | 11 ++++- 3 files changed, 97 insertions(+), 58 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index ec0b6a87da..824bca5e70 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -31,6 +31,9 @@ class phpbb_db_migrator /** @var phpbb_db_tools */ protected $db_tools; + /** @var phpbb_extension_manager */ + protected $extension_manager; + /** @var string */ protected $table_prefix; @@ -69,11 +72,12 @@ class phpbb_db_migrator /** * Constructor of the database migrator */ - public function __construct(phpbb_config $config, phpbb_db_driver $db, phpbb_db_tools $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) + public function __construct(phpbb_config $config, phpbb_db_driver $db, phpbb_db_tools $db_tools, phpbb_extension_manager $extension_manager, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) { $this->config = $config; $this->db = $db; $this->db_tools = $db_tools; + $this->extension_manager = $extension_manager; $this->migrations_table = $migrations_table; @@ -180,55 +184,26 @@ class phpbb_db_migrator * If FALSE, we will not check. You SHOULD check at least once * to prevent errors (if including multiple directories, check * with the last call to prevent throwing errors unnecessarily). - * @param bool $recursive Set to true to also load data files from subdirectories * @return array Array of migration names */ - public function load_migrations($path, $check_fulfillable = true, $recursive = true) + public function load_migrations($path, $check_fulfillable = true) { if (!is_dir($path)) { throw new phpbb_db_migration_exception('DIRECTORY INVALID', $path); } - $handle = opendir($path); - while (($file = readdir($handle)) !== false) + $finder = $this->extension_manager->get_finder(); + $migration_files = $finder + ->extension_directory("/") + ->find_from_paths(array('/' => $path)); + foreach ($migration_files as $migration) { - if ($file == '.' || $file == '..') - { - continue; - } + $migration_name = $migration['path'] . $migration['filename']; - // Recursion through subdirectories - if (is_dir($path . $file) && $recursive) + if (!in_array($migration_name, $this->migrations)) { - $this->load_migrations($path . $file . '/', $check_fulfillable, $recursive); - } - - if (strpos($file, '_') !== 0 && strrpos($file, '.' . $this->php_ext) === (strlen($file) - strlen($this->php_ext) - 1)) - { - // We try to find what class existed by comparing the classes declared before and after including the file. - $declared_classes = get_declared_classes(); - - include ($path . $file); - - $added_classes = array_diff(get_declared_classes(), $declared_classes); - - if ( - // If two classes have been added and phpbb_db_migration is one of them, we've only added one real migration - !(sizeof($added_classes) == 2 && in_array('phpbb_db_migration', $added_classes)) && - // Otherwise there should only be one class added - sizeof($added_classes) != 1 - ) - { - throw new phpbb_db_migration_exception('MIGRATION DATA FILE INVALID', $path . $file); - } - - $name = array_pop($added_classes); - - if (!in_array($name, $this->migrations)) - { - $this->migrations[] = $name; - } + $this->migrations[] = $migration_name; } } diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index fb19b98429..15e6db1bbe 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -247,15 +247,28 @@ class phpbb_extension_finder * phpBB naming rules an incorrect class name will be returned. * * @param bool $cache Whether the result should be cached + * @param bool $use_all_available Use all available instead of just all + * enabled extensions * @return array An array of found class names */ - public function get_classes($cache = true) + public function get_classes($cache = true, $use_all_available = false) { $this->query['extension_suffix'] .= $this->php_ext; $this->query['core_suffix'] .= $this->php_ext; - $files = $this->find($cache, false); + $files = $this->find($cache, false, $use_all_available); + return $this->get_classes_from_files($files); + } + + /** + * Get class names from a list of files + * + * @param array $files Array of files (from find()) + * @return array Array of class names + */ + public function get_classes_from_files($files) + { $classes = array(); foreach ($files as $file => $ext_name) { @@ -270,23 +283,27 @@ class phpbb_extension_finder * Finds all directories matching the configured options * * @param bool $cache Whether the result should be cached + * @param bool $use_all_available Use all available instead of just all + * enabled extensions * @param bool $extension_keys Whether the result should have extension name as array key * @return array An array of paths to found directories */ - public function get_directories($cache = true, $extension_keys = false) + public function get_directories($cache = true, $use_all_available = false, $extension_keys = false) { - return $this->find_with_root_path($cache, true, $extension_keys); + return $this->find_with_root_path($cache, true, $use_all_available, $extension_keys); } /** * Finds all files matching the configured options. * * @param bool $cache Whether the result should be cached + * @param bool $use_all_available Use all available instead of just all + * enabled extensions * @return array An array of paths to found files */ - public function get_files($cache = true) + public function get_files($cache = true, $use_all_available = false) { - return $this->find_with_root_path($cache, false); + return $this->find_with_root_path($cache, false, $use_all_available); } /** @@ -295,13 +312,15 @@ class phpbb_extension_finder * @param bool $cache Whether the result should be cached * @param bool $is_dir Directories will be returned when true, only files * otherwise + * @param bool $use_all_available Use all available instead of just all + * enabled extensions * @param bool $extension_keys If true, result will be associative array * with extension name as key * @return array An array of paths to found items */ - protected function find_with_root_path($cache = true, $is_dir = false, $extension_keys = false) + protected function find_with_root_path($cache = true, $is_dir = false, $use_all_available = false, $extension_keys = false) { - $items = $this->find($cache, $is_dir); + $items = $this->find($cache, $is_dir, $use_all_available); $result = array(); foreach ($items as $item => $ext_name) @@ -325,27 +344,59 @@ class phpbb_extension_finder * @param bool $cache Whether the result should be cached * @param bool $is_dir Directories will be returned when true, only files * otherwise + * @param bool $use_all_available Use all available instead of just all + * enabled extensions * @return array An array of paths to found items */ - public function find($cache = true, $is_dir = false) + public function find($cache = true, $is_dir = false, $use_all_available = false) { - $this->query['is_dir'] = $is_dir; - $query = md5(serialize($this->query)); + if ($use_all_available) + { + $extensions = $this->extension_manager->all_available(); + } + else + { + $extensions = $this->extension_manager->all_enabled(); + } - if (!defined('DEBUG') && $cache && isset($this->cached_queries[$query])) + if ($this->query['core_path']) { - return $this->cached_queries[$query]; + $extensions['/'] = $this->phpbb_root_path . $this->query['core_path']; } $files = array(); + $file_list = $this->find_from_paths($extensions, $cache, $is_dir); - $extensions = $this->extension_manager->all_enabled(); + foreach ($file_list as $file) + { + $files[$file['named_path']] = $file['ext_name']; + } - if ($this->query['core_path']) + return $files; + } + + /** + * Finds all file system entries matching the configured options from + * an array of paths + * + * @param array $extensions Array of extensions (name => full relative path) + * @param bool $cache Whether the result should be cached + * @param bool $is_dir Directories will be returned when true, only files + * otherwise + * @return array An array of paths to found items + */ + public function find_from_paths($extensions, $cache = true, $is_dir = false) + { + $this->query['is_dir'] = $is_dir; + $query = md5(serialize($this->query) . serialize($extensions)); + + if (!defined('DEBUG') && $cache && isset($this->cached_queries[$query])) { - $extensions['/'] = $this->phpbb_root_path . $this->query['core_path']; + return $this->cached_queries[$query]; } + $files = array(); + foreach ($extensions as $name => $path) { $ext_name = $name; @@ -419,7 +470,13 @@ class phpbb_extension_finder (!$prefix || substr($filename, 0, strlen($prefix)) === $prefix) && (!$directory || preg_match($directory_pattern, $relative_path))) { - $files[str_replace(DIRECTORY_SEPARATOR, '/', $location . $name . substr($relative_path, 1))] = $ext_name; + $files[] = array( + 'named_path' => str_replace(DIRECTORY_SEPARATOR, '/', $location . $name . substr($relative_path, 1)), + 'ext_name' => $ext_name, + 'path' => str_replace(array(DIRECTORY_SEPARATOR, $this->phpbb_root_path), array('/', ''), $file_info->getPath()) . '/', + 'filename' => $filename, + 'file_info' => $file_info, + ); } } } diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 21a9ec1370..0d760681b9 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -49,13 +49,12 @@ class phpbb_extension_manager * @param phpbb_cache_driver_interface $cache A cache instance or null * @param string $cache_name The name of the cache variable, defaults to _ext */ - public function __construct(ContainerInterface $container, phpbb_db_driver $db, phpbb_config $config, phpbb_db_migrator $migrator, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') + public function __construct(ContainerInterface $container, phpbb_db_driver $db, phpbb_config $config, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') { $this->container = $container; $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; $this->config = $config; - $this->migrator = $migrator; $this->cache = $cache; $this->php_ext = $php_ext; $this->extension_table = $extension_table; @@ -69,6 +68,14 @@ class phpbb_extension_manager } } + /** + * Set migrator (get around circular reference) + */ + public function set_migrator(phpbb_db_migrator $migrator) + { + $this->migrator = $migrator; + } + /** * Loads all extension information from the database * -- cgit v1.2.1 From 1368470f7488b278cdc214745a7d4c9557d407e2 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 2 Mar 2013 11:42:30 -0600 Subject: [ticket/11386] Forgot to get the migration classes PHPBB3-11386 --- phpBB/includes/db/migrator.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 824bca5e70..855e640554 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -193,17 +193,23 @@ class phpbb_db_migrator throw new phpbb_db_migration_exception('DIRECTORY INVALID', $path); } + $migrations = array(); + $finder = $this->extension_manager->get_finder(); - $migration_files = $finder + $files = $finder ->extension_directory("/") ->find_from_paths(array('/' => $path)); - foreach ($migration_files as $migration) + foreach ($files as $file) { - $migration_name = $migration['path'] . $migration['filename']; + $migrations[$file['path'] . $file['filename']] = ''; + } + $migrations = $finder->get_classes_from_files($migrations); - if (!in_array($migration_name, $this->migrations)) + foreach ($migrations as $migration) + { + if (!in_array($migration, $this->migrations)) { - $this->migrations[] = $migration_name; + $this->migrations[] = $migration; } } -- cgit v1.2.1 From a6f877c0d84ff102d3812246eae7469e191983e2 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 2 Mar 2013 14:15:59 -0600 Subject: [ticket/11386] Fix circular reference error & serialize error PHPBB3-11386 --- phpBB/includes/db/migrator.php | 13 +++++++++++-- phpBB/includes/extension/finder.php | 1 - 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 855e640554..de9c06948c 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -72,12 +72,11 @@ class phpbb_db_migrator /** * Constructor of the database migrator */ - public function __construct(phpbb_config $config, phpbb_db_driver $db, phpbb_db_tools $db_tools, phpbb_extension_manager $extension_manager, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) + public function __construct(phpbb_config $config, phpbb_db_driver $db, phpbb_db_tools $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) { $this->config = $config; $this->db = $db; $this->db_tools = $db_tools; - $this->extension_manager = $extension_manager; $this->migrations_table = $migrations_table; @@ -94,6 +93,16 @@ class phpbb_db_migrator $this->load_migration_state(); } + /** + * Set Extension Manager (required) + * + * Not in constructor to prevent circular reference error + */ + public function set_extension_manager(phpbb_extension_manager $extension_manager) + { + $this->extension_manager = $extension_manager; + } + /** * Loads all migrations and their application state from the database. * diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index 15e6db1bbe..f71e32bc8d 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -475,7 +475,6 @@ class phpbb_extension_finder 'ext_name' => $ext_name, 'path' => str_replace(array(DIRECTORY_SEPARATOR, $this->phpbb_root_path), array('/', ''), $file_info->getPath()) . '/', 'filename' => $filename, - 'file_info' => $file_info, ); } } -- cgit v1.2.1 From c73f0a7c7870109a8e3d517f4967a7018dbb8669 Mon Sep 17 00:00:00 2001 From: OpenShift guest Date: Fri, 1 Mar 2013 20:36:32 -0500 Subject: [ticket/11385] Fix issue with migration module tool not getting extension module info PHPBB3-11385 --- phpBB/includes/db/migration/tool/module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/tool/module.php b/phpBB/includes/db/migration/tool/module.php index 6ffb073543..ad94c5aadb 100644 --- a/phpBB/includes/db/migration/tool/module.php +++ b/phpBB/includes/db/migration/tool/module.php @@ -492,7 +492,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac $acp_modules = new acp_modules(); $module = $acp_modules->get_module_infos($basename, $class, true); - if (empty($module)); + if (empty($module)) { throw new phpbb_db_migration_exception('MODULE_INFO_FILE_NOT_EXIST', $class, $basename); } -- cgit v1.2.1