diff options
-rw-r--r-- | phpBB/config/notifications.yml | 30 | ||||
-rw-r--r-- | phpBB/config/services.yml | 2 | ||||
-rw-r--r-- | phpBB/config/tables.yml | 2 | ||||
-rw-r--r-- | phpBB/includes/constants.php | 3 | ||||
-rw-r--r-- | phpBB/includes/notification/manager.php | 52 | ||||
-rw-r--r-- | phpBB/includes/notification/type/base.php | 12 | ||||
-rw-r--r-- | phpBB/install/database_update.php | 18 |
7 files changed, 81 insertions, 38 deletions
diff --git a/phpBB/config/notifications.yml b/phpBB/config/notifications.yml index 78fcd7c2d9..7c8e05494c 100644 --- a/phpBB/config/notifications.yml +++ b/phpBB/config/notifications.yml @@ -12,6 +12,8 @@ services: - @config - %core.root_path% - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% tags: - { name: notification.type } @@ -28,6 +30,8 @@ services: - @config - %core.root_path% - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% tags: - { name: notification.type } @@ -44,6 +48,8 @@ services: - @config - %core.root_path% - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% tags: - { name: notification.type } @@ -60,6 +66,8 @@ services: - @config - %core.root_path% - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% tags: - { name: notification.type } @@ -76,6 +84,8 @@ services: - @config - %core.root_path% - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% tags: - { name: notification.type } @@ -92,6 +102,8 @@ services: - @config - %core.root_path% - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% tags: - { name: notification.type } @@ -108,6 +120,8 @@ services: - @config - %core.root_path% - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% tags: - { name: notification.type } @@ -124,6 +138,8 @@ services: - @config - %core.root_path% - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% tags: - { name: notification.type } @@ -140,6 +156,8 @@ services: - @config - %core.root_path% - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% tags: - { name: notification.type } @@ -156,6 +174,8 @@ services: - @config - %core.root_path% - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% tags: - { name: notification.type } @@ -172,6 +192,8 @@ services: - @config - %core.root_path% - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% tags: - { name: notification.type } @@ -188,6 +210,8 @@ services: - @config - %core.root_path% - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% tags: - { name: notification.type } @@ -204,6 +228,8 @@ services: - @config - %core.root_path% - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% tags: - { name: notification.type } @@ -220,6 +246,8 @@ services: - @config - %core.root_path% - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% tags: - { name: notification.type } @@ -236,6 +264,8 @@ services: - @config - %core.root_path% - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% tags: - { name: notification.type } diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index e780dc986f..cbae3d49dd 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -103,6 +103,8 @@ services: - @config - %core.root_path% - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% processor.ext: class: phpbb_di_processor_ext diff --git a/phpBB/config/tables.yml b/phpBB/config/tables.yml index cfc6dbcfed..8791c5e89b 100644 --- a/phpBB/config/tables.yml +++ b/phpBB/config/tables.yml @@ -1,3 +1,5 @@ parameters: tables.config: %core.table_prefix%config tables.ext: %core.table_prefix%ext + tables.notifications: %core.table_prefix%notifications + tables.user_notifications: %core.table_prefix%user_notifications 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; } /** diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 94a4749313..9e884b0a37 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -110,14 +110,6 @@ if (!defined('EXT_TABLE')) { define('EXT_TABLE', $table_prefix . 'ext'); } -if (!defined('NOTIFICATIONS_TABLE')) -{ - define('NOTIFICATIONS_TABLE', $table_prefix . 'notifications'); -} -if (!defined('USER_NOTIFICATIONS_TABLE')) -{ - define('USER_NOTIFICATIONS_TABLE', $table_prefix . 'user_notifications'); -} $phpbb_container = new ContainerBuilder(); $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); @@ -1125,7 +1117,7 @@ function database_update_info() 'ext_name' => array('UNIQUE', 'ext_name'), ), ), - NOTIFICATIONS_TABLE => array( + $table_prefix . 'notifications' => array( 'COLUMNS' => array( 'notification_id' => array('UINT', NULL, 'auto_increment'), 'item_type' => array('VCHAR:255', ''), @@ -1148,7 +1140,7 @@ function database_update_info() 'is_enabled' => array('INDEX', 'is_enabled'), ), ), - USER_NOTIFICATIONS_TABLE => array( + $table_prefix . 'user_notifications' => array( 'COLUMNS' => array( 'item_type' => array('VCHAR:255', ''), 'item_id' => array('UINT', 0), @@ -2791,7 +2783,7 @@ function change_database_data(&$no_updates, $version) $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { - _sql('INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . $db->sql_build_array('INSERT', array( + _sql('INSERT INTO ' . $table_prefix . 'user_notifications ' . $db->sql_build_array('INSERT', array( 'item_type' => $convert_data['item_type'], 'item_id' => 0, 'user_id' => $row['user_id'], @@ -2800,7 +2792,7 @@ function change_database_data(&$no_updates, $version) if ($row['user_notify_type'] == NOTIFY_EMAIL || $row['user_notify_type'] == NOTIFY_BOTH) { - _sql('INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . $db->sql_build_array('INSERT', array( + _sql('INSERT INTO ' . $table_prefix . 'user_notifications ' . $db->sql_build_array('INSERT', array( 'item_type' => $convert_data['item_type'], 'item_id' => 0, 'user_id' => $row['user_id'], @@ -2810,7 +2802,7 @@ function change_database_data(&$no_updates, $version) if ($row['user_notify_type'] == NOTIFY_IM || $row['user_notify_type'] == NOTIFY_BOTH) { - _sql('INSERT INTO ' . USER_NOTIFICATIONS_TABLE . ' ' . $db->sql_build_array('INSERT', array( + _sql('INSERT INTO ' . $table_prefix . 'user_notifications ' . $db->sql_build_array('INSERT', array( 'item_type' => $convert_data['item_type'], 'item_id' => 0, 'user_id' => $row['user_id'], |