From a9cf558af7fc08539e15ceca1e889e087c815c8d Mon Sep 17 00:00:00 2001 From: Sajaki Date: Sat, 28 Apr 2012 10:43:43 +0200 Subject: [ticket/10854] sql server drop default constraint when dropping column drops default columns with T-SQL before attempting drop column to avoids sql exception. This is a huge annoyance in UMIL scripts running under sql server. --- phpBB/includes/db/db_tools.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index c6dd23e6bd..f63ff18cbe 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -1819,6 +1819,22 @@ class phpbb_db_tools case 'mssql': case 'mssqlnative': + // remove default cosntraints first + // http://msdn.microsoft.com/en-us/library/aa175912%28v=sql.80%29.aspx + $statements[] = "DECLARE @drop_default_name VARCHAR(100), @cmd VARCHAR(1000) + SET @drop_default_name = + (SELECT so.name FROM sysobjects so + JOIN sysconstraints sc ON so.id = sc.constid + WHERE object_name(so.parent_obj) = '{$table_name}' + AND so.xtype = 'D' + AND sc.colid = (SELECT colid FROM syscolumns + WHERE id = object_id('{$table_name}') + AND name = '{$column_name}')) + IF @drop_default_name <> '' + BEGIN + SET @cmd = 'ALTER TABLE [{$table_name}] DROP CONSTRAINT [' + @drop_default_name + ']' + EXEC(@cmd) + END"; $statements[] = 'ALTER TABLE [' . $table_name . '] DROP COLUMN [' . $column_name . ']'; break; -- cgit v1.2.1 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 83a71a2e777dcc9d1c717b6bf438b9aaf41dffba Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Sun, 2 Dec 2012 23:01:29 +0000 Subject: [ticket/11171] Use the options stored to decide how to show it Added what's needed so that the post in the report is parsed the same way as it was being parsed when the post was reported PHPBB3-11171 --- phpBB/includes/mcp/mcp_reports.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php index 3426d62cdb..ca730f7728 100644 --- a/phpBB/includes/mcp/mcp_reports.php +++ b/phpBB/includes/mcp/mcp_reports.php @@ -71,7 +71,7 @@ class mcp_reports // closed reports are accessed by report id $report_id = request_var('r', 0); - $sql = 'SELECT r.post_id, r.user_id, r.report_id, r.report_closed, report_time, r.report_text, r.reported_post_text, r.reported_post_uid, r.reported_post_bitfield, rr.reason_title, rr.reason_description, u.username, u.username_clean, u.user_colour + $sql = 'SELECT r.post_id, r.user_id, r.report_id, r.report_closed, report_time, r.report_text, r.reported_post_text, r.reported_post_uid, r.reported_post_bitfield, r.reported_post_enable_magic_url, r.reported_post_enable_smilies, r.reported_post_enable_bbcode, rr.reason_title, rr.reason_description, u.username, u.username_clean, u.user_colour FROM ' . REPORTS_TABLE . ' r, ' . REPORTS_REASONS_TABLE . ' rr, ' . USERS_TABLE . ' u WHERE ' . (($report_id) ? 'r.report_id = ' . $report_id : "r.post_id = $post_id") . ' AND rr.reason_id = r.reason_id @@ -94,6 +94,10 @@ class mcp_reports $post_id = $report['post_id']; $report_id = $report['report_id']; + + $parse_post_flags = $report['reported_post_enable_bbcode'] ? OPTION_FLAG_BBCODE : 0; + $parse_post_flags += $report['reported_post_enable_smilies'] ? OPTION_FLAG_SMILIES : 0; + $parse_post_flags += $report['reported_post_enable_magic_url'] ? OPTION_FLAG_LINKS : 0; $post_info = get_post_data(array($post_id), 'm_report', true); @@ -227,7 +231,7 @@ class mcp_reports 'REPORTER_NAME' => get_username_string('username', $report['user_id'], $report['username'], $report['user_colour']), 'U_VIEW_REPORTER_PROFILE' => get_username_string('profile', $report['user_id'], $report['username'], $report['user_colour']), - 'POST_PREVIEW' => generate_text_for_display($report['reported_post_text'], $report['reported_post_uid'], $report['reported_post_bitfield'], OPTION_FLAG_BBCODE | OPTION_FLAG_SMILIES, false), + 'POST_PREVIEW' => generate_text_for_display($report['reported_post_text'], $report['reported_post_uid'], $report['reported_post_bitfield'], $parse_post_flags, false), 'POST_SUBJECT' => ($post_info['post_subject']) ? $post_info['post_subject'] : $user->lang['NO_SUBJECT'], 'POST_DATE' => $user->format_date($post_info['post_time']), 'POST_IP' => $post_info['poster_ip'], -- cgit v1.2.1 From 73971ef0fa2a53b056847a524bb84f8b2d3e5a4b Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Sun, 2 Dec 2012 23:19:59 +0000 Subject: [ticket/11171] Cleanup of leftovers I didn't notice that there were actually leftovers from the other PR. Anyway, this will remove all the leftovers I noticed from the other PR. PHPBB3-11171 --- phpBB/includes/mcp/mcp_reports.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php index ca730f7728..8da303f6e3 100644 --- a/phpBB/includes/mcp/mcp_reports.php +++ b/phpBB/includes/mcp/mcp_reports.php @@ -140,18 +140,7 @@ class mcp_reports $post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false; - // Process message, leave it uncensored - $message = $post_info['post_text']; - if ($post_info['bbcode_bitfield']) - { - include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx); - $bbcode = new bbcode($post_info['bbcode_bitfield']); - $bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']); - } - - $message = bbcode_nl2br($message); - $message = smiley_text($message); $report['report_text'] = make_clickable(bbcode_nl2br($report['report_text'])); if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id'])) @@ -172,7 +161,7 @@ class mcp_reports if (sizeof($attachments)) { $update_count = array(); - parse_attachments($post_info['forum_id'], $message, $attachments, $update_count); + parse_attachments($post_info['forum_id'], $report['reported_post_text'], $attachments, $update_count); } // Display not already displayed Attachments for this post, we already parsed them. ;) -- cgit v1.2.1 From 03d2c6413c25b1faf7f37ff20625ce986b19eb88 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 7 Dec 2012 21:57:33 -0500 Subject: [ticket/11248] Convert line endings to LF - develop edition. PHPBB3-11248 --- phpBB/includes/sphinxapi.php | 3424 +++++++++++++++++++++--------------------- 1 file changed, 1712 insertions(+), 1712 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/sphinxapi.php b/phpBB/includes/sphinxapi.php index bd83b1d2e0..6c3b66710c 100644 --- a/phpBB/includes/sphinxapi.php +++ b/phpBB/includes/sphinxapi.php @@ -1,1712 +1,1712 @@ -=8 ) - { - $v = (int)$v; - return pack ( "NN", $v>>32, $v&0xFFFFFFFF ); - } - - // x32, int - if ( is_int($v) ) - return pack ( "NN", $v < 0 ? -1 : 0, $v ); - - // x32, bcmath - if ( function_exists("bcmul") ) - { - if ( bccomp ( $v, 0 ) == -1 ) - $v = bcadd ( "18446744073709551616", $v ); - $h = bcdiv ( $v, "4294967296", 0 ); - $l = bcmod ( $v, "4294967296" ); - return pack ( "NN", (float)$h, (float)$l ); // conversion to float is intentional; int would lose 31st bit - } - - // x32, no-bcmath - $p = max(0, strlen($v) - 13); - $lo = abs((float)substr($v, $p)); - $hi = abs((float)substr($v, 0, $p)); - - $m = $lo + $hi*1316134912.0; // (10 ^ 13) % (1 << 32) = 1316134912 - $q = floor($m/4294967296.0); - $l = $m - ($q*4294967296.0); - $h = $hi*2328.0 + $q; // (10 ^ 13) / (1 << 32) = 2328 - - if ( $v<0 ) - { - if ( $l==0 ) - $h = 4294967296.0 - $h; - else - { - $h = 4294967295.0 - $h; - $l = 4294967296.0 - $l; - } - } - return pack ( "NN", $h, $l ); -} - -/// pack 64-bit unsigned -function sphPackU64 ( $v ) -{ - assert ( is_numeric($v) ); - - // x64 - if ( PHP_INT_SIZE>=8 ) - { - assert ( $v>=0 ); - - // x64, int - if ( is_int($v) ) - return pack ( "NN", $v>>32, $v&0xFFFFFFFF ); - - // x64, bcmath - if ( function_exists("bcmul") ) - { - $h = bcdiv ( $v, 4294967296, 0 ); - $l = bcmod ( $v, 4294967296 ); - return pack ( "NN", $h, $l ); - } - - // x64, no-bcmath - $p = max ( 0, strlen($v) - 13 ); - $lo = (int)substr ( $v, $p ); - $hi = (int)substr ( $v, 0, $p ); - - $m = $lo + $hi*1316134912; - $l = $m % 4294967296; - $h = $hi*2328 + (int)($m/4294967296); - - return pack ( "NN", $h, $l ); - } - - // x32, int - if ( is_int($v) ) - return pack ( "NN", 0, $v ); - - // x32, bcmath - if ( function_exists("bcmul") ) - { - $h = bcdiv ( $v, "4294967296", 0 ); - $l = bcmod ( $v, "4294967296" ); - return pack ( "NN", (float)$h, (float)$l ); // conversion to float is intentional; int would lose 31st bit - } - - // x32, no-bcmath - $p = max(0, strlen($v) - 13); - $lo = (float)substr($v, $p); - $hi = (float)substr($v, 0, $p); - - $m = $lo + $hi*1316134912.0; - $q = floor($m / 4294967296.0); - $l = $m - ($q * 4294967296.0); - $h = $hi*2328.0 + $q; - - return pack ( "NN", $h, $l ); -} - -// unpack 64-bit unsigned -function sphUnpackU64 ( $v ) -{ - list ( $hi, $lo ) = array_values ( unpack ( "N*N*", $v ) ); - - if ( PHP_INT_SIZE>=8 ) - { - if ( $hi<0 ) $hi += (1<<32); // because php 5.2.2 to 5.2.5 is totally fucked up again - if ( $lo<0 ) $lo += (1<<32); - - // x64, int - if ( $hi<=2147483647 ) - return ($hi<<32) + $lo; - - // x64, bcmath - if ( function_exists("bcmul") ) - return bcadd ( $lo, bcmul ( $hi, "4294967296" ) ); - - // x64, no-bcmath - $C = 100000; - $h = ((int)($hi / $C) << 32) + (int)($lo / $C); - $l = (($hi % $C) << 32) + ($lo % $C); - if ( $l>$C ) - { - $h += (int)($l / $C); - $l = $l % $C; - } - - if ( $h==0 ) - return $l; - return sprintf ( "%d%05d", $h, $l ); - } - - // x32, int - if ( $hi==0 ) - { - if ( $lo>0 ) - return $lo; - return sprintf ( "%u", $lo ); - } - - $hi = sprintf ( "%u", $hi ); - $lo = sprintf ( "%u", $lo ); - - // x32, bcmath - if ( function_exists("bcmul") ) - return bcadd ( $lo, bcmul ( $hi, "4294967296" ) ); - - // x32, no-bcmath - $hi = (float)$hi; - $lo = (float)$lo; - - $q = floor($hi/10000000.0); - $r = $hi - $q*10000000.0; - $m = $lo + $r*4967296.0; - $mq = floor($m/10000000.0); - $l = $m - $mq*10000000.0; - $h = $q*4294967296.0 + $r*429.0 + $mq; - - $h = sprintf ( "%.0f", $h ); - $l = sprintf ( "%07.0f", $l ); - if ( $h=="0" ) - return sprintf( "%.0f", (float)$l ); - return $h . $l; -} - -// unpack 64-bit signed -function sphUnpackI64 ( $v ) -{ - list ( $hi, $lo ) = array_values ( unpack ( "N*N*", $v ) ); - - // x64 - if ( PHP_INT_SIZE>=8 ) - { - if ( $hi<0 ) $hi += (1<<32); // because php 5.2.2 to 5.2.5 is totally fucked up again - if ( $lo<0 ) $lo += (1<<32); - - return ($hi<<32) + $lo; - } - - // x32, int - if ( $hi==0 ) - { - if ( $lo>0 ) - return $lo; - return sprintf ( "%u", $lo ); - } - // x32, int - elseif ( $hi==-1 ) - { - if ( $lo<0 ) - return $lo; - return sprintf ( "%.0f", $lo - 4294967296.0 ); - } - - $neg = ""; - $c = 0; - if ( $hi<0 ) - { - $hi = ~$hi; - $lo = ~$lo; - $c = 1; - $neg = "-"; - } - - $hi = sprintf ( "%u", $hi ); - $lo = sprintf ( "%u", $lo ); - - // x32, bcmath - if ( function_exists("bcmul") ) - return $neg . bcadd ( bcadd ( $lo, bcmul ( $hi, "4294967296" ) ), $c ); - - // x32, no-bcmath - $hi = (float)$hi; - $lo = (float)$lo; - - $q = floor($hi/10000000.0); - $r = $hi - $q*10000000.0; - $m = $lo + $r*4967296.0; - $mq = floor($m/10000000.0); - $l = $m - $mq*10000000.0 + $c; - $h = $q*4294967296.0 + $r*429.0 + $mq; - if ( $l==10000000 ) - { - $l = 0; - $h += 1; - } - - $h = sprintf ( "%.0f", $h ); - $l = sprintf ( "%07.0f", $l ); - if ( $h=="0" ) - return $neg . sprintf( "%.0f", (float)$l ); - return $neg . $h . $l; -} - - -function sphFixUint ( $value ) -{ - if ( PHP_INT_SIZE>=8 ) - { - // x64 route, workaround broken unpack() in 5.2.2+ - if ( $value<0 ) $value += (1<<32); - return $value; - } - else - { - // x32 route, workaround php signed/unsigned braindamage - return sprintf ( "%u", $value ); - } -} - - -/// sphinx searchd client class -class SphinxClient -{ - var $_host; ///< searchd host (default is "localhost") - var $_port; ///< searchd port (default is 9312) - var $_offset; ///< how many records to seek from result-set start (default is 0) - var $_limit; ///< how many records to return from result-set starting at offset (default is 20) - var $_mode; ///< query matching mode (default is SPH_MATCH_ALL) - var $_weights; ///< per-field weights (default is 1 for all fields) - var $_sort; ///< match sorting mode (default is SPH_SORT_RELEVANCE) - var $_sortby; ///< attribute to sort by (defualt is "") - var $_min_id; ///< min ID to match (default is 0, which means no limit) - var $_max_id; ///< max ID to match (default is 0, which means no limit) - var $_filters; ///< search filters - var $_groupby; ///< group-by attribute name - var $_groupfunc; ///< group-by function (to pre-process group-by attribute value with) - var $_groupsort; ///< group-by sorting clause (to sort groups in result set with) - var $_groupdistinct;///< group-by count-distinct attribute - var $_maxmatches; ///< max matches to retrieve - var $_cutoff; ///< cutoff to stop searching at (default is 0) - var $_retrycount; ///< distributed retries count - var $_retrydelay; ///< distributed retries delay - var $_anchor; ///< geographical anchor point - var $_indexweights; ///< per-index weights - var $_ranker; ///< ranking mode (default is SPH_RANK_PROXIMITY_BM25) - var $_rankexpr; ///< ranking mode expression (for SPH_RANK_EXPR) - var $_maxquerytime; ///< max query time, milliseconds (default is 0, do not limit) - var $_fieldweights; ///< per-field-name weights - var $_overrides; ///< per-query attribute values overrides - var $_select; ///< select-list (attributes or expressions, with optional aliases) - - var $_error; ///< last error message - var $_warning; ///< last warning message - var $_connerror; ///< connection error vs remote error flag - - var $_reqs; ///< requests array for multi-query - var $_mbenc; ///< stored mbstring encoding - var $_arrayresult; ///< whether $result["matches"] should be a hash or an array - var $_timeout; ///< connect timeout - - ///////////////////////////////////////////////////////////////////////////// - // common stuff - ///////////////////////////////////////////////////////////////////////////// - - /// create a new client object and fill defaults - function SphinxClient () - { - // per-client-object settings - $this->_host = "localhost"; - $this->_port = 9312; - $this->_path = false; - $this->_socket = false; - - // per-query settings - $this->_offset = 0; - $this->_limit = 20; - $this->_mode = SPH_MATCH_ALL; - $this->_weights = array (); - $this->_sort = SPH_SORT_RELEVANCE; - $this->_sortby = ""; - $this->_min_id = 0; - $this->_max_id = 0; - $this->_filters = array (); - $this->_groupby = ""; - $this->_groupfunc = SPH_GROUPBY_DAY; - $this->_groupsort = "@group desc"; - $this->_groupdistinct= ""; - $this->_maxmatches = 1000; - $this->_cutoff = 0; - $this->_retrycount = 0; - $this->_retrydelay = 0; - $this->_anchor = array (); - $this->_indexweights= array (); - $this->_ranker = SPH_RANK_PROXIMITY_BM25; - $this->_rankexpr = ""; - $this->_maxquerytime= 0; - $this->_fieldweights= array(); - $this->_overrides = array(); - $this->_select = "*"; - - $this->_error = ""; // per-reply fields (for single-query case) - $this->_warning = ""; - $this->_connerror = false; - - $this->_reqs = array (); // requests storage (for multi-query case) - $this->_mbenc = ""; - $this->_arrayresult = false; - $this->_timeout = 0; - } - - function __destruct() - { - if ( $this->_socket !== false ) - fclose ( $this->_socket ); - } - - /// get last error message (string) - function GetLastError () - { - return $this->_error; - } - - /// get last warning message (string) - function GetLastWarning () - { - return $this->_warning; - } - - /// get last error flag (to tell network connection errors from searchd errors or broken responses) - function IsConnectError() - { - return $this->_connerror; - } - - /// set searchd host name (string) and port (integer) - function SetServer ( $host, $port = 0 ) - { - assert ( is_string($host) ); - if ( $host[0] == '/') - { - $this->_path = 'unix://' . $host; - return; - } - if ( substr ( $host, 0, 7 )=="unix://" ) - { - $this->_path = $host; - return; - } - - assert ( is_int($port) ); - $this->_host = $host; - $this->_port = $port; - $this->_path = ''; - - } - - /// set server connection timeout (0 to remove) - function SetConnectTimeout ( $timeout ) - { - assert ( is_numeric($timeout) ); - $this->_timeout = $timeout; - } - - - function _Send ( $handle, $data, $length ) - { - if ( feof($handle) || fwrite ( $handle, $data, $length ) !== $length ) - { - $this->_error = 'connection unexpectedly closed (timed out?)'; - $this->_connerror = true; - return false; - } - return true; - } - - ///////////////////////////////////////////////////////////////////////////// - - /// enter mbstring workaround mode - function _MBPush () - { - $this->_mbenc = ""; - if ( ini_get ( "mbstring.func_overload" ) & 2 ) - { - $this->_mbenc = mb_internal_encoding(); - mb_internal_encoding ( "latin1" ); - } - } - - /// leave mbstring workaround mode - function _MBPop () - { - if ( $this->_mbenc ) - mb_internal_encoding ( $this->_mbenc ); - } - - /// connect to searchd server - function _Connect () - { - if ( $this->_socket!==false ) - { - // we are in persistent connection mode, so we have a socket - // however, need to check whether it's still alive - if ( !@feof ( $this->_socket ) ) - return $this->_socket; - - // force reopen - $this->_socket = false; - } - - $errno = 0; - $errstr = ""; - $this->_connerror = false; - - if ( $this->_path ) - { - $host = $this->_path; - $port = 0; - } - else - { - $host = $this->_host; - $port = $this->_port; - } - - if ( $this->_timeout<=0 ) - $fp = @fsockopen ( $host, $port, $errno, $errstr ); - else - $fp = @fsockopen ( $host, $port, $errno, $errstr, $this->_timeout ); - - if ( !$fp ) - { - if ( $this->_path ) - $location = $this->_path; - else - $location = "{$this->_host}:{$this->_port}"; - - $errstr = trim ( $errstr ); - $this->_error = "connection to $location failed (errno=$errno, msg=$errstr)"; - $this->_connerror = true; - return false; - } - - // send my version - // this is a subtle part. we must do it before (!) reading back from searchd. - // because otherwise under some conditions (reported on FreeBSD for instance) - // TCP stack could throttle write-write-read pattern because of Nagle. - if ( !$this->_Send ( $fp, pack ( "N", 1 ), 4 ) ) - { - fclose ( $fp ); - $this->_error = "failed to send client protocol version"; - return false; - } - - // check version - list(,$v) = unpack ( "N*", fread ( $fp, 4 ) ); - $v = (int)$v; - if ( $v<1 ) - { - fclose ( $fp ); - $this->_error = "expected searchd protocol version 1+, got version '$v'"; - return false; - } - - return $fp; - } - - /// get and check response packet from searchd server - function _GetResponse ( $fp, $client_ver ) - { - $response = ""; - $len = 0; - - $header = fread ( $fp, 8 ); - if ( strlen($header)==8 ) - { - list ( $status, $ver, $len ) = array_values ( unpack ( "n2a/Nb", $header ) ); - $left = $len; - while ( $left>0 && !feof($fp) ) - { - $chunk = fread ( $fp, min ( 8192, $left ) ); - if ( $chunk ) - { - $response .= $chunk; - $left -= strlen($chunk); - } - } - } - if ( $this->_socket === false ) - fclose ( $fp ); - - // check response - $read = strlen ( $response ); - if ( !$response || $read!=$len ) - { - $this->_error = $len - ? "failed to read searchd response (status=$status, ver=$ver, len=$len, read=$read)" - : "received zero-sized searchd response"; - return false; - } - - // check status - if ( $status==SEARCHD_WARNING ) - { - list(,$wlen) = unpack ( "N*", substr ( $response, 0, 4 ) ); - $this->_warning = substr ( $response, 4, $wlen ); - return substr ( $response, 4+$wlen ); - } - if ( $status==SEARCHD_ERROR ) - { - $this->_error = "searchd error: " . substr ( $response, 4 ); - return false; - } - if ( $status==SEARCHD_RETRY ) - { - $this->_error = "temporary searchd error: " . substr ( $response, 4 ); - return false; - } - if ( $status!=SEARCHD_OK ) - { - $this->_error = "unknown status code '$status'"; - return false; - } - - // check version - if ( $ver<$client_ver ) - { - $this->_warning = sprintf ( "searchd command v.%d.%d older than client's v.%d.%d, some options might not work", - $ver>>8, $ver&0xff, $client_ver>>8, $client_ver&0xff ); - } - - return $response; - } - - ///////////////////////////////////////////////////////////////////////////// - // searching - ///////////////////////////////////////////////////////////////////////////// - - /// set offset and count into result set, - /// and optionally set max-matches and cutoff limits - function SetLimits ( $offset, $limit, $max=0, $cutoff=0 ) - { - assert ( is_int($offset) ); - assert ( is_int($limit) ); - assert ( $offset>=0 ); - assert ( $limit>0 ); - assert ( $max>=0 ); - $this->_offset = $offset; - $this->_limit = $limit; - if ( $max>0 ) - $this->_maxmatches = $max; - if ( $cutoff>0 ) - $this->_cutoff = $cutoff; - } - - /// set maximum query time, in milliseconds, per-index - /// integer, 0 means "do not limit" - function SetMaxQueryTime ( $max ) - { - assert ( is_int($max) ); - assert ( $max>=0 ); - $this->_maxquerytime = $max; - } - - /// set matching mode - function SetMatchMode ( $mode ) - { - assert ( $mode==SPH_MATCH_ALL - || $mode==SPH_MATCH_ANY - || $mode==SPH_MATCH_PHRASE - || $mode==SPH_MATCH_BOOLEAN - || $mode==SPH_MATCH_EXTENDED - || $mode==SPH_MATCH_FULLSCAN - || $mode==SPH_MATCH_EXTENDED2 ); - $this->_mode = $mode; - } - - /// set ranking mode - function SetRankingMode ( $ranker, $rankexpr="" ) - { - assert ( $ranker>=0 && $ranker_ranker = $ranker; - $this->_rankexpr = $rankexpr; - } - - /// set matches sorting mode - function SetSortMode ( $mode, $sortby="" ) - { - assert ( - $mode==SPH_SORT_RELEVANCE || - $mode==SPH_SORT_ATTR_DESC || - $mode==SPH_SORT_ATTR_ASC || - $mode==SPH_SORT_TIME_SEGMENTS || - $mode==SPH_SORT_EXTENDED || - $mode==SPH_SORT_EXPR ); - assert ( is_string($sortby) ); - assert ( $mode==SPH_SORT_RELEVANCE || strlen($sortby)>0 ); - - $this->_sort = $mode; - $this->_sortby = $sortby; - } - - /// bind per-field weights by order - /// DEPRECATED; use SetFieldWeights() instead - function SetWeights ( $weights ) - { - assert ( is_array($weights) ); - foreach ( $weights as $weight ) - assert ( is_int($weight) ); - - $this->_weights = $weights; - } - - /// bind per-field weights by name - function SetFieldWeights ( $weights ) - { - assert ( is_array($weights) ); - foreach ( $weights as $name=>$weight ) - { - assert ( is_string($name) ); - assert ( is_int($weight) ); - } - $this->_fieldweights = $weights; - } - - /// bind per-index weights by name - function SetIndexWeights ( $weights ) - { - assert ( is_array($weights) ); - foreach ( $weights as $index=>$weight ) - { - assert ( is_string($index) ); - assert ( is_int($weight) ); - } - $this->_indexweights = $weights; - } - - /// set IDs range to match - /// only match records if document ID is beetwen $min and $max (inclusive) - function SetIDRange ( $min, $max ) - { - assert ( is_numeric($min) ); - assert ( is_numeric($max) ); - assert ( $min<=$max ); - $this->_min_id = $min; - $this->_max_id = $max; - } - - /// set values set filter - /// only match records where $attribute value is in given set - function SetFilter ( $attribute, $values, $exclude=false ) - { - assert ( is_string($attribute) ); - assert ( is_array($values) ); - assert ( count($values) ); - - if ( is_array($values) && count($values) ) - { - foreach ( $values as $value ) - assert ( is_numeric($value) ); - - $this->_filters[] = array ( "type"=>SPH_FILTER_VALUES, "attr"=>$attribute, "exclude"=>$exclude, "values"=>$values ); - } - } - - /// set range filter - /// only match records if $attribute value is beetwen $min and $max (inclusive) - function SetFilterRange ( $attribute, $min, $max, $exclude=false ) - { - assert ( is_string($attribute) ); - assert ( is_numeric($min) ); - assert ( is_numeric($max) ); - assert ( $min<=$max ); - - $this->_filters[] = array ( "type"=>SPH_FILTER_RANGE, "attr"=>$attribute, "exclude"=>$exclude, "min"=>$min, "max"=>$max ); - } - - /// set float range filter - /// only match records if $attribute value is beetwen $min and $max (inclusive) - function SetFilterFloatRange ( $attribute, $min, $max, $exclude=false ) - { - assert ( is_string($attribute) ); - assert ( is_float($min) ); - assert ( is_float($max) ); - assert ( $min<=$max ); - - $this->_filters[] = array ( "type"=>SPH_FILTER_FLOATRANGE, "attr"=>$attribute, "exclude"=>$exclude, "min"=>$min, "max"=>$max ); - } - - /// setup anchor point for geosphere distance calculations - /// required to use @geodist in filters and sorting - /// latitude and longitude must be in radians - function SetGeoAnchor ( $attrlat, $attrlong, $lat, $long ) - { - assert ( is_string($attrlat) ); - assert ( is_string($attrlong) ); - assert ( is_float($lat) ); - assert ( is_float($long) ); - - $this->_anchor = array ( "attrlat"=>$attrlat, "attrlong"=>$attrlong, "lat"=>$lat, "long"=>$long ); - } - - /// set grouping attribute and function - function SetGroupBy ( $attribute, $func, $groupsort="@group desc" ) - { - assert ( is_string($attribute) ); - assert ( is_string($groupsort) ); - assert ( $func==SPH_GROUPBY_DAY - || $func==SPH_GROUPBY_WEEK - || $func==SPH_GROUPBY_MONTH - || $func==SPH_GROUPBY_YEAR - || $func==SPH_GROUPBY_ATTR - || $func==SPH_GROUPBY_ATTRPAIR ); - - $this->_groupby = $attribute; - $this->_groupfunc = $func; - $this->_groupsort = $groupsort; - } - - /// set count-distinct attribute for group-by queries - function SetGroupDistinct ( $attribute ) - { - assert ( is_string($attribute) ); - $this->_groupdistinct = $attribute; - } - - /// set distributed retries count and delay - function SetRetries ( $count, $delay=0 ) - { - assert ( is_int($count) && $count>=0 ); - assert ( is_int($delay) && $delay>=0 ); - $this->_retrycount = $count; - $this->_retrydelay = $delay; - } - - /// set result set format (hash or array; hash by default) - /// PHP specific; needed for group-by-MVA result sets that may contain duplicate IDs - function SetArrayResult ( $arrayresult ) - { - assert ( is_bool($arrayresult) ); - $this->_arrayresult = $arrayresult; - } - - /// set attribute values override - /// there can be only one override per attribute - /// $values must be a hash that maps document IDs to attribute values - function SetOverride ( $attrname, $attrtype, $values ) - { - assert ( is_string ( $attrname ) ); - assert ( in_array ( $attrtype, array ( SPH_ATTR_INTEGER, SPH_ATTR_TIMESTAMP, SPH_ATTR_BOOL, SPH_ATTR_FLOAT, SPH_ATTR_BIGINT ) ) ); - assert ( is_array ( $values ) ); - - $this->_overrides[$attrname] = array ( "attr"=>$attrname, "type"=>$attrtype, "values"=>$values ); - } - - /// set select-list (attributes or expressions), SQL-like syntax - function SetSelect ( $select ) - { - assert ( is_string ( $select ) ); - $this->_select = $select; - } - - ////////////////////////////////////////////////////////////////////////////// - - /// clear all filters (for multi-queries) - function ResetFilters () - { - $this->_filters = array(); - $this->_anchor = array(); - } - - /// clear groupby settings (for multi-queries) - function ResetGroupBy () - { - $this->_groupby = ""; - $this->_groupfunc = SPH_GROUPBY_DAY; - $this->_groupsort = "@group desc"; - $this->_groupdistinct= ""; - } - - /// clear all attribute value overrides (for multi-queries) - function ResetOverrides () - { - $this->_overrides = array (); - } - - ////////////////////////////////////////////////////////////////////////////// - - /// connect to searchd server, run given search query through given indexes, - /// and return the search results - function Query ( $query, $index="*", $comment="" ) - { - assert ( empty($this->_reqs) ); - - $this->AddQuery ( $query, $index, $comment ); - $results = $this->RunQueries (); - $this->_reqs = array (); // just in case it failed too early - - if ( !is_array($results) ) - return false; // probably network error; error message should be already filled - - $this->_error = $results[0]["error"]; - $this->_warning = $results[0]["warning"]; - if ( $results[0]["status"]==SEARCHD_ERROR ) - return false; - else - return $results[0]; - } - - /// helper to pack floats in network byte order - function _PackFloat ( $f ) - { - $t1 = pack ( "f", $f ); // machine order - list(,$t2) = unpack ( "L*", $t1 ); // int in machine order - return pack ( "N", $t2 ); - } - - /// add query to multi-query batch - /// returns index into results array from RunQueries() call - function AddQuery ( $query, $index="*", $comment="" ) - { - // mbstring workaround - $this->_MBPush (); - - // build request - $req = pack ( "NNNN", $this->_offset, $this->_limit, $this->_mode, $this->_ranker ); - if ( $this->_ranker==SPH_RANK_EXPR ) - $req .= pack ( "N", strlen($this->_rankexpr) ) . $this->_rankexpr; - $req .= pack ( "N", $this->_sort ); // (deprecated) sort mode - $req .= pack ( "N", strlen($this->_sortby) ) . $this->_sortby; - $req .= pack ( "N", strlen($query) ) . $query; // query itself - $req .= pack ( "N", count($this->_weights) ); // weights - foreach ( $this->_weights as $weight ) - $req .= pack ( "N", (int)$weight ); - $req .= pack ( "N", strlen($index) ) . $index; // indexes - $req .= pack ( "N", 1 ); // id64 range marker - $req .= sphPackU64 ( $this->_min_id ) . sphPackU64 ( $this->_max_id ); // id64 range - - // filters - $req .= pack ( "N", count($this->_filters) ); - foreach ( $this->_filters as $filter ) - { - $req .= pack ( "N", strlen($filter["attr"]) ) . $filter["attr"]; - $req .= pack ( "N", $filter["type"] ); - switch ( $filter["type"] ) - { - case SPH_FILTER_VALUES: - $req .= pack ( "N", count($filter["values"]) ); - foreach ( $filter["values"] as $value ) - $req .= sphPackI64 ( $value ); - break; - - case SPH_FILTER_RANGE: - $req .= sphPackI64 ( $filter["min"] ) . sphPackI64 ( $filter["max"] ); - break; - - case SPH_FILTER_FLOATRANGE: - $req .= $this->_PackFloat ( $filter["min"] ) . $this->_PackFloat ( $filter["max"] ); - break; - - default: - assert ( 0 && "internal error: unhandled filter type" ); - } - $req .= pack ( "N", $filter["exclude"] ); - } - - // group-by clause, max-matches count, group-sort clause, cutoff count - $req .= pack ( "NN", $this->_groupfunc, strlen($this->_groupby) ) . $this->_groupby; - $req .= pack ( "N", $this->_maxmatches ); - $req .= pack ( "N", strlen($this->_groupsort) ) . $this->_groupsort; - $req .= pack ( "NNN", $this->_cutoff, $this->_retrycount, $this->_retrydelay ); - $req .= pack ( "N", strlen($this->_groupdistinct) ) . $this->_groupdistinct; - - // anchor point - if ( empty($this->_anchor) ) - { - $req .= pack ( "N", 0 ); - } else - { - $a =& $this->_anchor; - $req .= pack ( "N", 1 ); - $req .= pack ( "N", strlen($a["attrlat"]) ) . $a["attrlat"]; - $req .= pack ( "N", strlen($a["attrlong"]) ) . $a["attrlong"]; - $req .= $this->_PackFloat ( $a["lat"] ) . $this->_PackFloat ( $a["long"] ); - } - - // per-index weights - $req .= pack ( "N", count($this->_indexweights) ); - foreach ( $this->_indexweights as $idx=>$weight ) - $req .= pack ( "N", strlen($idx) ) . $idx . pack ( "N", $weight ); - - // max query time - $req .= pack ( "N", $this->_maxquerytime ); - - // per-field weights - $req .= pack ( "N", count($this->_fieldweights) ); - foreach ( $this->_fieldweights as $field=>$weight ) - $req .= pack ( "N", strlen($field) ) . $field . pack ( "N", $weight ); - - // comment - $req .= pack ( "N", strlen($comment) ) . $comment; - - // attribute overrides - $req .= pack ( "N", count($this->_overrides) ); - foreach ( $this->_overrides as $key => $entry ) - { - $req .= pack ( "N", strlen($entry["attr"]) ) . $entry["attr"]; - $req .= pack ( "NN", $entry["type"], count($entry["values"]) ); - foreach ( $entry["values"] as $id=>$val ) - { - assert ( is_numeric($id) ); - assert ( is_numeric($val) ); - - $req .= sphPackU64 ( $id ); - switch ( $entry["type"] ) - { - case SPH_ATTR_FLOAT: $req .= $this->_PackFloat ( $val ); break; - case SPH_ATTR_BIGINT: $req .= sphPackI64 ( $val ); break; - default: $req .= pack ( "N", $val ); break; - } - } - } - - // select-list - $req .= pack ( "N", strlen($this->_select) ) . $this->_select; - - // mbstring workaround - $this->_MBPop (); - - // store request to requests array - $this->_reqs[] = $req; - return count($this->_reqs)-1; - } - - /// connect to searchd, run queries batch, and return an array of result sets - function RunQueries () - { - if ( empty($this->_reqs) ) - { - $this->_error = "no queries defined, issue AddQuery() first"; - return false; - } - - // mbstring workaround - $this->_MBPush (); - - if (!( $fp = $this->_Connect() )) - { - $this->_MBPop (); - return false; - } - - // send query, get response - $nreqs = count($this->_reqs); - $req = join ( "", $this->_reqs ); - $len = 8+strlen($req); - $req = pack ( "nnNNN", SEARCHD_COMMAND_SEARCH, VER_COMMAND_SEARCH, $len, 0, $nreqs ) . $req; // add header - - if ( !( $this->_Send ( $fp, $req, $len+8 ) ) || - !( $response = $this->_GetResponse ( $fp, VER_COMMAND_SEARCH ) ) ) - { - $this->_MBPop (); - return false; - } - - // query sent ok; we can reset reqs now - $this->_reqs = array (); - - // parse and return response - return $this->_ParseSearchResponse ( $response, $nreqs ); - } - - /// parse and return search query (or queries) response - function _ParseSearchResponse ( $response, $nreqs ) - { - $p = 0; // current position - $max = strlen($response); // max position for checks, to protect against broken responses - - $results = array (); - for ( $ires=0; $ires<$nreqs && $p<$max; $ires++ ) - { - $results[] = array(); - $result =& $results[$ires]; - - $result["error"] = ""; - $result["warning"] = ""; - - // extract status - list(,$status) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - $result["status"] = $status; - if ( $status!=SEARCHD_OK ) - { - list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - $message = substr ( $response, $p, $len ); $p += $len; - - if ( $status==SEARCHD_WARNING ) - { - $result["warning"] = $message; - } else - { - $result["error"] = $message; - continue; - } - } - - // read schema - $fields = array (); - $attrs = array (); - - list(,$nfields) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - while ( $nfields-->0 && $p<$max ) - { - list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - $fields[] = substr ( $response, $p, $len ); $p += $len; - } - $result["fields"] = $fields; - - list(,$nattrs) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - while ( $nattrs-->0 && $p<$max ) - { - list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - $attr = substr ( $response, $p, $len ); $p += $len; - list(,$type) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - $attrs[$attr] = $type; - } - $result["attrs"] = $attrs; - - // read match count - list(,$count) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - list(,$id64) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - - // read matches - $idx = -1; - while ( $count-->0 && $p<$max ) - { - // index into result array - $idx++; - - // parse document id and weight - if ( $id64 ) - { - $doc = sphUnpackU64 ( substr ( $response, $p, 8 ) ); $p += 8; - list(,$weight) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - } - else - { - list ( $doc, $weight ) = array_values ( unpack ( "N*N*", - substr ( $response, $p, 8 ) ) ); - $p += 8; - $doc = sphFixUint($doc); - } - $weight = sprintf ( "%u", $weight ); - - // create match entry - if ( $this->_arrayresult ) - $result["matches"][$idx] = array ( "id"=>$doc, "weight"=>$weight ); - else - $result["matches"][$doc]["weight"] = $weight; - - // parse and create attributes - $attrvals = array (); - foreach ( $attrs as $attr=>$type ) - { - // handle 64bit ints - if ( $type==SPH_ATTR_BIGINT ) - { - $attrvals[$attr] = sphUnpackI64 ( substr ( $response, $p, 8 ) ); $p += 8; - continue; - } - - // handle floats - if ( $type==SPH_ATTR_FLOAT ) - { - list(,$uval) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - list(,$fval) = unpack ( "f*", pack ( "L", $uval ) ); - $attrvals[$attr] = $fval; - continue; - } - - // handle everything else as unsigned ints - list(,$val) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - if ( $type==SPH_ATTR_MULTI ) - { - $attrvals[$attr] = array (); - $nvalues = $val; - while ( $nvalues-->0 && $p<$max ) - { - list(,$val) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - $attrvals[$attr][] = sphFixUint($val); - } - } else if ( $type==SPH_ATTR_MULTI64 ) - { - $attrvals[$attr] = array (); - $nvalues = $val; - while ( $nvalues>0 && $p<$max ) - { - $attrvals[$attr][] = sphUnpackU64 ( substr ( $response, $p, 8 ) ); $p += 8; - $nvalues -= 2; - } - } else if ( $type==SPH_ATTR_STRING ) - { - $attrvals[$attr] = substr ( $response, $p, $val ); - $p += $val; - } else - { - $attrvals[$attr] = sphFixUint($val); - } - } - - if ( $this->_arrayresult ) - $result["matches"][$idx]["attrs"] = $attrvals; - else - $result["matches"][$doc]["attrs"] = $attrvals; - } - - list ( $total, $total_found, $msecs, $words ) = - array_values ( unpack ( "N*N*N*N*", substr ( $response, $p, 16 ) ) ); - $result["total"] = sprintf ( "%u", $total ); - $result["total_found"] = sprintf ( "%u", $total_found ); - $result["time"] = sprintf ( "%.3f", $msecs/1000 ); - $p += 16; - - while ( $words-->0 && $p<$max ) - { - list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - $word = substr ( $response, $p, $len ); $p += $len; - list ( $docs, $hits ) = array_values ( unpack ( "N*N*", substr ( $response, $p, 8 ) ) ); $p += 8; - $result["words"][$word] = array ( - "docs"=>sprintf ( "%u", $docs ), - "hits"=>sprintf ( "%u", $hits ) ); - } - } - - $this->_MBPop (); - return $results; - } - - ///////////////////////////////////////////////////////////////////////////// - // excerpts generation - ///////////////////////////////////////////////////////////////////////////// - - /// connect to searchd server, and generate exceprts (snippets) - /// of given documents for given query. returns false on failure, - /// an array of snippets on success - function BuildExcerpts ( $docs, $index, $words, $opts=array() ) - { - assert ( is_array($docs) ); - assert ( is_string($index) ); - assert ( is_string($words) ); - assert ( is_array($opts) ); - - $this->_MBPush (); - - if (!( $fp = $this->_Connect() )) - { - $this->_MBPop(); - return false; - } - - ///////////////// - // fixup options - ///////////////// - - if ( !isset($opts["before_match"]) ) $opts["before_match"] = ""; - if ( !isset($opts["after_match"]) ) $opts["after_match"] = ""; - if ( !isset($opts["chunk_separator"]) ) $opts["chunk_separator"] = " ... "; - if ( !isset($opts["limit"]) ) $opts["limit"] = 256; - if ( !isset($opts["limit_passages"]) ) $opts["limit_passages"] = 0; - if ( !isset($opts["limit_words"]) ) $opts["limit_words"] = 0; - if ( !isset($opts["around"]) ) $opts["around"] = 5; - if ( !isset($opts["exact_phrase"]) ) $opts["exact_phrase"] = false; - if ( !isset($opts["single_passage"]) ) $opts["single_passage"] = false; - if ( !isset($opts["use_boundaries"]) ) $opts["use_boundaries"] = false; - if ( !isset($opts["weight_order"]) ) $opts["weight_order"] = false; - if ( !isset($opts["query_mode"]) ) $opts["query_mode"] = false; - if ( !isset($opts["force_all_words"]) ) $opts["force_all_words"] = false; - if ( !isset($opts["start_passage_id"]) ) $opts["start_passage_id"] = 1; - if ( !isset($opts["load_files"]) ) $opts["load_files"] = false; - if ( !isset($opts["html_strip_mode"]) ) $opts["html_strip_mode"] = "index"; - if ( !isset($opts["allow_empty"]) ) $opts["allow_empty"] = false; - if ( !isset($opts["passage_boundary"]) ) $opts["passage_boundary"] = "none"; - if ( !isset($opts["emit_zones"]) ) $opts["emit_zones"] = false; - if ( !isset($opts["load_files_scattered"]) ) $opts["load_files_scattered"] = false; - - - ///////////////// - // build request - ///////////////// - - // v.1.2 req - $flags = 1; // remove spaces - if ( $opts["exact_phrase"] ) $flags |= 2; - if ( $opts["single_passage"] ) $flags |= 4; - if ( $opts["use_boundaries"] ) $flags |= 8; - if ( $opts["weight_order"] ) $flags |= 16; - if ( $opts["query_mode"] ) $flags |= 32; - if ( $opts["force_all_words"] ) $flags |= 64; - if ( $opts["load_files"] ) $flags |= 128; - if ( $opts["allow_empty"] ) $flags |= 256; - if ( $opts["emit_zones"] ) $flags |= 512; - if ( $opts["load_files_scattered"] ) $flags |= 1024; - $req = pack ( "NN", 0, $flags ); // mode=0, flags=$flags - $req .= pack ( "N", strlen($index) ) . $index; // req index - $req .= pack ( "N", strlen($words) ) . $words; // req words - - // options - $req .= pack ( "N", strlen($opts["before_match"]) ) . $opts["before_match"]; - $req .= pack ( "N", strlen($opts["after_match"]) ) . $opts["after_match"]; - $req .= pack ( "N", strlen($opts["chunk_separator"]) ) . $opts["chunk_separator"]; - $req .= pack ( "NN", (int)$opts["limit"], (int)$opts["around"] ); - $req .= pack ( "NNN", (int)$opts["limit_passages"], (int)$opts["limit_words"], (int)$opts["start_passage_id"] ); // v.1.2 - $req .= pack ( "N", strlen($opts["html_strip_mode"]) ) . $opts["html_strip_mode"]; - $req .= pack ( "N", strlen($opts["passage_boundary"]) ) . $opts["passage_boundary"]; - - // documents - $req .= pack ( "N", count($docs) ); - foreach ( $docs as $doc ) - { - assert ( is_string($doc) ); - $req .= pack ( "N", strlen($doc) ) . $doc; - } - - //////////////////////////// - // send query, get response - //////////////////////////// - - $len = strlen($req); - $req = pack ( "nnN", SEARCHD_COMMAND_EXCERPT, VER_COMMAND_EXCERPT, $len ) . $req; // add header - if ( !( $this->_Send ( $fp, $req, $len+8 ) ) || - !( $response = $this->_GetResponse ( $fp, VER_COMMAND_EXCERPT ) ) ) - { - $this->_MBPop (); - return false; - } - - ////////////////// - // parse response - ////////////////// - - $pos = 0; - $res = array (); - $rlen = strlen($response); - for ( $i=0; $i $rlen ) - { - $this->_error = "incomplete reply"; - $this->_MBPop (); - return false; - } - $res[] = $len ? substr ( $response, $pos, $len ) : ""; - $pos += $len; - } - - $this->_MBPop (); - return $res; - } - - - ///////////////////////////////////////////////////////////////////////////// - // keyword generation - ///////////////////////////////////////////////////////////////////////////// - - /// connect to searchd server, and generate keyword list for a given query - /// returns false on failure, - /// an array of words on success - function BuildKeywords ( $query, $index, $hits ) - { - assert ( is_string($query) ); - assert ( is_string($index) ); - assert ( is_bool($hits) ); - - $this->_MBPush (); - - if (!( $fp = $this->_Connect() )) - { - $this->_MBPop(); - return false; - } - - ///////////////// - // build request - ///////////////// - - // v.1.0 req - $req = pack ( "N", strlen($query) ) . $query; // req query - $req .= pack ( "N", strlen($index) ) . $index; // req index - $req .= pack ( "N", (int)$hits ); - - //////////////////////////// - // send query, get response - //////////////////////////// - - $len = strlen($req); - $req = pack ( "nnN", SEARCHD_COMMAND_KEYWORDS, VER_COMMAND_KEYWORDS, $len ) . $req; // add header - if ( !( $this->_Send ( $fp, $req, $len+8 ) ) || - !( $response = $this->_GetResponse ( $fp, VER_COMMAND_KEYWORDS ) ) ) - { - $this->_MBPop (); - return false; - } - - ////////////////// - // parse response - ////////////////// - - $pos = 0; - $res = array (); - $rlen = strlen($response); - list(,$nwords) = unpack ( "N*", substr ( $response, $pos, 4 ) ); - $pos += 4; - for ( $i=0; $i<$nwords; $i++ ) - { - list(,$len) = unpack ( "N*", substr ( $response, $pos, 4 ) ); $pos += 4; - $tokenized = $len ? substr ( $response, $pos, $len ) : ""; - $pos += $len; - - list(,$len) = unpack ( "N*", substr ( $response, $pos, 4 ) ); $pos += 4; - $normalized = $len ? substr ( $response, $pos, $len ) : ""; - $pos += $len; - - $res[] = array ( "tokenized"=>$tokenized, "normalized"=>$normalized ); - - if ( $hits ) - { - list($ndocs,$nhits) = array_values ( unpack ( "N*N*", substr ( $response, $pos, 8 ) ) ); - $pos += 8; - $res [$i]["docs"] = $ndocs; - $res [$i]["hits"] = $nhits; - } - - if ( $pos > $rlen ) - { - $this->_error = "incomplete reply"; - $this->_MBPop (); - return false; - } - } - - $this->_MBPop (); - return $res; - } - - function EscapeString ( $string ) - { - $from = array ( '\\', '(',')','|','-','!','@','~','"','&', '/', '^', '$', '=' ); - $to = array ( '\\\\', '\(','\)','\|','\-','\!','\@','\~','\"', '\&', '\/', '\^', '\$', '\=' ); - - return str_replace ( $from, $to, $string ); - } - - ///////////////////////////////////////////////////////////////////////////// - // attribute updates - ///////////////////////////////////////////////////////////////////////////// - - /// batch update given attributes in given rows in given indexes - /// returns amount of updated documents (0 or more) on success, or -1 on failure - function UpdateAttributes ( $index, $attrs, $values, $mva=false ) - { - // verify everything - assert ( is_string($index) ); - assert ( is_bool($mva) ); - - assert ( is_array($attrs) ); - foreach ( $attrs as $attr ) - assert ( is_string($attr) ); - - assert ( is_array($values) ); - foreach ( $values as $id=>$entry ) - { - assert ( is_numeric($id) ); - assert ( is_array($entry) ); - assert ( count($entry)==count($attrs) ); - foreach ( $entry as $v ) - { - if ( $mva ) - { - assert ( is_array($v) ); - foreach ( $v as $vv ) - assert ( is_int($vv) ); - } else - assert ( is_int($v) ); - } - } - - // build request - $this->_MBPush (); - $req = pack ( "N", strlen($index) ) . $index; - - $req .= pack ( "N", count($attrs) ); - foreach ( $attrs as $attr ) - { - $req .= pack ( "N", strlen($attr) ) . $attr; - $req .= pack ( "N", $mva ? 1 : 0 ); - } - - $req .= pack ( "N", count($values) ); - foreach ( $values as $id=>$entry ) - { - $req .= sphPackU64 ( $id ); - foreach ( $entry as $v ) - { - $req .= pack ( "N", $mva ? count($v) : $v ); - if ( $mva ) - foreach ( $v as $vv ) - $req .= pack ( "N", $vv ); - } - } - - // connect, send query, get response - if (!( $fp = $this->_Connect() )) - { - $this->_MBPop (); - return -1; - } - - $len = strlen($req); - $req = pack ( "nnN", SEARCHD_COMMAND_UPDATE, VER_COMMAND_UPDATE, $len ) . $req; // add header - if ( !$this->_Send ( $fp, $req, $len+8 ) ) - { - $this->_MBPop (); - return -1; - } - - if (!( $response = $this->_GetResponse ( $fp, VER_COMMAND_UPDATE ) )) - { - $this->_MBPop (); - return -1; - } - - // parse response - list(,$updated) = unpack ( "N*", substr ( $response, 0, 4 ) ); - $this->_MBPop (); - return $updated; - } - - ///////////////////////////////////////////////////////////////////////////// - // persistent connections - ///////////////////////////////////////////////////////////////////////////// - - function Open() - { - if ( $this->_socket !== false ) - { - $this->_error = 'already connected'; - return false; - } - if ( !$fp = $this->_Connect() ) - return false; - - // command, command version = 0, body length = 4, body = 1 - $req = pack ( "nnNN", SEARCHD_COMMAND_PERSIST, 0, 4, 1 ); - if ( !$this->_Send ( $fp, $req, 12 ) ) - return false; - - $this->_socket = $fp; - return true; - } - - function Close() - { - if ( $this->_socket === false ) - { - $this->_error = 'not connected'; - return false; - } - - fclose ( $this->_socket ); - $this->_socket = false; - - return true; - } - - ////////////////////////////////////////////////////////////////////////// - // status - ////////////////////////////////////////////////////////////////////////// - - function Status () - { - $this->_MBPush (); - if (!( $fp = $this->_Connect() )) - { - $this->_MBPop(); - return false; - } - - $req = pack ( "nnNN", SEARCHD_COMMAND_STATUS, VER_COMMAND_STATUS, 4, 1 ); // len=4, body=1 - if ( !( $this->_Send ( $fp, $req, 12 ) ) || - !( $response = $this->_GetResponse ( $fp, VER_COMMAND_STATUS ) ) ) - { - $this->_MBPop (); - return false; - } - - $res = substr ( $response, 4 ); // just ignore length, error handling, etc - $p = 0; - list ( $rows, $cols ) = array_values ( unpack ( "N*N*", substr ( $response, $p, 8 ) ) ); $p += 8; - - $res = array(); - for ( $i=0; $i<$rows; $i++ ) - for ( $j=0; $j<$cols; $j++ ) - { - list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; - $res[$i][] = substr ( $response, $p, $len ); $p += $len; - } - - $this->_MBPop (); - return $res; - } - - ////////////////////////////////////////////////////////////////////////// - // flush - ////////////////////////////////////////////////////////////////////////// - - function FlushAttributes () - { - $this->_MBPush (); - if (!( $fp = $this->_Connect() )) - { - $this->_MBPop(); - return -1; - } - - $req = pack ( "nnN", SEARCHD_COMMAND_FLUSHATTRS, VER_COMMAND_FLUSHATTRS, 0 ); // len=0 - if ( !( $this->_Send ( $fp, $req, 8 ) ) || - !( $response = $this->_GetResponse ( $fp, VER_COMMAND_FLUSHATTRS ) ) ) - { - $this->_MBPop (); - return -1; - } - - $tag = -1; - if ( strlen($response)==4 ) - list(,$tag) = unpack ( "N*", $response ); - else - $this->_error = "unexpected response length"; - - $this->_MBPop (); - return $tag; - } -} - -// -// $Id: sphinxapi.php 3087 2012-01-30 23:07:35Z shodan $ -// +=8 ) + { + $v = (int)$v; + return pack ( "NN", $v>>32, $v&0xFFFFFFFF ); + } + + // x32, int + if ( is_int($v) ) + return pack ( "NN", $v < 0 ? -1 : 0, $v ); + + // x32, bcmath + if ( function_exists("bcmul") ) + { + if ( bccomp ( $v, 0 ) == -1 ) + $v = bcadd ( "18446744073709551616", $v ); + $h = bcdiv ( $v, "4294967296", 0 ); + $l = bcmod ( $v, "4294967296" ); + return pack ( "NN", (float)$h, (float)$l ); // conversion to float is intentional; int would lose 31st bit + } + + // x32, no-bcmath + $p = max(0, strlen($v) - 13); + $lo = abs((float)substr($v, $p)); + $hi = abs((float)substr($v, 0, $p)); + + $m = $lo + $hi*1316134912.0; // (10 ^ 13) % (1 << 32) = 1316134912 + $q = floor($m/4294967296.0); + $l = $m - ($q*4294967296.0); + $h = $hi*2328.0 + $q; // (10 ^ 13) / (1 << 32) = 2328 + + if ( $v<0 ) + { + if ( $l==0 ) + $h = 4294967296.0 - $h; + else + { + $h = 4294967295.0 - $h; + $l = 4294967296.0 - $l; + } + } + return pack ( "NN", $h, $l ); +} + +/// pack 64-bit unsigned +function sphPackU64 ( $v ) +{ + assert ( is_numeric($v) ); + + // x64 + if ( PHP_INT_SIZE>=8 ) + { + assert ( $v>=0 ); + + // x64, int + if ( is_int($v) ) + return pack ( "NN", $v>>32, $v&0xFFFFFFFF ); + + // x64, bcmath + if ( function_exists("bcmul") ) + { + $h = bcdiv ( $v, 4294967296, 0 ); + $l = bcmod ( $v, 4294967296 ); + return pack ( "NN", $h, $l ); + } + + // x64, no-bcmath + $p = max ( 0, strlen($v) - 13 ); + $lo = (int)substr ( $v, $p ); + $hi = (int)substr ( $v, 0, $p ); + + $m = $lo + $hi*1316134912; + $l = $m % 4294967296; + $h = $hi*2328 + (int)($m/4294967296); + + return pack ( "NN", $h, $l ); + } + + // x32, int + if ( is_int($v) ) + return pack ( "NN", 0, $v ); + + // x32, bcmath + if ( function_exists("bcmul") ) + { + $h = bcdiv ( $v, "4294967296", 0 ); + $l = bcmod ( $v, "4294967296" ); + return pack ( "NN", (float)$h, (float)$l ); // conversion to float is intentional; int would lose 31st bit + } + + // x32, no-bcmath + $p = max(0, strlen($v) - 13); + $lo = (float)substr($v, $p); + $hi = (float)substr($v, 0, $p); + + $m = $lo + $hi*1316134912.0; + $q = floor($m / 4294967296.0); + $l = $m - ($q * 4294967296.0); + $h = $hi*2328.0 + $q; + + return pack ( "NN", $h, $l ); +} + +// unpack 64-bit unsigned +function sphUnpackU64 ( $v ) +{ + list ( $hi, $lo ) = array_values ( unpack ( "N*N*", $v ) ); + + if ( PHP_INT_SIZE>=8 ) + { + if ( $hi<0 ) $hi += (1<<32); // because php 5.2.2 to 5.2.5 is totally fucked up again + if ( $lo<0 ) $lo += (1<<32); + + // x64, int + if ( $hi<=2147483647 ) + return ($hi<<32) + $lo; + + // x64, bcmath + if ( function_exists("bcmul") ) + return bcadd ( $lo, bcmul ( $hi, "4294967296" ) ); + + // x64, no-bcmath + $C = 100000; + $h = ((int)($hi / $C) << 32) + (int)($lo / $C); + $l = (($hi % $C) << 32) + ($lo % $C); + if ( $l>$C ) + { + $h += (int)($l / $C); + $l = $l % $C; + } + + if ( $h==0 ) + return $l; + return sprintf ( "%d%05d", $h, $l ); + } + + // x32, int + if ( $hi==0 ) + { + if ( $lo>0 ) + return $lo; + return sprintf ( "%u", $lo ); + } + + $hi = sprintf ( "%u", $hi ); + $lo = sprintf ( "%u", $lo ); + + // x32, bcmath + if ( function_exists("bcmul") ) + return bcadd ( $lo, bcmul ( $hi, "4294967296" ) ); + + // x32, no-bcmath + $hi = (float)$hi; + $lo = (float)$lo; + + $q = floor($hi/10000000.0); + $r = $hi - $q*10000000.0; + $m = $lo + $r*4967296.0; + $mq = floor($m/10000000.0); + $l = $m - $mq*10000000.0; + $h = $q*4294967296.0 + $r*429.0 + $mq; + + $h = sprintf ( "%.0f", $h ); + $l = sprintf ( "%07.0f", $l ); + if ( $h=="0" ) + return sprintf( "%.0f", (float)$l ); + return $h . $l; +} + +// unpack 64-bit signed +function sphUnpackI64 ( $v ) +{ + list ( $hi, $lo ) = array_values ( unpack ( "N*N*", $v ) ); + + // x64 + if ( PHP_INT_SIZE>=8 ) + { + if ( $hi<0 ) $hi += (1<<32); // because php 5.2.2 to 5.2.5 is totally fucked up again + if ( $lo<0 ) $lo += (1<<32); + + return ($hi<<32) + $lo; + } + + // x32, int + if ( $hi==0 ) + { + if ( $lo>0 ) + return $lo; + return sprintf ( "%u", $lo ); + } + // x32, int + elseif ( $hi==-1 ) + { + if ( $lo<0 ) + return $lo; + return sprintf ( "%.0f", $lo - 4294967296.0 ); + } + + $neg = ""; + $c = 0; + if ( $hi<0 ) + { + $hi = ~$hi; + $lo = ~$lo; + $c = 1; + $neg = "-"; + } + + $hi = sprintf ( "%u", $hi ); + $lo = sprintf ( "%u", $lo ); + + // x32, bcmath + if ( function_exists("bcmul") ) + return $neg . bcadd ( bcadd ( $lo, bcmul ( $hi, "4294967296" ) ), $c ); + + // x32, no-bcmath + $hi = (float)$hi; + $lo = (float)$lo; + + $q = floor($hi/10000000.0); + $r = $hi - $q*10000000.0; + $m = $lo + $r*4967296.0; + $mq = floor($m/10000000.0); + $l = $m - $mq*10000000.0 + $c; + $h = $q*4294967296.0 + $r*429.0 + $mq; + if ( $l==10000000 ) + { + $l = 0; + $h += 1; + } + + $h = sprintf ( "%.0f", $h ); + $l = sprintf ( "%07.0f", $l ); + if ( $h=="0" ) + return $neg . sprintf( "%.0f", (float)$l ); + return $neg . $h . $l; +} + + +function sphFixUint ( $value ) +{ + if ( PHP_INT_SIZE>=8 ) + { + // x64 route, workaround broken unpack() in 5.2.2+ + if ( $value<0 ) $value += (1<<32); + return $value; + } + else + { + // x32 route, workaround php signed/unsigned braindamage + return sprintf ( "%u", $value ); + } +} + + +/// sphinx searchd client class +class SphinxClient +{ + var $_host; ///< searchd host (default is "localhost") + var $_port; ///< searchd port (default is 9312) + var $_offset; ///< how many records to seek from result-set start (default is 0) + var $_limit; ///< how many records to return from result-set starting at offset (default is 20) + var $_mode; ///< query matching mode (default is SPH_MATCH_ALL) + var $_weights; ///< per-field weights (default is 1 for all fields) + var $_sort; ///< match sorting mode (default is SPH_SORT_RELEVANCE) + var $_sortby; ///< attribute to sort by (defualt is "") + var $_min_id; ///< min ID to match (default is 0, which means no limit) + var $_max_id; ///< max ID to match (default is 0, which means no limit) + var $_filters; ///< search filters + var $_groupby; ///< group-by attribute name + var $_groupfunc; ///< group-by function (to pre-process group-by attribute value with) + var $_groupsort; ///< group-by sorting clause (to sort groups in result set with) + var $_groupdistinct;///< group-by count-distinct attribute + var $_maxmatches; ///< max matches to retrieve + var $_cutoff; ///< cutoff to stop searching at (default is 0) + var $_retrycount; ///< distributed retries count + var $_retrydelay; ///< distributed retries delay + var $_anchor; ///< geographical anchor point + var $_indexweights; ///< per-index weights + var $_ranker; ///< ranking mode (default is SPH_RANK_PROXIMITY_BM25) + var $_rankexpr; ///< ranking mode expression (for SPH_RANK_EXPR) + var $_maxquerytime; ///< max query time, milliseconds (default is 0, do not limit) + var $_fieldweights; ///< per-field-name weights + var $_overrides; ///< per-query attribute values overrides + var $_select; ///< select-list (attributes or expressions, with optional aliases) + + var $_error; ///< last error message + var $_warning; ///< last warning message + var $_connerror; ///< connection error vs remote error flag + + var $_reqs; ///< requests array for multi-query + var $_mbenc; ///< stored mbstring encoding + var $_arrayresult; ///< whether $result["matches"] should be a hash or an array + var $_timeout; ///< connect timeout + + ///////////////////////////////////////////////////////////////////////////// + // common stuff + ///////////////////////////////////////////////////////////////////////////// + + /// create a new client object and fill defaults + function SphinxClient () + { + // per-client-object settings + $this->_host = "localhost"; + $this->_port = 9312; + $this->_path = false; + $this->_socket = false; + + // per-query settings + $this->_offset = 0; + $this->_limit = 20; + $this->_mode = SPH_MATCH_ALL; + $this->_weights = array (); + $this->_sort = SPH_SORT_RELEVANCE; + $this->_sortby = ""; + $this->_min_id = 0; + $this->_max_id = 0; + $this->_filters = array (); + $this->_groupby = ""; + $this->_groupfunc = SPH_GROUPBY_DAY; + $this->_groupsort = "@group desc"; + $this->_groupdistinct= ""; + $this->_maxmatches = 1000; + $this->_cutoff = 0; + $this->_retrycount = 0; + $this->_retrydelay = 0; + $this->_anchor = array (); + $this->_indexweights= array (); + $this->_ranker = SPH_RANK_PROXIMITY_BM25; + $this->_rankexpr = ""; + $this->_maxquerytime= 0; + $this->_fieldweights= array(); + $this->_overrides = array(); + $this->_select = "*"; + + $this->_error = ""; // per-reply fields (for single-query case) + $this->_warning = ""; + $this->_connerror = false; + + $this->_reqs = array (); // requests storage (for multi-query case) + $this->_mbenc = ""; + $this->_arrayresult = false; + $this->_timeout = 0; + } + + function __destruct() + { + if ( $this->_socket !== false ) + fclose ( $this->_socket ); + } + + /// get last error message (string) + function GetLastError () + { + return $this->_error; + } + + /// get last warning message (string) + function GetLastWarning () + { + return $this->_warning; + } + + /// get last error flag (to tell network connection errors from searchd errors or broken responses) + function IsConnectError() + { + return $this->_connerror; + } + + /// set searchd host name (string) and port (integer) + function SetServer ( $host, $port = 0 ) + { + assert ( is_string($host) ); + if ( $host[0] == '/') + { + $this->_path = 'unix://' . $host; + return; + } + if ( substr ( $host, 0, 7 )=="unix://" ) + { + $this->_path = $host; + return; + } + + assert ( is_int($port) ); + $this->_host = $host; + $this->_port = $port; + $this->_path = ''; + + } + + /// set server connection timeout (0 to remove) + function SetConnectTimeout ( $timeout ) + { + assert ( is_numeric($timeout) ); + $this->_timeout = $timeout; + } + + + function _Send ( $handle, $data, $length ) + { + if ( feof($handle) || fwrite ( $handle, $data, $length ) !== $length ) + { + $this->_error = 'connection unexpectedly closed (timed out?)'; + $this->_connerror = true; + return false; + } + return true; + } + + ///////////////////////////////////////////////////////////////////////////// + + /// enter mbstring workaround mode + function _MBPush () + { + $this->_mbenc = ""; + if ( ini_get ( "mbstring.func_overload" ) & 2 ) + { + $this->_mbenc = mb_internal_encoding(); + mb_internal_encoding ( "latin1" ); + } + } + + /// leave mbstring workaround mode + function _MBPop () + { + if ( $this->_mbenc ) + mb_internal_encoding ( $this->_mbenc ); + } + + /// connect to searchd server + function _Connect () + { + if ( $this->_socket!==false ) + { + // we are in persistent connection mode, so we have a socket + // however, need to check whether it's still alive + if ( !@feof ( $this->_socket ) ) + return $this->_socket; + + // force reopen + $this->_socket = false; + } + + $errno = 0; + $errstr = ""; + $this->_connerror = false; + + if ( $this->_path ) + { + $host = $this->_path; + $port = 0; + } + else + { + $host = $this->_host; + $port = $this->_port; + } + + if ( $this->_timeout<=0 ) + $fp = @fsockopen ( $host, $port, $errno, $errstr ); + else + $fp = @fsockopen ( $host, $port, $errno, $errstr, $this->_timeout ); + + if ( !$fp ) + { + if ( $this->_path ) + $location = $this->_path; + else + $location = "{$this->_host}:{$this->_port}"; + + $errstr = trim ( $errstr ); + $this->_error = "connection to $location failed (errno=$errno, msg=$errstr)"; + $this->_connerror = true; + return false; + } + + // send my version + // this is a subtle part. we must do it before (!) reading back from searchd. + // because otherwise under some conditions (reported on FreeBSD for instance) + // TCP stack could throttle write-write-read pattern because of Nagle. + if ( !$this->_Send ( $fp, pack ( "N", 1 ), 4 ) ) + { + fclose ( $fp ); + $this->_error = "failed to send client protocol version"; + return false; + } + + // check version + list(,$v) = unpack ( "N*", fread ( $fp, 4 ) ); + $v = (int)$v; + if ( $v<1 ) + { + fclose ( $fp ); + $this->_error = "expected searchd protocol version 1+, got version '$v'"; + return false; + } + + return $fp; + } + + /// get and check response packet from searchd server + function _GetResponse ( $fp, $client_ver ) + { + $response = ""; + $len = 0; + + $header = fread ( $fp, 8 ); + if ( strlen($header)==8 ) + { + list ( $status, $ver, $len ) = array_values ( unpack ( "n2a/Nb", $header ) ); + $left = $len; + while ( $left>0 && !feof($fp) ) + { + $chunk = fread ( $fp, min ( 8192, $left ) ); + if ( $chunk ) + { + $response .= $chunk; + $left -= strlen($chunk); + } + } + } + if ( $this->_socket === false ) + fclose ( $fp ); + + // check response + $read = strlen ( $response ); + if ( !$response || $read!=$len ) + { + $this->_error = $len + ? "failed to read searchd response (status=$status, ver=$ver, len=$len, read=$read)" + : "received zero-sized searchd response"; + return false; + } + + // check status + if ( $status==SEARCHD_WARNING ) + { + list(,$wlen) = unpack ( "N*", substr ( $response, 0, 4 ) ); + $this->_warning = substr ( $response, 4, $wlen ); + return substr ( $response, 4+$wlen ); + } + if ( $status==SEARCHD_ERROR ) + { + $this->_error = "searchd error: " . substr ( $response, 4 ); + return false; + } + if ( $status==SEARCHD_RETRY ) + { + $this->_error = "temporary searchd error: " . substr ( $response, 4 ); + return false; + } + if ( $status!=SEARCHD_OK ) + { + $this->_error = "unknown status code '$status'"; + return false; + } + + // check version + if ( $ver<$client_ver ) + { + $this->_warning = sprintf ( "searchd command v.%d.%d older than client's v.%d.%d, some options might not work", + $ver>>8, $ver&0xff, $client_ver>>8, $client_ver&0xff ); + } + + return $response; + } + + ///////////////////////////////////////////////////////////////////////////// + // searching + ///////////////////////////////////////////////////////////////////////////// + + /// set offset and count into result set, + /// and optionally set max-matches and cutoff limits + function SetLimits ( $offset, $limit, $max=0, $cutoff=0 ) + { + assert ( is_int($offset) ); + assert ( is_int($limit) ); + assert ( $offset>=0 ); + assert ( $limit>0 ); + assert ( $max>=0 ); + $this->_offset = $offset; + $this->_limit = $limit; + if ( $max>0 ) + $this->_maxmatches = $max; + if ( $cutoff>0 ) + $this->_cutoff = $cutoff; + } + + /// set maximum query time, in milliseconds, per-index + /// integer, 0 means "do not limit" + function SetMaxQueryTime ( $max ) + { + assert ( is_int($max) ); + assert ( $max>=0 ); + $this->_maxquerytime = $max; + } + + /// set matching mode + function SetMatchMode ( $mode ) + { + assert ( $mode==SPH_MATCH_ALL + || $mode==SPH_MATCH_ANY + || $mode==SPH_MATCH_PHRASE + || $mode==SPH_MATCH_BOOLEAN + || $mode==SPH_MATCH_EXTENDED + || $mode==SPH_MATCH_FULLSCAN + || $mode==SPH_MATCH_EXTENDED2 ); + $this->_mode = $mode; + } + + /// set ranking mode + function SetRankingMode ( $ranker, $rankexpr="" ) + { + assert ( $ranker>=0 && $ranker_ranker = $ranker; + $this->_rankexpr = $rankexpr; + } + + /// set matches sorting mode + function SetSortMode ( $mode, $sortby="" ) + { + assert ( + $mode==SPH_SORT_RELEVANCE || + $mode==SPH_SORT_ATTR_DESC || + $mode==SPH_SORT_ATTR_ASC || + $mode==SPH_SORT_TIME_SEGMENTS || + $mode==SPH_SORT_EXTENDED || + $mode==SPH_SORT_EXPR ); + assert ( is_string($sortby) ); + assert ( $mode==SPH_SORT_RELEVANCE || strlen($sortby)>0 ); + + $this->_sort = $mode; + $this->_sortby = $sortby; + } + + /// bind per-field weights by order + /// DEPRECATED; use SetFieldWeights() instead + function SetWeights ( $weights ) + { + assert ( is_array($weights) ); + foreach ( $weights as $weight ) + assert ( is_int($weight) ); + + $this->_weights = $weights; + } + + /// bind per-field weights by name + function SetFieldWeights ( $weights ) + { + assert ( is_array($weights) ); + foreach ( $weights as $name=>$weight ) + { + assert ( is_string($name) ); + assert ( is_int($weight) ); + } + $this->_fieldweights = $weights; + } + + /// bind per-index weights by name + function SetIndexWeights ( $weights ) + { + assert ( is_array($weights) ); + foreach ( $weights as $index=>$weight ) + { + assert ( is_string($index) ); + assert ( is_int($weight) ); + } + $this->_indexweights = $weights; + } + + /// set IDs range to match + /// only match records if document ID is beetwen $min and $max (inclusive) + function SetIDRange ( $min, $max ) + { + assert ( is_numeric($min) ); + assert ( is_numeric($max) ); + assert ( $min<=$max ); + $this->_min_id = $min; + $this->_max_id = $max; + } + + /// set values set filter + /// only match records where $attribute value is in given set + function SetFilter ( $attribute, $values, $exclude=false ) + { + assert ( is_string($attribute) ); + assert ( is_array($values) ); + assert ( count($values) ); + + if ( is_array($values) && count($values) ) + { + foreach ( $values as $value ) + assert ( is_numeric($value) ); + + $this->_filters[] = array ( "type"=>SPH_FILTER_VALUES, "attr"=>$attribute, "exclude"=>$exclude, "values"=>$values ); + } + } + + /// set range filter + /// only match records if $attribute value is beetwen $min and $max (inclusive) + function SetFilterRange ( $attribute, $min, $max, $exclude=false ) + { + assert ( is_string($attribute) ); + assert ( is_numeric($min) ); + assert ( is_numeric($max) ); + assert ( $min<=$max ); + + $this->_filters[] = array ( "type"=>SPH_FILTER_RANGE, "attr"=>$attribute, "exclude"=>$exclude, "min"=>$min, "max"=>$max ); + } + + /// set float range filter + /// only match records if $attribute value is beetwen $min and $max (inclusive) + function SetFilterFloatRange ( $attribute, $min, $max, $exclude=false ) + { + assert ( is_string($attribute) ); + assert ( is_float($min) ); + assert ( is_float($max) ); + assert ( $min<=$max ); + + $this->_filters[] = array ( "type"=>SPH_FILTER_FLOATRANGE, "attr"=>$attribute, "exclude"=>$exclude, "min"=>$min, "max"=>$max ); + } + + /// setup anchor point for geosphere distance calculations + /// required to use @geodist in filters and sorting + /// latitude and longitude must be in radians + function SetGeoAnchor ( $attrlat, $attrlong, $lat, $long ) + { + assert ( is_string($attrlat) ); + assert ( is_string($attrlong) ); + assert ( is_float($lat) ); + assert ( is_float($long) ); + + $this->_anchor = array ( "attrlat"=>$attrlat, "attrlong"=>$attrlong, "lat"=>$lat, "long"=>$long ); + } + + /// set grouping attribute and function + function SetGroupBy ( $attribute, $func, $groupsort="@group desc" ) + { + assert ( is_string($attribute) ); + assert ( is_string($groupsort) ); + assert ( $func==SPH_GROUPBY_DAY + || $func==SPH_GROUPBY_WEEK + || $func==SPH_GROUPBY_MONTH + || $func==SPH_GROUPBY_YEAR + || $func==SPH_GROUPBY_ATTR + || $func==SPH_GROUPBY_ATTRPAIR ); + + $this->_groupby = $attribute; + $this->_groupfunc = $func; + $this->_groupsort = $groupsort; + } + + /// set count-distinct attribute for group-by queries + function SetGroupDistinct ( $attribute ) + { + assert ( is_string($attribute) ); + $this->_groupdistinct = $attribute; + } + + /// set distributed retries count and delay + function SetRetries ( $count, $delay=0 ) + { + assert ( is_int($count) && $count>=0 ); + assert ( is_int($delay) && $delay>=0 ); + $this->_retrycount = $count; + $this->_retrydelay = $delay; + } + + /// set result set format (hash or array; hash by default) + /// PHP specific; needed for group-by-MVA result sets that may contain duplicate IDs + function SetArrayResult ( $arrayresult ) + { + assert ( is_bool($arrayresult) ); + $this->_arrayresult = $arrayresult; + } + + /// set attribute values override + /// there can be only one override per attribute + /// $values must be a hash that maps document IDs to attribute values + function SetOverride ( $attrname, $attrtype, $values ) + { + assert ( is_string ( $attrname ) ); + assert ( in_array ( $attrtype, array ( SPH_ATTR_INTEGER, SPH_ATTR_TIMESTAMP, SPH_ATTR_BOOL, SPH_ATTR_FLOAT, SPH_ATTR_BIGINT ) ) ); + assert ( is_array ( $values ) ); + + $this->_overrides[$attrname] = array ( "attr"=>$attrname, "type"=>$attrtype, "values"=>$values ); + } + + /// set select-list (attributes or expressions), SQL-like syntax + function SetSelect ( $select ) + { + assert ( is_string ( $select ) ); + $this->_select = $select; + } + + ////////////////////////////////////////////////////////////////////////////// + + /// clear all filters (for multi-queries) + function ResetFilters () + { + $this->_filters = array(); + $this->_anchor = array(); + } + + /// clear groupby settings (for multi-queries) + function ResetGroupBy () + { + $this->_groupby = ""; + $this->_groupfunc = SPH_GROUPBY_DAY; + $this->_groupsort = "@group desc"; + $this->_groupdistinct= ""; + } + + /// clear all attribute value overrides (for multi-queries) + function ResetOverrides () + { + $this->_overrides = array (); + } + + ////////////////////////////////////////////////////////////////////////////// + + /// connect to searchd server, run given search query through given indexes, + /// and return the search results + function Query ( $query, $index="*", $comment="" ) + { + assert ( empty($this->_reqs) ); + + $this->AddQuery ( $query, $index, $comment ); + $results = $this->RunQueries (); + $this->_reqs = array (); // just in case it failed too early + + if ( !is_array($results) ) + return false; // probably network error; error message should be already filled + + $this->_error = $results[0]["error"]; + $this->_warning = $results[0]["warning"]; + if ( $results[0]["status"]==SEARCHD_ERROR ) + return false; + else + return $results[0]; + } + + /// helper to pack floats in network byte order + function _PackFloat ( $f ) + { + $t1 = pack ( "f", $f ); // machine order + list(,$t2) = unpack ( "L*", $t1 ); // int in machine order + return pack ( "N", $t2 ); + } + + /// add query to multi-query batch + /// returns index into results array from RunQueries() call + function AddQuery ( $query, $index="*", $comment="" ) + { + // mbstring workaround + $this->_MBPush (); + + // build request + $req = pack ( "NNNN", $this->_offset, $this->_limit, $this->_mode, $this->_ranker ); + if ( $this->_ranker==SPH_RANK_EXPR ) + $req .= pack ( "N", strlen($this->_rankexpr) ) . $this->_rankexpr; + $req .= pack ( "N", $this->_sort ); // (deprecated) sort mode + $req .= pack ( "N", strlen($this->_sortby) ) . $this->_sortby; + $req .= pack ( "N", strlen($query) ) . $query; // query itself + $req .= pack ( "N", count($this->_weights) ); // weights + foreach ( $this->_weights as $weight ) + $req .= pack ( "N", (int)$weight ); + $req .= pack ( "N", strlen($index) ) . $index; // indexes + $req .= pack ( "N", 1 ); // id64 range marker + $req .= sphPackU64 ( $this->_min_id ) . sphPackU64 ( $this->_max_id ); // id64 range + + // filters + $req .= pack ( "N", count($this->_filters) ); + foreach ( $this->_filters as $filter ) + { + $req .= pack ( "N", strlen($filter["attr"]) ) . $filter["attr"]; + $req .= pack ( "N", $filter["type"] ); + switch ( $filter["type"] ) + { + case SPH_FILTER_VALUES: + $req .= pack ( "N", count($filter["values"]) ); + foreach ( $filter["values"] as $value ) + $req .= sphPackI64 ( $value ); + break; + + case SPH_FILTER_RANGE: + $req .= sphPackI64 ( $filter["min"] ) . sphPackI64 ( $filter["max"] ); + break; + + case SPH_FILTER_FLOATRANGE: + $req .= $this->_PackFloat ( $filter["min"] ) . $this->_PackFloat ( $filter["max"] ); + break; + + default: + assert ( 0 && "internal error: unhandled filter type" ); + } + $req .= pack ( "N", $filter["exclude"] ); + } + + // group-by clause, max-matches count, group-sort clause, cutoff count + $req .= pack ( "NN", $this->_groupfunc, strlen($this->_groupby) ) . $this->_groupby; + $req .= pack ( "N", $this->_maxmatches ); + $req .= pack ( "N", strlen($this->_groupsort) ) . $this->_groupsort; + $req .= pack ( "NNN", $this->_cutoff, $this->_retrycount, $this->_retrydelay ); + $req .= pack ( "N", strlen($this->_groupdistinct) ) . $this->_groupdistinct; + + // anchor point + if ( empty($this->_anchor) ) + { + $req .= pack ( "N", 0 ); + } else + { + $a =& $this->_anchor; + $req .= pack ( "N", 1 ); + $req .= pack ( "N", strlen($a["attrlat"]) ) . $a["attrlat"]; + $req .= pack ( "N", strlen($a["attrlong"]) ) . $a["attrlong"]; + $req .= $this->_PackFloat ( $a["lat"] ) . $this->_PackFloat ( $a["long"] ); + } + + // per-index weights + $req .= pack ( "N", count($this->_indexweights) ); + foreach ( $this->_indexweights as $idx=>$weight ) + $req .= pack ( "N", strlen($idx) ) . $idx . pack ( "N", $weight ); + + // max query time + $req .= pack ( "N", $this->_maxquerytime ); + + // per-field weights + $req .= pack ( "N", count($this->_fieldweights) ); + foreach ( $this->_fieldweights as $field=>$weight ) + $req .= pack ( "N", strlen($field) ) . $field . pack ( "N", $weight ); + + // comment + $req .= pack ( "N", strlen($comment) ) . $comment; + + // attribute overrides + $req .= pack ( "N", count($this->_overrides) ); + foreach ( $this->_overrides as $key => $entry ) + { + $req .= pack ( "N", strlen($entry["attr"]) ) . $entry["attr"]; + $req .= pack ( "NN", $entry["type"], count($entry["values"]) ); + foreach ( $entry["values"] as $id=>$val ) + { + assert ( is_numeric($id) ); + assert ( is_numeric($val) ); + + $req .= sphPackU64 ( $id ); + switch ( $entry["type"] ) + { + case SPH_ATTR_FLOAT: $req .= $this->_PackFloat ( $val ); break; + case SPH_ATTR_BIGINT: $req .= sphPackI64 ( $val ); break; + default: $req .= pack ( "N", $val ); break; + } + } + } + + // select-list + $req .= pack ( "N", strlen($this->_select) ) . $this->_select; + + // mbstring workaround + $this->_MBPop (); + + // store request to requests array + $this->_reqs[] = $req; + return count($this->_reqs)-1; + } + + /// connect to searchd, run queries batch, and return an array of result sets + function RunQueries () + { + if ( empty($this->_reqs) ) + { + $this->_error = "no queries defined, issue AddQuery() first"; + return false; + } + + // mbstring workaround + $this->_MBPush (); + + if (!( $fp = $this->_Connect() )) + { + $this->_MBPop (); + return false; + } + + // send query, get response + $nreqs = count($this->_reqs); + $req = join ( "", $this->_reqs ); + $len = 8+strlen($req); + $req = pack ( "nnNNN", SEARCHD_COMMAND_SEARCH, VER_COMMAND_SEARCH, $len, 0, $nreqs ) . $req; // add header + + if ( !( $this->_Send ( $fp, $req, $len+8 ) ) || + !( $response = $this->_GetResponse ( $fp, VER_COMMAND_SEARCH ) ) ) + { + $this->_MBPop (); + return false; + } + + // query sent ok; we can reset reqs now + $this->_reqs = array (); + + // parse and return response + return $this->_ParseSearchResponse ( $response, $nreqs ); + } + + /// parse and return search query (or queries) response + function _ParseSearchResponse ( $response, $nreqs ) + { + $p = 0; // current position + $max = strlen($response); // max position for checks, to protect against broken responses + + $results = array (); + for ( $ires=0; $ires<$nreqs && $p<$max; $ires++ ) + { + $results[] = array(); + $result =& $results[$ires]; + + $result["error"] = ""; + $result["warning"] = ""; + + // extract status + list(,$status) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $result["status"] = $status; + if ( $status!=SEARCHD_OK ) + { + list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $message = substr ( $response, $p, $len ); $p += $len; + + if ( $status==SEARCHD_WARNING ) + { + $result["warning"] = $message; + } else + { + $result["error"] = $message; + continue; + } + } + + // read schema + $fields = array (); + $attrs = array (); + + list(,$nfields) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + while ( $nfields-->0 && $p<$max ) + { + list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $fields[] = substr ( $response, $p, $len ); $p += $len; + } + $result["fields"] = $fields; + + list(,$nattrs) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + while ( $nattrs-->0 && $p<$max ) + { + list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $attr = substr ( $response, $p, $len ); $p += $len; + list(,$type) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $attrs[$attr] = $type; + } + $result["attrs"] = $attrs; + + // read match count + list(,$count) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + list(,$id64) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + + // read matches + $idx = -1; + while ( $count-->0 && $p<$max ) + { + // index into result array + $idx++; + + // parse document id and weight + if ( $id64 ) + { + $doc = sphUnpackU64 ( substr ( $response, $p, 8 ) ); $p += 8; + list(,$weight) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + } + else + { + list ( $doc, $weight ) = array_values ( unpack ( "N*N*", + substr ( $response, $p, 8 ) ) ); + $p += 8; + $doc = sphFixUint($doc); + } + $weight = sprintf ( "%u", $weight ); + + // create match entry + if ( $this->_arrayresult ) + $result["matches"][$idx] = array ( "id"=>$doc, "weight"=>$weight ); + else + $result["matches"][$doc]["weight"] = $weight; + + // parse and create attributes + $attrvals = array (); + foreach ( $attrs as $attr=>$type ) + { + // handle 64bit ints + if ( $type==SPH_ATTR_BIGINT ) + { + $attrvals[$attr] = sphUnpackI64 ( substr ( $response, $p, 8 ) ); $p += 8; + continue; + } + + // handle floats + if ( $type==SPH_ATTR_FLOAT ) + { + list(,$uval) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + list(,$fval) = unpack ( "f*", pack ( "L", $uval ) ); + $attrvals[$attr] = $fval; + continue; + } + + // handle everything else as unsigned ints + list(,$val) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + if ( $type==SPH_ATTR_MULTI ) + { + $attrvals[$attr] = array (); + $nvalues = $val; + while ( $nvalues-->0 && $p<$max ) + { + list(,$val) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $attrvals[$attr][] = sphFixUint($val); + } + } else if ( $type==SPH_ATTR_MULTI64 ) + { + $attrvals[$attr] = array (); + $nvalues = $val; + while ( $nvalues>0 && $p<$max ) + { + $attrvals[$attr][] = sphUnpackU64 ( substr ( $response, $p, 8 ) ); $p += 8; + $nvalues -= 2; + } + } else if ( $type==SPH_ATTR_STRING ) + { + $attrvals[$attr] = substr ( $response, $p, $val ); + $p += $val; + } else + { + $attrvals[$attr] = sphFixUint($val); + } + } + + if ( $this->_arrayresult ) + $result["matches"][$idx]["attrs"] = $attrvals; + else + $result["matches"][$doc]["attrs"] = $attrvals; + } + + list ( $total, $total_found, $msecs, $words ) = + array_values ( unpack ( "N*N*N*N*", substr ( $response, $p, 16 ) ) ); + $result["total"] = sprintf ( "%u", $total ); + $result["total_found"] = sprintf ( "%u", $total_found ); + $result["time"] = sprintf ( "%.3f", $msecs/1000 ); + $p += 16; + + while ( $words-->0 && $p<$max ) + { + list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $word = substr ( $response, $p, $len ); $p += $len; + list ( $docs, $hits ) = array_values ( unpack ( "N*N*", substr ( $response, $p, 8 ) ) ); $p += 8; + $result["words"][$word] = array ( + "docs"=>sprintf ( "%u", $docs ), + "hits"=>sprintf ( "%u", $hits ) ); + } + } + + $this->_MBPop (); + return $results; + } + + ///////////////////////////////////////////////////////////////////////////// + // excerpts generation + ///////////////////////////////////////////////////////////////////////////// + + /// connect to searchd server, and generate exceprts (snippets) + /// of given documents for given query. returns false on failure, + /// an array of snippets on success + function BuildExcerpts ( $docs, $index, $words, $opts=array() ) + { + assert ( is_array($docs) ); + assert ( is_string($index) ); + assert ( is_string($words) ); + assert ( is_array($opts) ); + + $this->_MBPush (); + + if (!( $fp = $this->_Connect() )) + { + $this->_MBPop(); + return false; + } + + ///////////////// + // fixup options + ///////////////// + + if ( !isset($opts["before_match"]) ) $opts["before_match"] = ""; + if ( !isset($opts["after_match"]) ) $opts["after_match"] = ""; + if ( !isset($opts["chunk_separator"]) ) $opts["chunk_separator"] = " ... "; + if ( !isset($opts["limit"]) ) $opts["limit"] = 256; + if ( !isset($opts["limit_passages"]) ) $opts["limit_passages"] = 0; + if ( !isset($opts["limit_words"]) ) $opts["limit_words"] = 0; + if ( !isset($opts["around"]) ) $opts["around"] = 5; + if ( !isset($opts["exact_phrase"]) ) $opts["exact_phrase"] = false; + if ( !isset($opts["single_passage"]) ) $opts["single_passage"] = false; + if ( !isset($opts["use_boundaries"]) ) $opts["use_boundaries"] = false; + if ( !isset($opts["weight_order"]) ) $opts["weight_order"] = false; + if ( !isset($opts["query_mode"]) ) $opts["query_mode"] = false; + if ( !isset($opts["force_all_words"]) ) $opts["force_all_words"] = false; + if ( !isset($opts["start_passage_id"]) ) $opts["start_passage_id"] = 1; + if ( !isset($opts["load_files"]) ) $opts["load_files"] = false; + if ( !isset($opts["html_strip_mode"]) ) $opts["html_strip_mode"] = "index"; + if ( !isset($opts["allow_empty"]) ) $opts["allow_empty"] = false; + if ( !isset($opts["passage_boundary"]) ) $opts["passage_boundary"] = "none"; + if ( !isset($opts["emit_zones"]) ) $opts["emit_zones"] = false; + if ( !isset($opts["load_files_scattered"]) ) $opts["load_files_scattered"] = false; + + + ///////////////// + // build request + ///////////////// + + // v.1.2 req + $flags = 1; // remove spaces + if ( $opts["exact_phrase"] ) $flags |= 2; + if ( $opts["single_passage"] ) $flags |= 4; + if ( $opts["use_boundaries"] ) $flags |= 8; + if ( $opts["weight_order"] ) $flags |= 16; + if ( $opts["query_mode"] ) $flags |= 32; + if ( $opts["force_all_words"] ) $flags |= 64; + if ( $opts["load_files"] ) $flags |= 128; + if ( $opts["allow_empty"] ) $flags |= 256; + if ( $opts["emit_zones"] ) $flags |= 512; + if ( $opts["load_files_scattered"] ) $flags |= 1024; + $req = pack ( "NN", 0, $flags ); // mode=0, flags=$flags + $req .= pack ( "N", strlen($index) ) . $index; // req index + $req .= pack ( "N", strlen($words) ) . $words; // req words + + // options + $req .= pack ( "N", strlen($opts["before_match"]) ) . $opts["before_match"]; + $req .= pack ( "N", strlen($opts["after_match"]) ) . $opts["after_match"]; + $req .= pack ( "N", strlen($opts["chunk_separator"]) ) . $opts["chunk_separator"]; + $req .= pack ( "NN", (int)$opts["limit"], (int)$opts["around"] ); + $req .= pack ( "NNN", (int)$opts["limit_passages"], (int)$opts["limit_words"], (int)$opts["start_passage_id"] ); // v.1.2 + $req .= pack ( "N", strlen($opts["html_strip_mode"]) ) . $opts["html_strip_mode"]; + $req .= pack ( "N", strlen($opts["passage_boundary"]) ) . $opts["passage_boundary"]; + + // documents + $req .= pack ( "N", count($docs) ); + foreach ( $docs as $doc ) + { + assert ( is_string($doc) ); + $req .= pack ( "N", strlen($doc) ) . $doc; + } + + //////////////////////////// + // send query, get response + //////////////////////////// + + $len = strlen($req); + $req = pack ( "nnN", SEARCHD_COMMAND_EXCERPT, VER_COMMAND_EXCERPT, $len ) . $req; // add header + if ( !( $this->_Send ( $fp, $req, $len+8 ) ) || + !( $response = $this->_GetResponse ( $fp, VER_COMMAND_EXCERPT ) ) ) + { + $this->_MBPop (); + return false; + } + + ////////////////// + // parse response + ////////////////// + + $pos = 0; + $res = array (); + $rlen = strlen($response); + for ( $i=0; $i $rlen ) + { + $this->_error = "incomplete reply"; + $this->_MBPop (); + return false; + } + $res[] = $len ? substr ( $response, $pos, $len ) : ""; + $pos += $len; + } + + $this->_MBPop (); + return $res; + } + + + ///////////////////////////////////////////////////////////////////////////// + // keyword generation + ///////////////////////////////////////////////////////////////////////////// + + /// connect to searchd server, and generate keyword list for a given query + /// returns false on failure, + /// an array of words on success + function BuildKeywords ( $query, $index, $hits ) + { + assert ( is_string($query) ); + assert ( is_string($index) ); + assert ( is_bool($hits) ); + + $this->_MBPush (); + + if (!( $fp = $this->_Connect() )) + { + $this->_MBPop(); + return false; + } + + ///////////////// + // build request + ///////////////// + + // v.1.0 req + $req = pack ( "N", strlen($query) ) . $query; // req query + $req .= pack ( "N", strlen($index) ) . $index; // req index + $req .= pack ( "N", (int)$hits ); + + //////////////////////////// + // send query, get response + //////////////////////////// + + $len = strlen($req); + $req = pack ( "nnN", SEARCHD_COMMAND_KEYWORDS, VER_COMMAND_KEYWORDS, $len ) . $req; // add header + if ( !( $this->_Send ( $fp, $req, $len+8 ) ) || + !( $response = $this->_GetResponse ( $fp, VER_COMMAND_KEYWORDS ) ) ) + { + $this->_MBPop (); + return false; + } + + ////////////////// + // parse response + ////////////////// + + $pos = 0; + $res = array (); + $rlen = strlen($response); + list(,$nwords) = unpack ( "N*", substr ( $response, $pos, 4 ) ); + $pos += 4; + for ( $i=0; $i<$nwords; $i++ ) + { + list(,$len) = unpack ( "N*", substr ( $response, $pos, 4 ) ); $pos += 4; + $tokenized = $len ? substr ( $response, $pos, $len ) : ""; + $pos += $len; + + list(,$len) = unpack ( "N*", substr ( $response, $pos, 4 ) ); $pos += 4; + $normalized = $len ? substr ( $response, $pos, $len ) : ""; + $pos += $len; + + $res[] = array ( "tokenized"=>$tokenized, "normalized"=>$normalized ); + + if ( $hits ) + { + list($ndocs,$nhits) = array_values ( unpack ( "N*N*", substr ( $response, $pos, 8 ) ) ); + $pos += 8; + $res [$i]["docs"] = $ndocs; + $res [$i]["hits"] = $nhits; + } + + if ( $pos > $rlen ) + { + $this->_error = "incomplete reply"; + $this->_MBPop (); + return false; + } + } + + $this->_MBPop (); + return $res; + } + + function EscapeString ( $string ) + { + $from = array ( '\\', '(',')','|','-','!','@','~','"','&', '/', '^', '$', '=' ); + $to = array ( '\\\\', '\(','\)','\|','\-','\!','\@','\~','\"', '\&', '\/', '\^', '\$', '\=' ); + + return str_replace ( $from, $to, $string ); + } + + ///////////////////////////////////////////////////////////////////////////// + // attribute updates + ///////////////////////////////////////////////////////////////////////////// + + /// batch update given attributes in given rows in given indexes + /// returns amount of updated documents (0 or more) on success, or -1 on failure + function UpdateAttributes ( $index, $attrs, $values, $mva=false ) + { + // verify everything + assert ( is_string($index) ); + assert ( is_bool($mva) ); + + assert ( is_array($attrs) ); + foreach ( $attrs as $attr ) + assert ( is_string($attr) ); + + assert ( is_array($values) ); + foreach ( $values as $id=>$entry ) + { + assert ( is_numeric($id) ); + assert ( is_array($entry) ); + assert ( count($entry)==count($attrs) ); + foreach ( $entry as $v ) + { + if ( $mva ) + { + assert ( is_array($v) ); + foreach ( $v as $vv ) + assert ( is_int($vv) ); + } else + assert ( is_int($v) ); + } + } + + // build request + $this->_MBPush (); + $req = pack ( "N", strlen($index) ) . $index; + + $req .= pack ( "N", count($attrs) ); + foreach ( $attrs as $attr ) + { + $req .= pack ( "N", strlen($attr) ) . $attr; + $req .= pack ( "N", $mva ? 1 : 0 ); + } + + $req .= pack ( "N", count($values) ); + foreach ( $values as $id=>$entry ) + { + $req .= sphPackU64 ( $id ); + foreach ( $entry as $v ) + { + $req .= pack ( "N", $mva ? count($v) : $v ); + if ( $mva ) + foreach ( $v as $vv ) + $req .= pack ( "N", $vv ); + } + } + + // connect, send query, get response + if (!( $fp = $this->_Connect() )) + { + $this->_MBPop (); + return -1; + } + + $len = strlen($req); + $req = pack ( "nnN", SEARCHD_COMMAND_UPDATE, VER_COMMAND_UPDATE, $len ) . $req; // add header + if ( !$this->_Send ( $fp, $req, $len+8 ) ) + { + $this->_MBPop (); + return -1; + } + + if (!( $response = $this->_GetResponse ( $fp, VER_COMMAND_UPDATE ) )) + { + $this->_MBPop (); + return -1; + } + + // parse response + list(,$updated) = unpack ( "N*", substr ( $response, 0, 4 ) ); + $this->_MBPop (); + return $updated; + } + + ///////////////////////////////////////////////////////////////////////////// + // persistent connections + ///////////////////////////////////////////////////////////////////////////// + + function Open() + { + if ( $this->_socket !== false ) + { + $this->_error = 'already connected'; + return false; + } + if ( !$fp = $this->_Connect() ) + return false; + + // command, command version = 0, body length = 4, body = 1 + $req = pack ( "nnNN", SEARCHD_COMMAND_PERSIST, 0, 4, 1 ); + if ( !$this->_Send ( $fp, $req, 12 ) ) + return false; + + $this->_socket = $fp; + return true; + } + + function Close() + { + if ( $this->_socket === false ) + { + $this->_error = 'not connected'; + return false; + } + + fclose ( $this->_socket ); + $this->_socket = false; + + return true; + } + + ////////////////////////////////////////////////////////////////////////// + // status + ////////////////////////////////////////////////////////////////////////// + + function Status () + { + $this->_MBPush (); + if (!( $fp = $this->_Connect() )) + { + $this->_MBPop(); + return false; + } + + $req = pack ( "nnNN", SEARCHD_COMMAND_STATUS, VER_COMMAND_STATUS, 4, 1 ); // len=4, body=1 + if ( !( $this->_Send ( $fp, $req, 12 ) ) || + !( $response = $this->_GetResponse ( $fp, VER_COMMAND_STATUS ) ) ) + { + $this->_MBPop (); + return false; + } + + $res = substr ( $response, 4 ); // just ignore length, error handling, etc + $p = 0; + list ( $rows, $cols ) = array_values ( unpack ( "N*N*", substr ( $response, $p, 8 ) ) ); $p += 8; + + $res = array(); + for ( $i=0; $i<$rows; $i++ ) + for ( $j=0; $j<$cols; $j++ ) + { + list(,$len) = unpack ( "N*", substr ( $response, $p, 4 ) ); $p += 4; + $res[$i][] = substr ( $response, $p, $len ); $p += $len; + } + + $this->_MBPop (); + return $res; + } + + ////////////////////////////////////////////////////////////////////////// + // flush + ////////////////////////////////////////////////////////////////////////// + + function FlushAttributes () + { + $this->_MBPush (); + if (!( $fp = $this->_Connect() )) + { + $this->_MBPop(); + return -1; + } + + $req = pack ( "nnN", SEARCHD_COMMAND_FLUSHATTRS, VER_COMMAND_FLUSHATTRS, 0 ); // len=0 + if ( !( $this->_Send ( $fp, $req, 8 ) ) || + !( $response = $this->_GetResponse ( $fp, VER_COMMAND_FLUSHATTRS ) ) ) + { + $this->_MBPop (); + return -1; + } + + $tag = -1; + if ( strlen($response)==4 ) + list(,$tag) = unpack ( "N*", $response ); + else + $this->_error = "unexpected response length"; + + $this->_MBPop (); + return $tag; + } +} + +// +// $Id: sphinxapi.php 3087 2012-01-30 23:07:35Z shodan $ +// -- 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 6dee2539419ba2c050830b7677294603a63b559a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Dec 2012 17:01:08 -0600 Subject: [ticket/11259] Make phpbb_admin_path available everywhere PHPBB3-11259 --- phpBB/includes/db/dbal.php | 4 ++-- phpBB/includes/functions.php | 4 ++-- phpBB/includes/functions_install.php | 3 +++ phpBB/includes/ucp/ucp_groups.php | 6 +++--- 4 files changed, 10 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php index ef1dd7d14d..c2708b09b2 100644 --- a/phpBB/includes/db/dbal.php +++ b/phpBB/includes/db/dbal.php @@ -822,7 +822,7 @@ class dbal */ function sql_report($mode, $query = '') { - global $cache, $starttime, $phpbb_root_path, $user; + global $cache, $starttime, $phpbb_root_path, $phpbb_admin_path, $user; global $request; if (is_object($request) && !$request->variable('explain', false)) @@ -852,7 +852,7 @@ class dbal SQL Report - +
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index e492f97022..5fa5c5f505 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5339,7 +5339,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 function page_footer($run_cron = true, $display_template = true, $exit_handler = true) { global $db, $config, $template, $user, $auth, $cache, $starttime, $phpbb_root_path, $phpEx; - global $request, $phpbb_dispatcher; + global $request, $phpbb_dispatcher, $phpbb_admin_path; // A listener can set this variable to `true` when it overrides this function $page_footer_override = false; @@ -5395,7 +5395,7 @@ function page_footer($run_cron = true, $display_template = true, $exit_handler = 'TRANSLATION_INFO' => (!empty($user->lang['TRANSLATION_INFO'])) ? $user->lang['TRANSLATION_INFO'] : '', 'CREDIT_LINE' => $user->lang('POWERED_BY', 'phpBB® Forum Software © phpBB Group'), - 'U_ACP' => ($auth->acl_get('a_') && !empty($user->data['is_registered'])) ? append_sid("{$phpbb_root_path}adm/index.$phpEx", false, true, $user->session_id) : '') + 'U_ACP' => ($auth->acl_get('a_') && !empty($user->data['is_registered'])) ? append_sid("{$phpbb_admin_path}index.$phpEx", false, true, $user->session_id) : '') ); // Call cron-type script diff --git a/phpBB/includes/functions_install.php b/phpBB/includes/functions_install.php index ab6b3ea009..1218ac401b 100644 --- a/phpBB/includes/functions_install.php +++ b/phpBB/includes/functions_install.php @@ -515,6 +515,9 @@ function phpbb_create_config_file_data($data, $dbms, $debug = false, $debug_test 'dbuser' => $data['dbuser'], 'dbpasswd' => htmlspecialchars_decode($data['dbpasswd']), 'table_prefix' => $data['table_prefix'], + + 'adm_relative_path' => 'adm/', + 'acm_type' => 'phpbb_cache_driver_file', ); diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 9652986cf2..d92aea91f8 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -25,7 +25,7 @@ class ucp_groups function main($id, $mode) { - global $config, $phpbb_root_path, $phpEx; + global $config, $phpbb_root_path, $phpEx, $phpbb_admin_path; global $db, $user, $auth, $cache, $template; global $request; @@ -438,7 +438,7 @@ class ucp_groups $group_name = $group_row['group_name']; $group_type = $group_row['group_type']; - $avatar_img = (!empty($group_row['group_avatar'])) ? get_user_avatar($group_row['group_avatar'], $group_row['group_avatar_type'], $group_row['group_avatar_width'], $group_row['group_avatar_height'], 'GROUP_AVATAR') : ''; + $avatar_img = (!empty($group_row['group_avatar'])) ? get_user_avatar($group_row['group_avatar'], $group_row['group_avatar_type'], $group_row['group_avatar_width'], $group_row['group_avatar_height'], 'GROUP_AVATAR') : ''; $template->assign_vars(array( 'GROUP_NAME' => ($group_type == GROUP_SPECIAL) ? $user->lang['G_' . $group_name] : $group_name, @@ -730,7 +730,7 @@ class ucp_groups 'GROUP_CLOSED' => $type_closed, 'GROUP_HIDDEN' => $type_hidden, - 'U_SWATCH' => append_sid("{$phpbb_root_path}adm/swatch.$phpEx", 'form=ucp&name=group_colour'), + 'U_SWATCH' => append_sid("{$phpbb_admin_path}swatch.$phpEx", 'form=ucp&name=group_colour'), 'S_UCP_ACTION' => $this->u_action . "&action=$action&g=$group_id", 'L_AVATAR_EXPLAIN' => phpbb_avatar_explanation_string(), )); -- cgit v1.2.1 From bff76f9ca81e30a03f116669645774ebd49ba1b1 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Dec 2012 17:05:12 -0600 Subject: [ticket/11259] Also make adm_relative_path available in the container PHPBB3-11259 --- phpBB/includes/di/extension/config.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/di/extension/config.php b/phpBB/includes/di/extension/config.php index fb5ca90070..bb3c04637a 100644 --- a/phpBB/includes/di/extension/config.php +++ b/phpBB/includes/di/extension/config.php @@ -42,6 +42,7 @@ class phpbb_di_extension_config extends Extension { require($this->config_file); + $container->setParameter('core.adm_relative_path', (isset($adm_relative_path) ? $adm_relative_path : 'adm/')); $container->setParameter('core.table_prefix', $table_prefix); $container->setParameter('cache.driver.class', $this->fix_acm_type($acm_type)); $container->setParameter('dbal.driver.class', 'dbal_'.$dbms); -- cgit v1.2.1 From 30de17f69f70a0c23fa314de479bac57e3dbae2b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 9 Dec 2012 19:29:51 -0600 Subject: [ticket/11259] adm_relative_path -> phpbb_adm_relative_path We can assume they properly format their config settings, right? PHPBB3-11259 --- phpBB/includes/di/extension/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/di/extension/config.php b/phpBB/includes/di/extension/config.php index bb3c04637a..59b4c66870 100644 --- a/phpBB/includes/di/extension/config.php +++ b/phpBB/includes/di/extension/config.php @@ -42,7 +42,7 @@ class phpbb_di_extension_config extends Extension { require($this->config_file); - $container->setParameter('core.adm_relative_path', (isset($adm_relative_path) ? $adm_relative_path : 'adm/')); + $container->setParameter('core.adm_relative_path', (isset($phpbb_adm_relative_path) ? $phpbb_adm_relative_path : 'adm/')); $container->setParameter('core.table_prefix', $table_prefix); $container->setParameter('cache.driver.class', $this->fix_acm_type($acm_type)); $container->setParameter('dbal.driver.class', 'dbal_'.$dbms); -- cgit v1.2.1 From 61391f648c95251466f805f148f1656e940f2027 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 10 Dec 2012 21:16:08 -0600 Subject: [ticket/11259] htmlspecialchars($phpbb_admin_path) PHPBB3-11259 --- phpBB/includes/acp/acp_ranks.php | 14 +++++++------- phpBB/includes/db/dbal.php | 2 +- phpBB/includes/functions_acp.php | 20 ++++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_ranks.php b/phpBB/includes/acp/acp_ranks.php index d9ed5b17f1..6b06d03f52 100644 --- a/phpBB/includes/acp/acp_ranks.php +++ b/phpBB/includes/acp/acp_ranks.php @@ -71,7 +71,7 @@ class acp_ranks 'rank_min' => $min_posts, 'rank_image' => htmlspecialchars_decode($rank_image) ); - + if ($rank_id) { $sql = 'UPDATE ' . RANKS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE rank_id = $rank_id"; @@ -122,7 +122,7 @@ class acp_ranks $cache->destroy('_ranks'); add_log('admin', 'LOG_RANK_REMOVED', $rank_title); - + if ($request->is_ajax()) { $json_response = new phpbb_json_response; @@ -151,7 +151,7 @@ class acp_ranks case 'add': $data = $ranks = $existing_imgs = array(); - + $sql = 'SELECT * FROM ' . RANKS_TABLE . ' ORDER BY rank_min ASC, rank_special ASC'; @@ -209,17 +209,17 @@ class acp_ranks 'RANK_TITLE' => (isset($ranks['rank_title'])) ? $ranks['rank_title'] : '', 'S_FILENAME_LIST' => $filename_list, - 'RANK_IMAGE' => ($edit_img) ? $phpbb_root_path . $config['ranks_path'] . '/' . $edit_img : $phpbb_admin_path . 'images/spacer.gif', + 'RANK_IMAGE' => ($edit_img) ? $phpbb_root_path . $config['ranks_path'] . '/' . $edit_img : htmlspecialchars($phpbb_admin_path) . 'images/spacer.gif', 'S_SPECIAL_RANK' => (isset($ranks['rank_special']) && $ranks['rank_special']) ? true : false, 'MIN_POSTS' => (isset($ranks['rank_min']) && !$ranks['rank_special']) ? $ranks['rank_min'] : 0) ); - + return; break; } - + $template->assign_vars(array( 'U_ACTION' => $this->u_action) ); @@ -241,7 +241,7 @@ class acp_ranks 'U_EDIT' => $this->u_action . '&action=edit&id=' . $row['rank_id'], 'U_DELETE' => $this->u_action . '&action=delete&id=' . $row['rank_id']) - ); + ); } $db->sql_freeresult($result); diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php index c2708b09b2..c6a3638f9f 100644 --- a/phpBB/includes/db/dbal.php +++ b/phpBB/includes/db/dbal.php @@ -852,7 +852,7 @@ class dbal SQL Report - +
diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index 2f3fd7bac0..32fd76e74d 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -82,16 +82,16 @@ function adm_page_header($page_title) 'T_RANKS_PATH' => "{$phpbb_root_path}{$config['ranks_path']}/", 'T_UPLOAD_PATH' => "{$phpbb_root_path}{$config['upload_path']}/", - 'ICON_MOVE_UP' => '' . $user->lang['MOVE_UP'] . '', - 'ICON_MOVE_UP_DISABLED' => '' . $user->lang['MOVE_UP'] . '', - 'ICON_MOVE_DOWN' => '' . $user->lang['MOVE_DOWN'] . '', - 'ICON_MOVE_DOWN_DISABLED' => '' . $user->lang['MOVE_DOWN'] . '', - 'ICON_EDIT' => '' . $user->lang['EDIT'] . '', - 'ICON_EDIT_DISABLED' => '' . $user->lang['EDIT'] . '', - 'ICON_DELETE' => '' . $user->lang['DELETE'] . '', - 'ICON_DELETE_DISABLED' => '' . $user->lang['DELETE'] . '', - 'ICON_SYNC' => '' . $user->lang['RESYNC'] . '', - 'ICON_SYNC_DISABLED' => '' . $user->lang['RESYNC'] . '', + 'ICON_MOVE_UP' => '' . $user->lang['MOVE_UP'] . '', + 'ICON_MOVE_UP_DISABLED' => '' . $user->lang['MOVE_UP'] . '', + 'ICON_MOVE_DOWN' => '' . $user->lang['MOVE_DOWN'] . '', + 'ICON_MOVE_DOWN_DISABLED' => '' . $user->lang['MOVE_DOWN'] . '', + 'ICON_EDIT' => '' . $user->lang['EDIT'] . '', + 'ICON_EDIT_DISABLED' => '' . $user->lang['EDIT'] . '', + 'ICON_DELETE' => '' . $user->lang['DELETE'] . '', + 'ICON_DELETE_DISABLED' => '' . $user->lang['DELETE'] . '', + 'ICON_SYNC' => '' . $user->lang['RESYNC'] . '', + 'ICON_SYNC_DISABLED' => '' . $user->lang['RESYNC'] . '', 'S_USER_LANG' => $user->lang['USER_LANG'], 'S_CONTENT_DIRECTION' => $user->lang['DIRECTION'], -- 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 5c496674f63b31e892d0f3bed7921feb947ed839 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 15 Dec 2012 01:19:55 -0500 Subject: [ticket/10758] Dependency inject parameters into cache_moderators. Also add phpbb prefix since the signature is being changed anyway. PHPBB3-10758 --- phpBB/includes/acp/acp_forums.php | 6 +++--- phpBB/includes/acp/acp_main.php | 18 +++++++++--------- phpBB/includes/acp/acp_permissions.php | 16 ++++++++-------- phpBB/includes/acp/acp_styles.php | 4 +++- phpBB/includes/functions_admin.php | 14 +++++++++----- phpBB/includes/functions_user.php | 12 ++++++------ 6 files changed, 38 insertions(+), 32 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index c6dbf5eb9c..7e8d5d8388 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -206,7 +206,7 @@ class acp_forums ($action != 'edit' || empty($forum_id) || ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth')))) { copy_forum_permissions($forum_perm_from, $forum_data['forum_id'], ($action == 'edit') ? true : false); - cache_moderators(); + phpbb_cache_moderators($db, $cache, $auth); $copied_permissions = true; } /* Commented out because of questionable UI workflow - re-visit for 3.0.7 @@ -266,7 +266,7 @@ class acp_forums add_log('admin', 'LOG_FORUM_' . strtoupper($action), $row['forum_name'], $move_forum_name); $cache->destroy('sql', FORUMS_TABLE); } - + if ($request->is_ajax()) { $json_response = new phpbb_json_response; @@ -768,7 +768,7 @@ class acp_forums if (!empty($forum_perm_from) && $forum_perm_from != $forum_id) { copy_forum_permissions($forum_perm_from, $forum_id, true); - cache_moderators(); + phpbb_cache_moderators($db, $cache, $auth); $auth->acl_clear_prefetch(); $cache->destroy('sql', FORUMS_TABLE); diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php index d419bc3b99..c44bc1b8a6 100644 --- a/phpBB/includes/acp/acp_main.php +++ b/phpBB/includes/acp/acp_main.php @@ -24,7 +24,7 @@ class acp_main function main($id, $mode) { - global $config, $db, $user, $auth, $template, $request; + global $config, $db, $cache, $user, $auth, $template, $request; global $phpbb_root_path, $phpbb_admin_path, $phpEx; // Show restore permissions notice @@ -129,7 +129,7 @@ class acp_main set_config('record_online_users', 1, true); set_config('record_online_date', time(), true); add_log('admin', 'LOG_RESET_ONLINE'); - + if ($request->is_ajax()) { trigger_error('RESET_ONLINE_SUCCESS'); @@ -184,7 +184,7 @@ class acp_main update_last_username(); add_log('admin', 'LOG_RESYNC_STATS'); - + if ($request->is_ajax()) { trigger_error('RESYNC_STATS_SUCCESS'); @@ -251,7 +251,7 @@ class acp_main } add_log('admin', 'LOG_RESYNC_POSTCOUNTS'); - + if ($request->is_ajax()) { trigger_error('RESYNC_POSTCOUNTS_SUCCESS'); @@ -266,7 +266,7 @@ class acp_main set_config('board_startdate', time() - 1); add_log('admin', 'LOG_RESET_DATE'); - + if ($request->is_ajax()) { trigger_error('RESET_DATE_SUCCESS'); @@ -346,7 +346,7 @@ class acp_main } add_log('admin', 'LOG_RESYNC_POST_MARKING'); - + if ($request->is_ajax()) { trigger_error('RESYNC_POST_MARKING_SUCCESS'); @@ -359,10 +359,10 @@ class acp_main // Clear permissions $auth->acl_clear_prefetch(); - cache_moderators(); + phpbb_cache_moderators($db, $cache, $auth); add_log('admin', 'LOG_PURGE_CACHE'); - + if ($request->is_ajax()) { trigger_error('PURGE_CACHE_SUCCESS'); @@ -413,7 +413,7 @@ class acp_main $db->sql_query($sql); add_log('admin', 'LOG_PURGE_SESSIONS'); - + if ($request->is_ajax()) { trigger_error('PURGE_SESSIONS_SUCCESS'); diff --git a/phpBB/includes/acp/acp_permissions.php b/phpBB/includes/acp/acp_permissions.php index dd071074de..d65a9cbb9e 100644 --- a/phpBB/includes/acp/acp_permissions.php +++ b/phpBB/includes/acp/acp_permissions.php @@ -656,7 +656,7 @@ class acp_permissions */ function set_permissions($mode, $permission_type, &$auth_admin, &$user_id, &$group_id) { - global $user, $auth; + global $db, $cache, $user, $auth; global $request; $psubmit = request_var('psubmit', array(0 => array(0 => 0))); @@ -726,7 +726,7 @@ class acp_permissions // Do we need to recache the moderator lists? if ($permission_type == 'm_') { - cache_moderators(); + phpbb_cache_moderators($db, $cache, $auth); } // Remove users who are now moderators or admins from everyones foes list @@ -745,7 +745,7 @@ class acp_permissions */ function set_all_permissions($mode, $permission_type, &$auth_admin, &$user_id, &$group_id) { - global $user, $auth; + global $db, $cache, $user, $auth; global $request; // User or group to be set? @@ -794,7 +794,7 @@ class acp_permissions // Do we need to recache the moderator lists? if ($permission_type == 'm_') { - cache_moderators(); + phpbb_cache_moderators($db, $cache, $auth); } // Remove users who are now moderators or admins from everyones foes list @@ -858,7 +858,7 @@ class acp_permissions */ function remove_permissions($mode, $permission_type, &$auth_admin, &$user_id, &$group_id, &$forum_id) { - global $user, $db, $auth; + global $user, $db, $cache, $auth; // User or group to be set? $ug_type = (sizeof($user_id)) ? 'user' : 'group'; @@ -874,7 +874,7 @@ class acp_permissions // Do we need to recache the moderator lists? if ($permission_type == 'm_') { - cache_moderators(); + phpbb_cache_moderators($db, $cache, $auth); } $this->log_action($mode, 'del', $permission_type, $ug_type, (($ug_type == 'user') ? $user_id : $group_id), (sizeof($forum_id) ? $forum_id : array(0 => 0))); @@ -1172,7 +1172,7 @@ class acp_permissions */ function copy_forum_permissions() { - global $auth, $cache, $template, $user; + global $db, $auth, $cache, $template, $user; $user->add_lang('acp/forums'); @@ -1187,7 +1187,7 @@ class acp_permissions { if (copy_forum_permissions($src, $dest)) { - cache_moderators(); + phpbb_cache_moderators($db, $cache, $auth); $auth->acl_clear_prefetch(); $cache->destroy('sql', FORUMS_TABLE); diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index db77825ae7..266495972b 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -137,11 +137,13 @@ class acp_styles */ protected function action_cache() { + global $db, $cache, $auth; + $this->cache->purge(); // Clear permissions $this->auth->acl_clear_prefetch(); - cache_moderators(); + phpbb_cache_moderators($db, $cache, $auth); add_log('admin', 'LOG_PURGE_CACHE'); diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 15930f9a2c..571f1acd1d 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2292,13 +2292,17 @@ function auto_prune($forum_id, $prune_mode, $prune_flags, $prune_days, $prune_fr } /** -* Cache moderators, called whenever permissions are changed via admin_permissions. Changes of username -* and group names must be carried through for the moderators table +* Cache moderators. Called whenever permissions are changed +* via admin_permissions. Changes of usernames and group names +* must be carried through for the moderators table +* +* @param phpbb_db_driver $db Database connection +* @param phpbb_cache_driver_interface Cache driver +* @param phpbb_auth $auth Authentication object +* @return null */ -function cache_moderators() +function phpbb_cache_moderators($db, $cache, $auth) { - global $db, $cache, $auth, $phpbb_root_path, $phpEx; - // Remove cached sql results $cache->destroy('sql', MODERATOR_CACHE_TABLE); diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 8f9c9198f4..2d6c15a5b1 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2842,7 +2842,7 @@ function avatar_remove_db($avatar_name) */ function group_delete($group_id, $group_name = false) { - global $db, $phpbb_root_path, $phpEx, $phpbb_dispatcher; + global $db, $cache, $auth, $phpbb_root_path, $phpEx, $phpbb_dispatcher; if (!$group_name) { @@ -2913,12 +2913,12 @@ function group_delete($group_id, $group_name = false) extract($phpbb_dispatcher->trigger_event('core.delete_group_after', compact($vars))); // Re-cache moderators - if (!function_exists('cache_moderators')) + if (!function_exists('phpbb_cache_moderators')) { include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); } - cache_moderators(); + phpbb_cache_moderators($db, $cache, $auth); add_log('admin', 'LOG_GROUP_DELETE', $group_name); @@ -3678,7 +3678,7 @@ function group_memberships($group_id_ary = false, $user_id_ary = false, $return_ */ function group_update_listings($group_id) { - global $auth; + global $db, $cache, $auth; $hold_ary = $auth->acl_group_raw_data($group_id, array('a_', 'm_')); @@ -3720,12 +3720,12 @@ function group_update_listings($group_id) if ($mod_permissions) { - if (!function_exists('cache_moderators')) + if (!function_exists('phpbb_cache_moderators')) { global $phpbb_root_path, $phpEx; include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); } - cache_moderators(); + phpbb_cache_moderators($db, $cache, $auth); } if ($mod_permissions || $admin_permissions) -- cgit v1.2.1 From e82833d4b8bc9241641577b12a779e12338ace39 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 15 Dec 2012 01:29:10 -0500 Subject: [ticket/10758] Dependency inject parameters into update_foes. Also add phpbb prefix since the signature is being changed anyway. PHPBB3-10758 --- phpBB/includes/acp/acp_permissions.php | 4 ++-- phpBB/includes/functions_admin.php | 12 ++++++++---- phpBB/includes/functions_user.php | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_permissions.php b/phpBB/includes/acp/acp_permissions.php index d65a9cbb9e..3d4c256a3f 100644 --- a/phpBB/includes/acp/acp_permissions.php +++ b/phpBB/includes/acp/acp_permissions.php @@ -732,7 +732,7 @@ class acp_permissions // Remove users who are now moderators or admins from everyones foes list if ($permission_type == 'm_' || $permission_type == 'a_') { - update_foes($group_id, $user_id); + phpbb_update_foes($db, $auth, $group_id, $user_id); } $this->log_action($mode, 'add', $permission_type, $ug_type, $ug_id, $forum_id); @@ -800,7 +800,7 @@ class acp_permissions // Remove users who are now moderators or admins from everyones foes list if ($permission_type == 'm_' || $permission_type == 'a_') { - update_foes($group_id, $user_id); + phpbb_update_foes($db, $auth, $group_id, $user_id); } $this->log_action($mode, 'add', $permission_type, $ug_type, $ug_ids, $forum_ids); diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 571f1acd1d..e8dd55813b 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2744,12 +2744,16 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id } /** -* Update foes - remove moderators and administrators from foe lists... +* Removes moderators and administrators from foe lists. +* +* @param phpbb_db_driver $db Database connection +* @param phpbb_auth $auth Authentication object +* @param array|bool $group_id If an array, remove all members of this group from foe lists, or false to ignore +* @param array|bool $user_id If an array, remove this user from foe lists, or false to ignore +* @return null */ -function update_foes($group_id = false, $user_id = false) +function phpbb_update_foes($db, $auth, $group_id = false, $user_id = false) { - global $db, $auth; - // update foes for some user if (is_array($user_id) && sizeof($user_id)) { diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 2d6c15a5b1..a50d5175fe 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3730,12 +3730,12 @@ function group_update_listings($group_id) if ($mod_permissions || $admin_permissions) { - if (!function_exists('update_foes')) + if (!function_exists('phpbb_update_foes')) { global $phpbb_root_path, $phpEx; include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); } - update_foes(array($group_id)); + phpbb_update_foes($db, $auth, array($group_id)); } } -- cgit v1.2.1 From 9e7d663e7638bac9add20d82467b8008e5c83e3b Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 15 Dec 2012 14:09:33 -0500 Subject: [ticket/10758] Spelling fix. PHPBB3-10758 --- phpBB/includes/auth/auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/auth/auth.php b/phpBB/includes/auth/auth.php index e3bccaf47b..1ad9f94d26 100644 --- a/phpBB/includes/auth/auth.php +++ b/phpBB/includes/auth/auth.php @@ -191,7 +191,7 @@ class phpbb_auth /** * Get forums with the specified permission setting - * if the option is prefixed with !, then the result becomes nagated + * if the option is prefixed with !, then the result becomes negated * * @param bool $clean set to true if only values needs to be returned which are set/unset */ -- 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 9a1df948c635d9dbabaff94313652c6d8d1df28d Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 19 Dec 2012 21:50:03 -0500 Subject: [ticket/10758] Extract obtain_user_data for the benefit of tests. PHPBB3-10758 --- phpBB/includes/acp/acp_permissions.php | 7 +------ phpBB/includes/auth/auth.php | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_permissions.php b/phpBB/includes/acp/acp_permissions.php index 3d4c256a3f..a64765f4f5 100644 --- a/phpBB/includes/acp/acp_permissions.php +++ b/phpBB/includes/acp/acp_permissions.php @@ -952,12 +952,7 @@ class acp_permissions if ($user_id != $user->data['user_id']) { - $sql = 'SELECT user_id, username, user_permissions, user_type - FROM ' . USERS_TABLE . ' - WHERE user_id = ' . $user_id; - $result = $db->sql_query($sql); - $userdata = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + $userdata = $auth->obtain_user_data($user_id); } else { diff --git a/phpBB/includes/auth/auth.php b/phpBB/includes/auth/auth.php index 1ad9f94d26..2535247571 100644 --- a/phpBB/includes/auth/auth.php +++ b/phpBB/includes/auth/auth.php @@ -102,6 +102,26 @@ class phpbb_auth return; } + /** + * Retrieves data wanted by acl function from the database for the + * specified user. + * + * @param int $user_id User ID + * @return array User attributes + */ + public function obtain_user_data($user_id) + { + global $db; + + $sql = 'SELECT user_id, username, user_permissions, user_type + FROM ' . USERS_TABLE . ' + WHERE user_id = ' . $user_id; + $result = $db->sql_query($sql); + $user_data = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + return $user_data; + } + /** * Fill ACL array with relevant bitstrings from user_permissions column * @access private -- cgit v1.2.1 From 69e373c1af09e10722c1146f44493e8dc3669918 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 19 Dec 2012 21:47:53 -0500 Subject: [ticket/10758] Add compat functions. PHPBB3-10758 --- phpBB/includes/functions_admin.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index e8dd55813b..496d3eba09 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2472,6 +2472,20 @@ function phpbb_cache_moderators($db, $cache, $auth) $db->sql_multi_insert(MODERATOR_CACHE_TABLE, $sql_ary); } +/** +* Cache moderators. Called whenever permissions are changed +* via admin_permissions. Changes of usernames and group names +* must be carried through for the moderators table +* +* @return null +*/ +function cache_moderators() +{ + global $db, $cache, $auth; + return phpbb_cache_moderators($db, $cache, $auth); +} + + /** * View log * If $log_count is set to false, we will skip counting all entries in the database. @@ -2862,6 +2876,19 @@ function phpbb_update_foes($db, $auth, $group_id = false, $user_id = false) unset($perms); } +/** +* Removes moderators and administrators from foe lists. +* +* @param array|bool $group_id If an array, remove all members of this group from foe lists, or false to ignore +* @param array|bool $user_id If an array, remove this user from foe lists, or false to ignore +* @return null +*/ +function update_foes($group_id = false, $user_id = false) +{ + global $db, $auth; + phpbb_update_foes($db, $auth, $group_id, $user_id); +} + /** * Lists inactive users */ -- cgit v1.2.1 From e50f69187f21e29a12512880e0c69f2876e84aa1 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 20 Dec 2012 04:35:30 -0500 Subject: [ticket/11037] Eliminate global $db usage in cache drivers. The only time $db is needed in cache drivers is to navigate the result set in sql_save. Pass it as a parameter in that function. PHPBB3-11037 --- phpBB/includes/cache/driver/file.php | 6 ++---- phpBB/includes/cache/driver/interface.php | 3 ++- phpBB/includes/cache/driver/memory.php | 6 ++---- phpBB/includes/cache/driver/null.php | 4 ++-- phpBB/includes/db/driver/firebird.php | 2 +- phpBB/includes/db/driver/mssql.php | 2 +- phpBB/includes/db/driver/mssql_odbc.php | 2 +- phpBB/includes/db/driver/mssqlnative.php | 2 +- phpBB/includes/db/driver/mysql.php | 2 +- phpBB/includes/db/driver/mysqli.php | 2 +- phpBB/includes/db/driver/oracle.php | 2 +- phpBB/includes/db/driver/postgres.php | 2 +- phpBB/includes/db/driver/sqlite.php | 2 +- 13 files changed, 17 insertions(+), 20 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php index 691abe0438..85decbe3e8 100644 --- a/phpBB/includes/cache/driver/file.php +++ b/phpBB/includes/cache/driver/file.php @@ -367,12 +367,10 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base } /** - * Save sql query + * {@inheritDoc} */ - function sql_save($query, $query_result, $ttl) + function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl) { - global $db; - // Remove extra spaces and tabs $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); diff --git a/phpBB/includes/cache/driver/interface.php b/phpBB/includes/cache/driver/interface.php index d403bbcd71..53f684d1c8 100644 --- a/phpBB/includes/cache/driver/interface.php +++ b/phpBB/includes/cache/driver/interface.php @@ -85,6 +85,7 @@ interface phpbb_cache_driver_interface * result to persistent storage. In other words, there is no need * to call save() afterwards. * + * @param phpbb_db_driver $db Database connection * @param string $query SQL query, should be used for generating storage key * @param mixed $query_result The result from dbal::sql_query, to be passed to * dbal::sql_fetchrow to get all rows and store them @@ -95,7 +96,7 @@ interface phpbb_cache_driver_interface * representing the query should be returned. Otherwise * the original $query_result should be returned. */ - public function sql_save($query, $query_result, $ttl); + public function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl); /** * Check if result for a given SQL query exists in cache. diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index c39f9f7850..f77a1df316 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -283,12 +283,10 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base } /** - * Save sql query + * {@inheritDoc} */ - function sql_save($query, $query_result, $ttl) + function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl) { - global $db; - // Remove extra spaces and tabs $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); $hash = md5($query); diff --git a/phpBB/includes/cache/driver/null.php b/phpBB/includes/cache/driver/null.php index 687604d14f..2fadc27ba3 100644 --- a/phpBB/includes/cache/driver/null.php +++ b/phpBB/includes/cache/driver/null.php @@ -105,9 +105,9 @@ class phpbb_cache_driver_null extends phpbb_cache_driver_base } /** - * Save sql query + * {@inheritDoc} */ - function sql_save($query, $query_result, $ttl) + function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl) { return $query_result; } diff --git a/phpBB/includes/db/driver/firebird.php b/phpBB/includes/db/driver/firebird.php index a55175c345..4767b29f63 100644 --- a/phpBB/includes/db/driver/firebird.php +++ b/phpBB/includes/db/driver/firebird.php @@ -270,7 +270,7 @@ class phpbb_db_driver_firebird extends phpbb_db_driver if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/driver/mssql.php b/phpBB/includes/db/driver/mssql.php index ac957e7698..215c6345c6 100644 --- a/phpBB/includes/db/driver/mssql.php +++ b/phpBB/includes/db/driver/mssql.php @@ -168,7 +168,7 @@ class phpbb_db_driver_mssql extends phpbb_db_driver if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/driver/mssql_odbc.php b/phpBB/includes/db/driver/mssql_odbc.php index 13e74e66d4..7d93f939a2 100644 --- a/phpBB/includes/db/driver/mssql_odbc.php +++ b/phpBB/includes/db/driver/mssql_odbc.php @@ -197,7 +197,7 @@ class phpbb_db_driver_mssql_odbc extends phpbb_db_driver if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/driver/mssqlnative.php b/phpBB/includes/db/driver/mssqlnative.php index 4b1639aba2..f88c702d07 100644 --- a/phpBB/includes/db/driver/mssqlnative.php +++ b/phpBB/includes/db/driver/mssqlnative.php @@ -337,7 +337,7 @@ class phpbb_db_driver_mssqlnative extends phpbb_db_driver if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/driver/mysql.php b/phpBB/includes/db/driver/mysql.php index 6fc6fab483..30f78c9231 100644 --- a/phpBB/includes/db/driver/mysql.php +++ b/phpBB/includes/db/driver/mysql.php @@ -206,7 +206,7 @@ class phpbb_db_driver_mysql extends phpbb_db_driver if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/driver/mysqli.php b/phpBB/includes/db/driver/mysqli.php index be28a95715..4f45c5781c 100644 --- a/phpBB/includes/db/driver/mysqli.php +++ b/phpBB/includes/db/driver/mysqli.php @@ -201,7 +201,7 @@ class phpbb_db_driver_mysqli extends phpbb_db_driver if ($cache_ttl) { - $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); } } else if (defined('DEBUG')) diff --git a/phpBB/includes/db/driver/oracle.php b/phpBB/includes/db/driver/oracle.php index 6263ea8414..53f9dd71e0 100644 --- a/phpBB/includes/db/driver/oracle.php +++ b/phpBB/includes/db/driver/oracle.php @@ -446,7 +446,7 @@ class phpbb_db_driver_oracle extends phpbb_db_driver if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/driver/postgres.php b/phpBB/includes/db/driver/postgres.php index 147ecd04d9..cca97c9c0e 100644 --- a/phpBB/includes/db/driver/postgres.php +++ b/phpBB/includes/db/driver/postgres.php @@ -211,7 +211,7 @@ class phpbb_db_driver_postgres extends phpbb_db_driver if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { diff --git a/phpBB/includes/db/driver/sqlite.php b/phpBB/includes/db/driver/sqlite.php index 6b9cc64d89..155409b665 100644 --- a/phpBB/includes/db/driver/sqlite.php +++ b/phpBB/includes/db/driver/sqlite.php @@ -152,7 +152,7 @@ class phpbb_db_driver_sqlite extends phpbb_db_driver if ($cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; - $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); + $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { -- cgit v1.2.1 From 5c817289834e7a34d47410f89907de1bafefff8a Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 20 Dec 2012 05:10:57 -0500 Subject: [ticket/10758] Add deprecated tags. PHPBB3-10758 --- phpBB/includes/functions_admin.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 496d3eba09..77c70eb6fc 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2477,6 +2477,7 @@ function phpbb_cache_moderators($db, $cache, $auth) * via admin_permissions. Changes of usernames and group names * must be carried through for the moderators table * +* @deprecated 3.1 * @return null */ function cache_moderators() @@ -2879,6 +2880,7 @@ function phpbb_update_foes($db, $auth, $group_id = false, $user_id = false) /** * Removes moderators and administrators from foe lists. * +* @deprecated 3.1 * @param array|bool $group_id If an array, remove all members of this group from foe lists, or false to ignore * @param array|bool $user_id If an array, remove this user from foe lists, or false to ignore * @return null -- cgit v1.2.1 From aaaf8a5332aa6679522c687f0c8144d0819c05a5 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 22 Dec 2012 17:40:25 -0500 Subject: [ticket/10758] Yes, only one empty line. PHPBB3-10758 --- phpBB/includes/functions_admin.php | 1 - 1 file changed, 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 77c70eb6fc..22735cf2cd 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2486,7 +2486,6 @@ function cache_moderators() return phpbb_cache_moderators($db, $cache, $auth); } - /** * View log * If $log_count is set to false, we will skip counting all entries in the database. -- cgit v1.2.1 From 496529fa714b6cdc6e8b8ffeb7750fe27907c267 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 22 Dec 2012 17:54:54 -0500 Subject: [ticket/10758] Add periods. PHPBB3-10758 --- 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 22735cf2cd..3864c9de36 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2294,7 +2294,7 @@ function auto_prune($forum_id, $prune_mode, $prune_flags, $prune_days, $prune_fr /** * Cache moderators. Called whenever permissions are changed * via admin_permissions. Changes of usernames and group names -* must be carried through for the moderators table +* must be carried through for the moderators table. * * @param phpbb_db_driver $db Database connection * @param phpbb_cache_driver_interface Cache driver @@ -2475,7 +2475,7 @@ function phpbb_cache_moderators($db, $cache, $auth) /** * Cache moderators. Called whenever permissions are changed * via admin_permissions. Changes of usernames and group names -* must be carried through for the moderators table +* must be carried through for the moderators table. * * @deprecated 3.1 * @return null -- cgit v1.2.1 From cac39360669b10c7a27549ca36865249014e6d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fre=CC=80rejean?= Date: Thu, 20 Dec 2012 16:27:33 +0100 Subject: [ticket/11283] Extension manager follow symlinks. All extensions are located in the `phpBB/ext` directory, however the `phpbb_extension_manager::all_available()` method only looks into actual directories and ignores symlinks. Add the `RecursiveDirectoryIterator::FOLLOW_SYMLINKS` flag to the `new RecursiveDirectoryIterator` call so that you can store extensions in a different location and use symlinks so that phpBB can recognise them. PHPBB3-11283 --- phpBB/includes/extension/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 67cc81e407..de6f364320 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -384,7 +384,7 @@ class phpbb_extension_manager } $iterator = new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($this->phpbb_root_path . 'ext/'), + new RecursiveDirectoryIterator($this->phpbb_root_path . 'ext/', FilesystemIterator::NEW_CURRENT_AND_KEY | FilesystemIterator::FOLLOW_SYMLINKS), RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $file_info) { -- cgit v1.2.1 From 5056f162351420440bf989d0b1cfc6c325499f7a Mon Sep 17 00:00:00 2001 From: Martin Beckmann Date: Mon, 24 Dec 2012 03:53:54 +0100 Subject: [ticket/11292] Fix: Newlines removed in display of PM reports Report text is run through make_clickable and bbcode_nl2br for PMs just as it is for posts. PHPBB3-11292 --- phpBB/includes/mcp/mcp_pm_reports.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_pm_reports.php b/phpBB/includes/mcp/mcp_pm_reports.php index 72f77fae7c..77bc7680e6 100644 --- a/phpBB/includes/mcp/mcp_pm_reports.php +++ b/phpBB/includes/mcp/mcp_pm_reports.php @@ -123,6 +123,7 @@ class mcp_pm_reports $message = bbcode_nl2br($message); $message = smiley_text($message); + $report['report_text'] = make_clickable(bbcode_nl2br($report['report_text'])); if ($pm_info['message_attachment'] && $auth->acl_get('u_pm_download')) { -- cgit v1.2.1 From 8707a3413504b0cf922086daa6fc497ccf090448 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 24 Dec 2012 15:12:57 -0500 Subject: [ticket/10758] Add return to the other compat function. PHPBB3-10758 --- 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 3864c9de36..5529f2af46 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2887,7 +2887,7 @@ function phpbb_update_foes($db, $auth, $group_id = false, $user_id = false) function update_foes($group_id = false, $user_id = false) { global $db, $auth; - phpbb_update_foes($db, $auth, $group_id, $user_id); + return phpbb_update_foes($db, $auth, $group_id, $user_id); } /** -- cgit v1.2.1 From 0b47a7823a8c48e31442595d4c802ae7f77096f3 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 24 Dec 2012 15:36:43 -0500 Subject: [ticket/11037] Eliminate globals from cache service. PHPBB3-11037 --- phpBB/includes/cache/service.php | 76 ++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 42 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cache/service.php b/phpBB/includes/cache/service.php index e63ec6e33a..0768236f3d 100644 --- a/phpBB/includes/cache/service.php +++ b/phpBB/includes/cache/service.php @@ -21,16 +21,24 @@ if (!defined('IN_PHPBB')) */ class phpbb_cache_service { - private $driver; + protected $driver; + protected $config; + protected $db; + protected $phpbb_root_path; + protected $php_ext; /** * Creates a cache service around a cache driver * * @param phpbb_cache_driver_interface $driver The cache driver */ - public function __construct(phpbb_cache_driver_interface $driver = null) + public function __construct(phpbb_cache_driver_interface $driver, phpbb_config $config, phpbb_db_driver $db, $phpbb_root_path, $php_ext) { $this->set_driver($driver); + $this->config = $config; + $this->db = $db; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; } /** @@ -64,21 +72,19 @@ class phpbb_cache_service */ function obtain_word_list() { - global $db; - if (($censors = $this->driver->get('_word_censors')) === false) { $sql = 'SELECT word, replacement FROM ' . WORDS_TABLE; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); $censors = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $censors['match'][] = get_censor_preg_expression($row['word']); $censors['replace'][] = $row['replacement']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); $this->driver->put('_word_censors', $censors); } @@ -93,23 +99,21 @@ class phpbb_cache_service { if (($icons = $this->driver->get('_icons')) === false) { - global $db; - // Topic icons $sql = 'SELECT * FROM ' . ICONS_TABLE . ' ORDER BY icons_order'; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); $icons = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $icons[$row['icons_id']]['img'] = $row['icons_url']; $icons[$row['icons_id']]['width'] = (int) $row['icons_width']; $icons[$row['icons_id']]['height'] = (int) $row['icons_height']; $icons[$row['icons_id']]['display'] = (bool) $row['display_on_posting']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); $this->driver->put('_icons', $icons); } @@ -124,15 +128,13 @@ class phpbb_cache_service { if (($ranks = $this->driver->get('_ranks')) === false) { - global $db; - $sql = 'SELECT * FROM ' . RANKS_TABLE . ' ORDER BY rank_min DESC'; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); $ranks = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { if ($row['rank_special']) { @@ -150,7 +152,7 @@ class phpbb_cache_service ); } } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); $this->driver->put('_ranks', $ranks); } @@ -169,8 +171,6 @@ class phpbb_cache_service { if (($extensions = $this->driver->get('_extensions')) === false) { - global $db; - $extensions = array( '_allowed_post' => array(), '_allowed_pm' => array(), @@ -181,9 +181,9 @@ class phpbb_cache_service FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g WHERE e.group_id = g.group_id AND (g.allow_group = 1 OR g.allow_in_pm = 1)'; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $extension = strtolower(trim($row['extension'])); @@ -210,7 +210,7 @@ class phpbb_cache_service $extensions['_allowed_pm'][$extension] = 0; } } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); $this->driver->put('_extensions', $extensions); } @@ -275,9 +275,7 @@ class phpbb_cache_service { if (($bots = $this->driver->get('_bots')) === false) { - global $db; - - switch ($db->sql_layer) + switch ($this->db->sql_layer) { case 'mssql': case 'mssql_odbc': @@ -303,14 +301,14 @@ class phpbb_cache_service ORDER BY LENGTH(bot_agent) DESC'; break; } - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); $bots = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $bots[] = $row; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); $this->driver->put('_bots', $bots); } @@ -323,8 +321,6 @@ class phpbb_cache_service */ function obtain_cfg_items($style) { - global $config, $phpbb_root_path; - $parsed_array = $this->driver->get('_cfg_' . $style['style_path']); if ($parsed_array === false) @@ -332,14 +328,14 @@ class phpbb_cache_service $parsed_array = array(); } - $filename = $phpbb_root_path . 'styles/' . $style['style_path'] . '/style.cfg'; + $filename = $this->phpbb_root_path . 'styles/' . $style['style_path'] . '/style.cfg'; if (!file_exists($filename)) { return $parsed_array; } - if (!isset($parsed_array['filetime']) || (($config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime']))) + if (!isset($parsed_array['filetime']) || (($this->config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime']))) { // Re-parse cfg file $parsed_array = parse_cfg_file($filename); @@ -358,18 +354,16 @@ class phpbb_cache_service { if (($usernames = $this->driver->get('_disallowed_usernames')) === false) { - global $db; - $sql = 'SELECT disallow_username FROM ' . DISALLOW_TABLE; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); $usernames = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $usernames[] = str_replace('%', '.*?', preg_quote(utf8_clean_string($row['disallow_username']), '#')); } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); $this->driver->put('_disallowed_usernames', $usernames); } @@ -382,22 +376,20 @@ class phpbb_cache_service */ function obtain_hooks() { - global $phpbb_root_path, $phpEx; - if (($hook_files = $this->driver->get('_hooks')) === false) { $hook_files = array(); // Now search for hooks... - $dh = @opendir($phpbb_root_path . 'includes/hooks/'); + $dh = @opendir($this->phpbb_root_path . 'includes/hooks/'); if ($dh) { while (($file = readdir($dh)) !== false) { - if (strpos($file, 'hook_') === 0 && substr($file, -(strlen($phpEx) + 1)) === '.' . $phpEx) + if (strpos($file, 'hook_') === 0 && substr($file, -(strlen($this->php_ext) + 1)) === '.' . $this->php_ext) { - $hook_files[] = substr($file, 0, -(strlen($phpEx) + 1)); + $hook_files[] = substr($file, 0, -(strlen($this->php_ext) + 1)); } } closedir($dh); -- cgit v1.2.1 From 989c4c3e6408e0d53b042161cfb34a0befe2570c Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 25 Dec 2012 00:11:34 -0500 Subject: [ticket/11293] Add a note that mysqli should be in front of mysql. php 5.5 alpha 2 deprecated mysql extension, prefer mysqli if both are available. PHPBB3-11293 --- phpBB/includes/functions_install.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_install.php b/phpBB/includes/functions_install.php index eae136808c..47f4eac627 100644 --- a/phpBB/includes/functions_install.php +++ b/phpBB/includes/functions_install.php @@ -55,6 +55,8 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20 'AVAILABLE' => true, '2.0.x' => false, ), + // Note: php 5.5 alpha 2 deprecated mysql. + // Keep mysqli before mysql in this list. 'mysqli' => array( 'LABEL' => 'MySQL with MySQLi Extension', 'SCHEMA' => 'mysql_41', -- cgit v1.2.1 From bad7661ee985e63b8765845d710367e9f4f8260b Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 26 Dec 2012 10:47:03 -0500 Subject: [ticket/11037] Add/update docblocks. PHPBB3-11037 --- phpBB/includes/cache/service.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/cache/service.php b/phpBB/includes/cache/service.php index 0768236f3d..8c1e1ea1f8 100644 --- a/phpBB/includes/cache/service.php +++ b/phpBB/includes/cache/service.php @@ -21,16 +21,49 @@ if (!defined('IN_PHPBB')) */ class phpbb_cache_service { + /** + * Cache driver. + * + * @var phpbb_cache_driver_interface + */ protected $driver; + + /** + * The config. + * + * @var phpbb_config + */ protected $config; + + /** + * Database connection. + * + * @var phpbb_db_driver + */ protected $db; + + /** + * Root path. + * + * @var string + */ protected $phpbb_root_path; + + /** + * PHP extension. + * + * @var string + */ protected $php_ext; /** * Creates a cache service around a cache driver * * @param phpbb_cache_driver_interface $driver The cache driver + * @param phpbb_config $config The config + * @param phpbb_db_driver $db Database connection + * @param string $phpbb_root_path Root path + * @param string $php_ext PHP extension */ public function __construct(phpbb_cache_driver_interface $driver, phpbb_config $config, phpbb_db_driver $db, $phpbb_root_path, $php_ext) { -- 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 979edc4113f8b9ecb3aa4e7d445a5b59eefd78ff Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 3 Dec 2012 00:48:19 +0530 Subject: [ticket/11188] add count query to postgres search PHPBB3-11188 --- phpBB/includes/search/fulltext_postgres.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index f22ee2ca16..a9b122931b 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -476,6 +476,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $tmp_sql_match[] = "to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', " . $sql_match_column . ") @@ to_tsquery ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', '" . $this->db->sql_escape($this->tsearch_query) . "')"; } + $this->db->sql_transaction('begin'); $sql = "SELECT $sql_select FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p WHERE (" . implode(' OR ', $tmp_sql_match) . ") @@ -499,7 +500,13 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base // if the total result count is not cached yet, retrieve it from the db if (!$result_count) { - $result_count = sizeof ($id_ary); + $sql_count = "SELECT COUNT(*) as result_count + FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p + WHERE (" . implode(' OR ', $tmp_sql_match) . ") + $sql_where_options"; + $result = $this->db->sql_query($sql_count); + $result_count = (int) $this->db->sql_fetchfield('result_count'); + $this->db->sql_freeresult($result); if (!$result_count) { @@ -507,6 +514,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base } } + $this->db->sql_transaction('commit'); + // store the ids, from start on then delete anything that isn't on the current page because we only need ids for one page $this->save_ids($search_key, implode(' ', $this->split_words), $author_ary, $result_count, $id_ary, $start, $sort_dir); $id_ary = array_slice($id_ary, 0, (int) $per_page); -- cgit v1.2.1 From 763f2929babcb65b503a60f712bfc552f1e296f9 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 3 Dec 2012 01:07:47 +0530 Subject: [ticket/11188] add result count query for author search PHPBB3-11188 --- phpBB/includes/search/fulltext_postgres.php | 34 ++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index a9b122931b..7d7b3f6fa8 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -656,6 +656,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $field = 'topic_id'; } + $this->db->sql_transaction('begin'); + // Only read one block of posts from the db and then cache it $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); @@ -668,7 +670,35 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base // retrieve the total result count if needed if (!$result_count) { - $result_count = sizeof ($id_ary); + if ($type == 'posts') + { + $sql_count = "SELECT COUNT(*) as result_count + FROM " . $sql_sort_table . POSTS_TABLE . ' p' . (($firstpost_only) ? ', ' . TOPICS_TABLE . ' t ' : ' ') . " + WHERE $sql_author + $sql_topic_id + $sql_firstpost + $m_approve_fid_sql + $sql_fora + $sql_sort_join + $sql_time"; + } + else + { + $sql_count = "SELECT COUNT(*) as result_count + FROM " . $sql_sort_table . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p + WHERE $sql_author + $sql_topic_id + $sql_firstpost + $m_approve_fid_sql + $sql_fora + AND t.topic_id = p.topic_id + $sql_sort_join + $sql_time + GROUP BY t.topic_id, $sort_by_sql[$sort_key]"; + } + + $result = $this->db->sql_query($sql_count); + $result_count = (int) $this->db->sql_fetchfield('result_count'); if (!$result_count) { @@ -676,6 +706,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base } } + $this->db->sql_transaction('commit'); + if (sizeof($id_ary)) { $this->save_ids($search_key, '', $author_ary, $result_count, $id_ary, $start, $sort_dir); -- cgit v1.2.1 From 3d27ed13f5ac960fc24a3f95e39c767be4a48f31 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 29 Dec 2012 19:34:21 -0500 Subject: [ticket/11188] Reduce waste. PHPBB3-11188 --- phpBB/includes/search/fulltext_postgres.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index 7d7b3f6fa8..1475cc31d0 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -477,10 +477,13 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base } $this->db->sql_transaction('begin'); + + $sql_from = "FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p"; + $sql_where = "WHERE (" . implode(' OR ', $tmp_sql_match) . ") + $sql_where_options"; $sql = "SELECT $sql_select - FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p - WHERE (" . implode(' OR ', $tmp_sql_match) . ") - $sql_where_options + $sql_from + $sql_where ORDER BY $sql_sort"; $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); @@ -501,9 +504,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base if (!$result_count) { $sql_count = "SELECT COUNT(*) as result_count - FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p - WHERE (" . implode(' OR ', $tmp_sql_match) . ") - $sql_where_options"; + $sql_from + $sql_where"; $result = $this->db->sql_query($sql_count); $result_count = (int) $this->db->sql_fetchfield('result_count'); $this->db->sql_freeresult($result); -- cgit v1.2.1 From ea24de8de3e4f451aa4394f0f46d6955ccb671c2 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 2 Jan 2013 04:04:01 +0100 Subject: [ticket/11306] Introduce phpbb_create_default_container Extracts default container construction to factory function, removing boilerplate duplication for container construction. PHPBB3-11306 --- phpBB/includes/functions_container.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_container.php b/phpBB/includes/functions_container.php index 8014574443..0634948002 100644 --- a/phpBB/includes/functions_container.php +++ b/phpBB/includes/functions_container.php @@ -135,6 +135,22 @@ function phpbb_create_dumped_container_unless_debug(array $extensions, array $pa return $container_factory($extensions, $passes, $phpbb_root_path, $php_ext); } +function phpbb_create_default_container($phpbb_root_path, $php_ext) +{ + return phpbb_create_dumped_container_unless_debug( + array( + new phpbb_di_extension_config($phpbb_root_path . 'config.' . $php_ext), + new phpbb_di_extension_core($phpbb_root_path), + ), + array( + new phpbb_di_pass_collection_pass(), + new phpbb_di_pass_kernel_pass(), + ), + $phpbb_root_path, + $php_ext + ); +} + function phpbb_container_filename($phpbb_root_path, $php_ext) { $filename = str_replace(array('/', '.'), array('slash', 'dot'), $phpbb_root_path); -- cgit v1.2.1 From 21eb8d842bc634a92f04c37e5de22c4c5692052d Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 2 Jan 2013 06:41:20 +0100 Subject: [ticket/11306] Add docblocks to all container related functions PHPBB3-11306 --- phpBB/includes/functions_container.php | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_container.php b/phpBB/includes/functions_container.php index 0634948002..a3ed21c35b 100644 --- a/phpBB/includes/functions_container.php +++ b/phpBB/includes/functions_container.php @@ -105,6 +105,15 @@ function phpbb_create_compiled_container(array $extensions, array $passes, $phpb return $container; } +/** +* Create a compiled and dumped ContainerBuilder object +* +* @param array $extensions Array of Container extension objects +* @param array $passes Array of Compiler Pass objects +* @param string $phpbb_root_path Root path +* @param string $php_ext PHP Extension +* @return ContainerBuilder object (compiled) +*/ function phpbb_create_dumped_container(array $extensions, array $passes, $phpbb_root_path, $php_ext) { // Check for our cached container; if it exists, use it @@ -129,12 +138,37 @@ function phpbb_create_dumped_container(array $extensions, array $passes, $phpbb_ return $container; } +/** +* Create an environment-specific ContainerBuilder object +* +* If debug is enabled, the container is re-compiled every time. +* This ensures that the latest changes will always be reflected +* during development. +* +* Otherwise it will get the existing dumped container and use +* that one instead. +* +* @param array $extensions Array of Container extension objects +* @param array $passes Array of Compiler Pass objects +* @param string $phpbb_root_path Root path +* @param string $php_ext PHP Extension +* @return ContainerBuilder object (compiled) +*/ function phpbb_create_dumped_container_unless_debug(array $extensions, array $passes, $phpbb_root_path, $php_ext) { $container_factory = defined('DEBUG') ? 'phpbb_create_compiled_container' : 'phpbb_create_dumped_container'; return $container_factory($extensions, $passes, $phpbb_root_path, $php_ext); } +/** +* Create a default ContainerBuilder object +* +* Contains the default configuration of the phpBB container. +* +* @param array $extensions Array of Container extension objects +* @param array $passes Array of Compiler Pass objects +* @return ContainerBuilder object (compiled) +*/ function phpbb_create_default_container($phpbb_root_path, $php_ext) { return phpbb_create_dumped_container_unless_debug( @@ -151,6 +185,13 @@ function phpbb_create_default_container($phpbb_root_path, $php_ext) ); } +/** +* Get the filename under which the dumped container will be stored. +* +* @param string $phpbb_root_path Root path +* @param string $php_ext PHP Extension +* @return Path for dumped container +*/ function phpbb_container_filename($phpbb_root_path, $php_ext) { $filename = str_replace(array('/', '.'), array('slash', 'dot'), $phpbb_root_path); -- cgit v1.2.1 From 7adae349a96d5dffbd47ea5eca1e6bee481b7ce1 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 1 Jan 2013 20:48:04 -0500 Subject: [ticket/11305] Extract hook finder from cache service. Unlike most other things in cache service, hook finder does not need a database connection. PHPBB3-11305 --- phpBB/includes/cache/service.php | 30 -------------- phpBB/includes/hook/finder.php | 84 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 30 deletions(-) create mode 100644 phpBB/includes/hook/finder.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/cache/service.php b/phpBB/includes/cache/service.php index 8c1e1ea1f8..69c5e0fdd0 100644 --- a/phpBB/includes/cache/service.php +++ b/phpBB/includes/cache/service.php @@ -403,34 +403,4 @@ class phpbb_cache_service return $usernames; } - - /** - * Obtain hooks... - */ - function obtain_hooks() - { - if (($hook_files = $this->driver->get('_hooks')) === false) - { - $hook_files = array(); - - // Now search for hooks... - $dh = @opendir($this->phpbb_root_path . 'includes/hooks/'); - - if ($dh) - { - while (($file = readdir($dh)) !== false) - { - if (strpos($file, 'hook_') === 0 && substr($file, -(strlen($this->php_ext) + 1)) === '.' . $this->php_ext) - { - $hook_files[] = substr($file, 0, -(strlen($this->php_ext) + 1)); - } - } - closedir($dh); - } - - $this->driver->put('_hooks', $hook_files); - } - - return $hook_files; - } } diff --git a/phpBB/includes/hook/finder.php b/phpBB/includes/hook/finder.php new file mode 100644 index 0000000000..065e685514 --- /dev/null +++ b/phpBB/includes/hook/finder.php @@ -0,0 +1,84 @@ +phpbb_root_path = $phpbb_root_path; + $this->cache = $cache; + $this->php_ext = $php_ext; + } + + /** + * Finds all hook files. + * + * @param bool $cache Whether the result should be cached + * @return array An array of paths to found hook files + */ + public function find($cache = true) + { + if (!defined('DEBUG') && $cache && $this->cache) + { + $hook_files = $this->cache->get('_hooks'); + if ($hook_files !== false) + { + return $hook_files; + } + } + + $hook_files = array(); + + // Now search for hooks... + $dh = @opendir($this->phpbb_root_path . 'includes/hooks/'); + + if ($dh) + { + while (($file = readdir($dh)) !== false) + { + if (strpos($file, 'hook_') === 0 && substr($file, -(strlen($this->php_ext) + 1)) === '.' . $this->php_ext) + { + $hook_files[] = substr($file, 0, -(strlen($this->php_ext) + 1)); + } + } + closedir($dh); + } + + if ($cache && $this->cache) + { + $this->cache->put('_hooks', $hook_files); + } + + return $hook_files; + } +} -- cgit v1.2.1 From b94f9ae3029777fa0aba2f3cb52b321925ce7e72 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 1 Jan 2013 20:57:21 -0500 Subject: [ticket/11305] Retrieve cache driver from container rather than cache service. This only covers some of the call sites. PHPBB3-11305 --- phpBB/includes/acp/acp_modules.php | 6 +++--- phpBB/includes/functions_user.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_modules.php b/phpBB/includes/acp/acp_modules.php index 8528dc91c4..52a82004e8 100644 --- a/phpBB/includes/acp/acp_modules.php +++ b/phpBB/includes/acp/acp_modules.php @@ -740,15 +740,15 @@ class acp_modules */ function remove_cache_file() { - global $cache; + global $phpbb_container; // Sanitise for future path use, it's escaped as appropriate for queries $p_class = str_replace(array('.', '/', '\\'), '', basename($this->module_class)); - $cache->destroy('_modules_' . $p_class); + $phpbb_container->get('cache.driver')->destroy('_modules_' . $p_class); // Additionally remove sql cache - $cache->destroy('sql', MODULES_TABLE); + $phpbb_container->get('cache.driver')->destroy('sql', MODULES_TABLE); } /** diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index a50d5175fe..6abcdee8f2 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3463,7 +3463,7 @@ function group_validate_groupname($group_id, $group_name) */ function group_set_user_default($group_id, $user_id_ary, $group_attributes = false, $update_listing = false) { - global $cache, $db, $phpbb_dispatcher; + global $phpbb_container, $db, $phpbb_dispatcher; if (empty($user_id_ary)) { @@ -3579,7 +3579,7 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal } // Because some tables/caches use usercolour-specific data we need to purge this here. - $cache->destroy('sql', MODERATOR_CACHE_TABLE); + $phpbb_container->get('cache.driver')->destroy('sql', MODERATOR_CACHE_TABLE); } /** -- cgit v1.2.1 From c8c6eb46ec6eefe0e58aebcd44f4c69f5df4b065 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 2 Jan 2013 14:36:14 -0500 Subject: [ticket/11305] Check for $cache being null before using it in db drivers. There is no reason why db drivers must have a cache to work. They query the database, that part works without caches. PHPBB3-11305 --- phpBB/includes/db/driver/driver.php | 4 ++-- phpBB/includes/db/driver/firebird.php | 8 ++++---- phpBB/includes/db/driver/mssql.php | 10 +++++----- phpBB/includes/db/driver/mssql_odbc.php | 8 ++++---- phpBB/includes/db/driver/mssqlnative.php | 2 +- phpBB/includes/db/driver/mysql.php | 10 +++++----- phpBB/includes/db/driver/mysqli.php | 10 +++++----- phpBB/includes/db/driver/oracle.php | 10 +++++----- phpBB/includes/db/driver/postgres.php | 10 +++++----- phpBB/includes/db/driver/sqlite.php | 10 +++++----- 10 files changed, 41 insertions(+), 41 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/driver/driver.php b/phpBB/includes/db/driver/driver.php index 52ac21a79f..8dda94bc2c 100644 --- a/phpBB/includes/db/driver/driver.php +++ b/phpBB/includes/db/driver/driver.php @@ -206,7 +206,7 @@ class phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -256,7 +256,7 @@ class phpbb_db_driver $this->sql_rowseek($rownum, $query_id); } - if (!is_object($query_id) && $cache->sql_exists($query_id)) + if ($cache && !is_object($query_id) && $cache->sql_exists($query_id)) { return $cache->sql_fetchfield($query_id, $field); } diff --git a/phpBB/includes/db/driver/firebird.php b/phpBB/includes/db/driver/firebird.php index 4767b29f63..787c28b812 100644 --- a/phpBB/includes/db/driver/firebird.php +++ b/phpBB/includes/db/driver/firebird.php @@ -154,7 +154,7 @@ class phpbb_db_driver_firebird extends phpbb_db_driver } $this->last_query_text = $query; - $this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false; + $this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -267,7 +267,7 @@ class phpbb_db_driver_firebird extends phpbb_db_driver } } - if ($cache_ttl) + if ($cache && $cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); @@ -330,7 +330,7 @@ class phpbb_db_driver_firebird extends phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -396,7 +396,7 @@ class phpbb_db_driver_firebird extends phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/driver/mssql.php b/phpBB/includes/db/driver/mssql.php index 215c6345c6..89c2c2351b 100644 --- a/phpBB/includes/db/driver/mssql.php +++ b/phpBB/includes/db/driver/mssql.php @@ -150,7 +150,7 @@ class phpbb_db_driver_mssql extends phpbb_db_driver $this->sql_report('start', $query); } - $this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false; + $this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -165,7 +165,7 @@ class phpbb_db_driver_mssql extends phpbb_db_driver $this->sql_report('stop', $query); } - if ($cache_ttl) + if ($cache && $cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); @@ -240,7 +240,7 @@ class phpbb_db_driver_mssql extends phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -277,7 +277,7 @@ class phpbb_db_driver_mssql extends phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -316,7 +316,7 @@ class phpbb_db_driver_mssql extends phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/driver/mssql_odbc.php b/phpBB/includes/db/driver/mssql_odbc.php index 7d93f939a2..f7834443eb 100644 --- a/phpBB/includes/db/driver/mssql_odbc.php +++ b/phpBB/includes/db/driver/mssql_odbc.php @@ -179,7 +179,7 @@ class phpbb_db_driver_mssql_odbc extends phpbb_db_driver } $this->last_query_text = $query; - $this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false; + $this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -194,7 +194,7 @@ class phpbb_db_driver_mssql_odbc extends phpbb_db_driver $this->sql_report('stop', $query); } - if ($cache_ttl) + if ($cache && $cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); @@ -270,7 +270,7 @@ class phpbb_db_driver_mssql_odbc extends phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -311,7 +311,7 @@ class phpbb_db_driver_mssql_odbc extends phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/driver/mssqlnative.php b/phpBB/includes/db/driver/mssqlnative.php index f88c702d07..656cbd2437 100644 --- a/phpBB/includes/db/driver/mssqlnative.php +++ b/phpBB/includes/db/driver/mssqlnative.php @@ -317,7 +317,7 @@ class phpbb_db_driver_mssqlnative extends phpbb_db_driver } $this->last_query_text = $query; - $this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false; + $this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) diff --git a/phpBB/includes/db/driver/mysql.php b/phpBB/includes/db/driver/mysql.php index 30f78c9231..9de7283a42 100644 --- a/phpBB/includes/db/driver/mysql.php +++ b/phpBB/includes/db/driver/mysql.php @@ -188,7 +188,7 @@ class phpbb_db_driver_mysql extends phpbb_db_driver $this->sql_report('start', $query); } - $this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false; + $this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -203,7 +203,7 @@ class phpbb_db_driver_mysql extends phpbb_db_driver $this->sql_report('stop', $query); } - if ($cache_ttl) + if ($cache && $cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); @@ -265,7 +265,7 @@ class phpbb_db_driver_mysql extends phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -286,7 +286,7 @@ class phpbb_db_driver_mysql extends phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -314,7 +314,7 @@ class phpbb_db_driver_mysql extends phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/driver/mysqli.php b/phpBB/includes/db/driver/mysqli.php index 4f45c5781c..7448bf1670 100644 --- a/phpBB/includes/db/driver/mysqli.php +++ b/phpBB/includes/db/driver/mysqli.php @@ -184,7 +184,7 @@ class phpbb_db_driver_mysqli extends phpbb_db_driver $this->sql_report('start', $query); } - $this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false; + $this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -199,7 +199,7 @@ class phpbb_db_driver_mysqli extends phpbb_db_driver $this->sql_report('stop', $query); } - if ($cache_ttl) + if ($cache && $cache_ttl) { $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); } @@ -256,7 +256,7 @@ class phpbb_db_driver_mysqli extends phpbb_db_driver $query_id = $this->query_result; } - if (!is_object($query_id) && $cache->sql_exists($query_id)) + if ($cache && !is_object($query_id) && $cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -283,7 +283,7 @@ class phpbb_db_driver_mysqli extends phpbb_db_driver $query_id = $this->query_result; } - if (!is_object($query_id) && $cache->sql_exists($query_id)) + if ($cache && !is_object($query_id) && $cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -311,7 +311,7 @@ class phpbb_db_driver_mysqli extends phpbb_db_driver $query_id = $this->query_result; } - if (!is_object($query_id) && $cache->sql_exists($query_id)) + if ($cache && !is_object($query_id) && $cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/driver/oracle.php b/phpBB/includes/db/driver/oracle.php index 53f9dd71e0..e21e07055d 100644 --- a/phpBB/includes/db/driver/oracle.php +++ b/phpBB/includes/db/driver/oracle.php @@ -267,7 +267,7 @@ class phpbb_db_driver_oracle extends phpbb_db_driver } $this->last_query_text = $query; - $this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false; + $this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -443,7 +443,7 @@ class phpbb_db_driver_oracle extends phpbb_db_driver $this->sql_report('stop', $query); } - if ($cache_ttl) + if ($cache && $cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); @@ -498,7 +498,7 @@ class phpbb_db_driver_oracle extends phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -550,7 +550,7 @@ class phpbb_db_driver_oracle extends phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -619,7 +619,7 @@ class phpbb_db_driver_oracle extends phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/driver/postgres.php b/phpBB/includes/db/driver/postgres.php index cca97c9c0e..14854d179d 100644 --- a/phpBB/includes/db/driver/postgres.php +++ b/phpBB/includes/db/driver/postgres.php @@ -193,7 +193,7 @@ class phpbb_db_driver_postgres extends phpbb_db_driver } $this->last_query_text = $query; - $this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false; + $this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -208,7 +208,7 @@ class phpbb_db_driver_postgres extends phpbb_db_driver $this->sql_report('stop', $query); } - if ($cache_ttl) + if ($cache && $cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); @@ -278,7 +278,7 @@ class phpbb_db_driver_postgres extends phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -299,7 +299,7 @@ class phpbb_db_driver_postgres extends phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -348,7 +348,7 @@ class phpbb_db_driver_postgres extends phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } diff --git a/phpBB/includes/db/driver/sqlite.php b/phpBB/includes/db/driver/sqlite.php index 155409b665..7188f0daa2 100644 --- a/phpBB/includes/db/driver/sqlite.php +++ b/phpBB/includes/db/driver/sqlite.php @@ -134,7 +134,7 @@ class phpbb_db_driver_sqlite extends phpbb_db_driver $this->sql_report('start', $query); } - $this->query_result = ($cache_ttl) ? $cache->sql_load($query) : false; + $this->query_result = ($cache && $cache_ttl) ? $cache->sql_load($query) : false; $this->sql_add_num_queries($this->query_result); if ($this->query_result === false) @@ -149,7 +149,7 @@ class phpbb_db_driver_sqlite extends phpbb_db_driver $this->sql_report('stop', $query); } - if ($cache_ttl) + if ($cache && $cache_ttl) { $this->open_queries[(int) $this->query_result] = $this->query_result; $this->query_result = $cache->sql_save($this, $query, $this->query_result, $cache_ttl); @@ -210,7 +210,7 @@ class phpbb_db_driver_sqlite extends phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_fetchrow($query_id); } @@ -231,7 +231,7 @@ class phpbb_db_driver_sqlite extends phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_rowseek($rownum, $query_id); } @@ -259,7 +259,7 @@ class phpbb_db_driver_sqlite extends phpbb_db_driver $query_id = $this->query_result; } - if ($cache->sql_exists($query_id)) + if ($cache && $cache->sql_exists($query_id)) { return $cache->sql_freeresult($query_id); } -- cgit v1.2.1 From 68baee4ce2388f9c6233e48ffb4b1223e7671373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fre=CC=80rejean?= Date: Thu, 3 Jan 2013 13:16:38 +0100 Subject: [ticket/11309] phpbb_extension_interface::disable_step correct docblock. The `@return` documentation of the `phpbb_extension_interface::disable_step` method states incorrect that the method returns null, as it returns false or a state. PHPBB3-11309 --- phpBB/includes/extension/interface.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/interface.php b/phpBB/includes/extension/interface.php index 74ecb9b762..7b36a12bf6 100644 --- a/phpBB/includes/extension/interface.php +++ b/phpBB/includes/extension/interface.php @@ -45,7 +45,9 @@ interface phpbb_extension_interface * * @param mixed $old_state The return value of the previous call * of this method, or false on the first call - * @return null + * @return mixed Returns false after last step, otherwise + * temporary state which is passed as an + * argument to the next step */ public function disable_step($old_state); -- cgit v1.2.1 From 24befac7b4879ae02a4416e47ca0deea93766b93 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 8 Jan 2013 23:18:17 +0100 Subject: [ticket/11301] Explicitly cast str offset to int to prevent E_NOTICE on 5.4. PHPBB3-11301 --- phpBB/includes/captcha/captcha_non_gd.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/captcha/captcha_non_gd.php b/phpBB/includes/captcha/captcha_non_gd.php index f82896f628..a823fa4226 100644 --- a/phpBB/includes/captcha/captcha_non_gd.php +++ b/phpBB/includes/captcha/captcha_non_gd.php @@ -119,7 +119,7 @@ class captcha $new_line = ''; $end = strlen($scanline) - ceil($width/2); - for ($i = floor($width/2); $i < $end; $i++) + for ($i = (int) floor($width/2); $i < $end; $i++) { $pixel = ord($scanline{$i}); -- cgit v1.2.1 From 41a07eedeb13349305977bb8882f0bd6429480e3 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 8 Jan 2013 23:20:30 +0100 Subject: [ticket/11301] Guidelines: Add spaces in front and after the / operator. PHPBB3-11301 --- phpBB/includes/captcha/captcha_non_gd.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/captcha/captcha_non_gd.php b/phpBB/includes/captcha/captcha_non_gd.php index a823fa4226..2adf909b96 100644 --- a/phpBB/includes/captcha/captcha_non_gd.php +++ b/phpBB/includes/captcha/captcha_non_gd.php @@ -119,7 +119,7 @@ class captcha $new_line = ''; $end = strlen($scanline) - ceil($width/2); - for ($i = (int) floor($width/2); $i < $end; $i++) + for ($i = (int) floor($width / 2); $i < $end; $i++) { $pixel = ord($scanline{$i}); -- cgit v1.2.1 From f817e20f287a21e2dddfba9721f5e02dce162d29 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 15 Jul 2011 11:57:53 -0400 Subject: [feature/migrations] Basic migrations with schema and data changes The migrator takes care of applying migrations as necessary. RFC: http://area51.phpbb.com/phpBB/viewtopic.php?f=84&t=41337 PHPBB3-9737 --- phpBB/includes/constants.php | 1 + phpBB/includes/db/migration.php | 79 ++++++++++++++ phpBB/includes/db/migrator.php | 227 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 307 insertions(+) create mode 100644 phpBB/includes/db/migration.php create mode 100644 phpBB/includes/db/migrator.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index 68af41ab20..68c96a2759 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -237,6 +237,7 @@ define('ICONS_TABLE', $table_prefix . 'icons'); define('LANG_TABLE', $table_prefix . 'lang'); define('LOG_TABLE', $table_prefix . 'log'); define('LOGIN_ATTEMPT_TABLE', $table_prefix . 'login_attempts'); +define('MIGRATIONS_TABLE', $table_prefix . 'migrations'); define('MODERATOR_CACHE_TABLE', $table_prefix . 'moderator_cache'); define('MODULES_TABLE', $table_prefix . 'modules'); define('POLL_OPTIONS_TABLE', $table_prefix . 'poll_options'); diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php new file mode 100644 index 0000000000..f96fcb9568 --- /dev/null +++ b/phpBB/includes/db/migration.php @@ -0,0 +1,79 @@ +db = &$db; + $this->db_tools = &$db_tools; + } + + /** + * Defines other migrationsto be applied first (abstract method) + * + * @return array An array of migration class names + */ + function depends_on() + { + return array(); + } + + /** + * Updates the database schema + * + * @return null + */ + function update_schema() + { + } + + /** + * Updates data + * + * @return null + */ + function update_data() + { + } + + /** + * Adds a column to a database table + */ + function db_column_add($table_name, $column_name, $column_data) + { + $this->db_tools->sql_column_add($table_name, $column_name, $column_data); + } +} diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php new file mode 100644 index 0000000000..d5d938ca28 --- /dev/null +++ b/phpBB/includes/db/migrator.php @@ -0,0 +1,227 @@ +db = &$db; + $this->db_tools = &$db_tools; + $this->migrations_table = $migrations_table; + $this->migrations = array(); + + $this->load_migration_state(); + } + + /** + * Loads all migrations and their application state from the database. + * + * @return null + */ + function load_migration_state() + { + $sql = "SELECT * + FROM " . $this->migrations_table; + $result = $this->db->sql_query($sql); + + $this->migration_state = array(); + while ($migration = $this->db->sql_fetchrow($result)) + { + $this->migration_state[$migration['migration_name']] = $migration; + } + + $this->db->sql_freeresult($result); + } + + /** + * Sets the list of available migration class names to the given array. + * + * @param array $class_names An array of migration class names + * @return null + */ + function set_migrations($class_names) + { + $this->migrations = $class_names; + } + + /** + * Runs a single update step from the next migration to be applied. + * + * The update step can either be a schema or a (partial) data update. To + * check if update() needs to be called again use the finished() method. + * + * @return null + */ + function update() + { + foreach ($this->migrations as $name) + { + if (!isset($this->migration_state[$name]) || + !$this->migration_state[$name]['migration_schema_done'] || + !$this->migration_state[$name]['migration_data_done']) + { + if (!$this->try_apply($name)) + { + continue; + } + else + { + return; + } + } + } + } + + /** + * Attempts to apply a step of the given migration or one of its dependencies + * + * @param string The class name of the migration + * @return bool Whether any update step was successfully run + */ + function try_apply($name) + { + if (!class_exists($name)) + { + return false; + } + + $migration =& new $name($this->db, $this->db_tools); + $state = (isset($this->migration_state[$name])) ? + $this->migration_state[$name] : + array( + 'migration_schema_done' => false, + 'migration_data_done' => false, + 'migration_data_state' => '', + ); + + $depends = $migration->depends_on(); + + foreach ($depends as $depend) + { + if (!isset($this->migration_state[$depend]) || + !$this->migration_state[$depend]['migration_schema_done'] || + !$this->migration_state[$depend]['migration_data_done']) + { + return $this->try_apply($depend); + } + } + + if (!$state['migration_schema_done']) + { + $migration->update_schema(); + $state['migration_schema_done'] = true; + } + else + { + $migration->update_data(); + $state['migration_data_done'] = true; + } + + $sql = 'UPDATE ' . $this->migrations_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $state) . " + WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + + $this->migration_state[$name] = $state; + + return true; + } + + /** + * Checks if a migration's dependencies can even theoretically be satisfied. + * + * @param string $name The class name of the migration + * @return bool Whether the migration cannot be fulfilled + */ + function unfulfillable($name) + { + if (isset($this->migration_state[$name])) + { + return false; + } + + if (!class_exists($name)) + { + return true; + } + + $migration =& new $name($this->db, $this->db_tools); + $depends = $migration->depends_on(); + + foreach ($depends as $depend) + { + if ($this->unfulfillable($depend)) + { + return true; + } + } + + return false; + } + + /** + * Checks whether all available, fulfillable migrations have been applied. + * + * @return bool Whether the migrations have been applied + */ + function finished() + { + foreach ($this->migrations as $name) + { + if (!isset($this->migration_state[$name])) + { + // skip unfulfillable migrations, but fulfillables mean we + // are not finished yet + if ($this->unfulfillable($name)) + { + continue; + } + return false; + } + + $migration = $this->migration_state[$name]; + + if (!$migration['migration_schema_done'] || !$migration['migration_data_done']) + { + return false; + } + } + + return true; + } +} -- cgit v1.2.1 From d304b6449db6e7c6f3c9058062aca0c641f023a4 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 7 Aug 2011 19:10:38 -0400 Subject: [feature/migrations] Store start and end time of migrations PHPBB3-9737 --- phpBB/includes/db/migrator.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index d5d938ca28..f4613e3aec 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -127,6 +127,8 @@ class phpbb_db_migrator 'migration_schema_done' => false, 'migration_data_done' => false, 'migration_data_state' => '', + 'migration_start_time' => 0, + 'migration_end_time' => 0, ); $depends = $migration->depends_on(); @@ -141,6 +143,12 @@ class phpbb_db_migrator } } + if (!isset($this->migration_state[$name])) + { + $state['migration_start_time'] = time(); + $this->insert_migration($name, $state); + } + if (!$state['migration_schema_done']) { $migration->update_schema(); @@ -150,6 +158,7 @@ class phpbb_db_migrator { $migration->update_data(); $state['migration_data_done'] = true; + $state['migration_end_time'] = time(); } $sql = 'UPDATE ' . $this->migrations_table . ' @@ -162,6 +171,18 @@ class phpbb_db_migrator return true; } + function insert_migration($name, $state) + { + $migration_row = $state; + $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; + } + /** * Checks if a migration's dependencies can even theoretically be satisfied. * -- cgit v1.2.1 From 8645321f40d0b13de6201688c69f9f05bc649dcf Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 25 Oct 2012 12:26:44 -0700 Subject: [feature/migrations] Return schema changes in database update style array Returning the set of schema changes allows potentially aggregating to generate the overall install schema automatically from a set of migrations PHPBB3-9737 --- phpBB/includes/db/migration.php | 5 +++-- phpBB/includes/db/migrator.php | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php index f96fcb9568..ee916aedc0 100644 --- a/phpBB/includes/db/migration.php +++ b/phpBB/includes/db/migration.php @@ -52,12 +52,13 @@ class phpbb_db_migration } /** - * Updates the database schema + * Updates the database schema by providing a set of change instructions * - * @return null + * @return array */ function update_schema() { + return array(); } /** diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index f4613e3aec..4a178af468 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -151,7 +151,7 @@ class phpbb_db_migrator if (!$state['migration_schema_done']) { - $migration->update_schema(); + $this->apply_schema_changes($migration->update_schema()); $state['migration_schema_done'] = true; } else @@ -245,4 +245,9 @@ class phpbb_db_migrator return true; } + + function apply_schema_changes($schema_changes) + { + $this->db_tools->perform_schema_changes($schema_changes); + } } -- cgit v1.2.1 From c802f2a66c577781036b7bfd6d6689159028c3a6 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 25 Oct 2012 13:02:56 -0700 Subject: [feature/migrations] Standard vars for migrations and run sql with feedback PHPBB3-9737 --- phpBB/includes/db/migration.php | 52 +++++++++++++++++++++++++++++++++++++---- phpBB/includes/db/migrator.php | 17 +++++++++++--- 2 files changed, 62 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php index ee916aedc0..09d4e31344 100644 --- a/phpBB/includes/db/migration.php +++ b/phpBB/includes/db/migration.php @@ -28,17 +28,32 @@ class phpbb_db_migration { var $db; var $db_tools; + var $table_prefix; + + var $phpbb_root_path; + var $php_ext; + + var $errors; /** * Migration constructor * * @param dbal $db Connected database abstraction instance * @param phpbb_db_tools $db_tools Instance of db schema manipulation tools + * @param string $table_prefix The prefix for all table names + * @param string $phpbb_root_path + * @param string $php_ext */ - function phpbb_db_migration(&$db, &$db_tools) + function phpbb_db_migration(&$db, &$db_tools, $table_prefix, $phpbb_root_path, $php_ext) { $this->db = &$db; $this->db_tools = &$db_tools; + $this->table_prefix = $table_prefix; + + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + + $this->errors = array(); } /** @@ -71,10 +86,39 @@ class phpbb_db_migration } /** - * Adds a column to a database table + * Wrapper for running queries to generate user feedback on updates */ - function db_column_add($table_name, $column_name, $column_data) + function sql_query($sql) { - $this->db_tools->sql_column_add($table_name, $column_name, $column_data); + if (defined('DEBUG_EXTRA')) + { + echo "
\n{$sql}\n
"; + } + + $db->sql_return_on_error(true); + + if ($sql === 'begin') + { + $result = $db->sql_transaction('begin'); + } + else if ($sql === 'commit') + { + $result = $db->sql_transaction('commit'); + } + else + { + $result = $db->sql_query($sql); + if ($db->sql_error_triggered) + { + $this->errors[] = array( + 'sql' => $db->sql_error_sql, + 'code' => $db->sql_error_returned, + ); + } + } + + $db->sql_return_on_error(false); + + return $result; } } diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 4a178af468..4ce54a4b92 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -24,6 +24,10 @@ class phpbb_db_migrator { var $db; var $db_tools; + var $table_prefix; + + var $phpbb_root_path; + var $php_ext; var $migrations_table; var $migration_state; @@ -35,16 +39,23 @@ class phpbb_db_migrator * * @param dbal $db Connected database abstraction instance * @param phpbb_db_tools $db_tools Instance of db schema manipulation tools + * @param string $table_prefix The prefix for all table names * @param string $migrations_table The name of the db table storing * information on applied migrations + * @param string $phpbb_root_path + * @param string $php_ext */ - function phpbb_db_migrator(&$db, &$db_tools, $migrations_table) + function phpbb_db_migrator(&$db, &$db_tools, $table_prefix, $migrations_table, $phpbb_root_path, $php_ext) { $this->db = &$db; $this->db_tools = &$db_tools; + $this->table_prefix = $table_prefix; $this->migrations_table = $migrations_table; $this->migrations = array(); + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->load_migration_state(); } @@ -120,7 +131,7 @@ class phpbb_db_migrator return false; } - $migration =& new $name($this->db, $this->db_tools); + $migration =& new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); $state = (isset($this->migration_state[$name])) ? $this->migration_state[$name] : array( @@ -201,7 +212,7 @@ class phpbb_db_migrator return true; } - $migration =& new $name($this->db, $this->db_tools); + $migration =& new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); $depends = $migration->depends_on(); foreach ($depends as $depend) -- cgit v1.2.1 From b1f9ca2f6541924c75a30c68dd8a4bc8db62205d Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 9 Nov 2012 17:10:48 +0100 Subject: [feature/migrations] Moved database_update info to individual migration classes --- phpBB/includes/db/migration.php | 2 +- phpBB/includes/db/migration/v301.php | 25 +++ phpBB/includes/db/migration/v3010.php | 25 +++ phpBB/includes/db/migration/v3010rc1.php | 29 +++ phpBB/includes/db/migration/v3010rc2.php | 25 +++ phpBB/includes/db/migration/v3010rc3.php | 25 +++ phpBB/includes/db/migration/v3011.php | 25 +++ phpBB/includes/db/migration/v3011rc1.php | 83 ++++++++ phpBB/includes/db/migration/v3011rc2.php | 31 +++ phpBB/includes/db/migration/v3012rc1.php | 26 +++ phpBB/includes/db/migration/v301rc1.php | 77 +++++++ phpBB/includes/db/migration/v302.php | 25 +++ phpBB/includes/db/migration/v302rc1.php | 30 +++ phpBB/includes/db/migration/v302rc2.php | 52 +++++ phpBB/includes/db/migration/v303.php | 25 +++ phpBB/includes/db/migration/v303rc1.php | 135 ++++++++++++ phpBB/includes/db/migration/v304.php | 40 ++++ phpBB/includes/db/migration/v304rc1.php | 96 +++++++++ phpBB/includes/db/migration/v305.php | 25 +++ phpBB/includes/db/migration/v305rc1.php | 146 +++++++++++++ phpBB/includes/db/migration/v306.php | 25 +++ phpBB/includes/db/migration/v306rc1.php | 350 +++++++++++++++++++++++++++++++ phpBB/includes/db/migration/v306rc2.php | 25 +++ phpBB/includes/db/migration/v306rc3.php | 31 +++ phpBB/includes/db/migration/v306rc4.php | 25 +++ phpBB/includes/db/migration/v307.php | 25 +++ phpBB/includes/db/migration/v307pl1.php | 25 +++ phpBB/includes/db/migration/v307rc1.php | 46 ++++ phpBB/includes/db/migration/v307rc2.php | 53 +++++ phpBB/includes/db/migration/v308.php | 25 +++ phpBB/includes/db/migration/v308rc1.php | 222 ++++++++++++++++++++ phpBB/includes/db/migration/v309.php | 25 +++ phpBB/includes/db/migration/v309rc1.php | 100 +++++++++ phpBB/includes/db/migration/v309rc2.php | 25 +++ phpBB/includes/db/migration/v309rc3.php | 25 +++ phpBB/includes/db/migration/v309rc4.php | 25 +++ 36 files changed, 1998 insertions(+), 1 deletion(-) create mode 100644 phpBB/includes/db/migration/v301.php create mode 100644 phpBB/includes/db/migration/v3010.php create mode 100644 phpBB/includes/db/migration/v3010rc1.php create mode 100644 phpBB/includes/db/migration/v3010rc2.php create mode 100644 phpBB/includes/db/migration/v3010rc3.php create mode 100644 phpBB/includes/db/migration/v3011.php create mode 100644 phpBB/includes/db/migration/v3011rc1.php create mode 100644 phpBB/includes/db/migration/v3011rc2.php create mode 100644 phpBB/includes/db/migration/v3012rc1.php create mode 100644 phpBB/includes/db/migration/v301rc1.php create mode 100644 phpBB/includes/db/migration/v302.php create mode 100644 phpBB/includes/db/migration/v302rc1.php create mode 100644 phpBB/includes/db/migration/v302rc2.php create mode 100644 phpBB/includes/db/migration/v303.php create mode 100644 phpBB/includes/db/migration/v303rc1.php create mode 100644 phpBB/includes/db/migration/v304.php create mode 100644 phpBB/includes/db/migration/v304rc1.php create mode 100644 phpBB/includes/db/migration/v305.php create mode 100644 phpBB/includes/db/migration/v305rc1.php create mode 100644 phpBB/includes/db/migration/v306.php create mode 100644 phpBB/includes/db/migration/v306rc1.php create mode 100644 phpBB/includes/db/migration/v306rc2.php create mode 100644 phpBB/includes/db/migration/v306rc3.php create mode 100644 phpBB/includes/db/migration/v306rc4.php create mode 100644 phpBB/includes/db/migration/v307.php create mode 100644 phpBB/includes/db/migration/v307pl1.php create mode 100644 phpBB/includes/db/migration/v307rc1.php create mode 100644 phpBB/includes/db/migration/v307rc2.php create mode 100644 phpBB/includes/db/migration/v308.php create mode 100644 phpBB/includes/db/migration/v308rc1.php create mode 100644 phpBB/includes/db/migration/v309.php create mode 100644 phpBB/includes/db/migration/v309rc1.php create mode 100644 phpBB/includes/db/migration/v309rc2.php create mode 100644 phpBB/includes/db/migration/v309rc3.php create mode 100644 phpBB/includes/db/migration/v309rc4.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php index 09d4e31344..aca9d264bb 100644 --- a/phpBB/includes/db/migration.php +++ b/phpBB/includes/db/migration.php @@ -3,7 +3,7 @@ * * @package db * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 * */ diff --git a/phpBB/includes/db/migration/v301.php b/phpBB/includes/db/migration/v301.php new file mode 100644 index 0000000000..8a2a265a3c --- /dev/null +++ b/phpBB/includes/db/migration/v301.php @@ -0,0 +1,25 @@ +sql_query($sql); + + $deactivated_style_ids = array(); + while ($style_id = $db->sql_fetchfield('style_id', false, $result)) + { + $deactivated_style_ids[] = (int) $style_id; + } + $db->sql_freeresult($result); + + if (!empty($deactivated_style_ids)) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_style = ' . (int) $config['default_style'] .' + WHERE ' . $db->sql_in_set('user_style', $deactivated_style_ids); + _sql($sql, $errored, $error_ary); + } + + // 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 = $db->sql_build_query('SELECT', $sql_array); + + do + { + $result = $db->sql_query_limit($sql, $batch_size); + + $delete_pms = array(); + while ($row = $db->sql_fetchrow($result)) + { + $delete_pms[] = (int) $row['msg_id']; + } + $db->sql_freeresult($result); + + if (!empty($delete_pms)) + { + $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' + WHERE ' . $db->sql_in_set('msg_id', $delete_pms); + _sql($sql, $errored, $error_ary); + } + } + while (sizeof($delete_pms) == $batch_size); + } +} diff --git a/phpBB/includes/db/migration/v3011rc2.php b/phpBB/includes/db/migration/v3011rc2.php new file mode 100644 index 0000000000..0f66eff156 --- /dev/null +++ b/phpBB/includes/db/migration/v3011rc2.php @@ -0,0 +1,31 @@ + array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_novalue' => array('BOOL', 0), + ), + ), + ); + } + + function update_data() + { + } +} diff --git a/phpBB/includes/db/migration/v3012rc1.php b/phpBB/includes/db/migration/v3012rc1.php new file mode 100644 index 0000000000..67f7a29b02 --- /dev/null +++ b/phpBB/includes/db/migration/v3012rc1.php @@ -0,0 +1,26 @@ + 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 update_data() + { + return array( + array('custom', array(array(&$this, 'fix_unset_last_view_time'))), + array('custom', array(array(&$this, 'reset_smiley_size'))), + ); + } + + 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/v302.php b/phpBB/includes/db/migration/v302.php new file mode 100644 index 0000000000..942a0ac58c --- /dev/null +++ b/phpBB/includes/db/migration/v302.php @@ -0,0 +1,25 @@ + 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() + { + } +} diff --git a/phpBB/includes/db/migration/v303.php b/phpBB/includes/db/migration/v303.php new file mode 100644 index 0000000000..409c396baf --- /dev/null +++ b/phpBB/includes/db/migration/v303.php @@ -0,0 +1,25 @@ + 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('set_group_default_max_recipients')) + + // Not prefilling yet + set_config('dbms_version', ''); + + // Add new permission u_masspm_group and duplicate settings from u_masspm + include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx); + $auth_admin = new auth_admin(); + + // Only add the new permission if it does not already exist + if (empty($auth_admin->acl_options['id']['u_masspm_group'])) + { + $auth_admin->acl_add_option(array('global' => array('u_masspm_group'))); + + // Now the tricky part, filling the permission + $old_id = $auth_admin->acl_options['id']['u_masspm']; + $new_id = $auth_admin->acl_options['id']['u_masspm_group']; + + $tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE); + + foreach ($tables as $table) + { + $sql = 'SELECT * + FROM ' . $table . ' + WHERE auth_option_id = ' . $old_id; + $result = _sql($sql, $errored, $error_ary); + + $sql_ary = array(); + while ($row = $db->sql_fetchrow($result)) + { + $row['auth_option_id'] = $new_id; + $sql_ary[] = $row; + } + $db->sql_freeresult($result); + + if (sizeof($sql_ary)) + { + $db->sql_multi_insert($table, $sql_ary); + } + } + + // Remove any old permission entries + $auth_admin->acl_clear_prefetch(); + } + + /** + * Do not resync post counts here. An admin may do this later from the ACP + $start = 0; + $step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000; + + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = 0'; + _sql($sql, $errored, $error_ary); + + do + { + $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id + FROM ' . POSTS_TABLE . ' + WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . ' + AND post_postcount = 1 AND post_approved = 1 + GROUP BY poster_id'; + $result = _sql($sql, $errored, $error_ary); + + if ($row = $db->sql_fetchrow($result)) + { + do + { + $sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}"; + _sql($sql, $errored, $error_ary); + } + while ($row = $db->sql_fetchrow($result)); + + $start += $step; + } + else + { + $start = 0; + } + $db->sql_freeresult($result); + } + while ($start); + */ + + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET module_auth = \'acl_a_email && cfg_email_enable\' + WHERE module_class = \'acp\' + AND module_basename = \'email\''; + _sql($sql, $errored, $error_ary); + } + + 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/v304.php b/phpBB/includes/db/migration/v304.php new file mode 100644 index 0000000000..2895caaa6d --- /dev/null +++ b/phpBB/includes/db/migration/v304.php @@ -0,0 +1,40 @@ +sql_layer == 'oracle') + { + // log_operation is CLOB - but we can change this later + $sql = 'UPDATE ' . LOG_TABLE . " + SET log_operation = 'LOG_DELETE_TOPIC' + WHERE log_operation LIKE 'LOG_TOPIC_DELETED'"; + _sql($sql, $errored, $error_ary); + } + else + { + $sql = 'UPDATE ' . LOG_TABLE . " + SET log_operation = 'LOG_DELETE_TOPIC' + WHERE log_operation = 'LOG_TOPIC_DELETED'"; + _sql($sql, $errored, $error_ary); + } + } +} diff --git a/phpBB/includes/db/migration/v304rc1.php b/phpBB/includes/db/migration/v304rc1.php new file mode 100644 index 0000000000..a7098ce62f --- /dev/null +++ b/phpBB/includes/db/migration/v304rc1.php @@ -0,0 +1,96 @@ + 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() + { + // 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 = _sql($sql, $errored, $error_ary); + + while ($row = $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; + } + + _sql('UPDATE ' . PROFILE_FIELDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary); + } + } +} diff --git a/phpBB/includes/db/migration/v305.php b/phpBB/includes/db/migration/v305.php new file mode 100644 index 0000000000..b4d676d72a --- /dev/null +++ b/phpBB/includes/db/migration/v305.php @@ -0,0 +1,25 @@ + array( + $this->table_prefix . 'forums' => array( + 'forum_style' => array('UINT', 0), + ), + ), + ); + } + + function update_data() + { + // Captcha config variables + set_config('captcha_gd_wave', 0); + set_config('captcha_gd_3d_noise', 1); + set_config('captcha_gd_fonts', 1); + set_config('confirm_refresh', 1); + + // Maximum number of keywords + set_config('max_num_search_keywords', 10); + + // Remove static config var and put it back as dynamic variable + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET is_dynamic = 1 + WHERE config_name = 'search_indexing_state'"; + _sql($sql, $errored, $error_ary); + + // Hash old MD5 passwords + $sql = 'SELECT user_id, user_password + FROM ' . USERS_TABLE . ' + WHERE user_pass_convert = 1'; + $result = _sql($sql, $errored, $error_ary); + + while ($row = $db->sql_fetchrow($result)) + { + if (strlen($row['user_password']) == 32) + { + $sql_ary = array( + 'user_password' => phpbb_hash($row['user_password']), + ); + + _sql('UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id'], $errored, $error_ary); + } + } + $db->sql_freeresult($result); + + // Adjust bot entry + $sql = 'UPDATE ' . BOTS_TABLE . " + SET bot_agent = 'ichiro/' + WHERE bot_agent = 'ichiro/2'"; + _sql($sql, $errored, $error_ary); + + + // Before we are able to add a unique key to auth_option, we need to remove duplicate entries + + // We get duplicate entries first + $sql = 'SELECT auth_option + FROM ' . ACL_OPTIONS_TABLE . ' + GROUP BY auth_option + HAVING COUNT(*) >= 2'; + $result = $db->sql_query($sql); + + $auth_options = array(); + while ($row = $db->sql_fetchrow($result)) + { + $auth_options[] = $row['auth_option']; + } + $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 = $db->sql_query($sql); + + // Skip first row, this is our original auth option we want to preserve + $row = $db->sql_fetchrow($result); + + while ($row = $db->sql_fetchrow($result)) + { + // Ok, remove this auth option... + _sql('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary); + _sql('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary); + _sql('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary); + _sql('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary); + } + $db->sql_freeresult($result); + } + } + + // Now make auth_option UNIQUE, by dropping the old index and adding a UNIQUE one. + $changes = array( + 'drop_keys' => array( + ACL_OPTIONS_TABLE => array('auth_option'), + ), + ); + + global $db_tools; + + $statements = $db_tools->perform_schema_changes($changes); + + foreach ($statements as $sql) + { + _sql($sql, $errored, $error_ary); + } + + $changes = array( + 'add_unique_index' => array( + ACL_OPTIONS_TABLE => array( + 'auth_option' => array('auth_option'), + ), + ), + ); + + $statements = $db_tools->perform_schema_changes($changes); + + foreach ($statements as $sql) + { + _sql($sql, $errored, $error_ary); + } + } +} diff --git a/phpBB/includes/db/migration/v306.php b/phpBB/includes/db/migration/v306.php new file mode 100644 index 0000000000..eec2f7c752 --- /dev/null +++ b/phpBB/includes/db/migration/v306.php @@ -0,0 +1,25 @@ + 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 . '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() + { + // Let's see if the GD Captcha can be enabled... we simply look for what *is* enabled... + if (!empty($config['captcha_gd']) && !isset($config['captcha_plugin'])) + { + set_config('captcha_plugin', 'phpbb_captcha_gd'); + } + else if (!isset($config['captcha_plugin'])) + { + set_config('captcha_plugin', 'phpbb_captcha_nogd'); + } + + // Entries for the Feed Feature + set_config('feed_enable', '0'); + set_config('feed_limit', '10'); + + set_config('feed_overall_forums', '1'); + set_config('feed_overall_forums_limit', '15'); + + set_config('feed_overall_topics', '0'); + set_config('feed_overall_topics_limit', '15'); + + set_config('feed_forum', '1'); + set_config('feed_topic', '1'); + set_config('feed_item_statistics', '1'); + + // Entries for smiley pagination + set_config('smilies_per_page', '50'); + + // Entry for reporting PMs + set_config('allow_pm_report', '1'); + + // Install modules + $modules_to_install = array( + 'feed' => array( + 'base' => 'board', + 'class' => 'acp', + 'title' => 'ACP_FEED_SETTINGS', + 'auth' => 'acl_a_board', + 'cat' => 'ACP_BOARD_CONFIGURATION', + 'after' => array('signature', 'ACP_SIGNATURE_SETTINGS') + ), + 'warnings' => array( + 'base' => 'users', + 'class' => 'acp', + 'title' => 'ACP_USER_WARNINGS', + 'auth' => 'acl_a_user', + 'display' => 0, + 'cat' => 'ACP_CAT_USERS', + 'after' => array('feedback', 'ACP_USER_FEEDBACK') + ), + 'send_statistics' => array( + 'base' => 'send_statistics', + 'class' => 'acp', + 'title' => 'ACP_SEND_STATISTICS', + 'auth' => 'acl_a_server', + 'cat' => 'ACP_SERVER_CONFIGURATION' + ), + 'setting_forum_copy' => array( + 'base' => 'permissions', + 'class' => 'acp', + 'title' => 'ACP_FORUM_PERMISSIONS_COPY', + 'auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth', + 'cat' => 'ACP_FORUM_BASED_PERMISSIONS', + 'after' => array('setting_forum_local', 'ACP_FORUM_PERMISSIONS') + ), + 'pm_reports' => array( + 'base' => 'pm_reports', + 'class' => 'mcp', + 'title' => 'MCP_PM_REPORTS_OPEN', + 'auth' => 'aclf_m_report', + 'cat' => 'MCP_REPORTS' + ), + 'pm_reports_closed' => array( + 'base' => 'pm_reports', + 'class' => 'mcp', + 'title' => 'MCP_PM_REPORTS_CLOSED', + 'auth' => 'aclf_m_report', + 'cat' => 'MCP_REPORTS' + ), + 'pm_report_details' => array( + 'base' => 'pm_reports', + 'class' => 'mcp', + 'title' => 'MCP_PM_REPORT_DETAILS', + 'auth' => 'aclf_m_report', + 'cat' => 'MCP_REPORTS' + ), + ); + + _add_modules($modules_to_install); + + // 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 = $db->sql_query($sql); + $group_id = (int) $db->sql_fetchfield('group_id'); + $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)"; + _sql($sql, $errored, $error_ary); + + $group_id = $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 = $db->sql_query($sql); + $u_role = (int) $db->sql_fetchfield('role_id'); + $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 = $db->sql_query($sql); + $next_order_id = (int) $db->sql_fetchfield('max_order_id'); + $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)"; + _sql($sql, $errored, $error_ary); + $u_role = $db->sql_nextid(); + + if (!$errored) + { + // 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')"; + _sql($sql, $errored, $error_ary); + + // 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)"; + _sql($sql, $errored, $error_ary); + } + } + + // Insert new forum role + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = 'ROLE_FORUM_NEW_MEMBER' + AND role_type = 'f_'"; + $result = $db->sql_query($sql); + $f_role = (int) $db->sql_fetchfield('role_id'); + $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 = $db->sql_query($sql); + $next_order_id = (int) $db->sql_fetchfield('max_order_id'); + $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)"; + _sql($sql, $errored, $error_ary); + $f_role = $db->sql_nextid(); + + if (!$errored) + { + $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')"; + _sql($sql, $errored, $error_ary); + } + } + + // 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 = $db->sql_query_limit($sql, 1); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (!$row) + { + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_new = 0'; + _sql($sql, $errored, $error_ary); + } + + // Newly registered users limit + if (!isset($config['new_member_post_limit'])) + { + set_config('new_member_post_limit', (!empty($config['enable_queue_trigger'])) ? $config['queue_trigger_posts'] : 0); + } + + if (!isset($config['new_member_group_default'])) + { + set_config('new_member_group_default', 0); + } + + // 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 = $db->sql_query($sql); + $is_options = (int) $db->sql_fetchfield('forum_id'); + $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 = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + _sql('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)', $errored, $error_ary); + } + $db->sql_freeresult($result); + } + + // Clear permissions... + include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx); + $auth_admin = new auth_admin(); + $auth_admin->acl_clear_prefetch(); + + if (!isset($config['allow_avatar'])) + { + if ($config['allow_avatar_upload'] || $config['allow_avatar_local'] || $config['allow_avatar_remote']) + { + set_config('allow_avatar', '1'); + } + else + { + set_config('allow_avatar', '0'); + } + } + + if (!isset($config['allow_avatar_remote_upload'])) + { + if ($config['allow_avatar_remote'] && $config['allow_avatar_upload']) + { + set_config('allow_avatar_remote_upload', '1'); + } + else + { + set_config('allow_avatar_remote_upload', '0'); + } + } + + // Minimum number of characters + if (!isset($config['min_post_chars'])) + { + set_config('min_post_chars', '1'); + } + + if (!isset($config['allow_quick_reply'])) + { + set_config('allow_quick_reply', '1'); + } + + // Set every members user_options column to enable + // bbcode, smilies and URLs for signatures by default + $sql = 'SELECT user_options + FROM ' . USERS_TABLE . ' + WHERE user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')'; + $result = $db->sql_query_limit($sql, 1); + $user_option = (int) $db->sql_fetchfield('user_options'); + $db->sql_freeresult($result); + + // Check if we already updated the database by checking bit 15 which we used to store the sig_bbcode option + if (!($user_option & 1 << 15)) + { + // 229376 is the added value to enable all three signature options + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376'; + _sql($sql, $errored, $error_ary); + } + + if (!isset($config['delete_time'])) + { + set_config('delete_time', $config['edit_time']); + } + } +} diff --git a/phpBB/includes/db/migration/v306rc2.php b/phpBB/includes/db/migration/v306rc2.php new file mode 100644 index 0000000000..0a6c388da6 --- /dev/null +++ b/phpBB/includes/db/migration/v306rc2.php @@ -0,0 +1,25 @@ + 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() + { + // ATOM Feeds + set_config('feed_overall', '1'); + set_config('feed_http_auth', '0'); + set_config('feed_limit_post', (string) (isset($config['feed_limit']) ? (int) $config['feed_limit'] : 15)); + set_config('feed_limit_topic', (string) (isset($config['feed_overall_topics_limit']) ? (int) $config['feed_overall_topics_limit'] : 10)); + set_config('feed_topics_new', (!empty($config['feed_overall_topics']) ? '1' : '0')); + set_config('feed_topics_active', (!empty($config['feed_overall_topics']) ? '1' : '0')); + + // Delete all text-templates from the template_data + $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' + WHERE template_filename ' . $db->sql_like_expression($db->any_char . '.txt'); + _sql($sql, $errored, $error_ary); + } +} diff --git a/phpBB/includes/db/migration/v307rc2.php b/phpBB/includes/db/migration/v307rc2.php new file mode 100644 index 0000000000..f9492f3d1c --- /dev/null +++ b/phpBB/includes/db/migration/v307rc2.php @@ -0,0 +1,53 @@ + ' . USER_IGNORE . " + AND user_email <> ''"; + $result = $db->sql_query($sql); + + $i = 0; + while ($row = $db->sql_fetchrow($result)) + { + // 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 ' . $db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE user_id = ' . (int) $row['user_id']; + _sql($sql, $errored, $error_ary, ($i % 100 == 0)); + + ++$i; + } + } + $db->sql_freeresult($result); + } +} diff --git a/phpBB/includes/db/migration/v308.php b/phpBB/includes/db/migration/v308.php new file mode 100644 index 0000000000..8a0d96b2e7 --- /dev/null +++ b/phpBB/includes/db/migration/v308.php @@ -0,0 +1,25 @@ +sql_query($sql); + + $extension_groups_updated = array(); + while ($lang_dir = $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( + "{$phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.$phpEx", + "{$phpbb_root_path}language/$lang_dir/install.$phpEx", + "{$phpbb_root_path}language/$lang_dir/acp/attachments.$phpEx", + ); + + 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 ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE group_name = '" . $db->sql_escape($lang_val) . "'"; + _sql($sql, $errored, $error_ary); + + $extension_groups_updated[$lang_key] = true; + } + } + } + $db->sql_freeresult($result); + + // Install modules + $modules_to_install = array( + 'post' => array( + 'base' => 'board', + 'class' => 'acp', + 'title' => 'ACP_POST_SETTINGS', + 'auth' => 'acl_a_board', + 'cat' => 'ACP_MESSAGES', + 'after' => array('message', 'ACP_MESSAGE_SETTINGS') + ), + ); + + _add_modules($modules_to_install); + + // update + $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\''; + _sql($sql, $errored, $error_ary); + + // add Bing Bot + $bot_name = 'Bing [Bot]'; + $bot_name_clean = utf8_clean_string($bot_name); + + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . " + WHERE username_clean = '" . $db->sql_escape($bot_name_clean) . "'"; + $result = $db->sql_query($sql); + $bing_already_added = (bool) $db->sql_fetchfield('user_id'); + $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 = $db->sql_query($sql); + $group_row = $db->sql_fetchrow($result); + $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($phpbb_root_path . 'includes/functions_user.' . $phpEx); + } + + $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' => $config['default_lang'], + 'user_style' => $config['default_style'], + 'user_timezone' => 0, + 'user_dateformat' => $config['default_dateformat'], + 'user_allow_massemail' => 0, + ); + + $user_id = user_add($user_row); + + $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $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, + )); + + _sql($sql, $errored, $error_ary); + } + // end Bing Bot addition + + // Delete shadow topics pointing to not existing topics + $batch_size = 500; + + // Set of affected forums we have to resync + $sync_forum_ids = array(); + + do + { + $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 = $db->sql_build_query('SELECT', $sql_array); + $result = $db->sql_query_limit($sql, $batch_size); + + $topic_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $topic_ids[] = (int) $row['topic_id']; + + $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; + } + $db->sql_freeresult($result); + + if (!empty($topic_ids)) + { + $sql = 'DELETE FROM ' . TOPICS_TABLE . ' + WHERE ' . $db->sql_in_set('topic_id', $topic_ids); + $db->sql_query($sql); + } + } + while (sizeof($topic_ids) == $batch_size); + + // Sync the forums we have deleted shadow topics from. + sync('forum', 'forum_id', $sync_forum_ids, true, true); + + // Unread posts search load switch + set_config('load_unreads_search', '1'); + + // Reduce queue interval to 60 seconds, email package size to 20 + if ($config['queue_interval'] == 600) + { + set_config('queue_interval', '60'); + } + + if ($config['email_package_size'] == 50) + { + set_config('email_package_size', '20'); + } + } +} diff --git a/phpBB/includes/db/migration/v309.php b/phpBB/includes/db/migration/v309.php new file mode 100644 index 0000000000..ebb246da3a --- /dev/null +++ b/phpBB/includes/db/migration/v309.php @@ -0,0 +1,25 @@ + 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 . 'bbcode' => array( + 'bbcode_id' => array('USINT', 0), + ), + ), + ); + } + + function update_data() + { + set_config('ip_login_limit_max', '50'); + set_config('ip_login_limit_time', '21600'); + set_config('ip_login_limit_use_forwarded', '0'); + + // Update file extension group names to use language strings, again. + $sql = 'SELECT group_id, group_name + FROM ' . EXTENSION_GROUPS_TABLE . ' + WHERE group_name ' . $db->sql_like_expression('EXT_GROUP_' . $db->any_char); + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $sql_ary = array( + 'group_name' => substr($row['group_name'], 10), // Strip off 'EXT_GROUP_' + ); + + $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE group_id = ' . $row['group_id']; + _sql($sql, $errored, $error_ary); + } + $db->sql_freeresult($result); + + global $db_tools, $table_prefix; + + // 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 ($db_tools->sql_layer == 'firebird') + { + $tables = array( + $table_prefix . 'captcha_questions', + $table_prefix . 'captcha_answers', + $table_prefix . 'qa_confirm', + ); + foreach ($tables as $table) + { + if ($db_tools->sql_table_exists($table)) + { + $db_tools->sql_table_drop($table); + } + } + } + } +} diff --git a/phpBB/includes/db/migration/v309rc2.php b/phpBB/includes/db/migration/v309rc2.php new file mode 100644 index 0000000000..d552b95e7a --- /dev/null +++ b/phpBB/includes/db/migration/v309rc2.php @@ -0,0 +1,25 @@ + Date: Fri, 9 Nov 2012 10:54:33 -0600 Subject: [feature/migrations] Some migrations data PHPBB3-9737 --- phpBB/includes/db/migration/v3010rc1.php | 7 ++-- phpBB/includes/db/migration/v3011rc1.php | 57 ++++++++++++++++++++------------ phpBB/includes/db/migration/v309rc1.php | 42 +++++++++++++---------- 3 files changed, 63 insertions(+), 43 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/v3010rc1.php b/phpBB/includes/db/migration/v3010rc1.php index 9a43b4c81d..847fe7c250 100644 --- a/phpBB/includes/db/migration/v3010rc1.php +++ b/phpBB/includes/db/migration/v3010rc1.php @@ -21,9 +21,8 @@ class phpbb_db_migration_v3010rc1 extends phpbb_db_migration function update_data() { - if (!isset($config['email_max_chunk_size'])) - { - set_config('email_max_chunk_size', '50'); - } + return array( + array('config.add', array('email_max_chunk_size', 50)), + ); } } diff --git a/phpBB/includes/db/migration/v3011rc1.php b/phpBB/includes/db/migration/v3011rc1.php index 04f86b47ae..aad80ba59f 100644 --- a/phpBB/includes/db/migration/v3011rc1.php +++ b/phpBB/includes/db/migration/v3011rc1.php @@ -20,28 +20,39 @@ class phpbb_db_migration_v3011rc1 extends phpbb_db_migration } function update_data() + { + return array( + array('custom', array(array(&$this, 'cleanup_deactivated_styles'))), + array('custom', array(array(&$this, 'delete_orphan_private_messages'))), + ); + } + + function cleanup_deactivated_styles() { // Updates users having current style a deactivated one $sql = 'SELECT style_id FROM ' . STYLES_TABLE . ' WHERE style_active = 0'; - $result = $db->sql_query($sql); + $result = $this->sql_query($sql); $deactivated_style_ids = array(); - while ($style_id = $db->sql_fetchfield('style_id', false, $result)) + while ($style_id = $this->db->sql_fetchfield('style_id', false, $result)) { $deactivated_style_ids[] = (int) $style_id; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (!empty($deactivated_style_ids)) { $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_style = ' . (int) $config['default_style'] .' - WHERE ' . $db->sql_in_set('user_style', $deactivated_style_ids); - _sql($sql, $errored, $error_ary); + SET user_style = ' . (int) $this->config['default_style'] .' + WHERE ' . $this->db->sql_in_set('user_style', $deactivated_style_ids); + $this->sql_query($sql, $errored, $error_ary); } + } + function delete_orphan_private_messages() + { // Delete orphan private messages $batch_size = 500; @@ -58,26 +69,28 @@ class phpbb_db_migration_v3011rc1 extends phpbb_db_migration ), 'WHERE' => 't.user_id IS NULL', ); - $sql = $db->sql_build_query('SELECT', $sql_array); + $sql = $this->db->sql_build_query('SELECT', $sql_array); - do + $result = $this->db->sql_query_limit($sql, $batch_size); + + $delete_pms = array(); + while ($row = $this->db->sql_fetchrow($result)) { - $result = $db->sql_query_limit($sql, $batch_size); + $delete_pms[] = (int) $row['msg_id']; + } + $db->sql_freeresult($result); - $delete_pms = array(); - while ($row = $db->sql_fetchrow($result)) - { - $delete_pms[] = (int) $row['msg_id']; - } - $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, $errored, $error_ary); - if (!empty($delete_pms)) - { - $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' - WHERE ' . $db->sql_in_set('msg_id', $delete_pms); - _sql($sql, $errored, $error_ary); - } + return true; + } + else + { + return false; } - while (sizeof($delete_pms) == $batch_size); } } diff --git a/phpBB/includes/db/migration/v309rc1.php b/phpBB/includes/db/migration/v309rc1.php index ca56a4e7d9..ce51e54642 100644 --- a/phpBB/includes/db/migration/v309rc1.php +++ b/phpBB/includes/db/migration/v309rc1.php @@ -53,46 +53,54 @@ class phpbb_db_migration_v309rc1 extends phpbb_db_migration function update_data() { - set_config('ip_login_limit_max', '50'); - set_config('ip_login_limit_time', '21600'); - set_config('ip_login_limit_use_forwarded', '0'); + 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'))), + ); + } + 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 ' . $db->sql_like_expression('EXT_GROUP_' . $db->any_char); - $result = $db->sql_query($sql); + WHERE group_name ' . $this->db->sql_like_expression('EXT_GROUP_' . $this->db->any_char); + $result = $this->db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + 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 ' . $db->sql_build_array('UPDATE', $sql_ary) . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE group_id = ' . $row['group_id']; - _sql($sql, $errored, $error_ary); + $this->sql_query($sql, $errored, $error_ary); } - $db->sql_freeresult($result); - - global $db_tools, $table_prefix; + $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 ($db_tools->sql_layer == 'firebird') + if ($this->db_tools->sql_layer == 'firebird') { $tables = array( - $table_prefix . 'captcha_questions', - $table_prefix . 'captcha_answers', - $table_prefix . 'qa_confirm', + $this->table_prefix . 'captcha_questions', + $this->table_prefix . 'captcha_answers', + $this->table_prefix . 'qa_confirm', ); foreach ($tables as $table) { - if ($db_tools->sql_table_exists($table)) + if ($this->db_tools->sql_table_exists($table)) { - $db_tools->sql_table_drop($table); + $this->db_tools->sql_table_drop($table); } } } -- cgit v1.2.1 From e7389e4c32f031fc6025880adf22b40d7d195f27 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 10 Nov 2012 04:00:38 -0600 Subject: [feature/migrations] 3.0.8-rc1 migration, fix some calls PHPBB3-9737 --- phpBB/includes/db/migration/v3011rc1.php | 4 +- phpBB/includes/db/migration/v308rc1.php | 169 ++++++++++++++++--------------- phpBB/includes/db/migration/v309rc1.php | 2 +- 3 files changed, 89 insertions(+), 86 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/v3011rc1.php b/phpBB/includes/db/migration/v3011rc1.php index aad80ba59f..3bae7a4a2d 100644 --- a/phpBB/includes/db/migration/v3011rc1.php +++ b/phpBB/includes/db/migration/v3011rc1.php @@ -47,7 +47,7 @@ class phpbb_db_migration_v3011rc1 extends phpbb_db_migration $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, $errored, $error_ary); + $this->sql_query($sql); } } @@ -84,7 +84,7 @@ class phpbb_db_migration_v3011rc1 extends phpbb_db_migration { $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' WHERE ' . $this->db->sql_in_set('msg_id', $delete_pms); - $this->sql_query($sql, $errored, $error_ary); + $this->sql_query($sql); return true; } diff --git a/phpBB/includes/db/migration/v308rc1.php b/phpBB/includes/db/migration/v308rc1.php index 13d0e98b1c..cbfedb1b53 100644 --- a/phpBB/includes/db/migration/v308rc1.php +++ b/phpBB/includes/db/migration/v308rc1.php @@ -20,14 +20,37 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration } 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( + 'post' => array( + 'base' => 'board', + 'class' => 'acp', + 'title' => 'ACP_POST_SETTINGS', + 'auth' => 'acl_a_board', + 'cat' => 'ACP_MESSAGES', + 'after' => array('message', 'ACP_MESSAGE_SETTINGS') + ), + )), + array('config.add', array('load_unreads_search', 1)), + array('config.update_if', array(600, 'queue_interval', 60)), + array('config.update_if', array(50, 'email_package_size', 20)), + ); + } + + function update_file_extension_group_names() { // Update file extension group names to use language strings. $sql = 'SELECT lang_dir FROM ' . LANG_TABLE; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); $extension_groups_updated = array(); - while ($lang_dir = $db->sql_fetchfield('lang_dir')) + while ($lang_dir = $this->db->sql_fetchfield('lang_dir')) { $lang_dir = basename($lang_dir); @@ -37,9 +60,9 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration // On an already updated board, they can also already be in language/.../acp/attachments.php // in the board root. $lang_files = array( - "{$phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.$phpEx", - "{$phpbb_root_path}language/$lang_dir/install.$phpEx", - "{$phpbb_root_path}language/$lang_dir/acp/attachments.$phpEx", + "{$this->phpbb_root_path}install/update/new/language/$lang_dir/acp/attachments.$this->phpEx", + "{$this->phpbb_root_path}language/$lang_dir/install.$this->phpEx", + "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.$this->phpEx", ); foreach ($lang_files as $lang_file) @@ -64,48 +87,38 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration ); $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE group_name = '" . $db->sql_escape($lang_val) . "'"; - _sql($sql, $errored, $error_ary); + 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; } } } - $db->sql_freeresult($result); - - // Install modules - $modules_to_install = array( - 'post' => array( - 'base' => 'board', - 'class' => 'acp', - 'title' => 'ACP_POST_SETTINGS', - 'auth' => 'acl_a_board', - 'cat' => 'ACP_MESSAGES', - 'after' => array('message', 'ACP_MESSAGE_SETTINGS') - ), - ); - - _add_modules($modules_to_install); + $this->db->sql_freeresult($result); + } - // update + 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\''; - _sql($sql, $errored, $error_ary); + $this->sql_query($sql); + } - // add Bing Bot + 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 = '" . $db->sql_escape($bot_name_clean) . "'"; - $result = $db->sql_query($sql); - $bing_already_added = (bool) $db->sql_fetchfield('user_id'); - $db->sql_freeresult($result); + 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) { @@ -114,9 +127,9 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration $sql = 'SELECT group_id, group_colour FROM ' . GROUPS_TABLE . " WHERE group_name = 'BOTS'"; - $result = $db->sql_query($sql); - $group_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $group_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); if (!$group_row) { @@ -127,7 +140,7 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration if (!function_exists('user_add')) { - include($phpbb_root_path . 'includes/functions_user.' . $phpEx); + include($this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx); } $user_row = array( @@ -138,16 +151,16 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration 'user_password' => '', 'user_colour' => $group_row['group_colour'], 'user_email' => '', - 'user_lang' => $config['default_lang'], - 'user_style' => $config['default_style'], + 'user_lang' => $this->config['default_lang'], + 'user_style' => $this->config['default_style'], 'user_timezone' => 0, - 'user_dateformat' => $config['default_dateformat'], + 'user_dateformat' => $this->config['default_dateformat'], 'user_allow_massemail' => 0, ); $user_id = user_add($user_row); - $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $db->sql_build_array('INSERT', array( + $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, @@ -155,68 +168,58 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration 'bot_ip' => (string) $bot_ip, )); - _sql($sql, $errored, $error_ary); + $this->sql_query($sql); } - // end Bing Bot addition + } + 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(); - do - { - $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', - ), + $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 = $db->sql_build_query('SELECT', $sql_array); - $result = $db->sql_query_limit($sql, $batch_size); - - $topic_ids = array(); - while ($row = $db->sql_fetchrow($result)) - { - $topic_ids[] = (int) $row['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); - $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; - } - $db->sql_freeresult($result); + $topic_ids = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $topic_ids[] = (int) $row['topic_id']; - if (!empty($topic_ids)) - { - $sql = 'DELETE FROM ' . TOPICS_TABLE . ' - WHERE ' . $db->sql_in_set('topic_id', $topic_ids); - $db->sql_query($sql); - } + $sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; } - while (sizeof($topic_ids) == $batch_size); + $this->db->sql_freeresult($result); - // Sync the forums we have deleted shadow topics from. - sync('forum', 'forum_id', $sync_forum_ids, true, true); + if (!empty($topic_ids)) + { + $sql = 'DELETE FROM ' . TOPICS_TABLE . ' + WHERE ' . $this->db->sql_in_set('topic_id', $topic_ids); + $this->db->sql_query($sql); - // Unread posts search load switch - set_config('load_unreads_search', '1'); + // Sync the forums we have deleted shadow topics from. + sync('forum', 'forum_id', $sync_forum_ids, true, true); - // Reduce queue interval to 60 seconds, email package size to 20 - if ($config['queue_interval'] == 600) - { - set_config('queue_interval', '60'); + return true; } - - if ($config['email_package_size'] == 50) + else { - set_config('email_package_size', '20'); + return false; } } } diff --git a/phpBB/includes/db/migration/v309rc1.php b/phpBB/includes/db/migration/v309rc1.php index ce51e54642..e8db93c78d 100644 --- a/phpBB/includes/db/migration/v309rc1.php +++ b/phpBB/includes/db/migration/v309rc1.php @@ -79,7 +79,7 @@ class phpbb_db_migration_v309rc1 extends phpbb_db_migration $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE group_id = ' . $row['group_id']; - $this->sql_query($sql, $errored, $error_ary); + $this->sql_query($sql); } $this->db->sql_freeresult($result); } -- cgit v1.2.1 From 2a7985c26fcf558c30fa316262344307ffc99e9e Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 10 Nov 2012 05:59:01 -0600 Subject: [feature/migrations] Migrations back through 3.0.6 PHPBB3-9737 --- phpBB/includes/db/migration/v306rc1.php | 344 ++++++++++++++------------------ phpBB/includes/db/migration/v306rc3.php | 9 +- phpBB/includes/db/migration/v307rc1.php | 23 ++- phpBB/includes/db/migration/v307rc2.php | 29 ++- phpBB/includes/db/migration/v308rc1.php | 4 +- 5 files changed, 201 insertions(+), 208 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/v306rc1.php b/phpBB/includes/db/migration/v306rc1.php index 63d1c66c2d..45b597d56b 100644 --- a/phpBB/includes/db/migration/v306rc1.php +++ b/phpBB/includes/db/migration/v306rc1.php @@ -61,109 +61,141 @@ class phpbb_db_migration_v306rc1 extends phpbb_db_migration function update_data() { - // Let's see if the GD Captcha can be enabled... we simply look for what *is* enabled... - if (!empty($config['captcha_gd']) && !isset($config['captcha_plugin'])) - { - set_config('captcha_plugin', 'phpbb_captcha_gd'); - } - else if (!isset($config['captcha_plugin'])) - { - set_config('captcha_plugin', 'phpbb_captcha_nogd'); - } - - // Entries for the Feed Feature - set_config('feed_enable', '0'); - set_config('feed_limit', '10'); - - set_config('feed_overall_forums', '1'); - set_config('feed_overall_forums_limit', '15'); - - set_config('feed_overall_topics', '0'); - set_config('feed_overall_topics_limit', '15'); - - set_config('feed_forum', '1'); - set_config('feed_topic', '1'); - set_config('feed_item_statistics', '1'); - - // Entries for smiley pagination - set_config('smilies_per_page', '50'); - - // Entry for reporting PMs - set_config('allow_pm_report', '1'); - - // Install modules - $modules_to_install = array( - 'feed' => array( - 'base' => 'board', - 'class' => 'acp', - 'title' => 'ACP_FEED_SETTINGS', - 'auth' => 'acl_a_board', - 'cat' => 'ACP_BOARD_CONFIGURATION', - 'after' => array('signature', 'ACP_SIGNATURE_SETTINGS') - ), - 'warnings' => array( - 'base' => 'users', - 'class' => 'acp', - 'title' => 'ACP_USER_WARNINGS', - 'auth' => 'acl_a_user', - 'display' => 0, - 'cat' => 'ACP_CAT_USERS', - 'after' => array('feedback', 'ACP_USER_FEEDBACK') - ), - 'send_statistics' => array( - 'base' => 'send_statistics', - 'class' => 'acp', - 'title' => 'ACP_SEND_STATISTICS', - 'auth' => 'acl_a_server', - 'cat' => 'ACP_SERVER_CONFIGURATION' - ), - 'setting_forum_copy' => array( - 'base' => 'permissions', - 'class' => 'acp', - 'title' => 'ACP_FORUM_PERMISSIONS_COPY', - 'auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth', - 'cat' => 'ACP_FORUM_BASED_PERMISSIONS', - 'after' => array('setting_forum_local', 'ACP_FORUM_PERMISSIONS') - ), - 'pm_reports' => array( - 'base' => 'pm_reports', - 'class' => 'mcp', - 'title' => 'MCP_PM_REPORTS_OPEN', - 'auth' => 'aclf_m_report', - 'cat' => 'MCP_REPORTS' - ), - 'pm_reports_closed' => array( - 'base' => 'pm_reports', - 'class' => 'mcp', - 'title' => 'MCP_PM_REPORTS_CLOSED', - 'auth' => 'aclf_m_report', - 'cat' => 'MCP_REPORTS' - ), - 'pm_report_details' => array( - 'base' => 'pm_reports', - 'class' => 'mcp', - 'title' => 'MCP_PM_REPORT_DETAILS', - 'auth' => 'aclf_m_report', - 'cat' => 'MCP_REPORTS' - ), + return array( + //array('custom', array(array(&$this, ''))) + array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')), + array('config.update_if', array( + ($this->config['captcha_gd']), + '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('config.add_if', array( + ($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']), + 'allow_avatar', + 1, + )), + array('config.add', array('allow_avatar_remote_upload', 0)), + array('config.add_if', array( + ($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']), + 'allow_avatar_remote_upload', + 1, + )), + + array('module.add', array( + 'feed' => array( + 'base' => 'board', + 'class' => 'acp', + 'title' => 'ACP_FEED_SETTINGS', + 'auth' => 'acl_a_board', + 'cat' => 'ACP_BOARD_CONFIGURATION', + 'after' => array('signature', 'ACP_SIGNATURE_SETTINGS') + ), + )), + array('module.add', array( + 'warnings' => array( + 'base' => 'users', + 'class' => 'acp', + 'title' => 'ACP_USER_WARNINGS', + 'auth' => 'acl_a_user', + 'display' => 0, + 'cat' => 'ACP_CAT_USERS', + 'after' => array('feedback', 'ACP_USER_FEEDBACK') + ), + )), + array('module.add', array( + 'send_statistics' => array( + 'base' => 'send_statistics', + 'class' => 'acp', + 'title' => 'ACP_SEND_STATISTICS', + 'auth' => 'acl_a_server', + 'cat' => 'ACP_SERVER_CONFIGURATION' + ), + )), + array('module.add', array( + 'setting_forum_copy' => array( + 'base' => 'permissions', + 'class' => 'acp', + 'title' => 'ACP_FORUM_PERMISSIONS_COPY', + 'auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth', + 'cat' => 'ACP_FORUM_BASED_PERMISSIONS', + 'after' => array('setting_forum_local', 'ACP_FORUM_PERMISSIONS') + ), + )), + array('module.add', array( + 'pm_reports' => array( + 'base' => 'pm_reports', + 'class' => 'mcp', + 'title' => 'MCP_PM_REPORTS_OPEN', + 'auth' => 'aclf_m_report', + 'cat' => 'MCP_REPORTS' + ), + )), + array('module.add', array( + 'pm_reports_closed' => array( + 'base' => 'pm_reports', + 'class' => 'mcp', + 'title' => 'MCP_PM_REPORTS_CLOSED', + 'auth' => 'aclf_m_report', + 'cat' => 'MCP_REPORTS' + ), + )), + array('module.add', array( + 'pm_report_details' => array( + 'base' => 'pm_reports', + 'class' => 'mcp', + 'title' => 'MCP_PM_REPORT_DETAILS', + 'auth' => 'aclf_m_report', + 'cat' => 'MCP_REPORTS' + ), + )), + array('custom', array(array(&$this, 'add_newly_registered_group'))), + array('custom', array(array(&$this, 'set_user_options_default'))), ); + } - _add_modules($modules_to_install); + 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 = $db->sql_query($sql); - $group_id = (int) $db->sql_fetchfield('group_id'); - $db->sql_freeresult($result); + $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)"; - _sql($sql, $errored, $error_ary); + $this->sql_query($sql); - $group_id = $db->sql_nextid(); + $group_id = $this->db->sql_nextid(); } // Insert new user role... at the end of the chain @@ -171,35 +203,35 @@ class phpbb_db_migration_v306rc1 extends phpbb_db_migration FROM ' . ACL_ROLES_TABLE . " WHERE role_name = 'ROLE_USER_NEW_MEMBER' AND role_type = 'u_'"; - $result = $db->sql_query($sql); - $u_role = (int) $db->sql_fetchfield('role_id'); - $db->sql_freeresult($result); + $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 = $db->sql_query($sql); - $next_order_id = (int) $db->sql_fetchfield('max_order_id'); - $db->sql_freeresult($result); + $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)"; - _sql($sql, $errored, $error_ary); - $u_role = $db->sql_nextid(); + $this->sql_query($sql); + $u_role = $this->db->sql_nextid(); if (!$errored) { // 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')"; - _sql($sql, $errored, $error_ary); + $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)"; - _sql($sql, $errored, $error_ary); + $this->sql_query($sql); } } @@ -208,29 +240,29 @@ class phpbb_db_migration_v306rc1 extends phpbb_db_migration FROM ' . ACL_ROLES_TABLE . " WHERE role_name = 'ROLE_FORUM_NEW_MEMBER' AND role_type = 'f_'"; - $result = $db->sql_query($sql); - $f_role = (int) $db->sql_fetchfield('role_id'); - $db->sql_freeresult($result); + $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 = $db->sql_query($sql); - $next_order_id = (int) $db->sql_fetchfield('max_order_id'); - $db->sql_freeresult($result); + $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)"; - _sql($sql, $errored, $error_ary); - $f_role = $db->sql_nextid(); + $this->sql_query($sql); + $f_role = $this->db->sql_nextid(); if (!$errored) { $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')"; - _sql($sql, $errored, $error_ary); + $this->sql_query($sql); } } @@ -238,25 +270,14 @@ class phpbb_db_migration_v306rc1 extends phpbb_db_migration $sql = 'SELECT 1 FROM ' . USERS_TABLE . ' WHERE user_new = 0'; - $result = $db->sql_query_limit($sql, 1); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + $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'; - _sql($sql, $errored, $error_ary); - } - - // Newly registered users limit - if (!isset($config['new_member_post_limit'])) - { - set_config('new_member_post_limit', (!empty($config['enable_queue_trigger'])) ? $config['queue_trigger_posts'] : 0); - } - - if (!isset($config['new_member_group_default'])) - { - set_config('new_member_group_default', 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... @@ -265,9 +286,9 @@ class phpbb_db_migration_v306rc1 extends phpbb_db_migration FROM ' . ACL_GROUPS_TABLE . ' WHERE group_id = ' . $group_id . ' AND auth_role_id = ' . $f_role; - $result = $db->sql_query($sql); - $is_options = (int) $db->sql_fetchfield('forum_id'); - $db->sql_freeresult($result); + $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) @@ -276,75 +297,18 @@ class phpbb_db_migration_v306rc1 extends phpbb_db_migration $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' WHERE forum_type != ' . FORUM_LINK; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { - _sql('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)', $errored, $error_ary); + $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)'); } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); } // Clear permissions... - include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx); + include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->phpEx); $auth_admin = new auth_admin(); $auth_admin->acl_clear_prefetch(); - - if (!isset($config['allow_avatar'])) - { - if ($config['allow_avatar_upload'] || $config['allow_avatar_local'] || $config['allow_avatar_remote']) - { - set_config('allow_avatar', '1'); - } - else - { - set_config('allow_avatar', '0'); - } - } - - if (!isset($config['allow_avatar_remote_upload'])) - { - if ($config['allow_avatar_remote'] && $config['allow_avatar_upload']) - { - set_config('allow_avatar_remote_upload', '1'); - } - else - { - set_config('allow_avatar_remote_upload', '0'); - } - } - - // Minimum number of characters - if (!isset($config['min_post_chars'])) - { - set_config('min_post_chars', '1'); - } - - if (!isset($config['allow_quick_reply'])) - { - set_config('allow_quick_reply', '1'); - } - - // Set every members user_options column to enable - // bbcode, smilies and URLs for signatures by default - $sql = 'SELECT user_options - FROM ' . USERS_TABLE . ' - WHERE user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')'; - $result = $db->sql_query_limit($sql, 1); - $user_option = (int) $db->sql_fetchfield('user_options'); - $db->sql_freeresult($result); - - // Check if we already updated the database by checking bit 15 which we used to store the sig_bbcode option - if (!($user_option & 1 << 15)) - { - // 229376 is the added value to enable all three signature options - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_options = user_options + 229376'; - _sql($sql, $errored, $error_ary); - } - - if (!isset($config['delete_time'])) - { - set_config('delete_time', $config['edit_time']); - } } } diff --git a/phpBB/includes/db/migration/v306rc3.php b/phpBB/includes/db/migration/v306rc3.php index b3bd49eafa..e2c4e66ada 100644 --- a/phpBB/includes/db/migration/v306rc3.php +++ b/phpBB/includes/db/migration/v306rc3.php @@ -20,12 +20,19 @@ class phpbb_db_migration_v306rc3 extends phpbb_db_migration } function update_data() + { + return array( + array('custom', array(array(&$this, 'update_cp_fields'))), + ); + } + + 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)'; - _sql($sql, $errored, $error_ary); + $this->sql_query($sql); } } diff --git a/phpBB/includes/db/migration/v307rc1.php b/phpBB/includes/db/migration/v307rc1.php index f1c8b3384a..9b55cb2757 100644 --- a/phpBB/includes/db/migration/v307rc1.php +++ b/phpBB/includes/db/migration/v307rc1.php @@ -30,17 +30,22 @@ class phpbb_db_migration_v307rc1 extends phpbb_db_migration function update_data() { - // ATOM Feeds - set_config('feed_overall', '1'); - set_config('feed_http_auth', '0'); - set_config('feed_limit_post', (string) (isset($config['feed_limit']) ? (int) $config['feed_limit'] : 15)); - set_config('feed_limit_topic', (string) (isset($config['feed_overall_topics_limit']) ? (int) $config['feed_overall_topics_limit'] : 10)); - set_config('feed_topics_new', (!empty($config['feed_overall_topics']) ? '1' : '0')); - set_config('feed_topics_active', (!empty($config['feed_overall_topics']) ? '1' : '0')); + 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'))), + ); + } + function delete_text_templates() + { // Delete all text-templates from the template_data $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' - WHERE template_filename ' . $db->sql_like_expression($db->any_char . '.txt'); - _sql($sql, $errored, $error_ary); + WHERE template_filename ' . $this->db->sql_like_expression($this->db->any_char . '.txt'); + $this->sql_query($sql); } } diff --git a/phpBB/includes/db/migration/v307rc2.php b/phpBB/includes/db/migration/v307rc2.php index f9492f3d1c..438ebfb8c2 100644 --- a/phpBB/includes/db/migration/v307rc2.php +++ b/phpBB/includes/db/migration/v307rc2.php @@ -21,15 +21,26 @@ class phpbb_db_migration_v307rc2 extends phpbb_db_migration function update_data() { + return array( + array('custom', array(array(&$this, 'update_email_hash'))), + ); + } + + 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 = $db->sql_query($sql); + $result = $this->db->sql_query_limit($sql, $limit, $start); $i = 0; - while ($row = $db->sql_fetchrow($result)) + 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']); @@ -41,13 +52,19 @@ class phpbb_db_migration_v307rc2 extends phpbb_db_migration ); $sql = 'UPDATE ' . USERS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . (int) $row['user_id']; - _sql($sql, $errored, $error_ary, ($i % 100 == 0)); - - ++$i; + $this->sql_query($sql); } } $db->sql_freeresult($result); + + if ($i < $limit) + { + // Completed + return false; + } + + return $start + $limit; } } diff --git a/phpBB/includes/db/migration/v308rc1.php b/phpBB/includes/db/migration/v308rc1.php index cbfedb1b53..f365695058 100644 --- a/phpBB/includes/db/migration/v308rc1.php +++ b/phpBB/includes/db/migration/v308rc1.php @@ -37,8 +37,8 @@ class phpbb_db_migration_v308rc1 extends phpbb_db_migration ), )), array('config.add', array('load_unreads_search', 1)), - array('config.update_if', array(600, 'queue_interval', 60)), - array('config.update_if', array(50, 'email_package_size', 20)), + array('config.update_if_equals', array(600, 'queue_interval', 60)), + array('config.update_if_equals', array(50, 'email_package_size', 20)), ); } -- cgit v1.2.1 From ae8edf7b0e74c54b5b02b66a8b2a436a4172c63e Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 10 Nov 2012 06:26:38 -0600 Subject: [feature/migrations] Use $this->db PHPBB3-9737 --- phpBB/includes/db/migration.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php index aca9d264bb..de9f6d07e3 100644 --- a/phpBB/includes/db/migration.php +++ b/phpBB/includes/db/migration.php @@ -95,29 +95,29 @@ class phpbb_db_migration echo "
\n{$sql}\n
"; } - $db->sql_return_on_error(true); + $this->db->sql_return_on_error(true); if ($sql === 'begin') { - $result = $db->sql_transaction('begin'); + $result = $this->db->sql_transaction('begin'); } else if ($sql === 'commit') { - $result = $db->sql_transaction('commit'); + $result = $this->db->sql_transaction('commit'); } else { - $result = $db->sql_query($sql); - if ($db->sql_error_triggered) + $result = $this->db->sql_query($sql); + if ($this->db->sql_error_triggered) { $this->errors[] = array( - 'sql' => $db->sql_error_sql, - 'code' => $db->sql_error_returned, + 'sql' => $this->db->sql_error_sql, + 'code' => $this->db->sql_error_returned, ); } } - $db->sql_return_on_error(false); + $this->db->sql_return_on_error(false); return $result; } -- cgit v1.2.1 From 167faed1630d01e3d592a6696f58316c1d832ff9 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 10 Nov 2012 06:32:02 -0600 Subject: [feature/migrations] Depend on part2 PHPBB3-9737 --- phpBB/includes/db/migration/v305.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/v305.php b/phpBB/includes/db/migration/v305.php index b4d676d72a..71e28c6b7b 100644 --- a/phpBB/includes/db/migration/v305.php +++ b/phpBB/includes/db/migration/v305.php @@ -11,7 +11,7 @@ class phpbb_db_migration_v305 extends phpbb_db_migration { function depends_on() { - return array('phpbb_db_migration_v305rc1'); + return array('phpbb_db_migration_v305rc1part2'); } function update_schema() -- cgit v1.2.1 From b52a0f50ab980ca941267ddb4f509f104b07db77 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sat, 10 Nov 2012 13:32:44 +0100 Subject: [feature/migrations] Update 3.0.3-3.0.5 migrations to work --- phpBB/includes/db/migration/305rc1part2.php | 34 +++++++++ phpBB/includes/db/migration/v303rc1.php | 100 ++++---------------------- phpBB/includes/db/migration/v304.php | 15 ++-- phpBB/includes/db/migration/v304rc1.php | 13 +++- phpBB/includes/db/migration/v305rc1.php | 105 +++++++++++----------------- 5 files changed, 107 insertions(+), 160 deletions(-) create mode 100644 phpBB/includes/db/migration/305rc1part2.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/305rc1part2.php b/phpBB/includes/db/migration/305rc1part2.php new file mode 100644 index 0000000000..238e533b06 --- /dev/null +++ b/phpBB/includes/db/migration/305rc1part2.php @@ -0,0 +1,34 @@ + array( + ACL_OPTIONS_TABLE => array('auth_option'), + ), + 'add_unique_index' => array( + ACL_OPTIONS_TABLE => array( + 'auth_option' => array('auth_option'), + ), + ), + ); + } + + function update_data() + { + } +} diff --git a/phpBB/includes/db/migration/v303rc1.php b/phpBB/includes/db/migration/v303rc1.php index b8ec5668fd..7518a6ed54 100644 --- a/phpBB/includes/db/migration/v303rc1.php +++ b/phpBB/includes/db/migration/v303rc1.php @@ -35,93 +35,20 @@ class phpbb_db_migration_v303rc1 extends phpbb_db_migration 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('set_group_default_max_recipients')) - - // Not prefilling yet - set_config('dbms_version', ''); - - // Add new permission u_masspm_group and duplicate settings from u_masspm - include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx); - $auth_admin = new auth_admin(); - - // Only add the new permission if it does not already exist - if (empty($auth_admin->acl_options['id']['u_masspm_group'])) - { - $auth_admin->acl_add_option(array('global' => array('u_masspm_group'))); - - // Now the tricky part, filling the permission - $old_id = $auth_admin->acl_options['id']['u_masspm']; - $new_id = $auth_admin->acl_options['id']['u_masspm_group']; - - $tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE); - - foreach ($tables as $table) - { - $sql = 'SELECT * - FROM ' . $table . ' - WHERE auth_option_id = ' . $old_id; - $result = _sql($sql, $errored, $error_ary); - - $sql_ary = array(); - while ($row = $db->sql_fetchrow($result)) - { - $row['auth_option_id'] = $new_id; - $sql_ary[] = $row; - } - $db->sql_freeresult($result); - - if (sizeof($sql_ary)) - { - $db->sql_multi_insert($table, $sql_ary); - } - } - - // Remove any old permission entries - $auth_admin->acl_clear_prefetch(); - } - - /** - * Do not resync post counts here. An admin may do this later from the ACP - $start = 0; - $step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000; - - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = 0'; - _sql($sql, $errored, $error_ary); - - do - { - $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id - FROM ' . POSTS_TABLE . ' - WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . ' - AND post_postcount = 1 AND post_approved = 1 - GROUP BY poster_id'; - $result = _sql($sql, $errored, $error_ary); - - if ($row = $db->sql_fetchrow($result)) - { - do - { - $sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}"; - _sql($sql, $errored, $error_ary); - } - while ($row = $db->sql_fetchrow($result)); - - $start += $step; - } - else - { - $start = 0; - } - $db->sql_freeresult($result); - } - while ($start); - */ + array('custom', array(array(&$this, 'set_group_default_max_recipients'))), + array('config.add', array('dbms_version', '')), + array('permission.add', array('u_masspm_group', phpbb_auth::IS_GLOBAL), + array('custom', array(array(&$this, 'correct_acp_email_permissions'))), + )); + } - $sql = 'UPDATE ' . MODULES_TABLE . ' - SET module_auth = \'acl_a_email && cfg_email_enable\' - WHERE module_class = \'acp\' - AND module_basename = \'email\''; - _sql($sql, $errored, $error_ary); + 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() @@ -131,5 +58,4 @@ class phpbb_db_migration_v303rc1 extends phpbb_db_migration 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/v304.php b/phpBB/includes/db/migration/v304.php index 2895caaa6d..5358bcc20f 100644 --- a/phpBB/includes/db/migration/v304.php +++ b/phpBB/includes/db/migration/v304.php @@ -20,21 +20,28 @@ class phpbb_db_migration_v304 extends phpbb_db_migration } function update_data() + { + return array( + array('custom', array(array(&$this, 'rename_log_delete_topic'))), + ); + } + + function rename_log_delete_topic() { if ($db->sql_layer == 'oracle') { // log_operation is CLOB - but we can change this later - $sql = 'UPDATE ' . LOG_TABLE . " + $sql = 'UPDATE ' . $this->table_prefix . "log SET log_operation = 'LOG_DELETE_TOPIC' WHERE log_operation LIKE 'LOG_TOPIC_DELETED'"; - _sql($sql, $errored, $error_ary); + $this->sql_query($sql); } else { - $sql = 'UPDATE ' . LOG_TABLE . " + $sql = 'UPDATE ' . $this->table_prefix . "log SET log_operation = 'LOG_DELETE_TOPIC' WHERE log_operation = 'LOG_TOPIC_DELETED'"; - _sql($sql, $errored, $error_ary); + $this->sql_query($sql); } } } diff --git a/phpBB/includes/db/migration/v304rc1.php b/phpBB/includes/db/migration/v304rc1.php index a7098ce62f..2daad4e826 100644 --- a/phpBB/includes/db/migration/v304rc1.php +++ b/phpBB/includes/db/migration/v304rc1.php @@ -56,13 +56,20 @@ class phpbb_db_migration_v304rc1 extends phpbb_db_migration } function update_data() + { + return array( + array('custom', array(array(&$this, 'update_custom_profile_fields'))), + ); + } + + 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 = _sql($sql, $errored, $error_ary); + $result = $this->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $sql_ary = array( 'field_required' => 0, @@ -90,7 +97,7 @@ class phpbb_db_migration_v304rc1 extends phpbb_db_migration $sql_ary['field_show_profile'] = 1; } - _sql('UPDATE ' . PROFILE_FIELDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE field_id = ' . $row['field_id'], $errored, $error_ary); + $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); } } } diff --git a/phpBB/includes/db/migration/v305rc1.php b/phpBB/includes/db/migration/v305rc1.php index 8d9c4d2456..4f20796608 100644 --- a/phpBB/includes/db/migration/v305rc1.php +++ b/phpBB/includes/db/migration/v305rc1.php @@ -27,28 +27,29 @@ class phpbb_db_migration_v305rc1 extends phpbb_db_migration function update_data() { - // Captcha config variables - set_config('captcha_gd_wave', 0); - set_config('captcha_gd_3d_noise', 1); - set_config('captcha_gd_fonts', 1); - set_config('confirm_refresh', 1); + $search_indexing_state = $this->config['search_indexing_state']; - // Maximum number of keywords - set_config('max_num_search_keywords', 10); - - // Remove static config var and put it back as dynamic variable - $sql = 'UPDATE ' . CONFIG_TABLE . " - SET is_dynamic = 1 - WHERE config_name = 'search_indexing_state'"; - _sql($sql, $errored, $error_ary); + 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_refresh', 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'))), + ); + } - // Hash old MD5 passwords + function hash_old_passwords() + { $sql = 'SELECT user_id, user_password - FROM ' . USERS_TABLE . ' + FROM ' . $this->table_prefix . 'users WHERE user_pass_convert = 1'; - $result = _sql($sql, $errored, $error_ary); + $result = $this->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { if (strlen($row['user_password']) == 32) { @@ -56,33 +57,36 @@ class phpbb_db_migration_v305rc1 extends phpbb_db_migration 'user_password' => phpbb_hash($row['user_password']), ); - _sql('UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id'], $errored, $error_ary); + $this->sql_query('UPDATE ' . $this->table_prefix . 'users SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id']); } } $db->sql_freeresult($result); + } + function update_ichiro_bot() + { // Adjust bot entry - $sql = 'UPDATE ' . BOTS_TABLE . " + $sql = 'UPDATE ' . $this->table_prefix . "bots SET bot_agent = 'ichiro/' WHERE bot_agent = 'ichiro/2'"; - _sql($sql, $errored, $error_ary); - + $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 - - // We get duplicate entries first $sql = 'SELECT auth_option - FROM ' . ACL_OPTIONS_TABLE . ' + FROM ' . $this->table_prefix . 'acl_options GROUP BY auth_option HAVING COUNT(*) >= 2'; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); $auth_options = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $auth_options[] = $row['auth_option']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); // Remove specific auth options if (!empty($auth_options)) @@ -95,52 +99,21 @@ class phpbb_db_migration_v305rc1 extends phpbb_db_migration 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 = $db->sql_query($sql); + $result = $this->sql_query($sql); // Skip first row, this is our original auth option we want to preserve - $row = $db->sql_fetchrow($result); + $row = $this->db->sql_fetchrow($result); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { // Ok, remove this auth option... - _sql('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary); - _sql('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary); - _sql('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary); - _sql('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $row['auth_option_id'], $errored, $error_ary); + $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']); } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); } } - - // Now make auth_option UNIQUE, by dropping the old index and adding a UNIQUE one. - $changes = array( - 'drop_keys' => array( - ACL_OPTIONS_TABLE => array('auth_option'), - ), - ); - - global $db_tools; - - $statements = $db_tools->perform_schema_changes($changes); - - foreach ($statements as $sql) - { - _sql($sql, $errored, $error_ary); - } - - $changes = array( - 'add_unique_index' => array( - ACL_OPTIONS_TABLE => array( - 'auth_option' => array('auth_option'), - ), - ), - ); - - $statements = $db_tools->perform_schema_changes($changes); - - foreach ($statements as $sql) - { - _sql($sql, $errored, $error_ary); - } } } -- cgit v1.2.1 From ce021710fbe4d594e4f66c3338da8bb2610a0c75 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 8 Jan 2013 22:07:01 -0600 Subject: [feature/migrations] Rename classes, depends on PHPBB3-9737 --- phpBB/includes/db/migration/305rc1part2.php | 34 - phpBB/includes/db/migration/3_0_1.php | 25 + phpBB/includes/db/migration/3_0_10.php | 25 + phpBB/includes/db/migration/3_0_10_rc1.php | 28 + phpBB/includes/db/migration/3_0_10_rc2.php | 25 + phpBB/includes/db/migration/3_0_10_rc3.php | 25 + phpBB/includes/db/migration/3_0_11.php | 25 + phpBB/includes/db/migration/3_0_11_rc1.php | 96 + phpBB/includes/db/migration/3_0_11_rc2 | 31 + phpBB/includes/db/migration/3_0_12_rc1.php | 26 + phpBB/includes/db/migration/3_0_1_rc1.php | 77 + phpBB/includes/db/migration/3_0_2.php | 25 + phpBB/includes/db/migration/3_0_2_rc1.php | 30 + phpBB/includes/db/migration/3_0_2_rc2.php | 52 + phpBB/includes/db/migration/3_0_3.php | 25 + phpBB/includes/db/migration/3_0_3_rc1.php | 61 + phpBB/includes/db/migration/3_0_4.php | 47 + phpBB/includes/db/migration/3_0_4_rc1.php | 103 + phpBB/includes/db/migration/3_0_5.php | 25 + phpBB/includes/db/migration/3_0_5_rc1.php | 119 + phpBB/includes/db/migration/3_0_5_rc1part2.php | 34 + phpBB/includes/db/migration/3_0_6.php | 25 + phpBB/includes/db/migration/3_0_6_rc1.php | 314 +++ phpBB/includes/db/migration/3_0_6_rc2.php | 25 + phpBB/includes/db/migration/3_0_6_rc3.php | 38 + phpBB/includes/db/migration/3_0_6_rc4.php | 25 + phpBB/includes/db/migration/3_0_7.php | 25 + phpBB/includes/db/migration/3_0_7_pl1.php | 25 + phpBB/includes/db/migration/3_0_7_rc1.php | 51 + phpBB/includes/db/migration/3_0_7_rc2.php | 70 + phpBB/includes/db/migration/3_0_8.php | 25 + phpBB/includes/db/migration/3_0_8_rc1.php | 225 ++ phpBB/includes/db/migration/3_0_9.php | 25 + phpBB/includes/db/migration/3_0_9_rc1.php | 108 + phpBB/includes/db/migration/3_0_9_rc2.php | 25 + phpBB/includes/db/migration/3_0_9_rc3.php | 25 + phpBB/includes/db/migration/3_0_9_rc4.php | 25 + phpBB/includes/db/migration/v301.php | 25 - phpBB/includes/db/migration/v3010.php | 25 - phpBB/includes/db/migration/v3010rc1.php | 28 - phpBB/includes/db/migration/v3010rc2.php | 25 - phpBB/includes/db/migration/v3010rc3.php | 25 - phpBB/includes/db/migration/v3011.php | 25 - phpBB/includes/db/migration/v3011rc1.php | 96 - phpBB/includes/db/migration/v3011rc2.php | 31 - phpBB/includes/db/migration/v3012rc1.php | 26 - phpBB/includes/db/migration/v301rc1.php | 77 - phpBB/includes/db/migration/v302.php | 25 - phpBB/includes/db/migration/v302rc1.php | 30 - phpBB/includes/db/migration/v302rc2.php | 52 - phpBB/includes/db/migration/v303.php | 25 - phpBB/includes/db/migration/v303rc1.php | 61 - phpBB/includes/db/migration/v304.php | 47 - phpBB/includes/db/migration/v304rc1.php | 103 - phpBB/includes/db/migration/v305.php | 25 - phpBB/includes/db/migration/v305rc1.php | 119 - phpBB/includes/db/migration/v306.php | 25 - phpBB/includes/db/migration/v306rc1.php | 314 --- phpBB/includes/db/migration/v306rc2.php | 25 - phpBB/includes/db/migration/v306rc3.php | 38 - phpBB/includes/db/migration/v306rc4.php | 25 - phpBB/includes/db/migration/v307.php | 25 - phpBB/includes/db/migration/v307pl1.php | 25 - phpBB/includes/db/migration/v307rc1.php | 51 - phpBB/includes/db/migration/v307rc2.php | 70 - phpBB/includes/db/migration/v308.php | 25 - phpBB/includes/db/migration/v308rc1.php | 225 -- phpBB/includes/db/migration/v309.php | 25 - phpBB/includes/db/migration/v309rc1.php | 108 - phpBB/includes/db/migration/v309rc2.php | 25 - phpBB/includes/db/migration/v309rc3.php | 25 - phpBB/includes/db/migration/v309rc4.php | 25 - phpBB/includes/db/migrationtools/base.php | 15 + phpBB/includes/db/migrationtools/config.php | 121 + phpBB/includes/db/migrationtools/umil.php | 3037 ++++++++++++++++++++++++ 75 files changed, 5133 insertions(+), 1960 deletions(-) delete mode 100644 phpBB/includes/db/migration/305rc1part2.php create mode 100644 phpBB/includes/db/migration/3_0_1.php create mode 100644 phpBB/includes/db/migration/3_0_10.php create mode 100644 phpBB/includes/db/migration/3_0_10_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_10_rc2.php create mode 100644 phpBB/includes/db/migration/3_0_10_rc3.php create mode 100644 phpBB/includes/db/migration/3_0_11.php create mode 100644 phpBB/includes/db/migration/3_0_11_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_11_rc2 create mode 100644 phpBB/includes/db/migration/3_0_12_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_1_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_2.php create mode 100644 phpBB/includes/db/migration/3_0_2_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_2_rc2.php create mode 100644 phpBB/includes/db/migration/3_0_3.php create mode 100644 phpBB/includes/db/migration/3_0_3_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_4.php create mode 100644 phpBB/includes/db/migration/3_0_4_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_5.php create mode 100644 phpBB/includes/db/migration/3_0_5_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_5_rc1part2.php create mode 100644 phpBB/includes/db/migration/3_0_6.php create mode 100644 phpBB/includes/db/migration/3_0_6_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_6_rc2.php create mode 100644 phpBB/includes/db/migration/3_0_6_rc3.php create mode 100644 phpBB/includes/db/migration/3_0_6_rc4.php create mode 100644 phpBB/includes/db/migration/3_0_7.php create mode 100644 phpBB/includes/db/migration/3_0_7_pl1.php create mode 100644 phpBB/includes/db/migration/3_0_7_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_7_rc2.php create mode 100644 phpBB/includes/db/migration/3_0_8.php create mode 100644 phpBB/includes/db/migration/3_0_8_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_9.php create mode 100644 phpBB/includes/db/migration/3_0_9_rc1.php create mode 100644 phpBB/includes/db/migration/3_0_9_rc2.php create mode 100644 phpBB/includes/db/migration/3_0_9_rc3.php create mode 100644 phpBB/includes/db/migration/3_0_9_rc4.php delete mode 100644 phpBB/includes/db/migration/v301.php delete mode 100644 phpBB/includes/db/migration/v3010.php delete mode 100644 phpBB/includes/db/migration/v3010rc1.php delete mode 100644 phpBB/includes/db/migration/v3010rc2.php delete mode 100644 phpBB/includes/db/migration/v3010rc3.php delete mode 100644 phpBB/includes/db/migration/v3011.php delete mode 100644 phpBB/includes/db/migration/v3011rc1.php delete mode 100644 phpBB/includes/db/migration/v3011rc2.php delete mode 100644 phpBB/includes/db/migration/v3012rc1.php delete mode 100644 phpBB/includes/db/migration/v301rc1.php delete mode 100644 phpBB/includes/db/migration/v302.php delete mode 100644 phpBB/includes/db/migration/v302rc1.php delete mode 100644 phpBB/includes/db/migration/v302rc2.php delete mode 100644 phpBB/includes/db/migration/v303.php delete mode 100644 phpBB/includes/db/migration/v303rc1.php delete mode 100644 phpBB/includes/db/migration/v304.php delete mode 100644 phpBB/includes/db/migration/v304rc1.php delete mode 100644 phpBB/includes/db/migration/v305.php delete mode 100644 phpBB/includes/db/migration/v305rc1.php delete mode 100644 phpBB/includes/db/migration/v306.php delete mode 100644 phpBB/includes/db/migration/v306rc1.php delete mode 100644 phpBB/includes/db/migration/v306rc2.php delete mode 100644 phpBB/includes/db/migration/v306rc3.php delete mode 100644 phpBB/includes/db/migration/v306rc4.php delete mode 100644 phpBB/includes/db/migration/v307.php delete mode 100644 phpBB/includes/db/migration/v307pl1.php delete mode 100644 phpBB/includes/db/migration/v307rc1.php delete mode 100644 phpBB/includes/db/migration/v307rc2.php delete mode 100644 phpBB/includes/db/migration/v308.php delete mode 100644 phpBB/includes/db/migration/v308rc1.php delete mode 100644 phpBB/includes/db/migration/v309.php delete mode 100644 phpBB/includes/db/migration/v309rc1.php delete mode 100644 phpBB/includes/db/migration/v309rc2.php delete mode 100644 phpBB/includes/db/migration/v309rc3.php delete mode 100644 phpBB/includes/db/migration/v309rc4.php create mode 100644 phpBB/includes/db/migrationtools/base.php create mode 100644 phpBB/includes/db/migrationtools/config.php create mode 100644 phpBB/includes/db/migrationtools/umil.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/305rc1part2.php b/phpBB/includes/db/migration/305rc1part2.php deleted file mode 100644 index 238e533b06..0000000000 --- a/phpBB/includes/db/migration/305rc1part2.php +++ /dev/null @@ -1,34 +0,0 @@ - array( - ACL_OPTIONS_TABLE => array('auth_option'), - ), - 'add_unique_index' => array( - ACL_OPTIONS_TABLE => array( - 'auth_option' => array('auth_option'), - ), - ), - ); - } - - function update_data() - { - } -} diff --git a/phpBB/includes/db/migration/3_0_1.php b/phpBB/includes/db/migration/3_0_1.php new file mode 100644 index 0000000000..1cb069a2b1 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_1.php @@ -0,0 +1,25 @@ +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']; + } + $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 true; + } + else + { + return false; + } + } +} diff --git a/phpBB/includes/db/migration/3_0_11_rc2 b/phpBB/includes/db/migration/3_0_11_rc2 new file mode 100644 index 0000000000..f4e64871ed --- /dev/null +++ b/phpBB/includes/db/migration/3_0_11_rc2 @@ -0,0 +1,31 @@ + array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_novalue' => array('BOOL', 0), + ), + ), + ); + } + + function update_data() + { + } +} diff --git a/phpBB/includes/db/migration/3_0_12_rc1.php b/phpBB/includes/db/migration/3_0_12_rc1.php new file mode 100644 index 0000000000..58e112a43a --- /dev/null +++ b/phpBB/includes/db/migration/3_0_12_rc1.php @@ -0,0 +1,26 @@ + 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 update_data() + { + return array( + array('custom', array(array(&$this, 'fix_unset_last_view_time'))), + array('custom', array(array(&$this, 'reset_smiley_size'))), + ); + } + + 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/3_0_2.php b/phpBB/includes/db/migration/3_0_2.php new file mode 100644 index 0000000000..36e8d52e6b --- /dev/null +++ b/phpBB/includes/db/migration/3_0_2.php @@ -0,0 +1,25 @@ + 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() + { + } +} diff --git a/phpBB/includes/db/migration/3_0_3.php b/phpBB/includes/db/migration/3_0_3.php new file mode 100644 index 0000000000..c9ca33ee88 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_3.php @@ -0,0 +1,25 @@ + 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', '')), + array('permission.add', array('u_masspm_group', phpbb_auth::IS_GLOBAL), + array('custom', array(array(&$this, 'correct_acp_email_permissions'))), + )); + } + + 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/3_0_4.php b/phpBB/includes/db/migration/3_0_4.php new file mode 100644 index 0000000000..bbaaea54c9 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_4.php @@ -0,0 +1,47 @@ +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/3_0_4_rc1.php b/phpBB/includes/db/migration/3_0_4_rc1.php new file mode 100644 index 0000000000..b783e58e24 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_4_rc1.php @@ -0,0 +1,103 @@ + 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'))), + ); + } + + 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->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); + } + } +} diff --git a/phpBB/includes/db/migration/3_0_5.php b/phpBB/includes/db/migration/3_0_5.php new file mode 100644 index 0000000000..272779f083 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_5.php @@ -0,0 +1,25 @@ + 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_refresh', 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->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']); + } + } + $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->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/3_0_5_rc1part2.php b/phpBB/includes/db/migration/3_0_5_rc1part2.php new file mode 100644 index 0000000000..710c8dce91 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_5_rc1part2.php @@ -0,0 +1,34 @@ + array( + ACL_OPTIONS_TABLE => array('auth_option'), + ), + 'add_unique_index' => array( + ACL_OPTIONS_TABLE => array( + 'auth_option' => array('auth_option'), + ), + ), + ); + } + + function update_data() + { + } +} diff --git a/phpBB/includes/db/migration/3_0_6.php b/phpBB/includes/db/migration/3_0_6.php new file mode 100644 index 0000000000..9582038b36 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_6.php @@ -0,0 +1,25 @@ + 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 . '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('custom', array(array(&$this, ''))) + array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')), + array('config.update_if', array( + ($this->config['captcha_gd']), + '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('config.add_if', array( + ($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']), + 'allow_avatar', + 1, + )), + array('config.add', array('allow_avatar_remote_upload', 0)), + array('config.add_if', array( + ($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']), + 'allow_avatar_remote_upload', + 1, + )), + + array('module.add', array( + 'feed' => array( + 'base' => 'board', + 'class' => 'acp', + 'title' => 'ACP_FEED_SETTINGS', + 'auth' => 'acl_a_board', + 'cat' => 'ACP_BOARD_CONFIGURATION', + 'after' => array('signature', 'ACP_SIGNATURE_SETTINGS') + ), + )), + array('module.add', array( + 'warnings' => array( + 'base' => 'users', + 'class' => 'acp', + 'title' => 'ACP_USER_WARNINGS', + 'auth' => 'acl_a_user', + 'display' => 0, + 'cat' => 'ACP_CAT_USERS', + 'after' => array('feedback', 'ACP_USER_FEEDBACK') + ), + )), + array('module.add', array( + 'send_statistics' => array( + 'base' => 'send_statistics', + 'class' => 'acp', + 'title' => 'ACP_SEND_STATISTICS', + 'auth' => 'acl_a_server', + 'cat' => 'ACP_SERVER_CONFIGURATION' + ), + )), + array('module.add', array( + 'setting_forum_copy' => array( + 'base' => 'permissions', + 'class' => 'acp', + 'title' => 'ACP_FORUM_PERMISSIONS_COPY', + 'auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth', + 'cat' => 'ACP_FORUM_BASED_PERMISSIONS', + 'after' => array('setting_forum_local', 'ACP_FORUM_PERMISSIONS') + ), + )), + array('module.add', array( + 'pm_reports' => array( + 'base' => 'pm_reports', + 'class' => 'mcp', + 'title' => 'MCP_PM_REPORTS_OPEN', + 'auth' => 'aclf_m_report', + 'cat' => 'MCP_REPORTS' + ), + )), + array('module.add', array( + 'pm_reports_closed' => array( + 'base' => 'pm_reports', + 'class' => 'mcp', + 'title' => 'MCP_PM_REPORTS_CLOSED', + 'auth' => 'aclf_m_report', + 'cat' => 'MCP_REPORTS' + ), + )), + array('module.add', array( + 'pm_report_details' => array( + 'base' => 'pm_reports', + 'class' => 'mcp', + 'title' => 'MCP_PM_REPORT_DETAILS', + 'auth' => 'aclf_m_report', + 'cat' => 'MCP_REPORTS' + ), + )), + array('custom', array(array(&$this, 'add_newly_registered_group'))), + array('custom', array(array(&$this, 'set_user_options_default'))), + ); + } + + 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(); + + if (!$errored) + { + // 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(); + + if (!$errored) + { + $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->phpEx); + $auth_admin = new auth_admin(); + $auth_admin->acl_clear_prefetch(); + } +} diff --git a/phpBB/includes/db/migration/3_0_6_rc2.php b/phpBB/includes/db/migration/3_0_6_rc2.php new file mode 100644 index 0000000000..1552485d0a --- /dev/null +++ b/phpBB/includes/db/migration/3_0_6_rc2.php @@ -0,0 +1,25 @@ +sql_query($sql); + } +} diff --git a/phpBB/includes/db/migration/3_0_6_rc4.php b/phpBB/includes/db/migration/3_0_6_rc4.php new file mode 100644 index 0000000000..00161456b6 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_6_rc4.php @@ -0,0 +1,25 @@ + 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'))), + ); + } + + 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/3_0_7_rc2.php b/phpBB/includes/db/migration/3_0_7_rc2.php new file mode 100644 index 0000000000..4ab4e906d7 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_7_rc2.php @@ -0,0 +1,70 @@ + ' . 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); + } + } + $db->sql_freeresult($result); + + if ($i < $limit) + { + // Completed + return false; + } + + return $start + $limit; + } +} diff --git a/phpBB/includes/db/migration/3_0_8.php b/phpBB/includes/db/migration/3_0_8.php new file mode 100644 index 0000000000..3e7f843a65 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_8.php @@ -0,0 +1,25 @@ + array( + 'base' => 'board', + 'class' => 'acp', + 'title' => 'ACP_POST_SETTINGS', + 'auth' => 'acl_a_board', + 'cat' => 'ACP_MESSAGES', + 'after' => array('message', 'ACP_MESSAGE_SETTINGS') + ), + )), + 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)), + ); + } + + 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->phpEx", + "{$this->phpbb_root_path}language/$lang_dir/install.$this->phpEx", + "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.$this->phpEx", + ); + + 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->phpEx); + } + + $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 true; + } + else + { + return false; + } + } +} diff --git a/phpBB/includes/db/migration/3_0_9.php b/phpBB/includes/db/migration/3_0_9.php new file mode 100644 index 0000000000..2e1eab26e7 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_9.php @@ -0,0 +1,25 @@ + 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 . 'bbcode' => 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'))), + ); + } + + 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/3_0_9_rc2.php b/phpBB/includes/db/migration/3_0_9_rc2.php new file mode 100644 index 0000000000..96782b2b01 --- /dev/null +++ b/phpBB/includes/db/migration/3_0_9_rc2.php @@ -0,0 +1,25 @@ +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']; - } - $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 true; - } - else - { - return false; - } - } -} diff --git a/phpBB/includes/db/migration/v3011rc2.php b/phpBB/includes/db/migration/v3011rc2.php deleted file mode 100644 index 0f66eff156..0000000000 --- a/phpBB/includes/db/migration/v3011rc2.php +++ /dev/null @@ -1,31 +0,0 @@ - array( - $this->table_prefix . 'profile_fields' => array( - 'field_show_novalue' => array('BOOL', 0), - ), - ), - ); - } - - function update_data() - { - } -} diff --git a/phpBB/includes/db/migration/v3012rc1.php b/phpBB/includes/db/migration/v3012rc1.php deleted file mode 100644 index 67f7a29b02..0000000000 --- a/phpBB/includes/db/migration/v3012rc1.php +++ /dev/null @@ -1,26 +0,0 @@ - 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 update_data() - { - return array( - array('custom', array(array(&$this, 'fix_unset_last_view_time'))), - array('custom', array(array(&$this, 'reset_smiley_size'))), - ); - } - - 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/v302.php b/phpBB/includes/db/migration/v302.php deleted file mode 100644 index 942a0ac58c..0000000000 --- a/phpBB/includes/db/migration/v302.php +++ /dev/null @@ -1,25 +0,0 @@ - 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() - { - } -} diff --git a/phpBB/includes/db/migration/v303.php b/phpBB/includes/db/migration/v303.php deleted file mode 100644 index 409c396baf..0000000000 --- a/phpBB/includes/db/migration/v303.php +++ /dev/null @@ -1,25 +0,0 @@ - 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', '')), - array('permission.add', array('u_masspm_group', phpbb_auth::IS_GLOBAL), - array('custom', array(array(&$this, 'correct_acp_email_permissions'))), - )); - } - - 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/v304.php b/phpBB/includes/db/migration/v304.php deleted file mode 100644 index 5358bcc20f..0000000000 --- a/phpBB/includes/db/migration/v304.php +++ /dev/null @@ -1,47 +0,0 @@ -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/v304rc1.php b/phpBB/includes/db/migration/v304rc1.php deleted file mode 100644 index 2daad4e826..0000000000 --- a/phpBB/includes/db/migration/v304rc1.php +++ /dev/null @@ -1,103 +0,0 @@ - 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'))), - ); - } - - 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->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); - } - } -} diff --git a/phpBB/includes/db/migration/v305.php b/phpBB/includes/db/migration/v305.php deleted file mode 100644 index 71e28c6b7b..0000000000 --- a/phpBB/includes/db/migration/v305.php +++ /dev/null @@ -1,25 +0,0 @@ - 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_refresh', 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->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']); - } - } - $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->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/v306.php b/phpBB/includes/db/migration/v306.php deleted file mode 100644 index eec2f7c752..0000000000 --- a/phpBB/includes/db/migration/v306.php +++ /dev/null @@ -1,25 +0,0 @@ - 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 . '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('custom', array(array(&$this, ''))) - array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')), - array('config.update_if', array( - ($this->config['captcha_gd']), - '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('config.add_if', array( - ($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']), - 'allow_avatar', - 1, - )), - array('config.add', array('allow_avatar_remote_upload', 0)), - array('config.add_if', array( - ($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']), - 'allow_avatar_remote_upload', - 1, - )), - - array('module.add', array( - 'feed' => array( - 'base' => 'board', - 'class' => 'acp', - 'title' => 'ACP_FEED_SETTINGS', - 'auth' => 'acl_a_board', - 'cat' => 'ACP_BOARD_CONFIGURATION', - 'after' => array('signature', 'ACP_SIGNATURE_SETTINGS') - ), - )), - array('module.add', array( - 'warnings' => array( - 'base' => 'users', - 'class' => 'acp', - 'title' => 'ACP_USER_WARNINGS', - 'auth' => 'acl_a_user', - 'display' => 0, - 'cat' => 'ACP_CAT_USERS', - 'after' => array('feedback', 'ACP_USER_FEEDBACK') - ), - )), - array('module.add', array( - 'send_statistics' => array( - 'base' => 'send_statistics', - 'class' => 'acp', - 'title' => 'ACP_SEND_STATISTICS', - 'auth' => 'acl_a_server', - 'cat' => 'ACP_SERVER_CONFIGURATION' - ), - )), - array('module.add', array( - 'setting_forum_copy' => array( - 'base' => 'permissions', - 'class' => 'acp', - 'title' => 'ACP_FORUM_PERMISSIONS_COPY', - 'auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth', - 'cat' => 'ACP_FORUM_BASED_PERMISSIONS', - 'after' => array('setting_forum_local', 'ACP_FORUM_PERMISSIONS') - ), - )), - array('module.add', array( - 'pm_reports' => array( - 'base' => 'pm_reports', - 'class' => 'mcp', - 'title' => 'MCP_PM_REPORTS_OPEN', - 'auth' => 'aclf_m_report', - 'cat' => 'MCP_REPORTS' - ), - )), - array('module.add', array( - 'pm_reports_closed' => array( - 'base' => 'pm_reports', - 'class' => 'mcp', - 'title' => 'MCP_PM_REPORTS_CLOSED', - 'auth' => 'aclf_m_report', - 'cat' => 'MCP_REPORTS' - ), - )), - array('module.add', array( - 'pm_report_details' => array( - 'base' => 'pm_reports', - 'class' => 'mcp', - 'title' => 'MCP_PM_REPORT_DETAILS', - 'auth' => 'aclf_m_report', - 'cat' => 'MCP_REPORTS' - ), - )), - array('custom', array(array(&$this, 'add_newly_registered_group'))), - array('custom', array(array(&$this, 'set_user_options_default'))), - ); - } - - 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(); - - if (!$errored) - { - // 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(); - - if (!$errored) - { - $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->phpEx); - $auth_admin = new auth_admin(); - $auth_admin->acl_clear_prefetch(); - } -} diff --git a/phpBB/includes/db/migration/v306rc2.php b/phpBB/includes/db/migration/v306rc2.php deleted file mode 100644 index 0a6c388da6..0000000000 --- a/phpBB/includes/db/migration/v306rc2.php +++ /dev/null @@ -1,25 +0,0 @@ -sql_query($sql); - } -} diff --git a/phpBB/includes/db/migration/v306rc4.php b/phpBB/includes/db/migration/v306rc4.php deleted file mode 100644 index 92c1979311..0000000000 --- a/phpBB/includes/db/migration/v306rc4.php +++ /dev/null @@ -1,25 +0,0 @@ - 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'))), - ); - } - - 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/v307rc2.php b/phpBB/includes/db/migration/v307rc2.php deleted file mode 100644 index 438ebfb8c2..0000000000 --- a/phpBB/includes/db/migration/v307rc2.php +++ /dev/null @@ -1,70 +0,0 @@ - ' . 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); - } - } - $db->sql_freeresult($result); - - if ($i < $limit) - { - // Completed - return false; - } - - return $start + $limit; - } -} diff --git a/phpBB/includes/db/migration/v308.php b/phpBB/includes/db/migration/v308.php deleted file mode 100644 index 8a0d96b2e7..0000000000 --- a/phpBB/includes/db/migration/v308.php +++ /dev/null @@ -1,25 +0,0 @@ - array( - 'base' => 'board', - 'class' => 'acp', - 'title' => 'ACP_POST_SETTINGS', - 'auth' => 'acl_a_board', - 'cat' => 'ACP_MESSAGES', - 'after' => array('message', 'ACP_MESSAGE_SETTINGS') - ), - )), - 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)), - ); - } - - 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->phpEx", - "{$this->phpbb_root_path}language/$lang_dir/install.$this->phpEx", - "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.$this->phpEx", - ); - - 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->phpEx); - } - - $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 true; - } - else - { - return false; - } - } -} diff --git a/phpBB/includes/db/migration/v309.php b/phpBB/includes/db/migration/v309.php deleted file mode 100644 index ebb246da3a..0000000000 --- a/phpBB/includes/db/migration/v309.php +++ /dev/null @@ -1,25 +0,0 @@ - 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 . 'bbcode' => 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'))), - ); - } - - 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/v309rc2.php b/phpBB/includes/db/migration/v309rc2.php deleted file mode 100644 index d552b95e7a..0000000000 --- a/phpBB/includes/db/migration/v309rc2.php +++ /dev/null @@ -1,25 +0,0 @@ -db->sql_escape($config_name) . "'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + if (!isset($this->config[$config_name])) + { + $this->config[$config_name] = $row['config_value']; + + if (!$row['is_dynamic']) + { + $this->cache->destroy('config'); + } + } + + return ($return_result) ? $row : true; + } + + // this should never happen, but if it does, we need to remove the config from the array + if (isset($this->config[$config_name])) + { + unset($this->config[$config_name]); + $this->cache->destroy('config'); + } + + return false; + } + + /** + * Config Add + * + * This function allows you to add a config setting. + * + * @param string $config_name The name of the config setting you would like to add + * @param mixed $config_value The value of the config setting + * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + * + * @return result + */ + function config_add($config_name, $config_value = '', $is_dynamic = false) + { + if ($this->config_exists($config_name)) + { + return $this->umil_end('CONFIG_ALREADY_EXISTS', $config_name); + } + + set_config($config_name, $config_value, $is_dynamic); + } + + /** + * Config Update + * + * This function allows you to update an existing config setting. + * + * @param string $config_name The name of the config setting you would like to update + * @param mixed $config_value The value of the config setting + * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + * + * @return result + */ + function config_update($config_name, $config_value = '') + { + if (!$this->config_exists($config_name)) + { + return $this->umil_end('CONFIG_NOT_EXIST', $config_name); + } + + set_config($config_name, $config_value); + } + + /** + * Config Remove + * + * This function allows you to remove an existing config setting. + * + * @param string $config_name The name of the config setting you would like to remove + * + * @return result + */ + function config_remove($config_name) + { + if (!$this->config_exists($config_name)) + { + return $this->umil_end('CONFIG_NOT_EXIST', $config_name); + } + + $sql = 'DELETE FROM ' . CONFIG_TABLE . " + WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; + $this->db->sql_query($sql); + + unset($this->config[$config_name]); + $this->cache->destroy('config'); + } +} \ No newline at end of file diff --git a/phpBB/includes/db/migrationtools/umil.php b/phpBB/includes/db/migrationtools/umil.php new file mode 100644 index 0000000000..ce7b8ff3be --- /dev/null +++ b/phpBB/includes/db/migrationtools/umil.php @@ -0,0 +1,3037 @@ +config_add(array( +* array('config_name', 'config_value'), +* array('config_name1', 'config_value1'), +* array('config_name2', 'config_value2', true), +* array('config_name3', 'config_value3', true), +* ); +*/ + +/** +* UMIL - Unified MOD Installation Library class +* +* Cache Functions +* cache_purge($type = '', $style_id = 0) +* +* Config Functions: +* config_exists($config_name, $return_result = false) +* config_add($config_name, $config_value = '', $is_dynamic = false) +* config_update($config_name, $config_value, $is_dynamic = false) +* config_remove($config_name) +* +* Module Functions +* module_exists($class, $parent, $module) +* module_add($class, $parent = 0, $data = array()) +* module_remove($class, $parent = 0, $module = '') +* +* Permissions/Auth Functions +* permission_exists($auth_option, $global = true) +* permission_add($auth_option, $global = true) +* permission_remove($auth_option, $global = true) +* permission_set($name, $auth_option = array(), $type = 'role', $global = true, $has_permission = true) +* permission_unset($name, $auth_option = array(), $type = 'role', $global = true) +* +* Table Functions +* table_exists($table_name) +* table_add($table_name, $table_data = array()) +* table_remove($table_name) +* +* Table Column Functions +* table_column_exists($table_name, $column_name) +* table_column_add($table_name, $column_name = '', $column_data = array()) +* table_column_update($table_name, $column_name = '', $column_data = array()) +* table_column_remove($table_name, $column_name = '') +* +* Table Key/Index Functions +* table_index_exists($table_name, $index_name) +* table_index_add($table_name, $index_name = '', $column = array()) +* table_index_remove($table_name, $index_name = '') +* +* Table Row Functions (note that these actions are not reversed automatically during uninstallation) +* table_row_insert($table_name, $data = array()) +* table_row_remove($table_name, $data = array()) +* table_row_update($table_name, $data = array(), $new_data = array()) +* +* Version Check Function +* version_check($url, $path, $file) +*/ +class umil +{ + /** + * This will hold the text output for the inputted command (if the mod author would like to display the command that was ran) + * + * @var string + */ + var $command = ''; + + /** + * This will hold the text output for the result of the command. $user->lang['SUCCESS'] if everything worked. + * + * @var string + */ + var $result = ''; + + /** + * Auto run $this->display_results after running a command + */ + var $auto_display_results = false; + + /** + * Stand Alone option (this makes it possible to just use the single umil file and not worry about any language stuff + */ + var $stand_alone = false; + + /** + * Were any new permissions added (used in umil_frontend)? + */ + var $permissions_added = false; + + /** + * Database Object + */ + var $db = false; + + /** + * Database Tools Object + */ + var $db_tools = false; + + /** + * Do we want a custom prefix besides the phpBB table prefix? You *probably* should not change this... + */ + var $table_prefix = false; + + /** + * Constructor + */ + function umil($stand_alone = false, $db = false) + { + // Setup $this->db + if ($db !== false) + { + if (!is_object($db) || !method_exists($db, 'sql_query')) + { + trigger_error('Invalid $db Object'); + } + + $this->db = $db; + } + else + { + global $db; + $this->db = $db; + } + + // Setup $this->db_tools + if (!class_exists('phpbb_db_tools')) + { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/db/db_tools.' . $phpEx); + } + $this->db_tools = new phpbb_db_tools($this->db); + + $this->stand_alone = $stand_alone; + + if (!$stand_alone) + { + global $config, $user, $phpbb_root_path, $phpEx; + + /* Does not have the fall back option to use en/ if the user's language file does not exist, so we will not use it...unless that is changed. + if (method_exists('user', 'set_custom_lang_path')) + { + $user->set_custom_lang_path($phpbb_root_path . 'umil/language/'); + $user->add_lang('umil'); + $user->set_custom_lang_path($phpbb_root_path . 'language/'); + } + else + {*/ + // Include the umil language file. First we check if the language file for the user's language is available, if not we check if the board's default language is available, if not we use the english file. + if (isset($user->data['user_lang']) && file_exists("{$phpbb_root_path}umil/language/{$user->data['user_lang']}/umil.$phpEx")) + { + $path = $user->data['user_lang']; + } + else if (file_exists("{$phpbb_root_path}umil/language/" . basename($config['default_lang']) . "/umil.$phpEx")) + { + $path = basename($config['default_lang']); + } + else if (file_exists("{$phpbb_root_path}umil/language/en/umil.$phpEx")) + { + $path = 'en'; + } + else + { + trigger_error('Language Files Missing.

Please download the latest UMIL (Unified MOD Install Library) from: phpBB.com/mods/umil', E_USER_ERROR); + } + + $user->add_lang('./../../umil/language/' . $path . '/umil'); + //} + + $user->add_lang(array('acp/common', 'acp/permissions')); + + // Check to see if a newer version is available. + $info = $this->version_check('version.phpbb.com', '/umil', ((defined('PHPBB_QA')) ? 'umil_qa.txt' : 'umil.txt')); + if (is_array($info) && isset($info[0]) && isset($info[1])) + { + if (version_compare(UMIL_VERSION, $info[0], '<')) + { + global $template; + + // Make sure user->setup() has been called + if (empty($user->lang)) + { + $user->setup(); + } + + page_header('', false); + + $user->lang['UPDATE_UMIL'] = (isset($user->lang['UPDATE_UMIL'])) ? $user->lang['UPDATE_UMIL'] : 'This version of UMIL is outdated.

Please download the latest UMIL (Unified MOD Install Library) from: %1$s'; + $template->assign_vars(array( + 'S_BOARD_DISABLED' => true, + 'L_BOARD_DISABLED' => sprintf($user->lang['UPDATE_UMIL'], $info[1]), + )); + } + } + } + } + + /** + * umil_start + * + * A function which runs (almost) every time a function here is ran + */ + function umil_start() + { + global $user; + + // Set up the command. This will get the arguments sent to the function. + $args = func_get_args(); + $this->command = call_user_func_array(array($this, 'get_output_text'), $args); + + $this->result = (isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS'; + $this->db->sql_return_on_error(true); + + //$this->db->sql_transaction('begin'); + } + + /** + * umil_end + * + * A function which runs (almost) every time a function here is ran + */ + function umil_end() + { + global $user; + + // Set up the result. This will get the arguments sent to the function. + $args = func_get_args(); + $result = call_user_func_array(array($this, 'get_output_text'), $args); + $this->result = ($result) ? $result : $this->result; + + if ($this->db->sql_error_triggered) + { + if ($this->result == ((isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS')) + { + $this->result = 'SQL ERROR ' . $this->db->sql_error_returned['message']; + } + else + { + $this->result .= '

SQL ERROR ' . $this->db->sql_error_returned['message']; + } + + //$this->db->sql_transaction('rollback'); + } + else + { + //$this->db->sql_transaction('commit'); + } + + $this->db->sql_return_on_error(false); + + // Auto output if requested. + if ($this->auto_display_results && method_exists($this, 'display_results')) + { + $this->display_results(); + } + + return '' . $this->command . '
' . $this->result; + } + + /** + * Get text for output + * + * Takes the given arguments and prepares them for the UI + * + * First argument sent is used as the language key + * Further arguments (if send) are used on the language key through vsprintf() + * + * @return string Returns the prepared string for output + */ + function get_output_text() + { + global $user; + + // Set up the command. This will get the arguments sent to the function. + $args = func_get_args(); + if (sizeof($args)) + { + $lang_key = array_shift($args); + + if (sizeof($args)) + { + $lang_args = array(); + foreach ($args as $arg) + { + $lang_args[] = (isset($user->lang[$arg])) ? $user->lang[$arg] : $arg; + } + + return @vsprintf(((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key), $lang_args); + } + else + { + return ((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key); + } + } + + return ''; + } + + /** + * Run Actions + * + * Do-It-All function that can do everything required for installing/updating/uninstalling a mod based on an array of actions and the versions. + * + * @param string $action The action. install|update|uninstall + * @param array $versions The array of versions and the actions for each + * @param string $version_config_name The name of the config setting which holds/will hold the currently installed version + * @param string $version_select Added for the UMIL Auto system to allow you to select the version you want to install/update/uninstall to. + */ + function run_actions($action, $versions, $version_config_name, $version_select = '') + { + // We will sort the actions to prevent issues from mod authors incorrectly listing the version numbers + uksort($versions, 'version_compare'); + + // Find the current version to install + $current_version = '0.0.0'; + foreach ($versions as $version => $actions) + { + $current_version = $version; + } + + $db_version = ''; + if ($this->config_exists($version_config_name)) + { + global $config; + $db_version = $config[$version_config_name]; + } + + // Set the action to install from update if nothing is currently installed + if ($action == 'update' && !$db_version) + { + $action = 'install'; + } + + if ($action == 'install' || $action == 'update') + { + $version_installed = $db_version; + foreach ($versions as $version => $version_actions) + { + // If we are updating + if ($db_version && version_compare($version, $db_version, '<=')) + { + continue; + } + + if ($version_select && version_compare($version, $version_select, '>')) + { + break; + } + + foreach ($version_actions as $method => $params) + { + if ($method == 'custom') + { + $this->_call_custom_function($params, $action, $version); + } + else + { + if (method_exists($this, $method)) + { + call_user_func(array($this, $method), $params); + } + } + } + + $version_installed = $version; + } + + // update the version number or add it + if ($this->config_exists($version_config_name)) + { + $this->config_update($version_config_name, $version_installed); + } + else + { + $this->config_add($version_config_name, $version_installed); + } + } + else if ($action == 'uninstall' && $db_version) + { + // reverse version list + $versions = array_reverse($versions); + + foreach ($versions as $version => $version_actions) + { + // Uninstalling and this listed version is newer than installed + if (version_compare($version, $db_version, '>')) + { + continue; + } + + // Version selection stuff + if ($version_select && version_compare($version, $version_select, '<=')) + { + // update the version number + $this->config_update($version_config_name, $version); + break; + } + + $cache_purge = false; + $version_actions = array_reverse($version_actions); + foreach ($version_actions as $method => $params) + { + if ($method == 'custom') + { + $this->_call_custom_function($params, $action, $version); + } + else + { + // This way we always run the cache purge at the end of the version (done for the uninstall because the instructions are reversed, which would cause the cache purge to be run at the beginning if it was meant to run at the end). + if ($method == 'cache_purge') + { + $cache_purge = $params; + continue; + } + + // A few things are not possible for uninstallations update actions and table_row actions + if (strpos($method, 'update') !== false || strpos($method, 'table_insert') !== false || strpos($method, 'table_row_') !== false) + { + continue; + } + + // reverse function call + $method = str_replace(array('add', 'remove', 'temp'), array('temp', 'add', 'remove'), $method); + $method = str_replace(array('set', 'unset', 'temp'), array('temp', 'set', 'unset'), $method); + + if (method_exists($this, $method)) + { + call_user_func(array($this, $method), ((is_array($params) ? array_reverse($params) : $params))); + } + } + } + + if ($cache_purge !== false) + { + $this->cache_purge($cache_purge); + } + } + + if (!$version_select) + { + // Unset the version number + $this->config_remove($version_config_name); + } + } + } + + /** + * Call custom function helper + */ + function _call_custom_function($functions, $action, $version) + { + if (!is_array($functions)) + { + $functions = array($functions); + } + + $return = ''; + + foreach ($functions as $function) + { + if (function_exists($function)) + { + // Must reset before calling the function + $this->umil_start(); + + $returned = call_user_func($function, $action, $version); + if (is_string($returned)) + { + $this->command = $this->get_output_text($returned); + } + else if (is_array($returned) && isset($returned['command'])) + { + if (is_array($returned['command'])) + { + $this->command = call_user_func_array(array($this, 'get_output_text'), $returned['command']); + } + else + { + $this->command = $this->get_output_text($returned['command']); + } + + if (isset($returned['result'])) + { + $this->result = $this->get_output_text($returned['result']); + } + } + else + { + $this->command = $this->get_output_text('UNKNOWN'); + } + + $return .= $this->umil_end() . '
'; + } + } + + return $return; + } + + /** + * Multicall Helper + * + * @param mixed $function Function name to call + * @param mixed $params The parameters array + * + * @return bool True if we have done a multicall ($params is an array), false if not ($params is not an array) + */ + function multicall($function, $params) + { + if (is_array($params) && !empty($params)) + { + foreach ($params as $param) + { + if (!is_array($param)) + { + call_user_func(array($this, $function), $param); + } + else + { + call_user_func_array(array($this, $function), $param); + } + } + return true; + } + + return false; + } + + /** + * Cache Purge + * + * This function is for purging either phpBB3’s data cache, authorization cache, or the styles cache. + * + * @param string $type The type of cache you want purged. Available types: auth, imageset, template, theme. Anything else sent will purge the forum's cache. + * @param int $style_id The id of the item you want purged (if the type selected is imageset/template/theme, 0 for all items in that section) + */ + function cache_purge($type = '', $style_id = 0) + { + global $auth, $cache, $user, $phpbb_root_path, $phpEx; + + // Multicall + if ($this->multicall(__FUNCTION__, $type)) + { + return; + } + + $style_id = (int) $style_id; + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'auth' : + $this->umil_start('AUTH_CACHE_PURGE'); + $cache->destroy('_acl_options'); + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + break; + + case 'imageset' : + if ($style_id == 0) + { + $return = array(); + $sql = 'SELECT imageset_id + FROM ' . STYLES_IMAGESET_TABLE; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $return[] = $this->cache_purge('imageset', $row['imageset_id']); + } + $this->db->sql_freeresult($result); + + return implode('

', $return); + } + else + { + $sql = 'SELECT * + FROM ' . STYLES_IMAGESET_TABLE . " + WHERE imageset_id = $style_id"; + $result = $this->db->sql_query($sql); + $imageset_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$imageset_row) + { + $this->umil_start('IMAGESET_CACHE_PURGE', 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + $this->umil_start('IMAGESET_CACHE_PURGE', $imageset_row['imageset_name']); + + // The following is from includes/acp/acp_styles.php (edited) + $sql_ary = array(); + + $cfg_data_imageset = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/imageset.cfg"); + + $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . ' + WHERE imageset_id = ' . $style_id; + $result = $this->db->sql_query($sql); + + foreach ($cfg_data_imageset as $image_name => $value) + { + if (strpos($value, '*') !== false) + { + if (substr($value, -1, 1) === '*') + { + list($image_filename, $image_height) = explode('*', $value); + $image_width = 0; + } + else + { + list($image_filename, $image_height, $image_width) = explode('*', $value); + } + } + else + { + $image_filename = $value; + $image_height = $image_width = 0; + } + + if (strpos($image_name, 'img_') === 0 && $image_filename) + { + $image_name = substr($image_name, 4); + + $sql_ary[] = array( + 'image_name' => (string) $image_name, + 'image_filename' => (string) $image_filename, + 'image_height' => (int) $image_height, + 'image_width' => (int) $image_width, + 'imageset_id' => (int) $style_id, + 'image_lang' => '', + ); + } + } + + $sql = 'SELECT lang_dir + FROM ' . LANG_TABLE; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg")) + { + $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg"); + foreach ($cfg_data_imageset_data as $image_name => $value) + { + if (strpos($value, '*') !== false) + { + if (substr($value, -1, 1) === '*') + { + list($image_filename, $image_height) = explode('*', $value); + $image_width = 0; + } + else + { + list($image_filename, $image_height, $image_width) = explode('*', $value); + } + } + else + { + $image_filename = $value; + $image_height = $image_width = 0; + } + + if (strpos($image_name, 'img_') === 0 && $image_filename) + { + $image_name = substr($image_name, 4); + $sql_ary[] = array( + 'image_name' => (string) $image_name, + 'image_filename' => (string) $image_filename, + 'image_height' => (int) $image_height, + 'image_width' => (int) $image_width, + 'imageset_id' => (int) $style_id, + 'image_lang' => (string) $row['lang_dir'], + ); + } + } + } + } + $this->db->sql_freeresult($result); + + $this->db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary); + + $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE); + + return $this->umil_end(); + } + break; + //case 'imageset' : + + case 'template' : + if ($style_id == 0) + { + $return = array(); + $sql = 'SELECT template_id + FROM ' . STYLES_TEMPLATE_TABLE; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $return[] = $this->cache_purge('template', $row['template_id']); + } + $this->db->sql_freeresult($result); + + return implode('

', $return); + } + else + { + $sql = 'SELECT * + FROM ' . STYLES_TEMPLATE_TABLE . " + WHERE template_id = $style_id"; + $result = $this->db->sql_query($sql); + $template_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$template_row) + { + $this->umil_start('TEMPLATE_CACHE_PURGE', 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + $this->umil_start('TEMPLATE_CACHE_PURGE', $template_row['template_name']); + + // The following is from includes/acp/acp_styles.php + if ($template_row['template_storedb'] && file_exists("{$phpbb_root_path}styles/{$template_row['template_path']}/template/")) + { + $filelist = array('' => array()); + + $sql = 'SELECT template_filename, template_mtime + FROM ' . STYLES_TEMPLATE_DATA_TABLE . " + WHERE template_id = $style_id"; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { +// if (@filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}/template/" . $row['template_filename']) > $row['template_mtime']) +// { + // get folder info from the filename + if (($slash_pos = strrpos($row['template_filename'], '/')) === false) + { + $filelist[''][] = $row['template_filename']; + } + else + { + $filelist[substr($row['template_filename'], 0, $slash_pos + 1)][] = substr($row['template_filename'], $slash_pos + 1, strlen($row['template_filename']) - $slash_pos - 1); + } +// } + } + $this->db->sql_freeresult($result); + + $includes = array(); + foreach ($filelist as $pathfile => $file_ary) + { + foreach ($file_ary as $file) + { + if (!($fp = @fopen("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file", 'r'))) + { + return $this->umil_end('FILE_COULD_NOT_READ', "{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"); + } + $template_data = fread($fp, filesize("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file")); + fclose($fp); + + if (preg_match_all('##is', $template_data, $matches)) + { + foreach ($matches[1] as $match) + { + $includes[trim($match)][] = $file; + } + } + } + } + + foreach ($filelist as $pathfile => $file_ary) + { + foreach ($file_ary as $file) + { + // Skip index. + if (strpos($file, 'index.') === 0) + { + continue; + } + + // We could do this using extended inserts ... but that could be one + // heck of a lot of data ... + $sql_ary = array( + 'template_id' => (int) $style_id, + 'template_filename' => "$pathfile$file", + 'template_included' => (isset($includes[$file])) ? implode(':', $includes[$file]) . ':' : '', + 'template_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"), + 'template_data' => (string) file_get_contents("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"), + ); + + $sql = 'UPDATE ' . STYLES_TEMPLATE_DATA_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " + WHERE template_id = $style_id + AND template_filename = '" . $this->db->sql_escape("$pathfile$file") . "'"; + $this->db->sql_query($sql); + } + } + unset($filelist); + } + + // Purge the forum's cache as well. + $cache->purge(); + + return $this->umil_end(); + } + break; + //case 'template' : + + case 'theme' : + if ($style_id == 0) + { + $return = array(); + $sql = 'SELECT theme_id + FROM ' . STYLES_THEME_TABLE; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $return[] = $this->cache_purge('theme', $row['theme_id']); + } + $this->db->sql_freeresult($result); + + return implode('

', $return); + } + else + { + $sql = 'SELECT * + FROM ' . STYLES_THEME_TABLE . " + WHERE theme_id = $style_id"; + $result = $this->db->sql_query($sql); + $theme_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$theme_row) + { + $this->umil_start('THEME_CACHE_PURGE', 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + $this->umil_start('THEME_CACHE_PURGE', $theme_row['theme_name']); + + // The following is from includes/acp/acp_styles.php + if ($theme_row['theme_storedb'] && file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css")) + { + $stylesheet = file_get_contents($phpbb_root_path . 'styles/' . $theme_row['theme_path'] . '/theme/stylesheet.css'); + + // Match CSS imports + $matches = array(); + preg_match_all('/@import url\(["\'](.*)["\']\);/i', $stylesheet, $matches); + + if (sizeof($matches)) + { + foreach ($matches[0] as $idx => $match) + { + if (!file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}")) + { + continue; + } + + $content = trim(file_get_contents("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}")); + $stylesheet = str_replace($match, $content, $stylesheet); + } + } + + // adjust paths + $db_theme_data = str_replace('./', 'styles/' . $theme_row['theme_path'] . '/theme/', $stylesheet); + + // Save CSS contents + $sql_ary = array( + 'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"), + 'theme_data' => $db_theme_data, + ); + + $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " + WHERE theme_id = $style_id"; + $this->db->sql_query($sql); + + $cache->destroy('sql', STYLES_THEME_TABLE); + } + + return $this->umil_end(); + } + break; + //case 'theme' : + + default: + $this->umil_start('CACHE_PURGE'); + $cache->purge(); + + return $this->umil_end(); + break; + } + } + + /** + * Config Exists + * + * This function is to check to see if a config variable exists or if it does not. + * + * @param string $config_name The name of the config setting you wish to check for. + * @param bool $return_result - return the config value/default if true : default false. + * + * @return bool true/false if config exists + */ + function config_exists($config_name, $return_result = false) + { + global $config, $cache; + + $sql = 'SELECT * + FROM ' . CONFIG_TABLE . " + WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + if (!isset($config[$config_name])) + { + $config[$config_name] = $row['config_value']; + + if (!$row['is_dynamic']) + { + $cache->destroy('config'); + } + } + + return ($return_result) ? $row : true; + } + + // this should never happen, but if it does, we need to remove the config from the array + if (isset($config[$config_name])) + { + unset($config[$config_name]); + $cache->destroy('config'); + } + + return false; + } + + /** + * Config Add + * + * This function allows you to add a config setting. + * + * @param string $config_name The name of the config setting you would like to add + * @param mixed $config_value The value of the config setting + * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + * + * @return result + */ + function config_add($config_name, $config_value = '', $is_dynamic = false) + { + // Multicall + if ($this->multicall(__FUNCTION__, $config_name)) + { + return; + } + + $this->umil_start('CONFIG_ADD', $config_name); + + if ($this->config_exists($config_name)) + { + return $this->umil_end('CONFIG_ALREADY_EXISTS', $config_name); + } + + set_config($config_name, $config_value, $is_dynamic); + + return $this->umil_end(); + } + + /** + * Config Update + * + * This function allows you to update an existing config setting. + * + * @param string $config_name The name of the config setting you would like to update + * @param mixed $config_value The value of the config setting + * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + * + * @return result + */ + function config_update($config_name, $config_value = '', $is_dynamic = false) + { + // Multicall + if ($this->multicall(__FUNCTION__, $config_name)) + { + return; + } + + $this->umil_start('CONFIG_UPDATE', $config_name); + + if (!$this->config_exists($config_name)) + { + return $this->umil_end('CONFIG_NOT_EXIST', $config_name); + } + + set_config($config_name, $config_value, $is_dynamic); + + return $this->umil_end(); + } + + /** + * Config Remove + * + * This function allows you to remove an existing config setting. + * + * @param string $config_name The name of the config setting you would like to remove + * + * @return result + */ + function config_remove($config_name) + { + global $cache, $config; + + // Multicall + if ($this->multicall(__FUNCTION__, $config_name)) + { + return; + } + + $this->umil_start('CONFIG_REMOVE', $config_name); + + if (!$this->config_exists($config_name)) + { + return $this->umil_end('CONFIG_NOT_EXIST', $config_name); + } + + $sql = 'DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; + $this->db->sql_query($sql); + + unset($config[$config_name]); + $cache->destroy('config'); + + return $this->umil_end(); + } + + /** + * Module Exists + * + * Check if a module exists + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. + * @param int|string $module The module_id|module_langname you would like to check for to see if it exists + */ + function module_exists($class, $parent, $module) + { + // the main root directory should return true + if (!$module) + { + return true; + } + + $class = $this->db->sql_escape($class); + $module = $this->db->sql_escape($module); + + $parent_sql = ''; + if ($parent !== false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + return false; + } + + $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + } + else + { + $parent_sql = 'AND parent_id = ' . (int) $parent; + } + } + + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_class = '$class' + $parent_sql + AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '$module'"); + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + return true; + } + + return false; + } + + /** + * Module Add + * + * Add a new module + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string $parent The parent module_id|module_langname (0 for no parent) + * @param array $data an array of the data on the new module. This can be setup in two different ways. + * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below, + * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode. + * array( + * 'module_enabled' => 1, + * 'module_display' => 1, + * 'module_basename' => '', + * 'module_class' => $class, + * 'parent_id' => (int) $parent, + * 'module_langname' => '', + * 'module_mode' => '', + * 'module_auth' => '', + * ) + * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file. + * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file): + * array( + * 'module_basename' => 'asacp', + * 'modes' => array('settings', 'log', 'flag'), + * ) + * Optionally you may not send 'modes' and it will insert all of the modules in that info file. + * @param string|bool $include_path If you would like to use a custom include path, specify that here + */ + function module_add($class, $parent = 0, $data = array(), $include_path = false) + { + global $cache, $user, $phpbb_root_path, $phpEx; + + // Multicall + if ($this->multicall(__FUNCTION__, $class)) + { + return; + } + + // Prevent stupid things like trying to add a module with no name or any data on it + if (empty($data)) + { + $this->umil_start('MODULE_ADD', $class, 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + // allow sending the name as a string in $data to create a category + if (!is_array($data)) + { + $data = array('module_langname' => $data); + } + + if (!isset($data['module_langname'])) + { + // The "automatic" way + $basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; + $basename = str_replace(array('/', '\\'), '', $basename); + $class = str_replace(array('/', '\\'), '', $class); + $info_file = "$class/info/{$class}_$basename.$phpEx"; + + // The manual and automatic ways both failed... + if (!file_exists((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file)) + { + $this->umil_start('MODULE_ADD', $class, $info_file); + return $this->umil_end('FAIL'); + } + + $classname = "{$class}_{$basename}_info"; + + if (!class_exists($classname)) + { + include((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file); + } + + $info = new $classname; + $module = $info->module(); + unset($info); + + $result = ''; + foreach ($module['modes'] as $mode => $module_info) + { + if (!isset($data['modes']) || in_array($mode, $data['modes'])) + { + $new_module = array( + 'module_basename' => $basename, + 'module_langname' => $module_info['title'], + 'module_mode' => $mode, + 'module_auth' => $module_info['auth'], + 'module_display' => (isset($module_info['display'])) ? $module_info['display'] : true, + 'before' => (isset($module_info['before'])) ? $module_info['before'] : false, + 'after' => (isset($module_info['after'])) ? $module_info['after'] : false, + ); + + // Run the "manual" way with the data we've collected. + $result .= ((isset($data['spacer'])) ? $data['spacer'] : '
') . $this->module_add($class, $parent, $new_module); + } + } + + return $result; + } + + // The "manual" way + $this->umil_start('MODULE_ADD', $class, ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname'])); + add_log('admin', 'LOG_MODULE_ADD', ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname'])); + + $class = $this->db->sql_escape($class); + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + return $this->umil_end('PARENT_NOT_EXIST'); + } + + $parent = $data['parent_id'] = $row['module_id']; + } + else if (!$this->module_exists($class, false, $parent)) + { + return $this->umil_end('PARENT_NOT_EXIST'); + } + + if ($this->module_exists($class, $parent, $data['module_langname'])) + { + return $this->umil_end('MODULE_ALREADY_EXIST'); + } + + if (!class_exists('acp_modules')) + { + include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); + $user->add_lang('acp/modules'); + } + $acp_modules = new acp_modules(); + + $module_data = array( + 'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1, + 'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1, + 'module_basename' => (isset($data['module_basename'])) ? $data['module_basename'] : '', + 'module_class' => $class, + 'parent_id' => (int) $parent, + 'module_langname' => (isset($data['module_langname'])) ? $data['module_langname'] : '', + 'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '', + 'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '', + ); + $result = $acp_modules->update_module_data($module_data, true); + + // update_module_data can either return a string or an empty array... + if (is_string($result)) + { + // Error + $this->result = $this->get_output_text($result); + } + else + { + // Success + + // Move the module if requested above/below an existing one + if (isset($data['before']) && $data['before']) + { + $sql = 'SELECT left_id FROM ' . MODULES_TABLE . ' + WHERE module_class = \'' . $class . '\' + AND parent_id = ' . (int) $parent . ' + AND module_langname = \'' . $this->db->sql_escape($data['before']) . '\''; + $this->db->sql_query($sql); + $to_left = $this->db->sql_fetchfield('left_id'); + + $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 + WHERE module_class = '$class' + AND left_id >= $to_left + AND left_id < {$module_data['left_id']}"; + $this->db->sql_query($sql); + + $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = $to_left, right_id = " . ($to_left + 1) . " + WHERE module_class = '$class' + AND module_id = {$module_data['module_id']}"; + $this->db->sql_query($sql); + } + else if (isset($data['after']) && $data['after']) + { + $sql = 'SELECT right_id FROM ' . MODULES_TABLE . ' + WHERE module_class = \'' . $class . '\' + AND parent_id = ' . (int) $parent . ' + AND module_langname = \'' . $this->db->sql_escape($data['after']) . '\''; + $this->db->sql_query($sql); + $to_right = $this->db->sql_fetchfield('right_id'); + + $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 + WHERE module_class = '$class' + AND left_id >= $to_right + AND left_id < {$module_data['left_id']}"; + $this->db->sql_query($sql); + + $sql = 'UPDATE ' . MODULES_TABLE . ' SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . " + WHERE module_class = '$class' + AND module_id = {$module_data['module_id']}"; + $this->db->sql_query($sql); + } + } + + // Clear the Modules Cache + $cache->destroy("_modules_$class"); + + return $this->umil_end(); + } + + /** + * Module Remove + * + * Remove a module + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. + * @param int|string $module The module id|module_langname + * @param string|bool $include_path If you would like to use a custom include path, specify that here + */ + function module_remove($class, $parent = 0, $module = '', $include_path = false) + { + global $cache, $user, $phpbb_root_path, $phpEx; + + // Multicall + if ($this->multicall(__FUNCTION__, $class)) + { + return; + } + + // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto + if (is_array($module)) + { + if (isset($module['module_langname'])) + { + // Manual Method + return $this->module_remove($class, $parent, $module['module_langname'], $include_path); + } + + // Failed. + if (!isset($module['module_basename'])) + { + $this->umil_start('MODULE_REMOVE', $class, 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + // Automatic method + $basename = str_replace(array('/', '\\'), '', $module['module_basename']); + $class = str_replace(array('/', '\\'), '', $class); + $info_file = "$class/info/{$class}_$basename.$phpEx"; + + if (!file_exists((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file)) + { + $this->umil_start('MODULE_REMOVE', $class, $info_file); + return $this->umil_end('FAIL'); + } + + $classname = "{$class}_{$basename}_info"; + + if (!class_exists($classname)) + { + include((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file); + } + + $info = new $classname; + $module_info = $info->module(); + unset($info); + + $result = ''; + foreach ($module_info['modes'] as $mode => $info) + { + if (!isset($module['modes']) || in_array($mode, $module['modes'])) + { + $result .= $this->module_remove($class, $parent, $info['title']) . '
'; + } + } + return $result; + } + else + { + $class = $this->db->sql_escape($class); + + if (!$this->module_exists($class, $parent, $module)) + { + $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module])) ? $user->lang[$module] : $module)); + return $this->umil_end('MODULE_NOT_EXIST'); + } + + $parent_sql = ''; + if ($parent !== false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + // we know it exists from the module_exists check + $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + } + else + { + $parent_sql = 'AND parent_id = ' . (int) $parent; + } + } + + $module_ids = array(); + if (!is_numeric($module)) + { + $module = $this->db->sql_escape($module); + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '$module' + AND module_class = '$class' + $parent_sql"; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $module_ids[] = (int) $row['module_id']; + } + $this->db->sql_freeresult($result); + + $module_name = $module; + } + else + { + $module = (int) $module; + $sql = 'SELECT module_langname FROM ' . MODULES_TABLE . " + WHERE module_id = $module + AND module_class = '$class' + $parent_sql"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $module_name = $row['module_langname']; + $module_ids[] = $module; + } + + $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name)); + add_log('admin', 'LOG_MODULE_REMOVED', ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name)); + + if (!class_exists('acp_modules')) + { + include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); + $user->add_lang('acp/modules'); + } + $acp_modules = new acp_modules(); + $acp_modules->module_class = $class; + + foreach ($module_ids as $module_id) + { + $result = $acp_modules->delete_module($module_id); + if (!empty($result)) + { + if ($this->result == ((isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS')) + { + $this->result = implode('
', $result); + } + else + { + $this->result .= '
' . implode('
', $result); + } + } + } + + $cache->destroy("_modules_$class"); + + return $this->umil_end(); + } + } + + /** + * Permission Exists + * + * Check if a permission (auth) setting exists + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return bool true if it exists, false if not + */ + function permission_exists($auth_option, $global = true) + { + if ($global) + { + $type_sql = ' AND is_global = 1'; + } + else + { + $type_sql = ' AND is_local = 1'; + } + + $sql = 'SELECT auth_option_id + FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" + . $type_sql; + $result = $this->db->sql_query($sql); + + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + return true; + } + + return false; + } + + /** + * Permission Add + * + * Add a permission (auth) option + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return result + */ + function permission_add($auth_option, $global = true) + { + // Multicall + if ($this->multicall(__FUNCTION__, $auth_option)) + { + return; + } + + $this->umil_start('PERMISSION_ADD', $auth_option); + + if ($this->permission_exists($auth_option, $global)) + { + return $this->umil_end('PERMISSION_ALREADY_EXISTS', $auth_option); + } + + // We've added permissions, so set to true to notify the user. + $this->permissions_added = true; + + if (!class_exists('auth_admin')) + { + global $phpbb_root_path, $phpEx; + + include($phpbb_root_path . 'includes/acp/auth.' . $phpEx); + } + $auth_admin = new auth_admin(); + + // We have to add a check to see if the !$global (if global, local, and if local, global) permission already exists. If it does, acl_add_option currently has a bug which would break the ACL system, so we are having a work-around here. + if ($this->permission_exists($auth_option, !$global)) + { + $sql_ary = array( + 'is_global' => 1, + 'is_local' => 1, + ); + $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE auth_option = \'' . $this->db->sql_escape($auth_option) . "'"; + $this->db->sql_query($sql); + } + else + { + if ($global) + { + $auth_admin->acl_add_option(array('global' => array($auth_option))); + } + else + { + $auth_admin->acl_add_option(array('local' => array($auth_option))); + } + } + + return $this->umil_end(); + } + + /** + * Permission Remove + * + * Remove a permission (auth) option + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return result + */ + function permission_remove($auth_option, $global = true) + { + global $auth, $cache; + + // Multicall + if ($this->multicall(__FUNCTION__, $auth_option)) + { + return; + } + + $this->umil_start('PERMISSION_REMOVE', $auth_option); + + if (!$this->permission_exists($auth_option, $global)) + { + return $this->umil_end('PERMISSION_NOT_EXIST', $auth_option); + } + + if ($global) + { + $type_sql = ' AND is_global = 1'; + } + else + { + $type_sql = ' AND is_local = 1'; + } + $sql = 'SELECT auth_option_id, is_global, is_local FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" . + $type_sql; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $id = $row['auth_option_id']; + + // If it is a local and global permission, do not remove the row! :P + if ($row['is_global'] && $row['is_local']) + { + $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' + SET ' . (($global) ? 'is_global = 0' : 'is_local = 0') . ' + WHERE auth_option_id = ' . $id; + $this->db->sql_query($sql); + } + else + { + // Delete time + $this->db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $id); + } + + // Purge the auth cache + $cache->destroy('_acl_options'); + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + } + + /** + * Add a new permission role + * + * @param string $role_name The new role name + * @param sting $role_type The type (u_, m_, a_) + */ + function permission_role_add($role_name, $role_type = '', $role_description = '') + { + // Multicall + if ($this->multicall(__FUNCTION__, $role_name)) + { + return; + } + + $this->umil_start('PERMISSION_ROLE_ADD', $role_name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if ($role_id) + { + return $this->umil_end('ROLE_ALREADY_EXISTS', $old_role_name); + } + + $sql = 'SELECT MAX(role_order) AS max FROM ' . ACL_ROLES_TABLE . ' + WHERE role_type = \'' . $this->db->sql_escape($role_type) . '\''; + $this->db->sql_query($sql); + $role_order = $this->db->sql_fetchfield('max'); + $role_order = (!$role_order) ? 1 : $role_order + 1; + + $sql_ary = array( + 'role_name' => $role_name, + 'role_description' => $role_description, + 'role_type' => $role_type, + 'role_order' => $role_order, + ); + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->db->sql_query($sql); + + return $this->umil_end(); + } + + /** + * Update the name on a permission role + * + * @param string $old_role_name The old role name + * @param string $new_role_name The new role name + */ + function permission_role_update($old_role_name, $new_role_name = '') + { + // Multicall + if ($this->multicall(__FUNCTION__, $role_name)) + { + return; + } + + $this->umil_start('PERMISSION_ROLE_UPDATE', $old_role_name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + return $this->umil_end('ROLE_NOT_EXIST', $old_role_name); + } + + $sql = 'UPDATE ' . ACL_ROLES_TABLE . ' + SET role_name = \'' . $this->db->sql_escape($new_role_name) . '\' + WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; + $this->db->sql_query($sql); + + return $this->umil_end(); + } + + /** + * Remove a permission role + * + * @param string $role_name The role name to remove + */ + function permission_role_remove($role_name) + { + global $auth; + + // Multicall + if ($this->multicall(__FUNCTION__, $role_name)) + { + return; + } + + $this->umil_start('PERMISSION_ROLE_REMOVE', $role_name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + return $this->umil_end('ROLE_NOT_EXIST', $role_name); + } + + $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + + $sql = 'DELETE FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + } + + /** + * Permission Set + * + * Allows you to set permissions for a certain group/role + * + * @param string $name The name of the role/group + * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string $type The type (role|group) + * @param bool $has_permission True if you want to give them permission, false if you want to deny them permission + */ + function permission_set($name, $auth_option = array(), $type = 'role', $has_permission = true) + { + global $auth; + + // Multicall + if ($this->multicall(__FUNCTION__, $name)) + { + return; + } + + if (!is_array($auth_option)) + { + $auth_option = array($auth_option); + } + + $new_auth = array(); + $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $new_auth[] = $row['auth_option_id']; + } + $this->db->sql_freeresult($result); + + if (!sizeof($new_auth)) + { + return false; + } + + $current_auth = array(); + + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'role' : + $this->umil_start('PERMISSION_SET_ROLE', $name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + return $this->umil_end('ROLE_NOT_EXIST'); + } + + $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE role_id = ' . $role_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $current_auth[$row['auth_option_id']] = $row['auth_setting']; + } + $this->db->sql_freeresult($result); + break; + + case 'group' : + $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $group_id = $this->db->sql_fetchfield('group_id'); + + if (!$group_id) + { + $this->umil_start('PERMISSION_SET_GROUP', $name); + return $this->umil_end('GROUP_NOT_EXIST'); + } + + // If the group has a role set for them we will add the requested permissions to that role. + $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id <> 0 + AND forum_id = 0'; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('auth_role_id'); + if ($role_id) + { + $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + $role_name = $this->db->sql_fetchfield('role_name'); + + return $this->permission_set($role_name, $auth_option, 'role', $has_permission); + } + + $this->umil_start('PERMISSION_SET_GROUP', $name); + + $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $current_auth[$row['auth_option_id']] = $row['auth_setting']; + } + $this->db->sql_freeresult($result); + break; + } + + $sql_ary = array(); + switch ($type) + { + case 'role' : + foreach ($new_auth as $auth_option_id) + { + if (!isset($current_auth[$auth_option_id])) + { + $sql_ary[] = array( + 'role_id' => $role_id, + 'auth_option_id' => $auth_option_id, + 'auth_setting' => $has_permission, + ); + } + } + + $this->db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary); + break; + + case 'group' : + foreach ($new_auth as $auth_option_id) + { + if (!isset($current_auth[$auth_option_id])) + { + $sql_ary[] = array( + 'group_id' => $group_id, + 'auth_option_id' => $auth_option_id, + 'auth_setting' => $has_permission, + ); + } + } + + $this->db->sql_multi_insert(ACL_GROUPS_TABLE, $sql_ary); + break; + } + + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + } + + /** + * Permission Unset + * + * Allows you to unset (remove) permissions for a certain group/role + * + * @param string $name The name of the role/group + * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string $type The type (role|group) + */ + function permission_unset($name, $auth_option = array(), $type = 'role') + { + global $auth; + + // Multicall + if ($this->multicall(__FUNCTION__, $name)) + { + return; + } + + if (!is_array($auth_option)) + { + $auth_option = array($auth_option); + } + + $to_remove = array(); + $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $to_remove[] = $row['auth_option_id']; + } + $this->db->sql_freeresult($result); + + if (!sizeof($to_remove)) + { + return false; + } + + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'role' : + $this->umil_start('PERMISSION_UNSET_ROLE', $name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + return $this->umil_end('ROLE_NOT_EXIST'); + } + + $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); + $this->db->sql_query($sql); + break; + + case 'group' : + $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $group_id = $this->db->sql_fetchfield('group_id'); + + if (!$group_id) + { + $this->umil_start('PERMISSION_UNSET_GROUP', $name); + return $this->umil_end('GROUP_NOT_EXIST'); + } + + // If the group has a role set for them we will remove the requested permissions from that role. + $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id <> 0'; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('auth_role_id'); + if ($role_id) + { + $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + $role_name = $this->db->sql_fetchfield('role_name'); + + return $this->permission_unset($role_name, $auth_option, 'role'); + } + + $this->umil_start('PERMISSION_UNSET_GROUP', $name); + + $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); + $this->db->sql_query($sql); + break; + } + + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + } + + /** + * Table Exists + * + * Check if a table exists in the DB or not + * + * @param string $table_name The table name to check for + * + * @return bool true if the table exists, false if not + */ + function table_exists($table_name) + { + $this->get_table_name($table_name); + + // Use sql_table_exists if available + if (method_exists($this->db_tools, 'sql_table_exists')) + { + $roe = $this->db->return_on_error; + $result = $this->db_tools->sql_table_exists($table_name); + + // db_tools::sql_table_exists resets the return_on_error to false always after completing, so we must make sure we set it to true again if it was before + if ($roe) + { + $this->db->sql_return_on_error(true); + } + + return $result; + } + + if (!function_exists('get_tables')) + { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/functions_install.' . $phpEx); + } + + $tables = get_tables($this->db); + + if (in_array($table_name, $tables)) + { + return true; + } + else + { + return false; + } + } + + /** + * Table Add + * + * This only supports input from the array format of db_tools or create_schema_files. + */ + function table_add($table_name, $table_data = array()) + { + global $dbms, $user; + + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + /** + * $table_data can be empty when uninstalling a mod and table_remove was used, but no 2rd argument was given. + * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 2rd argument) and skip this to prevent an error + */ + if (empty($table_data)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_ADD', $table_name); + + if ($this->table_exists($table_name)) + { + return $this->umil_end('TABLE_ALREADY_EXISTS', $table_name); + } + + if (!is_array($table_data)) + { + return $this->umil_end('NO_TABLE_DATA'); + } + + if (!function_exists('get_available_dbms')) + { + global $phpbb_root_path, $phpEx; + include("{$phpbb_root_path}includes/functions_install.$phpEx"); + } + + /* + * This function has had numerous problems and is currently broken, so until phpBB uses it I will not be anymore + if (method_exists($this->db_tools, 'sql_create_table')) + { + // Added in 3.0.5 + $this->db_tools->sql_create_table($table_name, $table_data); + } + else + {*/ + $available_dbms = get_available_dbms($dbms); + + $sql_query = $this->create_table_sql($table_name, $table_data); + $sql_query = split_sql_file($sql_query, $available_dbms[$dbms]['DELIM']); + + foreach ($sql_query as $sql) + { + $this->db->sql_query($sql); + } + //} + + return $this->umil_end(); + } + + /** + * Table Remove + * + * Delete/Drop a DB table + */ + function table_remove($table_name) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_REMOVE', $table_name); + + if (!$this->table_exists($table_name)) + { + return $this->umil_end('TABLE_NOT_EXIST', $table_name); + } + + if (method_exists($this->db_tools, 'sql_table_drop')) + { + // Added in 3.0.5 + $this->db_tools->sql_table_drop($table_name); + } + else + { + $this->db->sql_query('DROP TABLE ' . $table_name); + } + + return $this->umil_end(); + } + + /** + * Table Column Exists + * + * Check to see if a column exists in a table + */ + function table_column_exists($table_name, $column_name) + { + $this->get_table_name($table_name); + + return $this->db_tools->sql_column_exists($table_name, $column_name); + } + + /** + * Table Column Add + * + * Add a new column to a table. + */ + function table_column_add($table_name, $column_name = '', $column_data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + /** + * $column_data can be empty when uninstalling a mod and table_column_remove was used, but no 3rd argument was given. + * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 3rd argument) and skip this to prevent an error + */ + if (empty($column_data)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_COLUMN_ADD', $table_name, $column_name); + + if ($this->table_column_exists($table_name, $column_name)) + { + return $this->umil_end('TABLE_COLUMN_ALREADY_EXISTS', $table_name, $column_name); + } + + $this->db_tools->sql_column_add($table_name, $column_name, $column_data); + + return $this->umil_end(); + } + + /** + * Table Column Update + * + * Alter/Update a column in a table. You can not change a column name with this. + */ + function table_column_update($table_name, $column_name = '', $column_data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_COLUMN_UPDATE', $table_name, $column_name); + + if (!$this->table_column_exists($table_name, $column_name)) + { + return $this->umil_end('TABLE_COLUMN_NOT_EXIST', $table_name, $column_name); + } + + $this->db_tools->sql_column_change($table_name, $column_name, $column_data); + + return $this->umil_end(); + } + + /** + * Table Column Remove + * + * Remove a column from a table + */ + function table_column_remove($table_name, $column_name = '') + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_COLUMN_REMOVE', $table_name, $column_name); + + if (!$this->table_column_exists($table_name, $column_name)) + { + return $this->umil_end('TABLE_COLUMN_NOT_EXIST', $table_name, $column_name); + } + + $this->db_tools->sql_column_remove($table_name, $column_name); + + return $this->umil_end(); + } + + /** + * Table Index Exists + * + * Check if a table key/index exists on a table (can not check primary or unique) + */ + function table_index_exists($table_name, $index_name) + { + $this->get_table_name($table_name); + + $indexes = $this->db_tools->sql_list_index($table_name); + + if (in_array($index_name, $indexes)) + { + return true; + } + + return false; + } + + /** + * Table Index Add + * + * Add a new key/index to a table + */ + function table_index_add($table_name, $index_name = '', $column = array()) + { + global $config; + + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + // Let them skip the column field and just use the index name in that case as the column as well + if (empty($column)) + { + $column = array($index_name); + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_KEY_ADD', $table_name, $index_name); + + if ($this->table_index_exists($table_name, $index_name)) + { + return $this->umil_end('TABLE_KEY_ALREADY_EXIST', $table_name, $index_name); + } + + if (!is_array($column)) + { + $column = array($column); + } + + // remove index length if we are before 3.0.8 + // the feature (required for some types when using MySQL4) + // was added in that release (ticket PHPBB3-8944) + if (version_compare($config['version'], '3.0.7-pl1', '<=')) + { + $column = preg_replace('#:.*$#', '', $column); + } + + $this->db_tools->sql_create_index($table_name, $index_name, $column); + + return $this->umil_end(); + } + + /** + * Table Index Remove + * + * Remove a key/index from a table + */ + function table_index_remove($table_name, $index_name = '') + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_KEY_REMOVE', $table_name, $index_name); + + if (!$this->table_index_exists($table_name, $index_name)) + { + return $this->umil_end('TABLE_KEY_NOT_EXIST', $table_name, $index_name); + } + + $this->db_tools->sql_index_drop($table_name, $index_name); + + return $this->umil_end(); + } + + // Ignore, function was renamed to table_row_insert and keeping for backwards compatibility + function table_insert($table_name, $data = array()) { $this->table_row_insert($table_name, $data); } + + /** + * Table Insert + * + * Insert data into a table + */ + function table_row_insert($table_name, $data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_ROW_INSERT_DATA', $table_name); + + if (!$this->table_exists($table_name)) + { + return $this->umil_end('TABLE_NOT_EXIST', $table_name); + } + + $this->db->sql_multi_insert($table_name, $data); + + return $this->umil_end(); + } + + /** + * Table Row Update + * + * Update a row in a table + * + * $data should be an array with the column names as keys and values as the items to check for each column. Example: + * array('user_id' => 123, 'user_name' => 'test user') would become: + * WHERE user_id = 123 AND user_name = 'test user' + * + * $new_data is the new data it will be updated to (same format as you'd enter into $db->sql_build_array('UPDATE' ). + */ + function table_row_update($table_name, $data = array(), $new_data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + if (!sizeof($data)) + { + return $this->umil_end('FAIL'); + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_ROW_UPDATE_DATA', $table_name); + + if (!$this->table_exists($table_name)) + { + return $this->umil_end('TABLE_NOT_EXIST', $table_name); + } + + $sql = 'UPDATE ' . $table_name . ' + SET ' . $this->db->sql_build_array('UPDATE', $new_data) . ' + WHERE ' . $this->db->sql_build_array('SELECT', $data); + $this->db->sql_query($sql); + + return $this->umil_end(); + } + + /** + * Table Row Remove + * + * Remove a row from a table + * + * $data should be an array with the column names as keys and values as the items to check for each column. Example: + * array('user_id' => 123, 'user_name' => 'test user') would become: + * WHERE user_id = 123 AND user_name = 'test user' + */ + function table_row_remove($table_name, $data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + if (!sizeof($data)) + { + return $this->umil_end('FAIL'); + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_ROW_REMOVE_DATA', $table_name); + + if (!$this->table_exists($table_name)) + { + return $this->umil_end('TABLE_NOT_EXIST', $table_name); + } + + $sql = 'DELETE FROM ' . $table_name . ' WHERE ' . $this->db->sql_build_array('SELECT', $data); + $this->db->sql_query($sql); + + return $this->umil_end(); + } + + /** + * Version Checker + * + * Format the file like the following: + * http://www.phpbb.com/updatecheck/30x.txt + * + * @param string $url The url to access (ex: www.phpbb.com) + * @param string $path The path to access (ex: /updatecheck) + * @param string $file The name of the file to access (ex: 30x.txt) + * + * @return array|string Error Message if there was any error, or an array (each line in the file as a value) + */ + function version_check($url, $path, $file, $timeout = 10, $port = 80) + { + if (!function_exists('get_remote_file')) + { + global $phpbb_root_path, $phpEx; + + include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + } + + $errstr = $errno = ''; + + $info = get_remote_file($url, $path, $file, $errstr, $errno, $port, $timeout); + + if ($info === false) + { + return $errstr . ' [ ' . $errno . ' ]'; + } + + $info = str_replace("\r\n", "\n", $info); + $info = explode("\n", $info); + + return $info; + } + + /** + * Create table SQL + * + * Create the SQL query for the specified DBMS on the fly from a create_schema_files type of table array + * + * @param string $table_name The name of the table + * @param array $table_data The table data (formatted in the array format used by create_schema_files) + * @param string $dbms The dbms this will be built for (for testing only, leave blank to use the current DBMS) + * + * @return The sql query to run for the submitted dbms to insert the table + */ + function create_table_sql($table_name, $table_data, $dbms = '') + { + // To allow testing + $dbms = ($dbms) ? $dbms : $this->db_tools->sql_layer; + + // A list of types being unsigned for better reference in some db's + $unsigned_types = array('UINT', 'UINT:', 'USINT', 'BOOL', 'TIMESTAMP'); + $supported_dbms = array('firebird', 'mssql', 'mysql_40', 'mysql_41', 'oracle', 'postgres', 'sqlite'); + + $sql = ''; + + // Create Table statement + $generator = $textimage = false; + + switch ($dbms) + { + case 'mysql_40': + case 'mysql_41': + case 'firebird': + case 'oracle': + case 'sqlite': + case 'postgres': + $sql .= "CREATE TABLE {$table_name} (\n"; + break; + + case 'mssql': + $sql .= "CREATE TABLE [{$table_name}] (\n"; + break; + } + + // Table specific so we don't get overlap + $modded_array = array(); + + // Write columns one by one... + foreach ($table_data['COLUMNS'] as $column_name => $column_data) + { + // Get type + if (strpos($column_data[0], ':') !== false) + { + list($orig_column_type, $column_length) = explode(':', $column_data[0]); + if (!is_array($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'])) + { + $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'], $column_length); + } + else + { + if (isset($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'])) + { + switch ($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'][0]) + { + case 'div': + $column_length /= $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'][1]; + $column_length = ceil($column_length); + $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length); + break; + } + } + + if (isset($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'])) + { + switch ($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][0]) + { + case 'mult': + $column_length *= $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][1]; + if ($column_length > $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][2]) + { + $column_type = $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][3]; + $modded_array[$column_name] = $column_type; + } + else + { + $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length); + } + break; + } + } + } + $orig_column_type .= ':'; + } + else + { + $orig_column_type = $column_data[0]; + $column_type = $this->db_tools->dbms_type_map[$dbms][$column_data[0]]; + if ($column_type == 'text' || $column_type == 'blob') + { + $modded_array[$column_name] = $column_type; + } + } + + // Adjust default value if db-dependant specified + if (is_array($column_data[1])) + { + $column_data[1] = (isset($column_data[1][$dbms])) ? $column_data[1][$dbms] : $column_data[1]['default']; + } + + switch ($dbms) + { + case 'mysql_40': + case 'mysql_41': + $sql .= "\t{$column_name} {$column_type} "; + + // For hexadecimal values do not use single quotes + if (!is_null($column_data[1]) && substr($column_type, -4) !== 'text' && substr($column_type, -4) !== 'blob') + { + $sql .= (strpos($column_data[1], '0x') === 0) ? "DEFAULT {$column_data[1]} " : "DEFAULT '{$column_data[1]}' "; + } + $sql .= 'NOT NULL'; + + if (isset($column_data[2])) + { + if ($column_data[2] == 'auto_increment') + { + $sql .= ' auto_increment'; + } + else if ($dbms === 'mysql_41' && $column_data[2] == 'true_sort') + { + $sql .= ' COLLATE utf8_unicode_ci'; + } + } + + $sql .= ",\n"; + break; + + case 'sqlite': + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $sql .= "\t{$column_name} INTEGER PRIMARY KEY "; + $generator = $column_name; + } + else + { + $sql .= "\t{$column_name} {$column_type} "; + } + + $sql .= 'NOT NULL '; + $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}'" : ''; + $sql .= ",\n"; + break; + + case 'firebird': + $sql .= "\t{$column_name} {$column_type} "; + + if (!is_null($column_data[1])) + { + $sql .= 'DEFAULT ' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ' '; + } + + $sql .= 'NOT NULL'; + + // This is a UNICODE column and thus should be given it's fair share + if (preg_match('/^X?STEXT_UNI|VCHAR_(CI|UNI:?)/', $column_data[0])) + { + $sql .= ' COLLATE UNICODE'; + } + + $sql .= ",\n"; + + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $generator = $column_name; + } + break; + + case 'mssql': + if ($column_type == '[text]') + { + $textimage = true; + } + + $sql .= "\t[{$column_name}] {$column_type} "; + + if (!is_null($column_data[1])) + { + // For hexadecimal values do not use single quotes + if (strpos($column_data[1], '0x') === 0) + { + $sql .= 'DEFAULT (' . $column_data[1] . ') '; + } + else + { + $sql .= 'DEFAULT (' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ') '; + } + } + + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $sql .= 'IDENTITY (1, 1) '; + } + + $sql .= 'NOT NULL'; + $sql .= " ,\n"; + break; + + case 'oracle': + $sql .= "\t{$column_name} {$column_type} "; + $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : ''; + + // In Oracle empty strings ('') are treated as NULL. + // Therefore in oracle we allow NULL's for all DEFAULT '' entries + $sql .= ($column_data[1] === '') ? ",\n" : "NOT NULL,\n"; + + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $generator = $column_name; + } + break; + + case 'postgres': + $sql .= "\t{$column_name} {$column_type} "; + + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $sql .= "DEFAULT nextval('{$table_name}_seq'),\n"; + + // Make sure the sequence will be created before creating the table + $sql = "CREATE SEQUENCE {$table_name}_seq;\n\n" . $sql; + } + else + { + $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : ''; + $sql .= "NOT NULL"; + + // Unsigned? Then add a CHECK contraint + if (in_array($orig_column_type, $unsigned_types)) + { + $sql .= " CHECK ({$column_name} >= 0)"; + } + + $sql .= ",\n"; + } + break; + } + } + + switch ($dbms) + { + case 'firebird': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n);;\n\n"; + break; + + case 'mssql': + $sql = substr($sql, 0, -2); + $sql .= "\n) ON [PRIMARY]" . (($textimage) ? ' TEXTIMAGE_ON [PRIMARY]' : '') . "\n"; + $sql .= "GO\n\n"; + break; + } + + // Write primary key + if (isset($table_data['PRIMARY_KEY'])) + { + if (!is_array($table_data['PRIMARY_KEY'])) + { + $table_data['PRIMARY_KEY'] = array($table_data['PRIMARY_KEY']); + } + + switch ($dbms) + { + case 'mysql_40': + case 'mysql_41': + case 'postgres': + $sql .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; + break; + + case 'firebird': + $sql .= "ALTER TABLE {$table_name} ADD PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . ");;\n\n"; + break; + + case 'sqlite': + if ($generator === false || !in_array($generator, $table_data['PRIMARY_KEY'])) + { + $sql .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; + } + break; + + case 'mssql': + $sql .= "ALTER TABLE [{$table_name}] WITH NOCHECK ADD \n"; + $sql .= "\tCONSTRAINT [PK_{$table_name}] PRIMARY KEY CLUSTERED \n"; + $sql .= "\t(\n"; + $sql .= "\t\t[" . implode("],\n\t\t[", $table_data['PRIMARY_KEY']) . "]\n"; + $sql .= "\t) ON [PRIMARY] \n"; + $sql .= "GO\n\n"; + break; + + case 'oracle': + $sql .= "\tCONSTRAINT pk_{$table_name} PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; + break; + } + } + + switch ($dbms) + { + case 'oracle': + // UNIQUE contrains to be added? + if (isset($table_data['KEYS'])) + { + foreach ($table_data['KEYS'] as $key_name => $key_data) + { + if (!is_array($key_data[1])) + { + $key_data[1] = array($key_data[1]); + } + + if ($key_data[0] == 'UNIQUE') + { + $sql .= "\tCONSTRAINT u_phpbb_{$key_name} UNIQUE (" . implode(', ', $key_data[1]) . "),\n"; + } + } + } + + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n)\n/\n\n"; + break; + + case 'postgres': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n);\n\n"; + break; + + case 'sqlite': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n);\n\n"; + break; + } + + // Write Keys + if (isset($table_data['KEYS'])) + { + foreach ($table_data['KEYS'] as $key_name => $key_data) + { + if (!is_array($key_data[1])) + { + $key_data[1] = array($key_data[1]); + } + + switch ($dbms) + { + case 'mysql_40': + case 'mysql_41': + $sql .= ($key_data[0] == 'INDEX') ? "\tKEY" : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? "\tUNIQUE" : ''; + foreach ($key_data[1] as $key => $col_name) + { + if (isset($modded_array[$col_name])) + { + switch ($modded_array[$col_name]) + { + case 'text': + case 'blob': + $key_data[1][$key] = $col_name . '(255)'; + break; + } + } + } + $sql .= ' ' . $key_name . ' (' . implode(', ', $key_data[1]) . "),\n"; + break; + + case 'firebird': + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; + + $sql .= ' ' . $table_name . '_' . $key_name . ' ON ' . $table_name . '(' . implode(', ', $key_data[1]) . ");;\n"; + break; + + case 'mssql': + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; + $sql .= " [{$key_name}] ON [{$table_name}]([" . implode('], [', $key_data[1]) . "]) ON [PRIMARY]\n"; + $sql .= "GO\n\n"; + break; + + case 'oracle': + if ($key_data[0] == 'UNIQUE') + { + continue; + } + + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + + $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ")\n"; + $sql .= "/\n"; + break; + + case 'sqlite': + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; + + $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n"; + break; + + case 'postgres': + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; + + $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n"; + break; + } + } + } + + switch ($dbms) + { + case 'mysql_40': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n);\n\n"; + break; + + case 'mysql_41': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n) CHARACTER SET utf8 COLLATE utf8_bin;\n\n"; + break; + + // Create Generator + case 'firebird': + if ($generator !== false) + { + $sql .= "\nCREATE GENERATOR {$table_name}_gen;;\n"; + $sql .= 'SET GENERATOR ' . $table_name . "_gen TO 0;;\n\n"; + + $sql .= 'CREATE TRIGGER t_' . $table_name . ' FOR ' . $table_name . "\n"; + $sql .= "BEFORE INSERT\nAS\nBEGIN\n"; + $sql .= "\tNEW.{$generator} = GEN_ID({$table_name}_gen, 1);\nEND;;\n\n"; + } + break; + + case 'oracle': + if ($generator !== false) + { + $sql .= "\nCREATE SEQUENCE {$table_name}_seq\n/\n\n"; + + $sql .= "CREATE OR REPLACE TRIGGER t_{$table_name}\n"; + $sql .= "BEFORE INSERT ON {$table_name}\n"; + $sql .= "FOR EACH ROW WHEN (\n"; + $sql .= "\tnew.{$generator} IS NULL OR new.{$generator} = 0\n"; + $sql .= ")\nBEGIN\n"; + $sql .= "\tSELECT {$table_name}_seq.nextval\n"; + $sql .= "\tINTO :new.{$generator}\n"; + $sql .= "\tFROM dual;\nEND;\n/\n\n"; + } + break; + } + + return $sql; + } + + /** + * Get the real table name + * By A_Jelly_Doughnut + * + * @param string $table_name The table name to get the real table name from + */ + function get_table_name(&$table_name) + { + // Use the global table prefix if a custom one is not specified + if ($this->table_prefix === false) + { + global $table_prefix; + } + else + { + $table_prefix = $this->table_prefix; + } + + static $constants = NULL; + + if (is_null($constants)) + { + $constants = get_defined_constants(); + } + + /** + * only do the replace if the table prefix is not already present + * this is required since UMIL supports specifying a table via phpbb_foo + * (where a replace would be needed) + * or by FOO_TABLE (where a replace is already done at constant-define time) + */ + if (!preg_match('#^' . preg_quote($table_prefix, '#') . '#', $table_name) || !in_array($table_name, $constants, true)) + { + $table_name = preg_replace('#^phpbb_#i', $table_prefix, $table_name); + } + } +} + +?> \ No newline at end of file -- cgit v1.2.1 From 91a921a96bf26607879de850fca105be78eadf1d Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 11 Nov 2012 09:43:07 +0100 Subject: [feature/migrations] Change migration data processing to run step by step --- phpBB/includes/db/migrator.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 4ce54a4b92..912a7b34ba 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -167,7 +167,7 @@ class phpbb_db_migrator } else { - $migration->update_data(); + $this->process_data_step($migration); $state['migration_data_done'] = true; $state['migration_end_time'] = time(); } @@ -182,6 +182,28 @@ class phpbb_db_migrator return true; } + function process_data_step(&$migration) + { + $continue = false; + $steps = $migration->update_data(); + + foreach ($steps as $step) + { + $continue = $this->run_step($step); + if (!$continue) + { + return false; + } + } + + return $continue; + } + + function run_step(&$step) + { + + } + function insert_migration($name, $state) { $migration_row = $state; -- cgit v1.2.1 From 82efb3e446efbb8ef05c6a777e3866901abfd07a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 8 Jan 2013 22:07:12 -0600 Subject: [feature/migrations] Remove references as it is now 3.1 code PHPBB3-9737 --- phpBB/includes/db/migration.php | 6 +- phpBB/includes/db/migration/3_0_1.php | 25 - phpBB/includes/db/migration/3_0_10.php | 25 - phpBB/includes/db/migration/3_0_10_rc1.php | 28 - phpBB/includes/db/migration/3_0_10_rc2.php | 25 - phpBB/includes/db/migration/3_0_10_rc3.php | 25 - phpBB/includes/db/migration/3_0_11.php | 25 - phpBB/includes/db/migration/3_0_11_rc1.php | 96 - phpBB/includes/db/migration/3_0_11_rc2 | 31 - phpBB/includes/db/migration/3_0_12_rc1.php | 26 - phpBB/includes/db/migration/3_0_1_rc1.php | 77 - phpBB/includes/db/migration/3_0_2.php | 25 - phpBB/includes/db/migration/3_0_2_rc1.php | 30 - phpBB/includes/db/migration/3_0_2_rc2.php | 52 - phpBB/includes/db/migration/3_0_3.php | 25 - phpBB/includes/db/migration/3_0_3_rc1.php | 61 - phpBB/includes/db/migration/3_0_4.php | 47 - phpBB/includes/db/migration/3_0_4_rc1.php | 103 - phpBB/includes/db/migration/3_0_5.php | 25 - phpBB/includes/db/migration/3_0_5_rc1.php | 119 - phpBB/includes/db/migration/3_0_5_rc1part2.php | 34 - phpBB/includes/db/migration/3_0_6.php | 25 - phpBB/includes/db/migration/3_0_6_rc1.php | 314 -- phpBB/includes/db/migration/3_0_6_rc2.php | 25 - phpBB/includes/db/migration/3_0_6_rc3.php | 38 - phpBB/includes/db/migration/3_0_6_rc4.php | 25 - phpBB/includes/db/migration/3_0_7.php | 25 - phpBB/includes/db/migration/3_0_7_pl1.php | 25 - phpBB/includes/db/migration/3_0_7_rc1.php | 51 - phpBB/includes/db/migration/3_0_7_rc2.php | 70 - phpBB/includes/db/migration/3_0_8.php | 25 - phpBB/includes/db/migration/3_0_8_rc1.php | 225 -- phpBB/includes/db/migration/3_0_9.php | 25 - phpBB/includes/db/migration/3_0_9_rc1.php | 108 - phpBB/includes/db/migration/3_0_9_rc2.php | 25 - phpBB/includes/db/migration/3_0_9_rc3.php | 25 - phpBB/includes/db/migration/3_0_9_rc4.php | 25 - phpBB/includes/db/migration/data/3_0_1.php | 25 + phpBB/includes/db/migration/data/3_0_10.php | 25 + phpBB/includes/db/migration/data/3_0_10_rc1.php | 28 + phpBB/includes/db/migration/data/3_0_10_rc2.php | 25 + phpBB/includes/db/migration/data/3_0_10_rc3.php | 25 + phpBB/includes/db/migration/data/3_0_11.php | 25 + phpBB/includes/db/migration/data/3_0_11_rc1.php | 96 + phpBB/includes/db/migration/data/3_0_11_rc2 | 31 + phpBB/includes/db/migration/data/3_0_12_rc1.php | 26 + phpBB/includes/db/migration/data/3_0_1_rc1.php | 77 + phpBB/includes/db/migration/data/3_0_2.php | 25 + phpBB/includes/db/migration/data/3_0_2_rc1.php | 30 + phpBB/includes/db/migration/data/3_0_2_rc2.php | 52 + phpBB/includes/db/migration/data/3_0_3.php | 25 + phpBB/includes/db/migration/data/3_0_3_rc1.php | 61 + phpBB/includes/db/migration/data/3_0_4.php | 47 + phpBB/includes/db/migration/data/3_0_4_rc1.php | 103 + phpBB/includes/db/migration/data/3_0_5.php | 25 + phpBB/includes/db/migration/data/3_0_5_rc1.php | 119 + .../includes/db/migration/data/3_0_5_rc1part2.php | 34 + phpBB/includes/db/migration/data/3_0_6.php | 25 + phpBB/includes/db/migration/data/3_0_6_rc1.php | 299 ++ phpBB/includes/db/migration/data/3_0_6_rc2.php | 25 + phpBB/includes/db/migration/data/3_0_6_rc3.php | 38 + phpBB/includes/db/migration/data/3_0_6_rc4.php | 25 + phpBB/includes/db/migration/data/3_0_7.php | 25 + phpBB/includes/db/migration/data/3_0_7_pl1.php | 25 + phpBB/includes/db/migration/data/3_0_7_rc1.php | 51 + phpBB/includes/db/migration/data/3_0_7_rc2.php | 70 + phpBB/includes/db/migration/data/3_0_8.php | 25 + phpBB/includes/db/migration/data/3_0_8_rc1.php | 223 ++ phpBB/includes/db/migration/data/3_0_9.php | 25 + phpBB/includes/db/migration/data/3_0_9_rc1.php | 108 + phpBB/includes/db/migration/data/3_0_9_rc2.php | 25 + phpBB/includes/db/migration/data/3_0_9_rc3.php | 25 + phpBB/includes/db/migration/data/3_0_9_rc4.php | 25 + phpBB/includes/db/migration/tools/base.php | 47 + phpBB/includes/db/migration/tools/config.php | 106 + phpBB/includes/db/migration/tools/module.php | 419 +++ phpBB/includes/db/migration/tools/permission.php | 480 ++++ phpBB/includes/db/migration/tools/umil.php | 3037 ++++++++++++++++++++ phpBB/includes/db/migrationtools/base.php | 15 - phpBB/includes/db/migrationtools/config.php | 121 - phpBB/includes/db/migrationtools/umil.php | 3037 -------------------- phpBB/includes/db/migrator.php | 14 +- 82 files changed, 6042 insertions(+), 5143 deletions(-) delete mode 100644 phpBB/includes/db/migration/3_0_1.php delete mode 100644 phpBB/includes/db/migration/3_0_10.php delete mode 100644 phpBB/includes/db/migration/3_0_10_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_10_rc2.php delete mode 100644 phpBB/includes/db/migration/3_0_10_rc3.php delete mode 100644 phpBB/includes/db/migration/3_0_11.php delete mode 100644 phpBB/includes/db/migration/3_0_11_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_11_rc2 delete mode 100644 phpBB/includes/db/migration/3_0_12_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_1_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_2.php delete mode 100644 phpBB/includes/db/migration/3_0_2_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_2_rc2.php delete mode 100644 phpBB/includes/db/migration/3_0_3.php delete mode 100644 phpBB/includes/db/migration/3_0_3_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_4.php delete mode 100644 phpBB/includes/db/migration/3_0_4_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_5.php delete mode 100644 phpBB/includes/db/migration/3_0_5_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_5_rc1part2.php delete mode 100644 phpBB/includes/db/migration/3_0_6.php delete mode 100644 phpBB/includes/db/migration/3_0_6_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_6_rc2.php delete mode 100644 phpBB/includes/db/migration/3_0_6_rc3.php delete mode 100644 phpBB/includes/db/migration/3_0_6_rc4.php delete mode 100644 phpBB/includes/db/migration/3_0_7.php delete mode 100644 phpBB/includes/db/migration/3_0_7_pl1.php delete mode 100644 phpBB/includes/db/migration/3_0_7_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_7_rc2.php delete mode 100644 phpBB/includes/db/migration/3_0_8.php delete mode 100644 phpBB/includes/db/migration/3_0_8_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_9.php delete mode 100644 phpBB/includes/db/migration/3_0_9_rc1.php delete mode 100644 phpBB/includes/db/migration/3_0_9_rc2.php delete mode 100644 phpBB/includes/db/migration/3_0_9_rc3.php delete mode 100644 phpBB/includes/db/migration/3_0_9_rc4.php 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 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/tools/base.php create mode 100644 phpBB/includes/db/migration/tools/config.php create mode 100644 phpBB/includes/db/migration/tools/module.php create mode 100644 phpBB/includes/db/migration/tools/permission.php create mode 100644 phpBB/includes/db/migration/tools/umil.php delete mode 100644 phpBB/includes/db/migrationtools/base.php delete mode 100644 phpBB/includes/db/migrationtools/config.php delete mode 100644 phpBB/includes/db/migrationtools/umil.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php index de9f6d07e3..c98ac8728a 100644 --- a/phpBB/includes/db/migration.php +++ b/phpBB/includes/db/migration.php @@ -44,10 +44,10 @@ class phpbb_db_migration * @param string $phpbb_root_path * @param string $php_ext */ - function phpbb_db_migration(&$db, &$db_tools, $table_prefix, $phpbb_root_path, $php_ext) + function phpbb_db_migration($db, $db_tools, $table_prefix, $phpbb_root_path, $php_ext) { - $this->db = &$db; - $this->db_tools = &$db_tools; + $this->db = $db; + $this->db_tools = $db_tools; $this->table_prefix = $table_prefix; $this->phpbb_root_path = $phpbb_root_path; diff --git a/phpBB/includes/db/migration/3_0_1.php b/phpBB/includes/db/migration/3_0_1.php deleted file mode 100644 index 1cb069a2b1..0000000000 --- a/phpBB/includes/db/migration/3_0_1.php +++ /dev/null @@ -1,25 +0,0 @@ -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']; - } - $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 true; - } - else - { - return false; - } - } -} diff --git a/phpBB/includes/db/migration/3_0_11_rc2 b/phpBB/includes/db/migration/3_0_11_rc2 deleted file mode 100644 index f4e64871ed..0000000000 --- a/phpBB/includes/db/migration/3_0_11_rc2 +++ /dev/null @@ -1,31 +0,0 @@ - array( - $this->table_prefix . 'profile_fields' => array( - 'field_show_novalue' => array('BOOL', 0), - ), - ), - ); - } - - function update_data() - { - } -} diff --git a/phpBB/includes/db/migration/3_0_12_rc1.php b/phpBB/includes/db/migration/3_0_12_rc1.php deleted file mode 100644 index 58e112a43a..0000000000 --- a/phpBB/includes/db/migration/3_0_12_rc1.php +++ /dev/null @@ -1,26 +0,0 @@ - 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 update_data() - { - return array( - array('custom', array(array(&$this, 'fix_unset_last_view_time'))), - array('custom', array(array(&$this, 'reset_smiley_size'))), - ); - } - - 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/3_0_2.php b/phpBB/includes/db/migration/3_0_2.php deleted file mode 100644 index 36e8d52e6b..0000000000 --- a/phpBB/includes/db/migration/3_0_2.php +++ /dev/null @@ -1,25 +0,0 @@ - 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() - { - } -} diff --git a/phpBB/includes/db/migration/3_0_3.php b/phpBB/includes/db/migration/3_0_3.php deleted file mode 100644 index c9ca33ee88..0000000000 --- a/phpBB/includes/db/migration/3_0_3.php +++ /dev/null @@ -1,25 +0,0 @@ - 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', '')), - array('permission.add', array('u_masspm_group', phpbb_auth::IS_GLOBAL), - array('custom', array(array(&$this, 'correct_acp_email_permissions'))), - )); - } - - 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/3_0_4.php b/phpBB/includes/db/migration/3_0_4.php deleted file mode 100644 index bbaaea54c9..0000000000 --- a/phpBB/includes/db/migration/3_0_4.php +++ /dev/null @@ -1,47 +0,0 @@ -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/3_0_4_rc1.php b/phpBB/includes/db/migration/3_0_4_rc1.php deleted file mode 100644 index b783e58e24..0000000000 --- a/phpBB/includes/db/migration/3_0_4_rc1.php +++ /dev/null @@ -1,103 +0,0 @@ - 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'))), - ); - } - - 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->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); - } - } -} diff --git a/phpBB/includes/db/migration/3_0_5.php b/phpBB/includes/db/migration/3_0_5.php deleted file mode 100644 index 272779f083..0000000000 --- a/phpBB/includes/db/migration/3_0_5.php +++ /dev/null @@ -1,25 +0,0 @@ - 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_refresh', 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->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']); - } - } - $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->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/3_0_5_rc1part2.php b/phpBB/includes/db/migration/3_0_5_rc1part2.php deleted file mode 100644 index 710c8dce91..0000000000 --- a/phpBB/includes/db/migration/3_0_5_rc1part2.php +++ /dev/null @@ -1,34 +0,0 @@ - array( - ACL_OPTIONS_TABLE => array('auth_option'), - ), - 'add_unique_index' => array( - ACL_OPTIONS_TABLE => array( - 'auth_option' => array('auth_option'), - ), - ), - ); - } - - function update_data() - { - } -} diff --git a/phpBB/includes/db/migration/3_0_6.php b/phpBB/includes/db/migration/3_0_6.php deleted file mode 100644 index 9582038b36..0000000000 --- a/phpBB/includes/db/migration/3_0_6.php +++ /dev/null @@ -1,25 +0,0 @@ - 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 . '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('custom', array(array(&$this, ''))) - array('config.add', array('captcha_plugin', 'phpbb_captcha_nogd')), - array('config.update_if', array( - ($this->config['captcha_gd']), - '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('config.add_if', array( - ($this->config['allow_avatar_upload'] || $this->config['allow_avatar_local'] || $this->config['allow_avatar_remote']), - 'allow_avatar', - 1, - )), - array('config.add', array('allow_avatar_remote_upload', 0)), - array('config.add_if', array( - ($this->config['allow_avatar_remote'] && $this->config['allow_avatar_upload']), - 'allow_avatar_remote_upload', - 1, - )), - - array('module.add', array( - 'feed' => array( - 'base' => 'board', - 'class' => 'acp', - 'title' => 'ACP_FEED_SETTINGS', - 'auth' => 'acl_a_board', - 'cat' => 'ACP_BOARD_CONFIGURATION', - 'after' => array('signature', 'ACP_SIGNATURE_SETTINGS') - ), - )), - array('module.add', array( - 'warnings' => array( - 'base' => 'users', - 'class' => 'acp', - 'title' => 'ACP_USER_WARNINGS', - 'auth' => 'acl_a_user', - 'display' => 0, - 'cat' => 'ACP_CAT_USERS', - 'after' => array('feedback', 'ACP_USER_FEEDBACK') - ), - )), - array('module.add', array( - 'send_statistics' => array( - 'base' => 'send_statistics', - 'class' => 'acp', - 'title' => 'ACP_SEND_STATISTICS', - 'auth' => 'acl_a_server', - 'cat' => 'ACP_SERVER_CONFIGURATION' - ), - )), - array('module.add', array( - 'setting_forum_copy' => array( - 'base' => 'permissions', - 'class' => 'acp', - 'title' => 'ACP_FORUM_PERMISSIONS_COPY', - 'auth' => 'acl_a_fauth && acl_a_authusers && acl_a_authgroups && acl_a_mauth', - 'cat' => 'ACP_FORUM_BASED_PERMISSIONS', - 'after' => array('setting_forum_local', 'ACP_FORUM_PERMISSIONS') - ), - )), - array('module.add', array( - 'pm_reports' => array( - 'base' => 'pm_reports', - 'class' => 'mcp', - 'title' => 'MCP_PM_REPORTS_OPEN', - 'auth' => 'aclf_m_report', - 'cat' => 'MCP_REPORTS' - ), - )), - array('module.add', array( - 'pm_reports_closed' => array( - 'base' => 'pm_reports', - 'class' => 'mcp', - 'title' => 'MCP_PM_REPORTS_CLOSED', - 'auth' => 'aclf_m_report', - 'cat' => 'MCP_REPORTS' - ), - )), - array('module.add', array( - 'pm_report_details' => array( - 'base' => 'pm_reports', - 'class' => 'mcp', - 'title' => 'MCP_PM_REPORT_DETAILS', - 'auth' => 'aclf_m_report', - 'cat' => 'MCP_REPORTS' - ), - )), - array('custom', array(array(&$this, 'add_newly_registered_group'))), - array('custom', array(array(&$this, 'set_user_options_default'))), - ); - } - - 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(); - - if (!$errored) - { - // 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(); - - if (!$errored) - { - $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->phpEx); - $auth_admin = new auth_admin(); - $auth_admin->acl_clear_prefetch(); - } -} diff --git a/phpBB/includes/db/migration/3_0_6_rc2.php b/phpBB/includes/db/migration/3_0_6_rc2.php deleted file mode 100644 index 1552485d0a..0000000000 --- a/phpBB/includes/db/migration/3_0_6_rc2.php +++ /dev/null @@ -1,25 +0,0 @@ -sql_query($sql); - } -} diff --git a/phpBB/includes/db/migration/3_0_6_rc4.php b/phpBB/includes/db/migration/3_0_6_rc4.php deleted file mode 100644 index 00161456b6..0000000000 --- a/phpBB/includes/db/migration/3_0_6_rc4.php +++ /dev/null @@ -1,25 +0,0 @@ - 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'))), - ); - } - - 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/3_0_7_rc2.php b/phpBB/includes/db/migration/3_0_7_rc2.php deleted file mode 100644 index 4ab4e906d7..0000000000 --- a/phpBB/includes/db/migration/3_0_7_rc2.php +++ /dev/null @@ -1,70 +0,0 @@ - ' . 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); - } - } - $db->sql_freeresult($result); - - if ($i < $limit) - { - // Completed - return false; - } - - return $start + $limit; - } -} diff --git a/phpBB/includes/db/migration/3_0_8.php b/phpBB/includes/db/migration/3_0_8.php deleted file mode 100644 index 3e7f843a65..0000000000 --- a/phpBB/includes/db/migration/3_0_8.php +++ /dev/null @@ -1,25 +0,0 @@ - array( - 'base' => 'board', - 'class' => 'acp', - 'title' => 'ACP_POST_SETTINGS', - 'auth' => 'acl_a_board', - 'cat' => 'ACP_MESSAGES', - 'after' => array('message', 'ACP_MESSAGE_SETTINGS') - ), - )), - 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)), - ); - } - - 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->phpEx", - "{$this->phpbb_root_path}language/$lang_dir/install.$this->phpEx", - "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.$this->phpEx", - ); - - 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->phpEx); - } - - $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 true; - } - else - { - return false; - } - } -} diff --git a/phpBB/includes/db/migration/3_0_9.php b/phpBB/includes/db/migration/3_0_9.php deleted file mode 100644 index 2e1eab26e7..0000000000 --- a/phpBB/includes/db/migration/3_0_9.php +++ /dev/null @@ -1,25 +0,0 @@ - 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 . 'bbcode' => 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'))), - ); - } - - 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/3_0_9_rc2.php b/phpBB/includes/db/migration/3_0_9_rc2.php deleted file mode 100644 index 96782b2b01..0000000000 --- a/phpBB/includes/db/migration/3_0_9_rc2.php +++ /dev/null @@ -1,25 +0,0 @@ -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']; + } + $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 true; + } + else + { + return false; + } + } +} diff --git a/phpBB/includes/db/migration/data/3_0_11_rc2 b/phpBB/includes/db/migration/data/3_0_11_rc2 new file mode 100644 index 0000000000..6add980c73 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_11_rc2 @@ -0,0 +1,31 @@ + array( + $this->table_prefix . 'profile_fields' => array( + 'field_show_novalue' => array('BOOL', 0), + ), + ), + ); + } + + function update_data() + { + } +} 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..734a57ecee --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_12_rc1.php @@ -0,0 +1,26 @@ + 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 update_data() + { + return array( + array('custom', array(array(&$this, 'fix_unset_last_view_time'))), + array('custom', array(array(&$this, 'reset_smiley_size'))), + ); + } + + 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..a5f94e644b --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_2.php @@ -0,0 +1,25 @@ + 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() + { + } +} 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..f989eea025 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_3.php @@ -0,0 +1,25 @@ + 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', '')), + array('permission.add', array('u_masspm_group', phpbb_auth::IS_GLOBAL), + array('custom', array(array(&$this, 'correct_acp_email_permissions'))), + )); + } + + 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..cd34fda9ab --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_4.php @@ -0,0 +1,47 @@ +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..342f1fa910 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_4_rc1.php @@ -0,0 +1,103 @@ + 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'))), + ); + } + + 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->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); + } + } +} 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..5671832a82 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_5.php @@ -0,0 +1,25 @@ + 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_refresh', 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->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']); + } + } + $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->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..6be8ea9845 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php @@ -0,0 +1,34 @@ + array( + ACL_OPTIONS_TABLE => array('auth_option'), + ), + 'add_unique_index' => array( + ACL_OPTIONS_TABLE => array( + 'auth_option' => array('auth_option'), + ), + ), + ); + } + + function update_data() + { + } +} 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..c2cb59e62a --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_6.php @@ -0,0 +1,25 @@ + 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 . '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.add', 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.add', array('allow_avatar_remote_upload', 1)), + )), + + array('module.add', array( + 'acp', + 'ACP_BOARD_CONFIGURATION', + array( + 'module_basename' => 'board', + 'modes' => array('feed'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_CAT_USERS', + array( + 'module_basename' => 'users', + 'modes' => array('warnings'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_SERVER_CONFIGURATION', + array( + 'module_basename' => 'send_statistics', + 'modes' => array('send_statistics'), + ), + )), + array('module.add', array( + 'acp', + 'ACP_FORUM_BASED_PERMISSIONS', + array( + 'module_basename' => 'permissions', + 'modes' => array('setting_forum_copy'), + ), + )), + array('module.add', array( + 'mcp', + 'MCP_REPORTS', + array( + 'module_basename' => 'pm_reports', + 'modes' => array('pm_reports'), + ), + )), + array('module.add', array( + 'mcp', + 'MCP_REPORTS', + array( + 'module_basename' => 'pm_reports', + 'modes' => array('pm_reports_closed'), + ), + )), + array('module.add', array( + 'mcp', + 'MCP_REPORTS', + array( + 'module_basename' => 'pm_reports', + 'modes' => array('pm_report_details'), + ), + )), + array('custom', array(array(&$this, 'add_newly_registered_group'))), + array('custom', array(array(&$this, 'set_user_options_default'))), + ); + } + + 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(); + + if (!$errored) + { + // 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(); + + if (!$errored) + { + $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->phpEx); + $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..07b31a53b9 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_6_rc2.php @@ -0,0 +1,25 @@ +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..c48b1ca394 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_6_rc4.php @@ -0,0 +1,25 @@ + 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'))), + ); + } + + 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..8a751328bf --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_7_rc2.php @@ -0,0 +1,70 @@ + ' . 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); + } + } + $db->sql_freeresult($result); + + if ($i < $limit) + { + // Completed + return false; + } + + 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..a714a3d2f6 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_8.php @@ -0,0 +1,25 @@ + '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)), + ); + } + + 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->phpEx", + "{$this->phpbb_root_path}language/$lang_dir/install.$this->phpEx", + "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.$this->phpEx", + ); + + 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->phpEx); + } + + $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 true; + } + else + { + 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..4b2c08a256 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_9.php @@ -0,0 +1,25 @@ + 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 . 'bbcode' => 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'))), + ); + } + + 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..589047670a --- /dev/null +++ b/phpBB/includes/db/migration/data/3_0_9_rc2.php @@ -0,0 +1,25 @@ +db = $db; + $this->cache = $cache; + $this->template = $template; + $this->user = $user; + $this->auth = $auth; + $this->config = $config; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } +} \ No newline at end of file diff --git a/phpBB/includes/db/migration/tools/config.php b/phpBB/includes/db/migration/tools/config.php new file mode 100644 index 0000000000..965ba1d136 --- /dev/null +++ b/phpBB/includes/db/migration/tools/config.php @@ -0,0 +1,106 @@ +config->offsetExists($config_name); + } + + /** + * Config Add + * + * This function allows you to add a config setting. + * + * @param string $config_name The name of the config setting you would like to add + * @param mixed $config_value The value of the config setting + * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + */ + public function add($config_name, $config_value = '', $is_dynamic = false) + { + if ($this->config_exists($config_name)) + { + throw new phpbb_db_migration_exception('CONFIG_ALREADY_EXISTS', $config_name); + } + + $this->config->set($config_name, $config_value, $is_dynamic); + + return false; + } + + /** + * Config Update + * + * This function allows you to update an existing config setting. + * + * @param string $config_name The name of the config setting you would like to update + * @param mixed $config_value The value of the config setting + */ + public function update($config_name, $config_value = '') + { + if (!$this->config_exists($config_name)) + { + throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); + } + + $this->config->set($config_name, $config_value); + + return false; + } + + /** + * Config Update If Equals + * + * This function allows you to update a config setting if the first argument equal to the current config value + * + * @param bool $compare If equal to the current config value, will be updated to the new config value, otherwise not + * @param string $config_name The name of the config setting you would like to update + * @param mixed $config_value The value of the config setting + */ + public function update_if_equals($compare, $config_name, $config_value = '') + { + if (!$this->config_exists($config_name)) + { + throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); + } + + $this->config->set_atomic($config_name, $compare, $config_value); + + return false; + } + + /** + * Config Remove + * + * This function allows you to remove an existing config setting. + * + * @param string $config_name The name of the config setting you would like to remove + */ + public function remove($config_name) + { + if (!$this->config_exists($config_name)) + { + throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); + } + + $this->config->delete($config_name); + + return false; + } +} \ No newline at end of file diff --git a/phpBB/includes/db/migration/tools/module.php b/phpBB/includes/db/migration/tools/module.php new file mode 100644 index 0000000000..df1912a022 --- /dev/null +++ b/phpBB/includes/db/migration/tools/module.php @@ -0,0 +1,419 @@ +db->sql_escape($class); + $module = $this->db->sql_escape($module); + + $parent_sql = ''; + if ($parent !== false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + return false; + } + + $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + } + else + { + $parent_sql = 'AND parent_id = ' . (int) $parent; + } + } + + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_class = '$class' + $parent_sql + AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '$module'"); + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + return true; + } + + return false; + } + + /** + * Module Add + * + * Add a new module + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string $parent The parent module_id|module_langname (0 for no parent) + * @param array $data an array of the data on the new module. This can be setup in two different ways. + * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below, + * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode. + * array( + * 'module_enabled' => 1, + * 'module_display' => 1, + * 'module_basename' => '', + * 'module_class' => $class, + * 'parent_id' => (int) $parent, + * 'module_langname' => '', + * 'module_mode' => '', + * 'module_auth' => '', + * ) + * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file. + * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file): + * array( + * 'module_basename' => 'asacp', + * 'modes' => array('settings', 'log', 'flag'), + * ) + * Optionally you may not send 'modes' and it will insert all of the modules in that info file. + * @param string|bool $include_path If you would like to use a custom include path, specify that here + */ + public function add($class, $parent = 0, $data = array(), $include_path = false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + // allow sending the name as a string in $data to create a category + if (!is_array($data)) + { + $data = array('module_langname' => $data); + } + + if (!isset($data['module_langname'])) + { + // The "automatic" way + $basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; + $basename = str_replace(array('/', '\\'), '', $basename); + $class = str_replace(array('/', '\\'), '', $class); + $info_file = "$class/info/{$class}_$basename.$this->phpEx"; + + // The manual and automatic ways both failed... + if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file)) + { + throw new phpbb_db_migration_exception('MODULE_ADD', $class, $info_file); + } + + $classname = "{$class}_{$basename}_info"; + + if (!class_exists($classname)) + { + include((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file); + } + + $info = new $classname; + $module = $info->module(); + unset($info); + + $result = ''; + foreach ($module['modes'] as $mode => $module_info) + { + if (!isset($data['modes']) || in_array($mode, $data['modes'])) + { + $new_module = array( + 'module_basename' => $basename, + 'module_langname' => $module_info['title'], + 'module_mode' => $mode, + 'module_auth' => $module_info['auth'], + 'module_display' => (isset($module_info['display'])) ? $module_info['display'] : true, + 'before' => (isset($module_info['before'])) ? $module_info['before'] : false, + 'after' => (isset($module_info['after'])) ? $module_info['after'] : false, + ); + + // Run the "manual" way with the data we've collected. + $result .= ((isset($data['spacer'])) ? $data['spacer'] : '
') . $this->add($class, $parent, $new_module); + } + } + + return $result; + } + + // The "manual" way + add_log('admin', 'LOG_MODULE_ADD', ((isset($this->user->lang[$data['module_langname']])) ? $this->user->lang[$data['module_langname']] : $data['module_langname'])); + + $class = $this->db->sql_escape($class); + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + throw new phpbb_db_migration_exception('MODULE_PARENT_NOT_EXIST', $parent); + } + + $parent = $data['parent_id'] = $row['module_id']; + } + else if (!$this->exists($class, false, $parent)) + { + throw new phpbb_db_migration_exception('MODULE_PARENT_NOT_EXIST', $parent); + } + + if ($this->exists($class, $parent, $data['module_langname'])) + { + throw new phpbb_db_migration_exception('MODULE_ALREADY_EXIST', $data['module_langname']); + } + + if (!class_exists('acp_modules')) + { + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->phpEx); + $this->user->add_lang('acp/modules'); + } + $acp_modules = new acp_modules(); + + $module_data = array( + 'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1, + 'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1, + 'module_basename' => (isset($data['module_basename'])) ? $data['module_basename'] : '', + 'module_class' => $class, + 'parent_id' => (int) $parent, + 'module_langname' => (isset($data['module_langname'])) ? $data['module_langname'] : '', + 'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '', + 'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '', + ); + $result = $acp_modules->update_module_data($module_data, true); + + // update_module_data can either return a string or an empty array... + if (is_string($result)) + { + // Error + throw new phpbb_db_migration_exception('MODULE_ERROR', $result); + } + else + { + // Success + + // Move the module if requested above/below an existing one + if (isset($data['before']) && $data['before']) + { + $sql = 'SELECT left_id FROM ' . MODULES_TABLE . ' + WHERE module_class = \'' . $class . '\' + AND parent_id = ' . (int) $parent . ' + AND module_langname = \'' . $this->db->sql_escape($data['before']) . '\''; + $this->db->sql_query($sql); + $to_left = $this->db->sql_fetchfield('left_id'); + + $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 + WHERE module_class = '$class' + AND left_id >= $to_left + AND left_id < {$module_data['left_id']}"; + $this->db->sql_query($sql); + + $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = $to_left, right_id = " . ($to_left + 1) . " + WHERE module_class = '$class' + AND module_id = {$module_data['module_id']}"; + $this->db->sql_query($sql); + } + else if (isset($data['after']) && $data['after']) + { + $sql = 'SELECT right_id FROM ' . MODULES_TABLE . ' + WHERE module_class = \'' . $class . '\' + AND parent_id = ' . (int) $parent . ' + AND module_langname = \'' . $this->db->sql_escape($data['after']) . '\''; + $this->db->sql_query($sql); + $to_right = $this->db->sql_fetchfield('right_id'); + + $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 + WHERE module_class = '$class' + AND left_id >= $to_right + AND left_id < {$module_data['left_id']}"; + $this->db->sql_query($sql); + + $sql = 'UPDATE ' . MODULES_TABLE . ' SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . " + WHERE module_class = '$class' + AND module_id = {$module_data['module_id']}"; + $this->db->sql_query($sql); + } + } + + // Clear the Modules Cache + $this->cache->destroy("_modules_$class"); + + return false; + } + + /** + * Module Remove + * + * Remove a module + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. + * @param int|string $module The module id|module_langname + * @param string|bool $include_path If you would like to use a custom include path, specify that here + */ + public function remove($class, $parent = 0, $module = '', $include_path = false) + { + // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto + if (is_array($module)) + { + if (isset($module['module_langname'])) + { + // Manual Method + return $this->remove($class, $parent, $module['module_langname'], $include_path); + } + + // Failed. + if (!isset($module['module_basename'])) + { + throw new phpbb_db_migration_exception('MODULE_NOT_EXIST'); + } + + // Automatic method + $basename = str_replace(array('/', '\\'), '', $module['module_basename']); + $class = str_replace(array('/', '\\'), '', $class); + $info_file = "$class/info/{$class}_$basename.$this->phpEx"; + + if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file)) + { + throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', $info_file); + } + + $classname = "{$class}_{$basename}_info"; + + if (!class_exists($classname)) + { + include((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file); + } + + $info = new $classname; + $module_info = $info->module(); + unset($info); + + foreach ($module_info['modes'] as $mode => $info) + { + if (!isset($module['modes']) || in_array($mode, $module['modes'])) + { + $this->remove($class, $parent, $info['title']) . '
'; + } + } + return false; + } + else + { + $class = $this->db->sql_escape($class); + + if (!$this->exists($class, $parent, $module)) + { + throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', ((isset($this->user->lang[$module])) ? $this->user->lang[$module] : $module)); + } + + $parent_sql = ''; + if ($parent !== false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + // we know it exists from the module_exists check + $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + } + else + { + $parent_sql = 'AND parent_id = ' . (int) $parent; + } + } + + $module_ids = array(); + if (!is_numeric($module)) + { + $module = $this->db->sql_escape($module); + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '$module' + AND module_class = '$class' + $parent_sql"; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $module_ids[] = (int) $row['module_id']; + } + $this->db->sql_freeresult($result); + + $module_name = $module; + } + else + { + $module = (int) $module; + $sql = 'SELECT module_langname FROM ' . MODULES_TABLE . " + WHERE module_id = $module + AND module_class = '$class' + $parent_sql"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $module_name = $row['module_langname']; + $module_ids[] = $module; + } + + if (!class_exists('acp_modules')) + { + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->phpEx); + $this->user->add_lang('acp/modules'); + } + $acp_modules = new acp_modules(); + $acp_modules->module_class = $class; + + foreach ($module_ids as $module_id) + { + $result = $acp_modules->delete_module($module_id); + if (!empty($result)) + { + throw new phpbb_db_migration_exception('CANNOT_REMOVE_MODULE', $module_id); + } + } + + $cache->destroy("_modules_$class"); + + return false; + } + } +} \ No newline at end of file diff --git a/phpBB/includes/db/migration/tools/permission.php b/phpBB/includes/db/migration/tools/permission.php new file mode 100644 index 0000000000..3fbe7c649c --- /dev/null +++ b/phpBB/includes/db/migration/tools/permission.php @@ -0,0 +1,480 @@ +db->sql_escape($auth_option) . "'" + . $type_sql; + $result = $this->db->sql_query($sql); + + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + return true; + } + + return false; + } + + /** + * Permission Add + * + * Add a permission (auth) option + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return result + */ + public function add($auth_option, $global = true) + { + if ($this->exists($auth_option, $global)) + { + throw new phpbb_db_migration_exception('PERMISSION_ALREADY_EXISTS', $auth_option); + } + + // We've added permissions, so set to true to notify the user. + $this->permissions_added = true; + + if (!class_exists('auth_admin')) + { + include($this->phpbb_root_path . 'includes/acp/auth.' . $this->phpEx); + } + $auth_admin = new auth_admin(); + + // We have to add a check to see if the !$global (if global, local, and if local, global) permission already exists. If it does, acl_add_option currently has a bug which would break the ACL system, so we are having a work-around here. + if ($this->exists($auth_option, !$global)) + { + $sql_ary = array( + 'is_global' => 1, + 'is_local' => 1, + ); + $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE auth_option = \'' . $this->db->sql_escape($auth_option) . "'"; + $this->db->sql_query($sql); + } + else + { + if ($global) + { + $auth_admin->acl_add_option(array('global' => array($auth_option))); + } + else + { + $auth_admin->acl_add_option(array('local' => array($auth_option))); + } + } + + return false; + } + + /** + * Permission Remove + * + * Remove a permission (auth) option + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return result + */ + public function remove($auth_option, $global = true) + { + if (!$this->exists($auth_option, $global)) + { + throw new phpbb_db_migration_exception('PERMISSION_NOT_EXIST', $auth_option); + } + + if ($global) + { + $type_sql = ' AND is_global = 1'; + } + else + { + $type_sql = ' AND is_local = 1'; + } + $sql = 'SELECT auth_option_id, is_global, is_local FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" . + $type_sql; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $id = $row['auth_option_id']; + + // If it is a local and global permission, do not remove the row! :P + if ($row['is_global'] && $row['is_local']) + { + $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' + SET ' . (($global) ? 'is_global = 0' : 'is_local = 0') . ' + WHERE auth_option_id = ' . $id; + $this->db->sql_query($sql); + } + else + { + // Delete time + $this->db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $id); + } + + // Purge the auth cache + $this->cache->destroy('_acl_options'); + $this->auth->acl_clear_prefetch(); + + return false; + } + + /** + * Add a new permission role + * + * @param string $role_name The new role name + * @param sting $role_type The type (u_, m_, a_) + */ + public function role_add($role_name, $role_type = '', $role_description = '') + { + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if ($role_id) + { + throw new phpbb_db_migration_exception('ROLE_ALREADY_EXISTS', $old_role_name); + } + + $sql = 'SELECT MAX(role_order) AS max FROM ' . ACL_ROLES_TABLE . ' + WHERE role_type = \'' . $this->db->sql_escape($role_type) . '\''; + $this->db->sql_query($sql); + $role_order = $this->db->sql_fetchfield('max'); + $role_order = (!$role_order) ? 1 : $role_order + 1; + + $sql_ary = array( + 'role_name' => $role_name, + 'role_description' => $role_description, + 'role_type' => $role_type, + 'role_order' => $role_order, + ); + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->db->sql_query($sql); + + return false; + } + + /** + * Update the name on a permission role + * + * @param string $old_role_name The old role name + * @param string $new_role_name The new role name + */ + public function role_update($old_role_name, $new_role_name = '') + { + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + throw new phpbb_db_migration_exception('ROLE_NOT_EXISTS', $old_role_name); + } + + $sql = 'UPDATE ' . ACL_ROLES_TABLE . ' + SET role_name = \'' . $this->db->sql_escape($new_role_name) . '\' + WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; + $this->db->sql_query($sql); + + return false; + } + + /** + * Remove a permission role + * + * @param string $role_name The role name to remove + */ + public function role_remove($role_name) + { + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $role_name); + } + + $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + + $sql = 'DELETE FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + + $this->auth->acl_clear_prefetch(); + + return false; + } + + /** + * Permission Set + * + * Allows you to set permissions for a certain group/role + * + * @param string $name The name of the role/group + * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string $type The type (role|group) + * @param bool $has_permission True if you want to give them permission, false if you want to deny them permission + */ + public function permission_set($name, $auth_option = array(), $type = 'role', $has_permission = true) + { + if (!is_array($auth_option)) + { + $auth_option = array($auth_option); + } + + $new_auth = array(); + $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $new_auth[] = $row['auth_option_id']; + } + $this->db->sql_freeresult($result); + + if (!sizeof($new_auth)) + { + return false; + } + + $current_auth = array(); + + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'role' : + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $name); + } + + $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE role_id = ' . $role_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $current_auth[$row['auth_option_id']] = $row['auth_setting']; + } + $this->db->sql_freeresult($result); + break; + + case 'group' : + $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $group_id = $this->db->sql_fetchfield('group_id'); + + if (!$group_id) + { + throw new phpbb_db_migration_exception('GROUP_NOT_EXIST', $name); + } + + // If the group has a role set for them we will add the requested permissions to that role. + $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id <> 0 + AND forum_id = 0'; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('auth_role_id'); + if ($role_id) + { + $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + $role_name = $this->db->sql_fetchfield('role_name'); + + return $this->set($role_name, $auth_option, 'role', $has_permission); + } + + $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $current_auth[$row['auth_option_id']] = $row['auth_setting']; + } + $this->db->sql_freeresult($result); + break; + } + + $sql_ary = array(); + switch ($type) + { + case 'role' : + foreach ($new_auth as $auth_option_id) + { + if (!isset($current_auth[$auth_option_id])) + { + $sql_ary[] = array( + 'role_id' => $role_id, + 'auth_option_id' => $auth_option_id, + 'auth_setting' => $has_permission, + ); + } + } + + $this->db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary); + break; + + case 'group' : + foreach ($new_auth as $auth_option_id) + { + if (!isset($current_auth[$auth_option_id])) + { + $sql_ary[] = array( + 'group_id' => $group_id, + 'auth_option_id' => $auth_option_id, + 'auth_setting' => $has_permission, + ); + } + } + + $this->db->sql_multi_insert(ACL_GROUPS_TABLE, $sql_ary); + break; + } + + $this->auth->acl_clear_prefetch(); + + return false; + } + + /** + * Permission Unset + * + * Allows you to unset (remove) permissions for a certain group/role + * + * @param string $name The name of the role/group + * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string $type The type (role|group) + */ + public function permission_unset($name, $auth_option = array(), $type = 'role') + { + if (!is_array($auth_option)) + { + $auth_option = array($auth_option); + } + + $to_remove = array(); + $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $to_remove[] = $row['auth_option_id']; + } + $this->db->sql_freeresult($result); + + if (!sizeof($to_remove)) + { + return false; + } + + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'role' : + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $name); + } + + $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); + $this->db->sql_query($sql); + break; + + case 'group' : + $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' + WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $group_id = $this->db->sql_fetchfield('group_id'); + + if (!$group_id) + { + throw new phpbb_db_migration_exception('GROUP_NOT_EXIST', $name); + } + + // If the group has a role set for them we will remove the requested permissions from that role. + $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id <> 0'; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('auth_role_id'); + if ($role_id) + { + $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + $role_name = $this->db->sql_fetchfield('role_name'); + + return $this->permission_unset($role_name, $auth_option, 'role'); + } + + $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); + $this->db->sql_query($sql); + break; + } + + $this->auth->acl_clear_prefetch(); + + return false; + } +} \ No newline at end of file diff --git a/phpBB/includes/db/migration/tools/umil.php b/phpBB/includes/db/migration/tools/umil.php new file mode 100644 index 0000000000..ce7b8ff3be --- /dev/null +++ b/phpBB/includes/db/migration/tools/umil.php @@ -0,0 +1,3037 @@ +config_add(array( +* array('config_name', 'config_value'), +* array('config_name1', 'config_value1'), +* array('config_name2', 'config_value2', true), +* array('config_name3', 'config_value3', true), +* ); +*/ + +/** +* UMIL - Unified MOD Installation Library class +* +* Cache Functions +* cache_purge($type = '', $style_id = 0) +* +* Config Functions: +* config_exists($config_name, $return_result = false) +* config_add($config_name, $config_value = '', $is_dynamic = false) +* config_update($config_name, $config_value, $is_dynamic = false) +* config_remove($config_name) +* +* Module Functions +* module_exists($class, $parent, $module) +* module_add($class, $parent = 0, $data = array()) +* module_remove($class, $parent = 0, $module = '') +* +* Permissions/Auth Functions +* permission_exists($auth_option, $global = true) +* permission_add($auth_option, $global = true) +* permission_remove($auth_option, $global = true) +* permission_set($name, $auth_option = array(), $type = 'role', $global = true, $has_permission = true) +* permission_unset($name, $auth_option = array(), $type = 'role', $global = true) +* +* Table Functions +* table_exists($table_name) +* table_add($table_name, $table_data = array()) +* table_remove($table_name) +* +* Table Column Functions +* table_column_exists($table_name, $column_name) +* table_column_add($table_name, $column_name = '', $column_data = array()) +* table_column_update($table_name, $column_name = '', $column_data = array()) +* table_column_remove($table_name, $column_name = '') +* +* Table Key/Index Functions +* table_index_exists($table_name, $index_name) +* table_index_add($table_name, $index_name = '', $column = array()) +* table_index_remove($table_name, $index_name = '') +* +* Table Row Functions (note that these actions are not reversed automatically during uninstallation) +* table_row_insert($table_name, $data = array()) +* table_row_remove($table_name, $data = array()) +* table_row_update($table_name, $data = array(), $new_data = array()) +* +* Version Check Function +* version_check($url, $path, $file) +*/ +class umil +{ + /** + * This will hold the text output for the inputted command (if the mod author would like to display the command that was ran) + * + * @var string + */ + var $command = ''; + + /** + * This will hold the text output for the result of the command. $user->lang['SUCCESS'] if everything worked. + * + * @var string + */ + var $result = ''; + + /** + * Auto run $this->display_results after running a command + */ + var $auto_display_results = false; + + /** + * Stand Alone option (this makes it possible to just use the single umil file and not worry about any language stuff + */ + var $stand_alone = false; + + /** + * Were any new permissions added (used in umil_frontend)? + */ + var $permissions_added = false; + + /** + * Database Object + */ + var $db = false; + + /** + * Database Tools Object + */ + var $db_tools = false; + + /** + * Do we want a custom prefix besides the phpBB table prefix? You *probably* should not change this... + */ + var $table_prefix = false; + + /** + * Constructor + */ + function umil($stand_alone = false, $db = false) + { + // Setup $this->db + if ($db !== false) + { + if (!is_object($db) || !method_exists($db, 'sql_query')) + { + trigger_error('Invalid $db Object'); + } + + $this->db = $db; + } + else + { + global $db; + $this->db = $db; + } + + // Setup $this->db_tools + if (!class_exists('phpbb_db_tools')) + { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/db/db_tools.' . $phpEx); + } + $this->db_tools = new phpbb_db_tools($this->db); + + $this->stand_alone = $stand_alone; + + if (!$stand_alone) + { + global $config, $user, $phpbb_root_path, $phpEx; + + /* Does not have the fall back option to use en/ if the user's language file does not exist, so we will not use it...unless that is changed. + if (method_exists('user', 'set_custom_lang_path')) + { + $user->set_custom_lang_path($phpbb_root_path . 'umil/language/'); + $user->add_lang('umil'); + $user->set_custom_lang_path($phpbb_root_path . 'language/'); + } + else + {*/ + // Include the umil language file. First we check if the language file for the user's language is available, if not we check if the board's default language is available, if not we use the english file. + if (isset($user->data['user_lang']) && file_exists("{$phpbb_root_path}umil/language/{$user->data['user_lang']}/umil.$phpEx")) + { + $path = $user->data['user_lang']; + } + else if (file_exists("{$phpbb_root_path}umil/language/" . basename($config['default_lang']) . "/umil.$phpEx")) + { + $path = basename($config['default_lang']); + } + else if (file_exists("{$phpbb_root_path}umil/language/en/umil.$phpEx")) + { + $path = 'en'; + } + else + { + trigger_error('Language Files Missing.

Please download the latest UMIL (Unified MOD Install Library) from: phpBB.com/mods/umil', E_USER_ERROR); + } + + $user->add_lang('./../../umil/language/' . $path . '/umil'); + //} + + $user->add_lang(array('acp/common', 'acp/permissions')); + + // Check to see if a newer version is available. + $info = $this->version_check('version.phpbb.com', '/umil', ((defined('PHPBB_QA')) ? 'umil_qa.txt' : 'umil.txt')); + if (is_array($info) && isset($info[0]) && isset($info[1])) + { + if (version_compare(UMIL_VERSION, $info[0], '<')) + { + global $template; + + // Make sure user->setup() has been called + if (empty($user->lang)) + { + $user->setup(); + } + + page_header('', false); + + $user->lang['UPDATE_UMIL'] = (isset($user->lang['UPDATE_UMIL'])) ? $user->lang['UPDATE_UMIL'] : 'This version of UMIL is outdated.

Please download the latest UMIL (Unified MOD Install Library) from: %1$s'; + $template->assign_vars(array( + 'S_BOARD_DISABLED' => true, + 'L_BOARD_DISABLED' => sprintf($user->lang['UPDATE_UMIL'], $info[1]), + )); + } + } + } + } + + /** + * umil_start + * + * A function which runs (almost) every time a function here is ran + */ + function umil_start() + { + global $user; + + // Set up the command. This will get the arguments sent to the function. + $args = func_get_args(); + $this->command = call_user_func_array(array($this, 'get_output_text'), $args); + + $this->result = (isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS'; + $this->db->sql_return_on_error(true); + + //$this->db->sql_transaction('begin'); + } + + /** + * umil_end + * + * A function which runs (almost) every time a function here is ran + */ + function umil_end() + { + global $user; + + // Set up the result. This will get the arguments sent to the function. + $args = func_get_args(); + $result = call_user_func_array(array($this, 'get_output_text'), $args); + $this->result = ($result) ? $result : $this->result; + + if ($this->db->sql_error_triggered) + { + if ($this->result == ((isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS')) + { + $this->result = 'SQL ERROR ' . $this->db->sql_error_returned['message']; + } + else + { + $this->result .= '

SQL ERROR ' . $this->db->sql_error_returned['message']; + } + + //$this->db->sql_transaction('rollback'); + } + else + { + //$this->db->sql_transaction('commit'); + } + + $this->db->sql_return_on_error(false); + + // Auto output if requested. + if ($this->auto_display_results && method_exists($this, 'display_results')) + { + $this->display_results(); + } + + return '' . $this->command . '
' . $this->result; + } + + /** + * Get text for output + * + * Takes the given arguments and prepares them for the UI + * + * First argument sent is used as the language key + * Further arguments (if send) are used on the language key through vsprintf() + * + * @return string Returns the prepared string for output + */ + function get_output_text() + { + global $user; + + // Set up the command. This will get the arguments sent to the function. + $args = func_get_args(); + if (sizeof($args)) + { + $lang_key = array_shift($args); + + if (sizeof($args)) + { + $lang_args = array(); + foreach ($args as $arg) + { + $lang_args[] = (isset($user->lang[$arg])) ? $user->lang[$arg] : $arg; + } + + return @vsprintf(((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key), $lang_args); + } + else + { + return ((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key); + } + } + + return ''; + } + + /** + * Run Actions + * + * Do-It-All function that can do everything required for installing/updating/uninstalling a mod based on an array of actions and the versions. + * + * @param string $action The action. install|update|uninstall + * @param array $versions The array of versions and the actions for each + * @param string $version_config_name The name of the config setting which holds/will hold the currently installed version + * @param string $version_select Added for the UMIL Auto system to allow you to select the version you want to install/update/uninstall to. + */ + function run_actions($action, $versions, $version_config_name, $version_select = '') + { + // We will sort the actions to prevent issues from mod authors incorrectly listing the version numbers + uksort($versions, 'version_compare'); + + // Find the current version to install + $current_version = '0.0.0'; + foreach ($versions as $version => $actions) + { + $current_version = $version; + } + + $db_version = ''; + if ($this->config_exists($version_config_name)) + { + global $config; + $db_version = $config[$version_config_name]; + } + + // Set the action to install from update if nothing is currently installed + if ($action == 'update' && !$db_version) + { + $action = 'install'; + } + + if ($action == 'install' || $action == 'update') + { + $version_installed = $db_version; + foreach ($versions as $version => $version_actions) + { + // If we are updating + if ($db_version && version_compare($version, $db_version, '<=')) + { + continue; + } + + if ($version_select && version_compare($version, $version_select, '>')) + { + break; + } + + foreach ($version_actions as $method => $params) + { + if ($method == 'custom') + { + $this->_call_custom_function($params, $action, $version); + } + else + { + if (method_exists($this, $method)) + { + call_user_func(array($this, $method), $params); + } + } + } + + $version_installed = $version; + } + + // update the version number or add it + if ($this->config_exists($version_config_name)) + { + $this->config_update($version_config_name, $version_installed); + } + else + { + $this->config_add($version_config_name, $version_installed); + } + } + else if ($action == 'uninstall' && $db_version) + { + // reverse version list + $versions = array_reverse($versions); + + foreach ($versions as $version => $version_actions) + { + // Uninstalling and this listed version is newer than installed + if (version_compare($version, $db_version, '>')) + { + continue; + } + + // Version selection stuff + if ($version_select && version_compare($version, $version_select, '<=')) + { + // update the version number + $this->config_update($version_config_name, $version); + break; + } + + $cache_purge = false; + $version_actions = array_reverse($version_actions); + foreach ($version_actions as $method => $params) + { + if ($method == 'custom') + { + $this->_call_custom_function($params, $action, $version); + } + else + { + // This way we always run the cache purge at the end of the version (done for the uninstall because the instructions are reversed, which would cause the cache purge to be run at the beginning if it was meant to run at the end). + if ($method == 'cache_purge') + { + $cache_purge = $params; + continue; + } + + // A few things are not possible for uninstallations update actions and table_row actions + if (strpos($method, 'update') !== false || strpos($method, 'table_insert') !== false || strpos($method, 'table_row_') !== false) + { + continue; + } + + // reverse function call + $method = str_replace(array('add', 'remove', 'temp'), array('temp', 'add', 'remove'), $method); + $method = str_replace(array('set', 'unset', 'temp'), array('temp', 'set', 'unset'), $method); + + if (method_exists($this, $method)) + { + call_user_func(array($this, $method), ((is_array($params) ? array_reverse($params) : $params))); + } + } + } + + if ($cache_purge !== false) + { + $this->cache_purge($cache_purge); + } + } + + if (!$version_select) + { + // Unset the version number + $this->config_remove($version_config_name); + } + } + } + + /** + * Call custom function helper + */ + function _call_custom_function($functions, $action, $version) + { + if (!is_array($functions)) + { + $functions = array($functions); + } + + $return = ''; + + foreach ($functions as $function) + { + if (function_exists($function)) + { + // Must reset before calling the function + $this->umil_start(); + + $returned = call_user_func($function, $action, $version); + if (is_string($returned)) + { + $this->command = $this->get_output_text($returned); + } + else if (is_array($returned) && isset($returned['command'])) + { + if (is_array($returned['command'])) + { + $this->command = call_user_func_array(array($this, 'get_output_text'), $returned['command']); + } + else + { + $this->command = $this->get_output_text($returned['command']); + } + + if (isset($returned['result'])) + { + $this->result = $this->get_output_text($returned['result']); + } + } + else + { + $this->command = $this->get_output_text('UNKNOWN'); + } + + $return .= $this->umil_end() . '
'; + } + } + + return $return; + } + + /** + * Multicall Helper + * + * @param mixed $function Function name to call + * @param mixed $params The parameters array + * + * @return bool True if we have done a multicall ($params is an array), false if not ($params is not an array) + */ + function multicall($function, $params) + { + if (is_array($params) && !empty($params)) + { + foreach ($params as $param) + { + if (!is_array($param)) + { + call_user_func(array($this, $function), $param); + } + else + { + call_user_func_array(array($this, $function), $param); + } + } + return true; + } + + return false; + } + + /** + * Cache Purge + * + * This function is for purging either phpBB3’s data cache, authorization cache, or the styles cache. + * + * @param string $type The type of cache you want purged. Available types: auth, imageset, template, theme. Anything else sent will purge the forum's cache. + * @param int $style_id The id of the item you want purged (if the type selected is imageset/template/theme, 0 for all items in that section) + */ + function cache_purge($type = '', $style_id = 0) + { + global $auth, $cache, $user, $phpbb_root_path, $phpEx; + + // Multicall + if ($this->multicall(__FUNCTION__, $type)) + { + return; + } + + $style_id = (int) $style_id; + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'auth' : + $this->umil_start('AUTH_CACHE_PURGE'); + $cache->destroy('_acl_options'); + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + break; + + case 'imageset' : + if ($style_id == 0) + { + $return = array(); + $sql = 'SELECT imageset_id + FROM ' . STYLES_IMAGESET_TABLE; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $return[] = $this->cache_purge('imageset', $row['imageset_id']); + } + $this->db->sql_freeresult($result); + + return implode('

', $return); + } + else + { + $sql = 'SELECT * + FROM ' . STYLES_IMAGESET_TABLE . " + WHERE imageset_id = $style_id"; + $result = $this->db->sql_query($sql); + $imageset_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$imageset_row) + { + $this->umil_start('IMAGESET_CACHE_PURGE', 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + $this->umil_start('IMAGESET_CACHE_PURGE', $imageset_row['imageset_name']); + + // The following is from includes/acp/acp_styles.php (edited) + $sql_ary = array(); + + $cfg_data_imageset = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/imageset.cfg"); + + $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . ' + WHERE imageset_id = ' . $style_id; + $result = $this->db->sql_query($sql); + + foreach ($cfg_data_imageset as $image_name => $value) + { + if (strpos($value, '*') !== false) + { + if (substr($value, -1, 1) === '*') + { + list($image_filename, $image_height) = explode('*', $value); + $image_width = 0; + } + else + { + list($image_filename, $image_height, $image_width) = explode('*', $value); + } + } + else + { + $image_filename = $value; + $image_height = $image_width = 0; + } + + if (strpos($image_name, 'img_') === 0 && $image_filename) + { + $image_name = substr($image_name, 4); + + $sql_ary[] = array( + 'image_name' => (string) $image_name, + 'image_filename' => (string) $image_filename, + 'image_height' => (int) $image_height, + 'image_width' => (int) $image_width, + 'imageset_id' => (int) $style_id, + 'image_lang' => '', + ); + } + } + + $sql = 'SELECT lang_dir + FROM ' . LANG_TABLE; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg")) + { + $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg"); + foreach ($cfg_data_imageset_data as $image_name => $value) + { + if (strpos($value, '*') !== false) + { + if (substr($value, -1, 1) === '*') + { + list($image_filename, $image_height) = explode('*', $value); + $image_width = 0; + } + else + { + list($image_filename, $image_height, $image_width) = explode('*', $value); + } + } + else + { + $image_filename = $value; + $image_height = $image_width = 0; + } + + if (strpos($image_name, 'img_') === 0 && $image_filename) + { + $image_name = substr($image_name, 4); + $sql_ary[] = array( + 'image_name' => (string) $image_name, + 'image_filename' => (string) $image_filename, + 'image_height' => (int) $image_height, + 'image_width' => (int) $image_width, + 'imageset_id' => (int) $style_id, + 'image_lang' => (string) $row['lang_dir'], + ); + } + } + } + } + $this->db->sql_freeresult($result); + + $this->db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary); + + $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE); + + return $this->umil_end(); + } + break; + //case 'imageset' : + + case 'template' : + if ($style_id == 0) + { + $return = array(); + $sql = 'SELECT template_id + FROM ' . STYLES_TEMPLATE_TABLE; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $return[] = $this->cache_purge('template', $row['template_id']); + } + $this->db->sql_freeresult($result); + + return implode('

', $return); + } + else + { + $sql = 'SELECT * + FROM ' . STYLES_TEMPLATE_TABLE . " + WHERE template_id = $style_id"; + $result = $this->db->sql_query($sql); + $template_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$template_row) + { + $this->umil_start('TEMPLATE_CACHE_PURGE', 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + $this->umil_start('TEMPLATE_CACHE_PURGE', $template_row['template_name']); + + // The following is from includes/acp/acp_styles.php + if ($template_row['template_storedb'] && file_exists("{$phpbb_root_path}styles/{$template_row['template_path']}/template/")) + { + $filelist = array('' => array()); + + $sql = 'SELECT template_filename, template_mtime + FROM ' . STYLES_TEMPLATE_DATA_TABLE . " + WHERE template_id = $style_id"; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { +// if (@filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}/template/" . $row['template_filename']) > $row['template_mtime']) +// { + // get folder info from the filename + if (($slash_pos = strrpos($row['template_filename'], '/')) === false) + { + $filelist[''][] = $row['template_filename']; + } + else + { + $filelist[substr($row['template_filename'], 0, $slash_pos + 1)][] = substr($row['template_filename'], $slash_pos + 1, strlen($row['template_filename']) - $slash_pos - 1); + } +// } + } + $this->db->sql_freeresult($result); + + $includes = array(); + foreach ($filelist as $pathfile => $file_ary) + { + foreach ($file_ary as $file) + { + if (!($fp = @fopen("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file", 'r'))) + { + return $this->umil_end('FILE_COULD_NOT_READ', "{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"); + } + $template_data = fread($fp, filesize("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file")); + fclose($fp); + + if (preg_match_all('##is', $template_data, $matches)) + { + foreach ($matches[1] as $match) + { + $includes[trim($match)][] = $file; + } + } + } + } + + foreach ($filelist as $pathfile => $file_ary) + { + foreach ($file_ary as $file) + { + // Skip index. + if (strpos($file, 'index.') === 0) + { + continue; + } + + // We could do this using extended inserts ... but that could be one + // heck of a lot of data ... + $sql_ary = array( + 'template_id' => (int) $style_id, + 'template_filename' => "$pathfile$file", + 'template_included' => (isset($includes[$file])) ? implode(':', $includes[$file]) . ':' : '', + 'template_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"), + 'template_data' => (string) file_get_contents("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"), + ); + + $sql = 'UPDATE ' . STYLES_TEMPLATE_DATA_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " + WHERE template_id = $style_id + AND template_filename = '" . $this->db->sql_escape("$pathfile$file") . "'"; + $this->db->sql_query($sql); + } + } + unset($filelist); + } + + // Purge the forum's cache as well. + $cache->purge(); + + return $this->umil_end(); + } + break; + //case 'template' : + + case 'theme' : + if ($style_id == 0) + { + $return = array(); + $sql = 'SELECT theme_id + FROM ' . STYLES_THEME_TABLE; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $return[] = $this->cache_purge('theme', $row['theme_id']); + } + $this->db->sql_freeresult($result); + + return implode('

', $return); + } + else + { + $sql = 'SELECT * + FROM ' . STYLES_THEME_TABLE . " + WHERE theme_id = $style_id"; + $result = $this->db->sql_query($sql); + $theme_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$theme_row) + { + $this->umil_start('THEME_CACHE_PURGE', 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + $this->umil_start('THEME_CACHE_PURGE', $theme_row['theme_name']); + + // The following is from includes/acp/acp_styles.php + if ($theme_row['theme_storedb'] && file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css")) + { + $stylesheet = file_get_contents($phpbb_root_path . 'styles/' . $theme_row['theme_path'] . '/theme/stylesheet.css'); + + // Match CSS imports + $matches = array(); + preg_match_all('/@import url\(["\'](.*)["\']\);/i', $stylesheet, $matches); + + if (sizeof($matches)) + { + foreach ($matches[0] as $idx => $match) + { + if (!file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}")) + { + continue; + } + + $content = trim(file_get_contents("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}")); + $stylesheet = str_replace($match, $content, $stylesheet); + } + } + + // adjust paths + $db_theme_data = str_replace('./', 'styles/' . $theme_row['theme_path'] . '/theme/', $stylesheet); + + // Save CSS contents + $sql_ary = array( + 'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"), + 'theme_data' => $db_theme_data, + ); + + $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " + WHERE theme_id = $style_id"; + $this->db->sql_query($sql); + + $cache->destroy('sql', STYLES_THEME_TABLE); + } + + return $this->umil_end(); + } + break; + //case 'theme' : + + default: + $this->umil_start('CACHE_PURGE'); + $cache->purge(); + + return $this->umil_end(); + break; + } + } + + /** + * Config Exists + * + * This function is to check to see if a config variable exists or if it does not. + * + * @param string $config_name The name of the config setting you wish to check for. + * @param bool $return_result - return the config value/default if true : default false. + * + * @return bool true/false if config exists + */ + function config_exists($config_name, $return_result = false) + { + global $config, $cache; + + $sql = 'SELECT * + FROM ' . CONFIG_TABLE . " + WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + if (!isset($config[$config_name])) + { + $config[$config_name] = $row['config_value']; + + if (!$row['is_dynamic']) + { + $cache->destroy('config'); + } + } + + return ($return_result) ? $row : true; + } + + // this should never happen, but if it does, we need to remove the config from the array + if (isset($config[$config_name])) + { + unset($config[$config_name]); + $cache->destroy('config'); + } + + return false; + } + + /** + * Config Add + * + * This function allows you to add a config setting. + * + * @param string $config_name The name of the config setting you would like to add + * @param mixed $config_value The value of the config setting + * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + * + * @return result + */ + function config_add($config_name, $config_value = '', $is_dynamic = false) + { + // Multicall + if ($this->multicall(__FUNCTION__, $config_name)) + { + return; + } + + $this->umil_start('CONFIG_ADD', $config_name); + + if ($this->config_exists($config_name)) + { + return $this->umil_end('CONFIG_ALREADY_EXISTS', $config_name); + } + + set_config($config_name, $config_value, $is_dynamic); + + return $this->umil_end(); + } + + /** + * Config Update + * + * This function allows you to update an existing config setting. + * + * @param string $config_name The name of the config setting you would like to update + * @param mixed $config_value The value of the config setting + * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + * + * @return result + */ + function config_update($config_name, $config_value = '', $is_dynamic = false) + { + // Multicall + if ($this->multicall(__FUNCTION__, $config_name)) + { + return; + } + + $this->umil_start('CONFIG_UPDATE', $config_name); + + if (!$this->config_exists($config_name)) + { + return $this->umil_end('CONFIG_NOT_EXIST', $config_name); + } + + set_config($config_name, $config_value, $is_dynamic); + + return $this->umil_end(); + } + + /** + * Config Remove + * + * This function allows you to remove an existing config setting. + * + * @param string $config_name The name of the config setting you would like to remove + * + * @return result + */ + function config_remove($config_name) + { + global $cache, $config; + + // Multicall + if ($this->multicall(__FUNCTION__, $config_name)) + { + return; + } + + $this->umil_start('CONFIG_REMOVE', $config_name); + + if (!$this->config_exists($config_name)) + { + return $this->umil_end('CONFIG_NOT_EXIST', $config_name); + } + + $sql = 'DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; + $this->db->sql_query($sql); + + unset($config[$config_name]); + $cache->destroy('config'); + + return $this->umil_end(); + } + + /** + * Module Exists + * + * Check if a module exists + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. + * @param int|string $module The module_id|module_langname you would like to check for to see if it exists + */ + function module_exists($class, $parent, $module) + { + // the main root directory should return true + if (!$module) + { + return true; + } + + $class = $this->db->sql_escape($class); + $module = $this->db->sql_escape($module); + + $parent_sql = ''; + if ($parent !== false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + return false; + } + + $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + } + else + { + $parent_sql = 'AND parent_id = ' . (int) $parent; + } + } + + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_class = '$class' + $parent_sql + AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '$module'"); + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + return true; + } + + return false; + } + + /** + * Module Add + * + * Add a new module + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string $parent The parent module_id|module_langname (0 for no parent) + * @param array $data an array of the data on the new module. This can be setup in two different ways. + * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below, + * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode. + * array( + * 'module_enabled' => 1, + * 'module_display' => 1, + * 'module_basename' => '', + * 'module_class' => $class, + * 'parent_id' => (int) $parent, + * 'module_langname' => '', + * 'module_mode' => '', + * 'module_auth' => '', + * ) + * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file. + * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file): + * array( + * 'module_basename' => 'asacp', + * 'modes' => array('settings', 'log', 'flag'), + * ) + * Optionally you may not send 'modes' and it will insert all of the modules in that info file. + * @param string|bool $include_path If you would like to use a custom include path, specify that here + */ + function module_add($class, $parent = 0, $data = array(), $include_path = false) + { + global $cache, $user, $phpbb_root_path, $phpEx; + + // Multicall + if ($this->multicall(__FUNCTION__, $class)) + { + return; + } + + // Prevent stupid things like trying to add a module with no name or any data on it + if (empty($data)) + { + $this->umil_start('MODULE_ADD', $class, 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + // allow sending the name as a string in $data to create a category + if (!is_array($data)) + { + $data = array('module_langname' => $data); + } + + if (!isset($data['module_langname'])) + { + // The "automatic" way + $basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; + $basename = str_replace(array('/', '\\'), '', $basename); + $class = str_replace(array('/', '\\'), '', $class); + $info_file = "$class/info/{$class}_$basename.$phpEx"; + + // The manual and automatic ways both failed... + if (!file_exists((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file)) + { + $this->umil_start('MODULE_ADD', $class, $info_file); + return $this->umil_end('FAIL'); + } + + $classname = "{$class}_{$basename}_info"; + + if (!class_exists($classname)) + { + include((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file); + } + + $info = new $classname; + $module = $info->module(); + unset($info); + + $result = ''; + foreach ($module['modes'] as $mode => $module_info) + { + if (!isset($data['modes']) || in_array($mode, $data['modes'])) + { + $new_module = array( + 'module_basename' => $basename, + 'module_langname' => $module_info['title'], + 'module_mode' => $mode, + 'module_auth' => $module_info['auth'], + 'module_display' => (isset($module_info['display'])) ? $module_info['display'] : true, + 'before' => (isset($module_info['before'])) ? $module_info['before'] : false, + 'after' => (isset($module_info['after'])) ? $module_info['after'] : false, + ); + + // Run the "manual" way with the data we've collected. + $result .= ((isset($data['spacer'])) ? $data['spacer'] : '
') . $this->module_add($class, $parent, $new_module); + } + } + + return $result; + } + + // The "manual" way + $this->umil_start('MODULE_ADD', $class, ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname'])); + add_log('admin', 'LOG_MODULE_ADD', ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname'])); + + $class = $this->db->sql_escape($class); + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + return $this->umil_end('PARENT_NOT_EXIST'); + } + + $parent = $data['parent_id'] = $row['module_id']; + } + else if (!$this->module_exists($class, false, $parent)) + { + return $this->umil_end('PARENT_NOT_EXIST'); + } + + if ($this->module_exists($class, $parent, $data['module_langname'])) + { + return $this->umil_end('MODULE_ALREADY_EXIST'); + } + + if (!class_exists('acp_modules')) + { + include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); + $user->add_lang('acp/modules'); + } + $acp_modules = new acp_modules(); + + $module_data = array( + 'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1, + 'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1, + 'module_basename' => (isset($data['module_basename'])) ? $data['module_basename'] : '', + 'module_class' => $class, + 'parent_id' => (int) $parent, + 'module_langname' => (isset($data['module_langname'])) ? $data['module_langname'] : '', + 'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '', + 'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '', + ); + $result = $acp_modules->update_module_data($module_data, true); + + // update_module_data can either return a string or an empty array... + if (is_string($result)) + { + // Error + $this->result = $this->get_output_text($result); + } + else + { + // Success + + // Move the module if requested above/below an existing one + if (isset($data['before']) && $data['before']) + { + $sql = 'SELECT left_id FROM ' . MODULES_TABLE . ' + WHERE module_class = \'' . $class . '\' + AND parent_id = ' . (int) $parent . ' + AND module_langname = \'' . $this->db->sql_escape($data['before']) . '\''; + $this->db->sql_query($sql); + $to_left = $this->db->sql_fetchfield('left_id'); + + $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 + WHERE module_class = '$class' + AND left_id >= $to_left + AND left_id < {$module_data['left_id']}"; + $this->db->sql_query($sql); + + $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = $to_left, right_id = " . ($to_left + 1) . " + WHERE module_class = '$class' + AND module_id = {$module_data['module_id']}"; + $this->db->sql_query($sql); + } + else if (isset($data['after']) && $data['after']) + { + $sql = 'SELECT right_id FROM ' . MODULES_TABLE . ' + WHERE module_class = \'' . $class . '\' + AND parent_id = ' . (int) $parent . ' + AND module_langname = \'' . $this->db->sql_escape($data['after']) . '\''; + $this->db->sql_query($sql); + $to_right = $this->db->sql_fetchfield('right_id'); + + $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 + WHERE module_class = '$class' + AND left_id >= $to_right + AND left_id < {$module_data['left_id']}"; + $this->db->sql_query($sql); + + $sql = 'UPDATE ' . MODULES_TABLE . ' SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . " + WHERE module_class = '$class' + AND module_id = {$module_data['module_id']}"; + $this->db->sql_query($sql); + } + } + + // Clear the Modules Cache + $cache->destroy("_modules_$class"); + + return $this->umil_end(); + } + + /** + * Module Remove + * + * Remove a module + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. + * @param int|string $module The module id|module_langname + * @param string|bool $include_path If you would like to use a custom include path, specify that here + */ + function module_remove($class, $parent = 0, $module = '', $include_path = false) + { + global $cache, $user, $phpbb_root_path, $phpEx; + + // Multicall + if ($this->multicall(__FUNCTION__, $class)) + { + return; + } + + // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto + if (is_array($module)) + { + if (isset($module['module_langname'])) + { + // Manual Method + return $this->module_remove($class, $parent, $module['module_langname'], $include_path); + } + + // Failed. + if (!isset($module['module_basename'])) + { + $this->umil_start('MODULE_REMOVE', $class, 'UNKNOWN'); + return $this->umil_end('FAIL'); + } + + // Automatic method + $basename = str_replace(array('/', '\\'), '', $module['module_basename']); + $class = str_replace(array('/', '\\'), '', $class); + $info_file = "$class/info/{$class}_$basename.$phpEx"; + + if (!file_exists((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file)) + { + $this->umil_start('MODULE_REMOVE', $class, $info_file); + return $this->umil_end('FAIL'); + } + + $classname = "{$class}_{$basename}_info"; + + if (!class_exists($classname)) + { + include((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file); + } + + $info = new $classname; + $module_info = $info->module(); + unset($info); + + $result = ''; + foreach ($module_info['modes'] as $mode => $info) + { + if (!isset($module['modes']) || in_array($mode, $module['modes'])) + { + $result .= $this->module_remove($class, $parent, $info['title']) . '
'; + } + } + return $result; + } + else + { + $class = $this->db->sql_escape($class); + + if (!$this->module_exists($class, $parent, $module)) + { + $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module])) ? $user->lang[$module] : $module)); + return $this->umil_end('MODULE_NOT_EXIST'); + } + + $parent_sql = ''; + if ($parent !== false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + // we know it exists from the module_exists check + $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + } + else + { + $parent_sql = 'AND parent_id = ' . (int) $parent; + } + } + + $module_ids = array(); + if (!is_numeric($module)) + { + $module = $this->db->sql_escape($module); + $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " + WHERE module_langname = '$module' + AND module_class = '$class' + $parent_sql"; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $module_ids[] = (int) $row['module_id']; + } + $this->db->sql_freeresult($result); + + $module_name = $module; + } + else + { + $module = (int) $module; + $sql = 'SELECT module_langname FROM ' . MODULES_TABLE . " + WHERE module_id = $module + AND module_class = '$class' + $parent_sql"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $module_name = $row['module_langname']; + $module_ids[] = $module; + } + + $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name)); + add_log('admin', 'LOG_MODULE_REMOVED', ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name)); + + if (!class_exists('acp_modules')) + { + include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); + $user->add_lang('acp/modules'); + } + $acp_modules = new acp_modules(); + $acp_modules->module_class = $class; + + foreach ($module_ids as $module_id) + { + $result = $acp_modules->delete_module($module_id); + if (!empty($result)) + { + if ($this->result == ((isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS')) + { + $this->result = implode('
', $result); + } + else + { + $this->result .= '
' . implode('
', $result); + } + } + } + + $cache->destroy("_modules_$class"); + + return $this->umil_end(); + } + } + + /** + * Permission Exists + * + * Check if a permission (auth) setting exists + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return bool true if it exists, false if not + */ + function permission_exists($auth_option, $global = true) + { + if ($global) + { + $type_sql = ' AND is_global = 1'; + } + else + { + $type_sql = ' AND is_local = 1'; + } + + $sql = 'SELECT auth_option_id + FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" + . $type_sql; + $result = $this->db->sql_query($sql); + + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + return true; + } + + return false; + } + + /** + * Permission Add + * + * Add a permission (auth) option + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return result + */ + function permission_add($auth_option, $global = true) + { + // Multicall + if ($this->multicall(__FUNCTION__, $auth_option)) + { + return; + } + + $this->umil_start('PERMISSION_ADD', $auth_option); + + if ($this->permission_exists($auth_option, $global)) + { + return $this->umil_end('PERMISSION_ALREADY_EXISTS', $auth_option); + } + + // We've added permissions, so set to true to notify the user. + $this->permissions_added = true; + + if (!class_exists('auth_admin')) + { + global $phpbb_root_path, $phpEx; + + include($phpbb_root_path . 'includes/acp/auth.' . $phpEx); + } + $auth_admin = new auth_admin(); + + // We have to add a check to see if the !$global (if global, local, and if local, global) permission already exists. If it does, acl_add_option currently has a bug which would break the ACL system, so we are having a work-around here. + if ($this->permission_exists($auth_option, !$global)) + { + $sql_ary = array( + 'is_global' => 1, + 'is_local' => 1, + ); + $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE auth_option = \'' . $this->db->sql_escape($auth_option) . "'"; + $this->db->sql_query($sql); + } + else + { + if ($global) + { + $auth_admin->acl_add_option(array('global' => array($auth_option))); + } + else + { + $auth_admin->acl_add_option(array('local' => array($auth_option))); + } + } + + return $this->umil_end(); + } + + /** + * Permission Remove + * + * Remove a permission (auth) option + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return result + */ + function permission_remove($auth_option, $global = true) + { + global $auth, $cache; + + // Multicall + if ($this->multicall(__FUNCTION__, $auth_option)) + { + return; + } + + $this->umil_start('PERMISSION_REMOVE', $auth_option); + + if (!$this->permission_exists($auth_option, $global)) + { + return $this->umil_end('PERMISSION_NOT_EXIST', $auth_option); + } + + if ($global) + { + $type_sql = ' AND is_global = 1'; + } + else + { + $type_sql = ' AND is_local = 1'; + } + $sql = 'SELECT auth_option_id, is_global, is_local FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" . + $type_sql; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $id = $row['auth_option_id']; + + // If it is a local and global permission, do not remove the row! :P + if ($row['is_global'] && $row['is_local']) + { + $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' + SET ' . (($global) ? 'is_global = 0' : 'is_local = 0') . ' + WHERE auth_option_id = ' . $id; + $this->db->sql_query($sql); + } + else + { + // Delete time + $this->db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $id); + } + + // Purge the auth cache + $cache->destroy('_acl_options'); + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + } + + /** + * Add a new permission role + * + * @param string $role_name The new role name + * @param sting $role_type The type (u_, m_, a_) + */ + function permission_role_add($role_name, $role_type = '', $role_description = '') + { + // Multicall + if ($this->multicall(__FUNCTION__, $role_name)) + { + return; + } + + $this->umil_start('PERMISSION_ROLE_ADD', $role_name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if ($role_id) + { + return $this->umil_end('ROLE_ALREADY_EXISTS', $old_role_name); + } + + $sql = 'SELECT MAX(role_order) AS max FROM ' . ACL_ROLES_TABLE . ' + WHERE role_type = \'' . $this->db->sql_escape($role_type) . '\''; + $this->db->sql_query($sql); + $role_order = $this->db->sql_fetchfield('max'); + $role_order = (!$role_order) ? 1 : $role_order + 1; + + $sql_ary = array( + 'role_name' => $role_name, + 'role_description' => $role_description, + 'role_type' => $role_type, + 'role_order' => $role_order, + ); + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->db->sql_query($sql); + + return $this->umil_end(); + } + + /** + * Update the name on a permission role + * + * @param string $old_role_name The old role name + * @param string $new_role_name The new role name + */ + function permission_role_update($old_role_name, $new_role_name = '') + { + // Multicall + if ($this->multicall(__FUNCTION__, $role_name)) + { + return; + } + + $this->umil_start('PERMISSION_ROLE_UPDATE', $old_role_name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + return $this->umil_end('ROLE_NOT_EXIST', $old_role_name); + } + + $sql = 'UPDATE ' . ACL_ROLES_TABLE . ' + SET role_name = \'' . $this->db->sql_escape($new_role_name) . '\' + WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; + $this->db->sql_query($sql); + + return $this->umil_end(); + } + + /** + * Remove a permission role + * + * @param string $role_name The role name to remove + */ + function permission_role_remove($role_name) + { + global $auth; + + // Multicall + if ($this->multicall(__FUNCTION__, $role_name)) + { + return; + } + + $this->umil_start('PERMISSION_ROLE_REMOVE', $role_name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + return $this->umil_end('ROLE_NOT_EXIST', $role_name); + } + + $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + + $sql = 'DELETE FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + } + + /** + * Permission Set + * + * Allows you to set permissions for a certain group/role + * + * @param string $name The name of the role/group + * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string $type The type (role|group) + * @param bool $has_permission True if you want to give them permission, false if you want to deny them permission + */ + function permission_set($name, $auth_option = array(), $type = 'role', $has_permission = true) + { + global $auth; + + // Multicall + if ($this->multicall(__FUNCTION__, $name)) + { + return; + } + + if (!is_array($auth_option)) + { + $auth_option = array($auth_option); + } + + $new_auth = array(); + $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $new_auth[] = $row['auth_option_id']; + } + $this->db->sql_freeresult($result); + + if (!sizeof($new_auth)) + { + return false; + } + + $current_auth = array(); + + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'role' : + $this->umil_start('PERMISSION_SET_ROLE', $name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + return $this->umil_end('ROLE_NOT_EXIST'); + } + + $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE role_id = ' . $role_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $current_auth[$row['auth_option_id']] = $row['auth_setting']; + } + $this->db->sql_freeresult($result); + break; + + case 'group' : + $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $group_id = $this->db->sql_fetchfield('group_id'); + + if (!$group_id) + { + $this->umil_start('PERMISSION_SET_GROUP', $name); + return $this->umil_end('GROUP_NOT_EXIST'); + } + + // If the group has a role set for them we will add the requested permissions to that role. + $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id <> 0 + AND forum_id = 0'; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('auth_role_id'); + if ($role_id) + { + $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + $role_name = $this->db->sql_fetchfield('role_name'); + + return $this->permission_set($role_name, $auth_option, 'role', $has_permission); + } + + $this->umil_start('PERMISSION_SET_GROUP', $name); + + $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $current_auth[$row['auth_option_id']] = $row['auth_setting']; + } + $this->db->sql_freeresult($result); + break; + } + + $sql_ary = array(); + switch ($type) + { + case 'role' : + foreach ($new_auth as $auth_option_id) + { + if (!isset($current_auth[$auth_option_id])) + { + $sql_ary[] = array( + 'role_id' => $role_id, + 'auth_option_id' => $auth_option_id, + 'auth_setting' => $has_permission, + ); + } + } + + $this->db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary); + break; + + case 'group' : + foreach ($new_auth as $auth_option_id) + { + if (!isset($current_auth[$auth_option_id])) + { + $sql_ary[] = array( + 'group_id' => $group_id, + 'auth_option_id' => $auth_option_id, + 'auth_setting' => $has_permission, + ); + } + } + + $this->db->sql_multi_insert(ACL_GROUPS_TABLE, $sql_ary); + break; + } + + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + } + + /** + * Permission Unset + * + * Allows you to unset (remove) permissions for a certain group/role + * + * @param string $name The name of the role/group + * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string $type The type (role|group) + */ + function permission_unset($name, $auth_option = array(), $type = 'role') + { + global $auth; + + // Multicall + if ($this->multicall(__FUNCTION__, $name)) + { + return; + } + + if (!is_array($auth_option)) + { + $auth_option = array($auth_option); + } + + $to_remove = array(); + $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $to_remove[] = $row['auth_option_id']; + } + $this->db->sql_freeresult($result); + + if (!sizeof($to_remove)) + { + return false; + } + + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'role' : + $this->umil_start('PERMISSION_UNSET_ROLE', $name); + + $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' + WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + return $this->umil_end('ROLE_NOT_EXIST'); + } + + $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); + $this->db->sql_query($sql); + break; + + case 'group' : + $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; + $this->db->sql_query($sql); + $group_id = $this->db->sql_fetchfield('group_id'); + + if (!$group_id) + { + $this->umil_start('PERMISSION_UNSET_GROUP', $name); + return $this->umil_end('GROUP_NOT_EXIST'); + } + + // If the group has a role set for them we will remove the requested permissions from that role. + $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id <> 0'; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('auth_role_id'); + if ($role_id) + { + $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + $role_name = $this->db->sql_fetchfield('role_name'); + + return $this->permission_unset($role_name, $auth_option, 'role'); + } + + $this->umil_start('PERMISSION_UNSET_GROUP', $name); + + $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); + $this->db->sql_query($sql); + break; + } + + $auth->acl_clear_prefetch(); + + return $this->umil_end(); + } + + /** + * Table Exists + * + * Check if a table exists in the DB or not + * + * @param string $table_name The table name to check for + * + * @return bool true if the table exists, false if not + */ + function table_exists($table_name) + { + $this->get_table_name($table_name); + + // Use sql_table_exists if available + if (method_exists($this->db_tools, 'sql_table_exists')) + { + $roe = $this->db->return_on_error; + $result = $this->db_tools->sql_table_exists($table_name); + + // db_tools::sql_table_exists resets the return_on_error to false always after completing, so we must make sure we set it to true again if it was before + if ($roe) + { + $this->db->sql_return_on_error(true); + } + + return $result; + } + + if (!function_exists('get_tables')) + { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/functions_install.' . $phpEx); + } + + $tables = get_tables($this->db); + + if (in_array($table_name, $tables)) + { + return true; + } + else + { + return false; + } + } + + /** + * Table Add + * + * This only supports input from the array format of db_tools or create_schema_files. + */ + function table_add($table_name, $table_data = array()) + { + global $dbms, $user; + + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + /** + * $table_data can be empty when uninstalling a mod and table_remove was used, but no 2rd argument was given. + * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 2rd argument) and skip this to prevent an error + */ + if (empty($table_data)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_ADD', $table_name); + + if ($this->table_exists($table_name)) + { + return $this->umil_end('TABLE_ALREADY_EXISTS', $table_name); + } + + if (!is_array($table_data)) + { + return $this->umil_end('NO_TABLE_DATA'); + } + + if (!function_exists('get_available_dbms')) + { + global $phpbb_root_path, $phpEx; + include("{$phpbb_root_path}includes/functions_install.$phpEx"); + } + + /* + * This function has had numerous problems and is currently broken, so until phpBB uses it I will not be anymore + if (method_exists($this->db_tools, 'sql_create_table')) + { + // Added in 3.0.5 + $this->db_tools->sql_create_table($table_name, $table_data); + } + else + {*/ + $available_dbms = get_available_dbms($dbms); + + $sql_query = $this->create_table_sql($table_name, $table_data); + $sql_query = split_sql_file($sql_query, $available_dbms[$dbms]['DELIM']); + + foreach ($sql_query as $sql) + { + $this->db->sql_query($sql); + } + //} + + return $this->umil_end(); + } + + /** + * Table Remove + * + * Delete/Drop a DB table + */ + function table_remove($table_name) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_REMOVE', $table_name); + + if (!$this->table_exists($table_name)) + { + return $this->umil_end('TABLE_NOT_EXIST', $table_name); + } + + if (method_exists($this->db_tools, 'sql_table_drop')) + { + // Added in 3.0.5 + $this->db_tools->sql_table_drop($table_name); + } + else + { + $this->db->sql_query('DROP TABLE ' . $table_name); + } + + return $this->umil_end(); + } + + /** + * Table Column Exists + * + * Check to see if a column exists in a table + */ + function table_column_exists($table_name, $column_name) + { + $this->get_table_name($table_name); + + return $this->db_tools->sql_column_exists($table_name, $column_name); + } + + /** + * Table Column Add + * + * Add a new column to a table. + */ + function table_column_add($table_name, $column_name = '', $column_data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + /** + * $column_data can be empty when uninstalling a mod and table_column_remove was used, but no 3rd argument was given. + * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 3rd argument) and skip this to prevent an error + */ + if (empty($column_data)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_COLUMN_ADD', $table_name, $column_name); + + if ($this->table_column_exists($table_name, $column_name)) + { + return $this->umil_end('TABLE_COLUMN_ALREADY_EXISTS', $table_name, $column_name); + } + + $this->db_tools->sql_column_add($table_name, $column_name, $column_data); + + return $this->umil_end(); + } + + /** + * Table Column Update + * + * Alter/Update a column in a table. You can not change a column name with this. + */ + function table_column_update($table_name, $column_name = '', $column_data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_COLUMN_UPDATE', $table_name, $column_name); + + if (!$this->table_column_exists($table_name, $column_name)) + { + return $this->umil_end('TABLE_COLUMN_NOT_EXIST', $table_name, $column_name); + } + + $this->db_tools->sql_column_change($table_name, $column_name, $column_data); + + return $this->umil_end(); + } + + /** + * Table Column Remove + * + * Remove a column from a table + */ + function table_column_remove($table_name, $column_name = '') + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_COLUMN_REMOVE', $table_name, $column_name); + + if (!$this->table_column_exists($table_name, $column_name)) + { + return $this->umil_end('TABLE_COLUMN_NOT_EXIST', $table_name, $column_name); + } + + $this->db_tools->sql_column_remove($table_name, $column_name); + + return $this->umil_end(); + } + + /** + * Table Index Exists + * + * Check if a table key/index exists on a table (can not check primary or unique) + */ + function table_index_exists($table_name, $index_name) + { + $this->get_table_name($table_name); + + $indexes = $this->db_tools->sql_list_index($table_name); + + if (in_array($index_name, $indexes)) + { + return true; + } + + return false; + } + + /** + * Table Index Add + * + * Add a new key/index to a table + */ + function table_index_add($table_name, $index_name = '', $column = array()) + { + global $config; + + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + // Let them skip the column field and just use the index name in that case as the column as well + if (empty($column)) + { + $column = array($index_name); + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_KEY_ADD', $table_name, $index_name); + + if ($this->table_index_exists($table_name, $index_name)) + { + return $this->umil_end('TABLE_KEY_ALREADY_EXIST', $table_name, $index_name); + } + + if (!is_array($column)) + { + $column = array($column); + } + + // remove index length if we are before 3.0.8 + // the feature (required for some types when using MySQL4) + // was added in that release (ticket PHPBB3-8944) + if (version_compare($config['version'], '3.0.7-pl1', '<=')) + { + $column = preg_replace('#:.*$#', '', $column); + } + + $this->db_tools->sql_create_index($table_name, $index_name, $column); + + return $this->umil_end(); + } + + /** + * Table Index Remove + * + * Remove a key/index from a table + */ + function table_index_remove($table_name, $index_name = '') + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_KEY_REMOVE', $table_name, $index_name); + + if (!$this->table_index_exists($table_name, $index_name)) + { + return $this->umil_end('TABLE_KEY_NOT_EXIST', $table_name, $index_name); + } + + $this->db_tools->sql_index_drop($table_name, $index_name); + + return $this->umil_end(); + } + + // Ignore, function was renamed to table_row_insert and keeping for backwards compatibility + function table_insert($table_name, $data = array()) { $this->table_row_insert($table_name, $data); } + + /** + * Table Insert + * + * Insert data into a table + */ + function table_row_insert($table_name, $data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_ROW_INSERT_DATA', $table_name); + + if (!$this->table_exists($table_name)) + { + return $this->umil_end('TABLE_NOT_EXIST', $table_name); + } + + $this->db->sql_multi_insert($table_name, $data); + + return $this->umil_end(); + } + + /** + * Table Row Update + * + * Update a row in a table + * + * $data should be an array with the column names as keys and values as the items to check for each column. Example: + * array('user_id' => 123, 'user_name' => 'test user') would become: + * WHERE user_id = 123 AND user_name = 'test user' + * + * $new_data is the new data it will be updated to (same format as you'd enter into $db->sql_build_array('UPDATE' ). + */ + function table_row_update($table_name, $data = array(), $new_data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + if (!sizeof($data)) + { + return $this->umil_end('FAIL'); + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_ROW_UPDATE_DATA', $table_name); + + if (!$this->table_exists($table_name)) + { + return $this->umil_end('TABLE_NOT_EXIST', $table_name); + } + + $sql = 'UPDATE ' . $table_name . ' + SET ' . $this->db->sql_build_array('UPDATE', $new_data) . ' + WHERE ' . $this->db->sql_build_array('SELECT', $data); + $this->db->sql_query($sql); + + return $this->umil_end(); + } + + /** + * Table Row Remove + * + * Remove a row from a table + * + * $data should be an array with the column names as keys and values as the items to check for each column. Example: + * array('user_id' => 123, 'user_name' => 'test user') would become: + * WHERE user_id = 123 AND user_name = 'test user' + */ + function table_row_remove($table_name, $data = array()) + { + // Multicall + if ($this->multicall(__FUNCTION__, $table_name)) + { + return; + } + + if (!sizeof($data)) + { + return $this->umil_end('FAIL'); + } + + $this->get_table_name($table_name); + + $this->umil_start('TABLE_ROW_REMOVE_DATA', $table_name); + + if (!$this->table_exists($table_name)) + { + return $this->umil_end('TABLE_NOT_EXIST', $table_name); + } + + $sql = 'DELETE FROM ' . $table_name . ' WHERE ' . $this->db->sql_build_array('SELECT', $data); + $this->db->sql_query($sql); + + return $this->umil_end(); + } + + /** + * Version Checker + * + * Format the file like the following: + * http://www.phpbb.com/updatecheck/30x.txt + * + * @param string $url The url to access (ex: www.phpbb.com) + * @param string $path The path to access (ex: /updatecheck) + * @param string $file The name of the file to access (ex: 30x.txt) + * + * @return array|string Error Message if there was any error, or an array (each line in the file as a value) + */ + function version_check($url, $path, $file, $timeout = 10, $port = 80) + { + if (!function_exists('get_remote_file')) + { + global $phpbb_root_path, $phpEx; + + include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + } + + $errstr = $errno = ''; + + $info = get_remote_file($url, $path, $file, $errstr, $errno, $port, $timeout); + + if ($info === false) + { + return $errstr . ' [ ' . $errno . ' ]'; + } + + $info = str_replace("\r\n", "\n", $info); + $info = explode("\n", $info); + + return $info; + } + + /** + * Create table SQL + * + * Create the SQL query for the specified DBMS on the fly from a create_schema_files type of table array + * + * @param string $table_name The name of the table + * @param array $table_data The table data (formatted in the array format used by create_schema_files) + * @param string $dbms The dbms this will be built for (for testing only, leave blank to use the current DBMS) + * + * @return The sql query to run for the submitted dbms to insert the table + */ + function create_table_sql($table_name, $table_data, $dbms = '') + { + // To allow testing + $dbms = ($dbms) ? $dbms : $this->db_tools->sql_layer; + + // A list of types being unsigned for better reference in some db's + $unsigned_types = array('UINT', 'UINT:', 'USINT', 'BOOL', 'TIMESTAMP'); + $supported_dbms = array('firebird', 'mssql', 'mysql_40', 'mysql_41', 'oracle', 'postgres', 'sqlite'); + + $sql = ''; + + // Create Table statement + $generator = $textimage = false; + + switch ($dbms) + { + case 'mysql_40': + case 'mysql_41': + case 'firebird': + case 'oracle': + case 'sqlite': + case 'postgres': + $sql .= "CREATE TABLE {$table_name} (\n"; + break; + + case 'mssql': + $sql .= "CREATE TABLE [{$table_name}] (\n"; + break; + } + + // Table specific so we don't get overlap + $modded_array = array(); + + // Write columns one by one... + foreach ($table_data['COLUMNS'] as $column_name => $column_data) + { + // Get type + if (strpos($column_data[0], ':') !== false) + { + list($orig_column_type, $column_length) = explode(':', $column_data[0]); + if (!is_array($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'])) + { + $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'], $column_length); + } + else + { + if (isset($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'])) + { + switch ($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'][0]) + { + case 'div': + $column_length /= $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'][1]; + $column_length = ceil($column_length); + $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length); + break; + } + } + + if (isset($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'])) + { + switch ($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][0]) + { + case 'mult': + $column_length *= $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][1]; + if ($column_length > $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][2]) + { + $column_type = $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][3]; + $modded_array[$column_name] = $column_type; + } + else + { + $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length); + } + break; + } + } + } + $orig_column_type .= ':'; + } + else + { + $orig_column_type = $column_data[0]; + $column_type = $this->db_tools->dbms_type_map[$dbms][$column_data[0]]; + if ($column_type == 'text' || $column_type == 'blob') + { + $modded_array[$column_name] = $column_type; + } + } + + // Adjust default value if db-dependant specified + if (is_array($column_data[1])) + { + $column_data[1] = (isset($column_data[1][$dbms])) ? $column_data[1][$dbms] : $column_data[1]['default']; + } + + switch ($dbms) + { + case 'mysql_40': + case 'mysql_41': + $sql .= "\t{$column_name} {$column_type} "; + + // For hexadecimal values do not use single quotes + if (!is_null($column_data[1]) && substr($column_type, -4) !== 'text' && substr($column_type, -4) !== 'blob') + { + $sql .= (strpos($column_data[1], '0x') === 0) ? "DEFAULT {$column_data[1]} " : "DEFAULT '{$column_data[1]}' "; + } + $sql .= 'NOT NULL'; + + if (isset($column_data[2])) + { + if ($column_data[2] == 'auto_increment') + { + $sql .= ' auto_increment'; + } + else if ($dbms === 'mysql_41' && $column_data[2] == 'true_sort') + { + $sql .= ' COLLATE utf8_unicode_ci'; + } + } + + $sql .= ",\n"; + break; + + case 'sqlite': + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $sql .= "\t{$column_name} INTEGER PRIMARY KEY "; + $generator = $column_name; + } + else + { + $sql .= "\t{$column_name} {$column_type} "; + } + + $sql .= 'NOT NULL '; + $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}'" : ''; + $sql .= ",\n"; + break; + + case 'firebird': + $sql .= "\t{$column_name} {$column_type} "; + + if (!is_null($column_data[1])) + { + $sql .= 'DEFAULT ' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ' '; + } + + $sql .= 'NOT NULL'; + + // This is a UNICODE column and thus should be given it's fair share + if (preg_match('/^X?STEXT_UNI|VCHAR_(CI|UNI:?)/', $column_data[0])) + { + $sql .= ' COLLATE UNICODE'; + } + + $sql .= ",\n"; + + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $generator = $column_name; + } + break; + + case 'mssql': + if ($column_type == '[text]') + { + $textimage = true; + } + + $sql .= "\t[{$column_name}] {$column_type} "; + + if (!is_null($column_data[1])) + { + // For hexadecimal values do not use single quotes + if (strpos($column_data[1], '0x') === 0) + { + $sql .= 'DEFAULT (' . $column_data[1] . ') '; + } + else + { + $sql .= 'DEFAULT (' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ') '; + } + } + + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $sql .= 'IDENTITY (1, 1) '; + } + + $sql .= 'NOT NULL'; + $sql .= " ,\n"; + break; + + case 'oracle': + $sql .= "\t{$column_name} {$column_type} "; + $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : ''; + + // In Oracle empty strings ('') are treated as NULL. + // Therefore in oracle we allow NULL's for all DEFAULT '' entries + $sql .= ($column_data[1] === '') ? ",\n" : "NOT NULL,\n"; + + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $generator = $column_name; + } + break; + + case 'postgres': + $sql .= "\t{$column_name} {$column_type} "; + + if (isset($column_data[2]) && $column_data[2] == 'auto_increment') + { + $sql .= "DEFAULT nextval('{$table_name}_seq'),\n"; + + // Make sure the sequence will be created before creating the table + $sql = "CREATE SEQUENCE {$table_name}_seq;\n\n" . $sql; + } + else + { + $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : ''; + $sql .= "NOT NULL"; + + // Unsigned? Then add a CHECK contraint + if (in_array($orig_column_type, $unsigned_types)) + { + $sql .= " CHECK ({$column_name} >= 0)"; + } + + $sql .= ",\n"; + } + break; + } + } + + switch ($dbms) + { + case 'firebird': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n);;\n\n"; + break; + + case 'mssql': + $sql = substr($sql, 0, -2); + $sql .= "\n) ON [PRIMARY]" . (($textimage) ? ' TEXTIMAGE_ON [PRIMARY]' : '') . "\n"; + $sql .= "GO\n\n"; + break; + } + + // Write primary key + if (isset($table_data['PRIMARY_KEY'])) + { + if (!is_array($table_data['PRIMARY_KEY'])) + { + $table_data['PRIMARY_KEY'] = array($table_data['PRIMARY_KEY']); + } + + switch ($dbms) + { + case 'mysql_40': + case 'mysql_41': + case 'postgres': + $sql .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; + break; + + case 'firebird': + $sql .= "ALTER TABLE {$table_name} ADD PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . ");;\n\n"; + break; + + case 'sqlite': + if ($generator === false || !in_array($generator, $table_data['PRIMARY_KEY'])) + { + $sql .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; + } + break; + + case 'mssql': + $sql .= "ALTER TABLE [{$table_name}] WITH NOCHECK ADD \n"; + $sql .= "\tCONSTRAINT [PK_{$table_name}] PRIMARY KEY CLUSTERED \n"; + $sql .= "\t(\n"; + $sql .= "\t\t[" . implode("],\n\t\t[", $table_data['PRIMARY_KEY']) . "]\n"; + $sql .= "\t) ON [PRIMARY] \n"; + $sql .= "GO\n\n"; + break; + + case 'oracle': + $sql .= "\tCONSTRAINT pk_{$table_name} PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; + break; + } + } + + switch ($dbms) + { + case 'oracle': + // UNIQUE contrains to be added? + if (isset($table_data['KEYS'])) + { + foreach ($table_data['KEYS'] as $key_name => $key_data) + { + if (!is_array($key_data[1])) + { + $key_data[1] = array($key_data[1]); + } + + if ($key_data[0] == 'UNIQUE') + { + $sql .= "\tCONSTRAINT u_phpbb_{$key_name} UNIQUE (" . implode(', ', $key_data[1]) . "),\n"; + } + } + } + + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n)\n/\n\n"; + break; + + case 'postgres': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n);\n\n"; + break; + + case 'sqlite': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n);\n\n"; + break; + } + + // Write Keys + if (isset($table_data['KEYS'])) + { + foreach ($table_data['KEYS'] as $key_name => $key_data) + { + if (!is_array($key_data[1])) + { + $key_data[1] = array($key_data[1]); + } + + switch ($dbms) + { + case 'mysql_40': + case 'mysql_41': + $sql .= ($key_data[0] == 'INDEX') ? "\tKEY" : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? "\tUNIQUE" : ''; + foreach ($key_data[1] as $key => $col_name) + { + if (isset($modded_array[$col_name])) + { + switch ($modded_array[$col_name]) + { + case 'text': + case 'blob': + $key_data[1][$key] = $col_name . '(255)'; + break; + } + } + } + $sql .= ' ' . $key_name . ' (' . implode(', ', $key_data[1]) . "),\n"; + break; + + case 'firebird': + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; + + $sql .= ' ' . $table_name . '_' . $key_name . ' ON ' . $table_name . '(' . implode(', ', $key_data[1]) . ");;\n"; + break; + + case 'mssql': + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; + $sql .= " [{$key_name}] ON [{$table_name}]([" . implode('], [', $key_data[1]) . "]) ON [PRIMARY]\n"; + $sql .= "GO\n\n"; + break; + + case 'oracle': + if ($key_data[0] == 'UNIQUE') + { + continue; + } + + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + + $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ")\n"; + $sql .= "/\n"; + break; + + case 'sqlite': + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; + + $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n"; + break; + + case 'postgres': + $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; + $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; + + $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n"; + break; + } + } + } + + switch ($dbms) + { + case 'mysql_40': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n);\n\n"; + break; + + case 'mysql_41': + // Remove last line delimiter... + $sql = substr($sql, 0, -2); + $sql .= "\n) CHARACTER SET utf8 COLLATE utf8_bin;\n\n"; + break; + + // Create Generator + case 'firebird': + if ($generator !== false) + { + $sql .= "\nCREATE GENERATOR {$table_name}_gen;;\n"; + $sql .= 'SET GENERATOR ' . $table_name . "_gen TO 0;;\n\n"; + + $sql .= 'CREATE TRIGGER t_' . $table_name . ' FOR ' . $table_name . "\n"; + $sql .= "BEFORE INSERT\nAS\nBEGIN\n"; + $sql .= "\tNEW.{$generator} = GEN_ID({$table_name}_gen, 1);\nEND;;\n\n"; + } + break; + + case 'oracle': + if ($generator !== false) + { + $sql .= "\nCREATE SEQUENCE {$table_name}_seq\n/\n\n"; + + $sql .= "CREATE OR REPLACE TRIGGER t_{$table_name}\n"; + $sql .= "BEFORE INSERT ON {$table_name}\n"; + $sql .= "FOR EACH ROW WHEN (\n"; + $sql .= "\tnew.{$generator} IS NULL OR new.{$generator} = 0\n"; + $sql .= ")\nBEGIN\n"; + $sql .= "\tSELECT {$table_name}_seq.nextval\n"; + $sql .= "\tINTO :new.{$generator}\n"; + $sql .= "\tFROM dual;\nEND;\n/\n\n"; + } + break; + } + + return $sql; + } + + /** + * Get the real table name + * By A_Jelly_Doughnut + * + * @param string $table_name The table name to get the real table name from + */ + function get_table_name(&$table_name) + { + // Use the global table prefix if a custom one is not specified + if ($this->table_prefix === false) + { + global $table_prefix; + } + else + { + $table_prefix = $this->table_prefix; + } + + static $constants = NULL; + + if (is_null($constants)) + { + $constants = get_defined_constants(); + } + + /** + * only do the replace if the table prefix is not already present + * this is required since UMIL supports specifying a table via phpbb_foo + * (where a replace would be needed) + * or by FOO_TABLE (where a replace is already done at constant-define time) + */ + if (!preg_match('#^' . preg_quote($table_prefix, '#') . '#', $table_name) || !in_array($table_name, $constants, true)) + { + $table_name = preg_replace('#^phpbb_#i', $table_prefix, $table_name); + } + } +} + +?> \ No newline at end of file diff --git a/phpBB/includes/db/migrationtools/base.php b/phpBB/includes/db/migrationtools/base.php deleted file mode 100644 index 7fc6057e3a..0000000000 --- a/phpBB/includes/db/migrationtools/base.php +++ /dev/null @@ -1,15 +0,0 @@ -db->sql_escape($config_name) . "'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if ($row) - { - if (!isset($this->config[$config_name])) - { - $this->config[$config_name] = $row['config_value']; - - if (!$row['is_dynamic']) - { - $this->cache->destroy('config'); - } - } - - return ($return_result) ? $row : true; - } - - // this should never happen, but if it does, we need to remove the config from the array - if (isset($this->config[$config_name])) - { - unset($this->config[$config_name]); - $this->cache->destroy('config'); - } - - return false; - } - - /** - * Config Add - * - * This function allows you to add a config setting. - * - * @param string $config_name The name of the config setting you would like to add - * @param mixed $config_value The value of the config setting - * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. - * - * @return result - */ - function config_add($config_name, $config_value = '', $is_dynamic = false) - { - if ($this->config_exists($config_name)) - { - return $this->umil_end('CONFIG_ALREADY_EXISTS', $config_name); - } - - set_config($config_name, $config_value, $is_dynamic); - } - - /** - * Config Update - * - * This function allows you to update an existing config setting. - * - * @param string $config_name The name of the config setting you would like to update - * @param mixed $config_value The value of the config setting - * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. - * - * @return result - */ - function config_update($config_name, $config_value = '') - { - if (!$this->config_exists($config_name)) - { - return $this->umil_end('CONFIG_NOT_EXIST', $config_name); - } - - set_config($config_name, $config_value); - } - - /** - * Config Remove - * - * This function allows you to remove an existing config setting. - * - * @param string $config_name The name of the config setting you would like to remove - * - * @return result - */ - function config_remove($config_name) - { - if (!$this->config_exists($config_name)) - { - return $this->umil_end('CONFIG_NOT_EXIST', $config_name); - } - - $sql = 'DELETE FROM ' . CONFIG_TABLE . " - WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; - $this->db->sql_query($sql); - - unset($this->config[$config_name]); - $this->cache->destroy('config'); - } -} \ No newline at end of file diff --git a/phpBB/includes/db/migrationtools/umil.php b/phpBB/includes/db/migrationtools/umil.php deleted file mode 100644 index ce7b8ff3be..0000000000 --- a/phpBB/includes/db/migrationtools/umil.php +++ /dev/null @@ -1,3037 +0,0 @@ -config_add(array( -* array('config_name', 'config_value'), -* array('config_name1', 'config_value1'), -* array('config_name2', 'config_value2', true), -* array('config_name3', 'config_value3', true), -* ); -*/ - -/** -* UMIL - Unified MOD Installation Library class -* -* Cache Functions -* cache_purge($type = '', $style_id = 0) -* -* Config Functions: -* config_exists($config_name, $return_result = false) -* config_add($config_name, $config_value = '', $is_dynamic = false) -* config_update($config_name, $config_value, $is_dynamic = false) -* config_remove($config_name) -* -* Module Functions -* module_exists($class, $parent, $module) -* module_add($class, $parent = 0, $data = array()) -* module_remove($class, $parent = 0, $module = '') -* -* Permissions/Auth Functions -* permission_exists($auth_option, $global = true) -* permission_add($auth_option, $global = true) -* permission_remove($auth_option, $global = true) -* permission_set($name, $auth_option = array(), $type = 'role', $global = true, $has_permission = true) -* permission_unset($name, $auth_option = array(), $type = 'role', $global = true) -* -* Table Functions -* table_exists($table_name) -* table_add($table_name, $table_data = array()) -* table_remove($table_name) -* -* Table Column Functions -* table_column_exists($table_name, $column_name) -* table_column_add($table_name, $column_name = '', $column_data = array()) -* table_column_update($table_name, $column_name = '', $column_data = array()) -* table_column_remove($table_name, $column_name = '') -* -* Table Key/Index Functions -* table_index_exists($table_name, $index_name) -* table_index_add($table_name, $index_name = '', $column = array()) -* table_index_remove($table_name, $index_name = '') -* -* Table Row Functions (note that these actions are not reversed automatically during uninstallation) -* table_row_insert($table_name, $data = array()) -* table_row_remove($table_name, $data = array()) -* table_row_update($table_name, $data = array(), $new_data = array()) -* -* Version Check Function -* version_check($url, $path, $file) -*/ -class umil -{ - /** - * This will hold the text output for the inputted command (if the mod author would like to display the command that was ran) - * - * @var string - */ - var $command = ''; - - /** - * This will hold the text output for the result of the command. $user->lang['SUCCESS'] if everything worked. - * - * @var string - */ - var $result = ''; - - /** - * Auto run $this->display_results after running a command - */ - var $auto_display_results = false; - - /** - * Stand Alone option (this makes it possible to just use the single umil file and not worry about any language stuff - */ - var $stand_alone = false; - - /** - * Were any new permissions added (used in umil_frontend)? - */ - var $permissions_added = false; - - /** - * Database Object - */ - var $db = false; - - /** - * Database Tools Object - */ - var $db_tools = false; - - /** - * Do we want a custom prefix besides the phpBB table prefix? You *probably* should not change this... - */ - var $table_prefix = false; - - /** - * Constructor - */ - function umil($stand_alone = false, $db = false) - { - // Setup $this->db - if ($db !== false) - { - if (!is_object($db) || !method_exists($db, 'sql_query')) - { - trigger_error('Invalid $db Object'); - } - - $this->db = $db; - } - else - { - global $db; - $this->db = $db; - } - - // Setup $this->db_tools - if (!class_exists('phpbb_db_tools')) - { - global $phpbb_root_path, $phpEx; - include($phpbb_root_path . 'includes/db/db_tools.' . $phpEx); - } - $this->db_tools = new phpbb_db_tools($this->db); - - $this->stand_alone = $stand_alone; - - if (!$stand_alone) - { - global $config, $user, $phpbb_root_path, $phpEx; - - /* Does not have the fall back option to use en/ if the user's language file does not exist, so we will not use it...unless that is changed. - if (method_exists('user', 'set_custom_lang_path')) - { - $user->set_custom_lang_path($phpbb_root_path . 'umil/language/'); - $user->add_lang('umil'); - $user->set_custom_lang_path($phpbb_root_path . 'language/'); - } - else - {*/ - // Include the umil language file. First we check if the language file for the user's language is available, if not we check if the board's default language is available, if not we use the english file. - if (isset($user->data['user_lang']) && file_exists("{$phpbb_root_path}umil/language/{$user->data['user_lang']}/umil.$phpEx")) - { - $path = $user->data['user_lang']; - } - else if (file_exists("{$phpbb_root_path}umil/language/" . basename($config['default_lang']) . "/umil.$phpEx")) - { - $path = basename($config['default_lang']); - } - else if (file_exists("{$phpbb_root_path}umil/language/en/umil.$phpEx")) - { - $path = 'en'; - } - else - { - trigger_error('Language Files Missing.

Please download the latest UMIL (Unified MOD Install Library) from: phpBB.com/mods/umil', E_USER_ERROR); - } - - $user->add_lang('./../../umil/language/' . $path . '/umil'); - //} - - $user->add_lang(array('acp/common', 'acp/permissions')); - - // Check to see if a newer version is available. - $info = $this->version_check('version.phpbb.com', '/umil', ((defined('PHPBB_QA')) ? 'umil_qa.txt' : 'umil.txt')); - if (is_array($info) && isset($info[0]) && isset($info[1])) - { - if (version_compare(UMIL_VERSION, $info[0], '<')) - { - global $template; - - // Make sure user->setup() has been called - if (empty($user->lang)) - { - $user->setup(); - } - - page_header('', false); - - $user->lang['UPDATE_UMIL'] = (isset($user->lang['UPDATE_UMIL'])) ? $user->lang['UPDATE_UMIL'] : 'This version of UMIL is outdated.

Please download the latest UMIL (Unified MOD Install Library) from: %1$s'; - $template->assign_vars(array( - 'S_BOARD_DISABLED' => true, - 'L_BOARD_DISABLED' => sprintf($user->lang['UPDATE_UMIL'], $info[1]), - )); - } - } - } - } - - /** - * umil_start - * - * A function which runs (almost) every time a function here is ran - */ - function umil_start() - { - global $user; - - // Set up the command. This will get the arguments sent to the function. - $args = func_get_args(); - $this->command = call_user_func_array(array($this, 'get_output_text'), $args); - - $this->result = (isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS'; - $this->db->sql_return_on_error(true); - - //$this->db->sql_transaction('begin'); - } - - /** - * umil_end - * - * A function which runs (almost) every time a function here is ran - */ - function umil_end() - { - global $user; - - // Set up the result. This will get the arguments sent to the function. - $args = func_get_args(); - $result = call_user_func_array(array($this, 'get_output_text'), $args); - $this->result = ($result) ? $result : $this->result; - - if ($this->db->sql_error_triggered) - { - if ($this->result == ((isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS')) - { - $this->result = 'SQL ERROR ' . $this->db->sql_error_returned['message']; - } - else - { - $this->result .= '

SQL ERROR ' . $this->db->sql_error_returned['message']; - } - - //$this->db->sql_transaction('rollback'); - } - else - { - //$this->db->sql_transaction('commit'); - } - - $this->db->sql_return_on_error(false); - - // Auto output if requested. - if ($this->auto_display_results && method_exists($this, 'display_results')) - { - $this->display_results(); - } - - return '' . $this->command . '
' . $this->result; - } - - /** - * Get text for output - * - * Takes the given arguments and prepares them for the UI - * - * First argument sent is used as the language key - * Further arguments (if send) are used on the language key through vsprintf() - * - * @return string Returns the prepared string for output - */ - function get_output_text() - { - global $user; - - // Set up the command. This will get the arguments sent to the function. - $args = func_get_args(); - if (sizeof($args)) - { - $lang_key = array_shift($args); - - if (sizeof($args)) - { - $lang_args = array(); - foreach ($args as $arg) - { - $lang_args[] = (isset($user->lang[$arg])) ? $user->lang[$arg] : $arg; - } - - return @vsprintf(((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key), $lang_args); - } - else - { - return ((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key); - } - } - - return ''; - } - - /** - * Run Actions - * - * Do-It-All function that can do everything required for installing/updating/uninstalling a mod based on an array of actions and the versions. - * - * @param string $action The action. install|update|uninstall - * @param array $versions The array of versions and the actions for each - * @param string $version_config_name The name of the config setting which holds/will hold the currently installed version - * @param string $version_select Added for the UMIL Auto system to allow you to select the version you want to install/update/uninstall to. - */ - function run_actions($action, $versions, $version_config_name, $version_select = '') - { - // We will sort the actions to prevent issues from mod authors incorrectly listing the version numbers - uksort($versions, 'version_compare'); - - // Find the current version to install - $current_version = '0.0.0'; - foreach ($versions as $version => $actions) - { - $current_version = $version; - } - - $db_version = ''; - if ($this->config_exists($version_config_name)) - { - global $config; - $db_version = $config[$version_config_name]; - } - - // Set the action to install from update if nothing is currently installed - if ($action == 'update' && !$db_version) - { - $action = 'install'; - } - - if ($action == 'install' || $action == 'update') - { - $version_installed = $db_version; - foreach ($versions as $version => $version_actions) - { - // If we are updating - if ($db_version && version_compare($version, $db_version, '<=')) - { - continue; - } - - if ($version_select && version_compare($version, $version_select, '>')) - { - break; - } - - foreach ($version_actions as $method => $params) - { - if ($method == 'custom') - { - $this->_call_custom_function($params, $action, $version); - } - else - { - if (method_exists($this, $method)) - { - call_user_func(array($this, $method), $params); - } - } - } - - $version_installed = $version; - } - - // update the version number or add it - if ($this->config_exists($version_config_name)) - { - $this->config_update($version_config_name, $version_installed); - } - else - { - $this->config_add($version_config_name, $version_installed); - } - } - else if ($action == 'uninstall' && $db_version) - { - // reverse version list - $versions = array_reverse($versions); - - foreach ($versions as $version => $version_actions) - { - // Uninstalling and this listed version is newer than installed - if (version_compare($version, $db_version, '>')) - { - continue; - } - - // Version selection stuff - if ($version_select && version_compare($version, $version_select, '<=')) - { - // update the version number - $this->config_update($version_config_name, $version); - break; - } - - $cache_purge = false; - $version_actions = array_reverse($version_actions); - foreach ($version_actions as $method => $params) - { - if ($method == 'custom') - { - $this->_call_custom_function($params, $action, $version); - } - else - { - // This way we always run the cache purge at the end of the version (done for the uninstall because the instructions are reversed, which would cause the cache purge to be run at the beginning if it was meant to run at the end). - if ($method == 'cache_purge') - { - $cache_purge = $params; - continue; - } - - // A few things are not possible for uninstallations update actions and table_row actions - if (strpos($method, 'update') !== false || strpos($method, 'table_insert') !== false || strpos($method, 'table_row_') !== false) - { - continue; - } - - // reverse function call - $method = str_replace(array('add', 'remove', 'temp'), array('temp', 'add', 'remove'), $method); - $method = str_replace(array('set', 'unset', 'temp'), array('temp', 'set', 'unset'), $method); - - if (method_exists($this, $method)) - { - call_user_func(array($this, $method), ((is_array($params) ? array_reverse($params) : $params))); - } - } - } - - if ($cache_purge !== false) - { - $this->cache_purge($cache_purge); - } - } - - if (!$version_select) - { - // Unset the version number - $this->config_remove($version_config_name); - } - } - } - - /** - * Call custom function helper - */ - function _call_custom_function($functions, $action, $version) - { - if (!is_array($functions)) - { - $functions = array($functions); - } - - $return = ''; - - foreach ($functions as $function) - { - if (function_exists($function)) - { - // Must reset before calling the function - $this->umil_start(); - - $returned = call_user_func($function, $action, $version); - if (is_string($returned)) - { - $this->command = $this->get_output_text($returned); - } - else if (is_array($returned) && isset($returned['command'])) - { - if (is_array($returned['command'])) - { - $this->command = call_user_func_array(array($this, 'get_output_text'), $returned['command']); - } - else - { - $this->command = $this->get_output_text($returned['command']); - } - - if (isset($returned['result'])) - { - $this->result = $this->get_output_text($returned['result']); - } - } - else - { - $this->command = $this->get_output_text('UNKNOWN'); - } - - $return .= $this->umil_end() . '
'; - } - } - - return $return; - } - - /** - * Multicall Helper - * - * @param mixed $function Function name to call - * @param mixed $params The parameters array - * - * @return bool True if we have done a multicall ($params is an array), false if not ($params is not an array) - */ - function multicall($function, $params) - { - if (is_array($params) && !empty($params)) - { - foreach ($params as $param) - { - if (!is_array($param)) - { - call_user_func(array($this, $function), $param); - } - else - { - call_user_func_array(array($this, $function), $param); - } - } - return true; - } - - return false; - } - - /** - * Cache Purge - * - * This function is for purging either phpBB3’s data cache, authorization cache, or the styles cache. - * - * @param string $type The type of cache you want purged. Available types: auth, imageset, template, theme. Anything else sent will purge the forum's cache. - * @param int $style_id The id of the item you want purged (if the type selected is imageset/template/theme, 0 for all items in that section) - */ - function cache_purge($type = '', $style_id = 0) - { - global $auth, $cache, $user, $phpbb_root_path, $phpEx; - - // Multicall - if ($this->multicall(__FUNCTION__, $type)) - { - return; - } - - $style_id = (int) $style_id; - $type = (string) $type; // Prevent PHP bug. - - switch ($type) - { - case 'auth' : - $this->umil_start('AUTH_CACHE_PURGE'); - $cache->destroy('_acl_options'); - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - break; - - case 'imageset' : - if ($style_id == 0) - { - $return = array(); - $sql = 'SELECT imageset_id - FROM ' . STYLES_IMAGESET_TABLE; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $return[] = $this->cache_purge('imageset', $row['imageset_id']); - } - $this->db->sql_freeresult($result); - - return implode('

', $return); - } - else - { - $sql = 'SELECT * - FROM ' . STYLES_IMAGESET_TABLE . " - WHERE imageset_id = $style_id"; - $result = $this->db->sql_query($sql); - $imageset_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$imageset_row) - { - $this->umil_start('IMAGESET_CACHE_PURGE', 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - $this->umil_start('IMAGESET_CACHE_PURGE', $imageset_row['imageset_name']); - - // The following is from includes/acp/acp_styles.php (edited) - $sql_ary = array(); - - $cfg_data_imageset = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/imageset.cfg"); - - $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . ' - WHERE imageset_id = ' . $style_id; - $result = $this->db->sql_query($sql); - - foreach ($cfg_data_imageset as $image_name => $value) - { - if (strpos($value, '*') !== false) - { - if (substr($value, -1, 1) === '*') - { - list($image_filename, $image_height) = explode('*', $value); - $image_width = 0; - } - else - { - list($image_filename, $image_height, $image_width) = explode('*', $value); - } - } - else - { - $image_filename = $value; - $image_height = $image_width = 0; - } - - if (strpos($image_name, 'img_') === 0 && $image_filename) - { - $image_name = substr($image_name, 4); - - $sql_ary[] = array( - 'image_name' => (string) $image_name, - 'image_filename' => (string) $image_filename, - 'image_height' => (int) $image_height, - 'image_width' => (int) $image_width, - 'imageset_id' => (int) $style_id, - 'image_lang' => '', - ); - } - } - - $sql = 'SELECT lang_dir - FROM ' . LANG_TABLE; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg")) - { - $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg"); - foreach ($cfg_data_imageset_data as $image_name => $value) - { - if (strpos($value, '*') !== false) - { - if (substr($value, -1, 1) === '*') - { - list($image_filename, $image_height) = explode('*', $value); - $image_width = 0; - } - else - { - list($image_filename, $image_height, $image_width) = explode('*', $value); - } - } - else - { - $image_filename = $value; - $image_height = $image_width = 0; - } - - if (strpos($image_name, 'img_') === 0 && $image_filename) - { - $image_name = substr($image_name, 4); - $sql_ary[] = array( - 'image_name' => (string) $image_name, - 'image_filename' => (string) $image_filename, - 'image_height' => (int) $image_height, - 'image_width' => (int) $image_width, - 'imageset_id' => (int) $style_id, - 'image_lang' => (string) $row['lang_dir'], - ); - } - } - } - } - $this->db->sql_freeresult($result); - - $this->db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary); - - $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE); - - return $this->umil_end(); - } - break; - //case 'imageset' : - - case 'template' : - if ($style_id == 0) - { - $return = array(); - $sql = 'SELECT template_id - FROM ' . STYLES_TEMPLATE_TABLE; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $return[] = $this->cache_purge('template', $row['template_id']); - } - $this->db->sql_freeresult($result); - - return implode('

', $return); - } - else - { - $sql = 'SELECT * - FROM ' . STYLES_TEMPLATE_TABLE . " - WHERE template_id = $style_id"; - $result = $this->db->sql_query($sql); - $template_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$template_row) - { - $this->umil_start('TEMPLATE_CACHE_PURGE', 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - $this->umil_start('TEMPLATE_CACHE_PURGE', $template_row['template_name']); - - // The following is from includes/acp/acp_styles.php - if ($template_row['template_storedb'] && file_exists("{$phpbb_root_path}styles/{$template_row['template_path']}/template/")) - { - $filelist = array('' => array()); - - $sql = 'SELECT template_filename, template_mtime - FROM ' . STYLES_TEMPLATE_DATA_TABLE . " - WHERE template_id = $style_id"; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { -// if (@filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}/template/" . $row['template_filename']) > $row['template_mtime']) -// { - // get folder info from the filename - if (($slash_pos = strrpos($row['template_filename'], '/')) === false) - { - $filelist[''][] = $row['template_filename']; - } - else - { - $filelist[substr($row['template_filename'], 0, $slash_pos + 1)][] = substr($row['template_filename'], $slash_pos + 1, strlen($row['template_filename']) - $slash_pos - 1); - } -// } - } - $this->db->sql_freeresult($result); - - $includes = array(); - foreach ($filelist as $pathfile => $file_ary) - { - foreach ($file_ary as $file) - { - if (!($fp = @fopen("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file", 'r'))) - { - return $this->umil_end('FILE_COULD_NOT_READ', "{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"); - } - $template_data = fread($fp, filesize("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file")); - fclose($fp); - - if (preg_match_all('##is', $template_data, $matches)) - { - foreach ($matches[1] as $match) - { - $includes[trim($match)][] = $file; - } - } - } - } - - foreach ($filelist as $pathfile => $file_ary) - { - foreach ($file_ary as $file) - { - // Skip index. - if (strpos($file, 'index.') === 0) - { - continue; - } - - // We could do this using extended inserts ... but that could be one - // heck of a lot of data ... - $sql_ary = array( - 'template_id' => (int) $style_id, - 'template_filename' => "$pathfile$file", - 'template_included' => (isset($includes[$file])) ? implode(':', $includes[$file]) . ':' : '', - 'template_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"), - 'template_data' => (string) file_get_contents("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"), - ); - - $sql = 'UPDATE ' . STYLES_TEMPLATE_DATA_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " - WHERE template_id = $style_id - AND template_filename = '" . $this->db->sql_escape("$pathfile$file") . "'"; - $this->db->sql_query($sql); - } - } - unset($filelist); - } - - // Purge the forum's cache as well. - $cache->purge(); - - return $this->umil_end(); - } - break; - //case 'template' : - - case 'theme' : - if ($style_id == 0) - { - $return = array(); - $sql = 'SELECT theme_id - FROM ' . STYLES_THEME_TABLE; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $return[] = $this->cache_purge('theme', $row['theme_id']); - } - $this->db->sql_freeresult($result); - - return implode('

', $return); - } - else - { - $sql = 'SELECT * - FROM ' . STYLES_THEME_TABLE . " - WHERE theme_id = $style_id"; - $result = $this->db->sql_query($sql); - $theme_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$theme_row) - { - $this->umil_start('THEME_CACHE_PURGE', 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - $this->umil_start('THEME_CACHE_PURGE', $theme_row['theme_name']); - - // The following is from includes/acp/acp_styles.php - if ($theme_row['theme_storedb'] && file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css")) - { - $stylesheet = file_get_contents($phpbb_root_path . 'styles/' . $theme_row['theme_path'] . '/theme/stylesheet.css'); - - // Match CSS imports - $matches = array(); - preg_match_all('/@import url\(["\'](.*)["\']\);/i', $stylesheet, $matches); - - if (sizeof($matches)) - { - foreach ($matches[0] as $idx => $match) - { - if (!file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}")) - { - continue; - } - - $content = trim(file_get_contents("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}")); - $stylesheet = str_replace($match, $content, $stylesheet); - } - } - - // adjust paths - $db_theme_data = str_replace('./', 'styles/' . $theme_row['theme_path'] . '/theme/', $stylesheet); - - // Save CSS contents - $sql_ary = array( - 'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"), - 'theme_data' => $db_theme_data, - ); - - $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " - WHERE theme_id = $style_id"; - $this->db->sql_query($sql); - - $cache->destroy('sql', STYLES_THEME_TABLE); - } - - return $this->umil_end(); - } - break; - //case 'theme' : - - default: - $this->umil_start('CACHE_PURGE'); - $cache->purge(); - - return $this->umil_end(); - break; - } - } - - /** - * Config Exists - * - * This function is to check to see if a config variable exists or if it does not. - * - * @param string $config_name The name of the config setting you wish to check for. - * @param bool $return_result - return the config value/default if true : default false. - * - * @return bool true/false if config exists - */ - function config_exists($config_name, $return_result = false) - { - global $config, $cache; - - $sql = 'SELECT * - FROM ' . CONFIG_TABLE . " - WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if ($row) - { - if (!isset($config[$config_name])) - { - $config[$config_name] = $row['config_value']; - - if (!$row['is_dynamic']) - { - $cache->destroy('config'); - } - } - - return ($return_result) ? $row : true; - } - - // this should never happen, but if it does, we need to remove the config from the array - if (isset($config[$config_name])) - { - unset($config[$config_name]); - $cache->destroy('config'); - } - - return false; - } - - /** - * Config Add - * - * This function allows you to add a config setting. - * - * @param string $config_name The name of the config setting you would like to add - * @param mixed $config_value The value of the config setting - * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. - * - * @return result - */ - function config_add($config_name, $config_value = '', $is_dynamic = false) - { - // Multicall - if ($this->multicall(__FUNCTION__, $config_name)) - { - return; - } - - $this->umil_start('CONFIG_ADD', $config_name); - - if ($this->config_exists($config_name)) - { - return $this->umil_end('CONFIG_ALREADY_EXISTS', $config_name); - } - - set_config($config_name, $config_value, $is_dynamic); - - return $this->umil_end(); - } - - /** - * Config Update - * - * This function allows you to update an existing config setting. - * - * @param string $config_name The name of the config setting you would like to update - * @param mixed $config_value The value of the config setting - * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. - * - * @return result - */ - function config_update($config_name, $config_value = '', $is_dynamic = false) - { - // Multicall - if ($this->multicall(__FUNCTION__, $config_name)) - { - return; - } - - $this->umil_start('CONFIG_UPDATE', $config_name); - - if (!$this->config_exists($config_name)) - { - return $this->umil_end('CONFIG_NOT_EXIST', $config_name); - } - - set_config($config_name, $config_value, $is_dynamic); - - return $this->umil_end(); - } - - /** - * Config Remove - * - * This function allows you to remove an existing config setting. - * - * @param string $config_name The name of the config setting you would like to remove - * - * @return result - */ - function config_remove($config_name) - { - global $cache, $config; - - // Multicall - if ($this->multicall(__FUNCTION__, $config_name)) - { - return; - } - - $this->umil_start('CONFIG_REMOVE', $config_name); - - if (!$this->config_exists($config_name)) - { - return $this->umil_end('CONFIG_NOT_EXIST', $config_name); - } - - $sql = 'DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; - $this->db->sql_query($sql); - - unset($config[$config_name]); - $cache->destroy('config'); - - return $this->umil_end(); - } - - /** - * Module Exists - * - * Check if a module exists - * - * @param string $class The module class(acp|mcp|ucp) - * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. - * @param int|string $module The module_id|module_langname you would like to check for to see if it exists - */ - function module_exists($class, $parent, $module) - { - // the main root directory should return true - if (!$module) - { - return true; - } - - $class = $this->db->sql_escape($class); - $module = $this->db->sql_escape($module); - - $parent_sql = ''; - if ($parent !== false) - { - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; - - if (!is_numeric($parent)) - { - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$row) - { - return false; - } - - $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; - } - else - { - $parent_sql = 'AND parent_id = ' . (int) $parent; - } - } - - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_class = '$class' - $parent_sql - AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '$module'"); - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if ($row) - { - return true; - } - - return false; - } - - /** - * Module Add - * - * Add a new module - * - * @param string $class The module class(acp|mcp|ucp) - * @param int|string $parent The parent module_id|module_langname (0 for no parent) - * @param array $data an array of the data on the new module. This can be setup in two different ways. - * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below, - * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode. - * array( - * 'module_enabled' => 1, - * 'module_display' => 1, - * 'module_basename' => '', - * 'module_class' => $class, - * 'parent_id' => (int) $parent, - * 'module_langname' => '', - * 'module_mode' => '', - * 'module_auth' => '', - * ) - * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file. - * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file): - * array( - * 'module_basename' => 'asacp', - * 'modes' => array('settings', 'log', 'flag'), - * ) - * Optionally you may not send 'modes' and it will insert all of the modules in that info file. - * @param string|bool $include_path If you would like to use a custom include path, specify that here - */ - function module_add($class, $parent = 0, $data = array(), $include_path = false) - { - global $cache, $user, $phpbb_root_path, $phpEx; - - // Multicall - if ($this->multicall(__FUNCTION__, $class)) - { - return; - } - - // Prevent stupid things like trying to add a module with no name or any data on it - if (empty($data)) - { - $this->umil_start('MODULE_ADD', $class, 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; - - // allow sending the name as a string in $data to create a category - if (!is_array($data)) - { - $data = array('module_langname' => $data); - } - - if (!isset($data['module_langname'])) - { - // The "automatic" way - $basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; - $basename = str_replace(array('/', '\\'), '', $basename); - $class = str_replace(array('/', '\\'), '', $class); - $info_file = "$class/info/{$class}_$basename.$phpEx"; - - // The manual and automatic ways both failed... - if (!file_exists((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file)) - { - $this->umil_start('MODULE_ADD', $class, $info_file); - return $this->umil_end('FAIL'); - } - - $classname = "{$class}_{$basename}_info"; - - if (!class_exists($classname)) - { - include((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file); - } - - $info = new $classname; - $module = $info->module(); - unset($info); - - $result = ''; - foreach ($module['modes'] as $mode => $module_info) - { - if (!isset($data['modes']) || in_array($mode, $data['modes'])) - { - $new_module = array( - 'module_basename' => $basename, - 'module_langname' => $module_info['title'], - 'module_mode' => $mode, - 'module_auth' => $module_info['auth'], - 'module_display' => (isset($module_info['display'])) ? $module_info['display'] : true, - 'before' => (isset($module_info['before'])) ? $module_info['before'] : false, - 'after' => (isset($module_info['after'])) ? $module_info['after'] : false, - ); - - // Run the "manual" way with the data we've collected. - $result .= ((isset($data['spacer'])) ? $data['spacer'] : '
') . $this->module_add($class, $parent, $new_module); - } - } - - return $result; - } - - // The "manual" way - $this->umil_start('MODULE_ADD', $class, ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname'])); - add_log('admin', 'LOG_MODULE_ADD', ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname'])); - - $class = $this->db->sql_escape($class); - - if (!is_numeric($parent)) - { - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$row) - { - return $this->umil_end('PARENT_NOT_EXIST'); - } - - $parent = $data['parent_id'] = $row['module_id']; - } - else if (!$this->module_exists($class, false, $parent)) - { - return $this->umil_end('PARENT_NOT_EXIST'); - } - - if ($this->module_exists($class, $parent, $data['module_langname'])) - { - return $this->umil_end('MODULE_ALREADY_EXIST'); - } - - if (!class_exists('acp_modules')) - { - include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); - $user->add_lang('acp/modules'); - } - $acp_modules = new acp_modules(); - - $module_data = array( - 'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1, - 'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1, - 'module_basename' => (isset($data['module_basename'])) ? $data['module_basename'] : '', - 'module_class' => $class, - 'parent_id' => (int) $parent, - 'module_langname' => (isset($data['module_langname'])) ? $data['module_langname'] : '', - 'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '', - 'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '', - ); - $result = $acp_modules->update_module_data($module_data, true); - - // update_module_data can either return a string or an empty array... - if (is_string($result)) - { - // Error - $this->result = $this->get_output_text($result); - } - else - { - // Success - - // Move the module if requested above/below an existing one - if (isset($data['before']) && $data['before']) - { - $sql = 'SELECT left_id FROM ' . MODULES_TABLE . ' - WHERE module_class = \'' . $class . '\' - AND parent_id = ' . (int) $parent . ' - AND module_langname = \'' . $this->db->sql_escape($data['before']) . '\''; - $this->db->sql_query($sql); - $to_left = $this->db->sql_fetchfield('left_id'); - - $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 - WHERE module_class = '$class' - AND left_id >= $to_left - AND left_id < {$module_data['left_id']}"; - $this->db->sql_query($sql); - - $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = $to_left, right_id = " . ($to_left + 1) . " - WHERE module_class = '$class' - AND module_id = {$module_data['module_id']}"; - $this->db->sql_query($sql); - } - else if (isset($data['after']) && $data['after']) - { - $sql = 'SELECT right_id FROM ' . MODULES_TABLE . ' - WHERE module_class = \'' . $class . '\' - AND parent_id = ' . (int) $parent . ' - AND module_langname = \'' . $this->db->sql_escape($data['after']) . '\''; - $this->db->sql_query($sql); - $to_right = $this->db->sql_fetchfield('right_id'); - - $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 - WHERE module_class = '$class' - AND left_id >= $to_right - AND left_id < {$module_data['left_id']}"; - $this->db->sql_query($sql); - - $sql = 'UPDATE ' . MODULES_TABLE . ' SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . " - WHERE module_class = '$class' - AND module_id = {$module_data['module_id']}"; - $this->db->sql_query($sql); - } - } - - // Clear the Modules Cache - $cache->destroy("_modules_$class"); - - return $this->umil_end(); - } - - /** - * Module Remove - * - * Remove a module - * - * @param string $class The module class(acp|mcp|ucp) - * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. - * @param int|string $module The module id|module_langname - * @param string|bool $include_path If you would like to use a custom include path, specify that here - */ - function module_remove($class, $parent = 0, $module = '', $include_path = false) - { - global $cache, $user, $phpbb_root_path, $phpEx; - - // Multicall - if ($this->multicall(__FUNCTION__, $class)) - { - return; - } - - // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto - if (is_array($module)) - { - if (isset($module['module_langname'])) - { - // Manual Method - return $this->module_remove($class, $parent, $module['module_langname'], $include_path); - } - - // Failed. - if (!isset($module['module_basename'])) - { - $this->umil_start('MODULE_REMOVE', $class, 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - // Automatic method - $basename = str_replace(array('/', '\\'), '', $module['module_basename']); - $class = str_replace(array('/', '\\'), '', $class); - $info_file = "$class/info/{$class}_$basename.$phpEx"; - - if (!file_exists((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file)) - { - $this->umil_start('MODULE_REMOVE', $class, $info_file); - return $this->umil_end('FAIL'); - } - - $classname = "{$class}_{$basename}_info"; - - if (!class_exists($classname)) - { - include((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file); - } - - $info = new $classname; - $module_info = $info->module(); - unset($info); - - $result = ''; - foreach ($module_info['modes'] as $mode => $info) - { - if (!isset($module['modes']) || in_array($mode, $module['modes'])) - { - $result .= $this->module_remove($class, $parent, $info['title']) . '
'; - } - } - return $result; - } - else - { - $class = $this->db->sql_escape($class); - - if (!$this->module_exists($class, $parent, $module)) - { - $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module])) ? $user->lang[$module] : $module)); - return $this->umil_end('MODULE_NOT_EXIST'); - } - - $parent_sql = ''; - if ($parent !== false) - { - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; - - if (!is_numeric($parent)) - { - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - // we know it exists from the module_exists check - $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; - } - else - { - $parent_sql = 'AND parent_id = ' . (int) $parent; - } - } - - $module_ids = array(); - if (!is_numeric($module)) - { - $module = $this->db->sql_escape($module); - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '$module' - AND module_class = '$class' - $parent_sql"; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $module_ids[] = (int) $row['module_id']; - } - $this->db->sql_freeresult($result); - - $module_name = $module; - } - else - { - $module = (int) $module; - $sql = 'SELECT module_langname FROM ' . MODULES_TABLE . " - WHERE module_id = $module - AND module_class = '$class' - $parent_sql"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - $module_name = $row['module_langname']; - $module_ids[] = $module; - } - - $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name)); - add_log('admin', 'LOG_MODULE_REMOVED', ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name)); - - if (!class_exists('acp_modules')) - { - include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); - $user->add_lang('acp/modules'); - } - $acp_modules = new acp_modules(); - $acp_modules->module_class = $class; - - foreach ($module_ids as $module_id) - { - $result = $acp_modules->delete_module($module_id); - if (!empty($result)) - { - if ($this->result == ((isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS')) - { - $this->result = implode('
', $result); - } - else - { - $this->result .= '
' . implode('
', $result); - } - } - } - - $cache->destroy("_modules_$class"); - - return $this->umil_end(); - } - } - - /** - * Permission Exists - * - * Check if a permission (auth) setting exists - * - * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return bool true if it exists, false if not - */ - function permission_exists($auth_option, $global = true) - { - if ($global) - { - $type_sql = ' AND is_global = 1'; - } - else - { - $type_sql = ' AND is_local = 1'; - } - - $sql = 'SELECT auth_option_id - FROM ' . ACL_OPTIONS_TABLE . " - WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" - . $type_sql; - $result = $this->db->sql_query($sql); - - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if ($row) - { - return true; - } - - return false; - } - - /** - * Permission Add - * - * Add a permission (auth) option - * - * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return result - */ - function permission_add($auth_option, $global = true) - { - // Multicall - if ($this->multicall(__FUNCTION__, $auth_option)) - { - return; - } - - $this->umil_start('PERMISSION_ADD', $auth_option); - - if ($this->permission_exists($auth_option, $global)) - { - return $this->umil_end('PERMISSION_ALREADY_EXISTS', $auth_option); - } - - // We've added permissions, so set to true to notify the user. - $this->permissions_added = true; - - if (!class_exists('auth_admin')) - { - global $phpbb_root_path, $phpEx; - - include($phpbb_root_path . 'includes/acp/auth.' . $phpEx); - } - $auth_admin = new auth_admin(); - - // We have to add a check to see if the !$global (if global, local, and if local, global) permission already exists. If it does, acl_add_option currently has a bug which would break the ACL system, so we are having a work-around here. - if ($this->permission_exists($auth_option, !$global)) - { - $sql_ary = array( - 'is_global' => 1, - 'is_local' => 1, - ); - $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE auth_option = \'' . $this->db->sql_escape($auth_option) . "'"; - $this->db->sql_query($sql); - } - else - { - if ($global) - { - $auth_admin->acl_add_option(array('global' => array($auth_option))); - } - else - { - $auth_admin->acl_add_option(array('local' => array($auth_option))); - } - } - - return $this->umil_end(); - } - - /** - * Permission Remove - * - * Remove a permission (auth) option - * - * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return result - */ - function permission_remove($auth_option, $global = true) - { - global $auth, $cache; - - // Multicall - if ($this->multicall(__FUNCTION__, $auth_option)) - { - return; - } - - $this->umil_start('PERMISSION_REMOVE', $auth_option); - - if (!$this->permission_exists($auth_option, $global)) - { - return $this->umil_end('PERMISSION_NOT_EXIST', $auth_option); - } - - if ($global) - { - $type_sql = ' AND is_global = 1'; - } - else - { - $type_sql = ' AND is_local = 1'; - } - $sql = 'SELECT auth_option_id, is_global, is_local FROM ' . ACL_OPTIONS_TABLE . " - WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" . - $type_sql; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - $id = $row['auth_option_id']; - - // If it is a local and global permission, do not remove the row! :P - if ($row['is_global'] && $row['is_local']) - { - $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' - SET ' . (($global) ? 'is_global = 0' : 'is_local = 0') . ' - WHERE auth_option_id = ' . $id; - $this->db->sql_query($sql); - } - else - { - // Delete time - $this->db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $id); - } - - // Purge the auth cache - $cache->destroy('_acl_options'); - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - } - - /** - * Add a new permission role - * - * @param string $role_name The new role name - * @param sting $role_type The type (u_, m_, a_) - */ - function permission_role_add($role_name, $role_type = '', $role_description = '') - { - // Multicall - if ($this->multicall(__FUNCTION__, $role_name)) - { - return; - } - - $this->umil_start('PERMISSION_ROLE_ADD', $role_name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if ($role_id) - { - return $this->umil_end('ROLE_ALREADY_EXISTS', $old_role_name); - } - - $sql = 'SELECT MAX(role_order) AS max FROM ' . ACL_ROLES_TABLE . ' - WHERE role_type = \'' . $this->db->sql_escape($role_type) . '\''; - $this->db->sql_query($sql); - $role_order = $this->db->sql_fetchfield('max'); - $role_order = (!$role_order) ? 1 : $role_order + 1; - - $sql_ary = array( - 'role_name' => $role_name, - 'role_description' => $role_description, - 'role_type' => $role_type, - 'role_order' => $role_order, - ); - - $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); - $this->db->sql_query($sql); - - return $this->umil_end(); - } - - /** - * Update the name on a permission role - * - * @param string $old_role_name The old role name - * @param string $new_role_name The new role name - */ - function permission_role_update($old_role_name, $new_role_name = '') - { - // Multicall - if ($this->multicall(__FUNCTION__, $role_name)) - { - return; - } - - $this->umil_start('PERMISSION_ROLE_UPDATE', $old_role_name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - return $this->umil_end('ROLE_NOT_EXIST', $old_role_name); - } - - $sql = 'UPDATE ' . ACL_ROLES_TABLE . ' - SET role_name = \'' . $this->db->sql_escape($new_role_name) . '\' - WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; - $this->db->sql_query($sql); - - return $this->umil_end(); - } - - /** - * Remove a permission role - * - * @param string $role_name The role name to remove - */ - function permission_role_remove($role_name) - { - global $auth; - - // Multicall - if ($this->multicall(__FUNCTION__, $role_name)) - { - return; - } - - $this->umil_start('PERMISSION_ROLE_REMOVE', $role_name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - return $this->umil_end('ROLE_NOT_EXIST', $role_name); - } - - $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - - $sql = 'DELETE FROM ' . ACL_ROLES_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - } - - /** - * Permission Set - * - * Allows you to set permissions for a certain group/role - * - * @param string $name The name of the role/group - * @param string|array $auth_option The auth_option or array of auth_options you would like to set - * @param string $type The type (role|group) - * @param bool $has_permission True if you want to give them permission, false if you want to deny them permission - */ - function permission_set($name, $auth_option = array(), $type = 'role', $has_permission = true) - { - global $auth; - - // Multicall - if ($this->multicall(__FUNCTION__, $name)) - { - return; - } - - if (!is_array($auth_option)) - { - $auth_option = array($auth_option); - } - - $new_auth = array(); - $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $new_auth[] = $row['auth_option_id']; - } - $this->db->sql_freeresult($result); - - if (!sizeof($new_auth)) - { - return false; - } - - $current_auth = array(); - - $type = (string) $type; // Prevent PHP bug. - - switch ($type) - { - case 'role' : - $this->umil_start('PERMISSION_SET_ROLE', $name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - return $this->umil_end('ROLE_NOT_EXIST'); - } - - $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_ROLES_DATA_TABLE . ' - WHERE role_id = ' . $role_id; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $current_auth[$row['auth_option_id']] = $row['auth_setting']; - } - $this->db->sql_freeresult($result); - break; - - case 'group' : - $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $group_id = $this->db->sql_fetchfield('group_id'); - - if (!$group_id) - { - $this->umil_start('PERMISSION_SET_GROUP', $name); - return $this->umil_end('GROUP_NOT_EXIST'); - } - - // If the group has a role set for them we will add the requested permissions to that role. - $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id . ' - AND auth_role_id <> 0 - AND forum_id = 0'; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('auth_role_id'); - if ($role_id) - { - $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - $role_name = $this->db->sql_fetchfield('role_name'); - - return $this->permission_set($role_name, $auth_option, 'role', $has_permission); - } - - $this->umil_start('PERMISSION_SET_GROUP', $name); - - $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $current_auth[$row['auth_option_id']] = $row['auth_setting']; - } - $this->db->sql_freeresult($result); - break; - } - - $sql_ary = array(); - switch ($type) - { - case 'role' : - foreach ($new_auth as $auth_option_id) - { - if (!isset($current_auth[$auth_option_id])) - { - $sql_ary[] = array( - 'role_id' => $role_id, - 'auth_option_id' => $auth_option_id, - 'auth_setting' => $has_permission, - ); - } - } - - $this->db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary); - break; - - case 'group' : - foreach ($new_auth as $auth_option_id) - { - if (!isset($current_auth[$auth_option_id])) - { - $sql_ary[] = array( - 'group_id' => $group_id, - 'auth_option_id' => $auth_option_id, - 'auth_setting' => $has_permission, - ); - } - } - - $this->db->sql_multi_insert(ACL_GROUPS_TABLE, $sql_ary); - break; - } - - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - } - - /** - * Permission Unset - * - * Allows you to unset (remove) permissions for a certain group/role - * - * @param string $name The name of the role/group - * @param string|array $auth_option The auth_option or array of auth_options you would like to set - * @param string $type The type (role|group) - */ - function permission_unset($name, $auth_option = array(), $type = 'role') - { - global $auth; - - // Multicall - if ($this->multicall(__FUNCTION__, $name)) - { - return; - } - - if (!is_array($auth_option)) - { - $auth_option = array($auth_option); - } - - $to_remove = array(); - $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $to_remove[] = $row['auth_option_id']; - } - $this->db->sql_freeresult($result); - - if (!sizeof($to_remove)) - { - return false; - } - - $type = (string) $type; // Prevent PHP bug. - - switch ($type) - { - case 'role' : - $this->umil_start('PERMISSION_UNSET_ROLE', $name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - return $this->umil_end('ROLE_NOT_EXIST'); - } - - $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); - $this->db->sql_query($sql); - break; - - case 'group' : - $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $group_id = $this->db->sql_fetchfield('group_id'); - - if (!$group_id) - { - $this->umil_start('PERMISSION_UNSET_GROUP', $name); - return $this->umil_end('GROUP_NOT_EXIST'); - } - - // If the group has a role set for them we will remove the requested permissions from that role. - $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id . ' - AND auth_role_id <> 0'; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('auth_role_id'); - if ($role_id) - { - $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - $role_name = $this->db->sql_fetchfield('role_name'); - - return $this->permission_unset($role_name, $auth_option, 'role'); - } - - $this->umil_start('PERMISSION_UNSET_GROUP', $name); - - $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); - $this->db->sql_query($sql); - break; - } - - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - } - - /** - * Table Exists - * - * Check if a table exists in the DB or not - * - * @param string $table_name The table name to check for - * - * @return bool true if the table exists, false if not - */ - function table_exists($table_name) - { - $this->get_table_name($table_name); - - // Use sql_table_exists if available - if (method_exists($this->db_tools, 'sql_table_exists')) - { - $roe = $this->db->return_on_error; - $result = $this->db_tools->sql_table_exists($table_name); - - // db_tools::sql_table_exists resets the return_on_error to false always after completing, so we must make sure we set it to true again if it was before - if ($roe) - { - $this->db->sql_return_on_error(true); - } - - return $result; - } - - if (!function_exists('get_tables')) - { - global $phpbb_root_path, $phpEx; - include($phpbb_root_path . 'includes/functions_install.' . $phpEx); - } - - $tables = get_tables($this->db); - - if (in_array($table_name, $tables)) - { - return true; - } - else - { - return false; - } - } - - /** - * Table Add - * - * This only supports input from the array format of db_tools or create_schema_files. - */ - function table_add($table_name, $table_data = array()) - { - global $dbms, $user; - - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - /** - * $table_data can be empty when uninstalling a mod and table_remove was used, but no 2rd argument was given. - * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 2rd argument) and skip this to prevent an error - */ - if (empty($table_data)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_ADD', $table_name); - - if ($this->table_exists($table_name)) - { - return $this->umil_end('TABLE_ALREADY_EXISTS', $table_name); - } - - if (!is_array($table_data)) - { - return $this->umil_end('NO_TABLE_DATA'); - } - - if (!function_exists('get_available_dbms')) - { - global $phpbb_root_path, $phpEx; - include("{$phpbb_root_path}includes/functions_install.$phpEx"); - } - - /* - * This function has had numerous problems and is currently broken, so until phpBB uses it I will not be anymore - if (method_exists($this->db_tools, 'sql_create_table')) - { - // Added in 3.0.5 - $this->db_tools->sql_create_table($table_name, $table_data); - } - else - {*/ - $available_dbms = get_available_dbms($dbms); - - $sql_query = $this->create_table_sql($table_name, $table_data); - $sql_query = split_sql_file($sql_query, $available_dbms[$dbms]['DELIM']); - - foreach ($sql_query as $sql) - { - $this->db->sql_query($sql); - } - //} - - return $this->umil_end(); - } - - /** - * Table Remove - * - * Delete/Drop a DB table - */ - function table_remove($table_name) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_REMOVE', $table_name); - - if (!$this->table_exists($table_name)) - { - return $this->umil_end('TABLE_NOT_EXIST', $table_name); - } - - if (method_exists($this->db_tools, 'sql_table_drop')) - { - // Added in 3.0.5 - $this->db_tools->sql_table_drop($table_name); - } - else - { - $this->db->sql_query('DROP TABLE ' . $table_name); - } - - return $this->umil_end(); - } - - /** - * Table Column Exists - * - * Check to see if a column exists in a table - */ - function table_column_exists($table_name, $column_name) - { - $this->get_table_name($table_name); - - return $this->db_tools->sql_column_exists($table_name, $column_name); - } - - /** - * Table Column Add - * - * Add a new column to a table. - */ - function table_column_add($table_name, $column_name = '', $column_data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - /** - * $column_data can be empty when uninstalling a mod and table_column_remove was used, but no 3rd argument was given. - * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 3rd argument) and skip this to prevent an error - */ - if (empty($column_data)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_COLUMN_ADD', $table_name, $column_name); - - if ($this->table_column_exists($table_name, $column_name)) - { - return $this->umil_end('TABLE_COLUMN_ALREADY_EXISTS', $table_name, $column_name); - } - - $this->db_tools->sql_column_add($table_name, $column_name, $column_data); - - return $this->umil_end(); - } - - /** - * Table Column Update - * - * Alter/Update a column in a table. You can not change a column name with this. - */ - function table_column_update($table_name, $column_name = '', $column_data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_COLUMN_UPDATE', $table_name, $column_name); - - if (!$this->table_column_exists($table_name, $column_name)) - { - return $this->umil_end('TABLE_COLUMN_NOT_EXIST', $table_name, $column_name); - } - - $this->db_tools->sql_column_change($table_name, $column_name, $column_data); - - return $this->umil_end(); - } - - /** - * Table Column Remove - * - * Remove a column from a table - */ - function table_column_remove($table_name, $column_name = '') - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_COLUMN_REMOVE', $table_name, $column_name); - - if (!$this->table_column_exists($table_name, $column_name)) - { - return $this->umil_end('TABLE_COLUMN_NOT_EXIST', $table_name, $column_name); - } - - $this->db_tools->sql_column_remove($table_name, $column_name); - - return $this->umil_end(); - } - - /** - * Table Index Exists - * - * Check if a table key/index exists on a table (can not check primary or unique) - */ - function table_index_exists($table_name, $index_name) - { - $this->get_table_name($table_name); - - $indexes = $this->db_tools->sql_list_index($table_name); - - if (in_array($index_name, $indexes)) - { - return true; - } - - return false; - } - - /** - * Table Index Add - * - * Add a new key/index to a table - */ - function table_index_add($table_name, $index_name = '', $column = array()) - { - global $config; - - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - // Let them skip the column field and just use the index name in that case as the column as well - if (empty($column)) - { - $column = array($index_name); - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_KEY_ADD', $table_name, $index_name); - - if ($this->table_index_exists($table_name, $index_name)) - { - return $this->umil_end('TABLE_KEY_ALREADY_EXIST', $table_name, $index_name); - } - - if (!is_array($column)) - { - $column = array($column); - } - - // remove index length if we are before 3.0.8 - // the feature (required for some types when using MySQL4) - // was added in that release (ticket PHPBB3-8944) - if (version_compare($config['version'], '3.0.7-pl1', '<=')) - { - $column = preg_replace('#:.*$#', '', $column); - } - - $this->db_tools->sql_create_index($table_name, $index_name, $column); - - return $this->umil_end(); - } - - /** - * Table Index Remove - * - * Remove a key/index from a table - */ - function table_index_remove($table_name, $index_name = '') - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_KEY_REMOVE', $table_name, $index_name); - - if (!$this->table_index_exists($table_name, $index_name)) - { - return $this->umil_end('TABLE_KEY_NOT_EXIST', $table_name, $index_name); - } - - $this->db_tools->sql_index_drop($table_name, $index_name); - - return $this->umil_end(); - } - - // Ignore, function was renamed to table_row_insert and keeping for backwards compatibility - function table_insert($table_name, $data = array()) { $this->table_row_insert($table_name, $data); } - - /** - * Table Insert - * - * Insert data into a table - */ - function table_row_insert($table_name, $data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_ROW_INSERT_DATA', $table_name); - - if (!$this->table_exists($table_name)) - { - return $this->umil_end('TABLE_NOT_EXIST', $table_name); - } - - $this->db->sql_multi_insert($table_name, $data); - - return $this->umil_end(); - } - - /** - * Table Row Update - * - * Update a row in a table - * - * $data should be an array with the column names as keys and values as the items to check for each column. Example: - * array('user_id' => 123, 'user_name' => 'test user') would become: - * WHERE user_id = 123 AND user_name = 'test user' - * - * $new_data is the new data it will be updated to (same format as you'd enter into $db->sql_build_array('UPDATE' ). - */ - function table_row_update($table_name, $data = array(), $new_data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - if (!sizeof($data)) - { - return $this->umil_end('FAIL'); - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_ROW_UPDATE_DATA', $table_name); - - if (!$this->table_exists($table_name)) - { - return $this->umil_end('TABLE_NOT_EXIST', $table_name); - } - - $sql = 'UPDATE ' . $table_name . ' - SET ' . $this->db->sql_build_array('UPDATE', $new_data) . ' - WHERE ' . $this->db->sql_build_array('SELECT', $data); - $this->db->sql_query($sql); - - return $this->umil_end(); - } - - /** - * Table Row Remove - * - * Remove a row from a table - * - * $data should be an array with the column names as keys and values as the items to check for each column. Example: - * array('user_id' => 123, 'user_name' => 'test user') would become: - * WHERE user_id = 123 AND user_name = 'test user' - */ - function table_row_remove($table_name, $data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - if (!sizeof($data)) - { - return $this->umil_end('FAIL'); - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_ROW_REMOVE_DATA', $table_name); - - if (!$this->table_exists($table_name)) - { - return $this->umil_end('TABLE_NOT_EXIST', $table_name); - } - - $sql = 'DELETE FROM ' . $table_name . ' WHERE ' . $this->db->sql_build_array('SELECT', $data); - $this->db->sql_query($sql); - - return $this->umil_end(); - } - - /** - * Version Checker - * - * Format the file like the following: - * http://www.phpbb.com/updatecheck/30x.txt - * - * @param string $url The url to access (ex: www.phpbb.com) - * @param string $path The path to access (ex: /updatecheck) - * @param string $file The name of the file to access (ex: 30x.txt) - * - * @return array|string Error Message if there was any error, or an array (each line in the file as a value) - */ - function version_check($url, $path, $file, $timeout = 10, $port = 80) - { - if (!function_exists('get_remote_file')) - { - global $phpbb_root_path, $phpEx; - - include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); - } - - $errstr = $errno = ''; - - $info = get_remote_file($url, $path, $file, $errstr, $errno, $port, $timeout); - - if ($info === false) - { - return $errstr . ' [ ' . $errno . ' ]'; - } - - $info = str_replace("\r\n", "\n", $info); - $info = explode("\n", $info); - - return $info; - } - - /** - * Create table SQL - * - * Create the SQL query for the specified DBMS on the fly from a create_schema_files type of table array - * - * @param string $table_name The name of the table - * @param array $table_data The table data (formatted in the array format used by create_schema_files) - * @param string $dbms The dbms this will be built for (for testing only, leave blank to use the current DBMS) - * - * @return The sql query to run for the submitted dbms to insert the table - */ - function create_table_sql($table_name, $table_data, $dbms = '') - { - // To allow testing - $dbms = ($dbms) ? $dbms : $this->db_tools->sql_layer; - - // A list of types being unsigned for better reference in some db's - $unsigned_types = array('UINT', 'UINT:', 'USINT', 'BOOL', 'TIMESTAMP'); - $supported_dbms = array('firebird', 'mssql', 'mysql_40', 'mysql_41', 'oracle', 'postgres', 'sqlite'); - - $sql = ''; - - // Create Table statement - $generator = $textimage = false; - - switch ($dbms) - { - case 'mysql_40': - case 'mysql_41': - case 'firebird': - case 'oracle': - case 'sqlite': - case 'postgres': - $sql .= "CREATE TABLE {$table_name} (\n"; - break; - - case 'mssql': - $sql .= "CREATE TABLE [{$table_name}] (\n"; - break; - } - - // Table specific so we don't get overlap - $modded_array = array(); - - // Write columns one by one... - foreach ($table_data['COLUMNS'] as $column_name => $column_data) - { - // Get type - if (strpos($column_data[0], ':') !== false) - { - list($orig_column_type, $column_length) = explode(':', $column_data[0]); - if (!is_array($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'])) - { - $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'], $column_length); - } - else - { - if (isset($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'])) - { - switch ($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'][0]) - { - case 'div': - $column_length /= $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'][1]; - $column_length = ceil($column_length); - $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length); - break; - } - } - - if (isset($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'])) - { - switch ($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][0]) - { - case 'mult': - $column_length *= $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][1]; - if ($column_length > $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][2]) - { - $column_type = $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][3]; - $modded_array[$column_name] = $column_type; - } - else - { - $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length); - } - break; - } - } - } - $orig_column_type .= ':'; - } - else - { - $orig_column_type = $column_data[0]; - $column_type = $this->db_tools->dbms_type_map[$dbms][$column_data[0]]; - if ($column_type == 'text' || $column_type == 'blob') - { - $modded_array[$column_name] = $column_type; - } - } - - // Adjust default value if db-dependant specified - if (is_array($column_data[1])) - { - $column_data[1] = (isset($column_data[1][$dbms])) ? $column_data[1][$dbms] : $column_data[1]['default']; - } - - switch ($dbms) - { - case 'mysql_40': - case 'mysql_41': - $sql .= "\t{$column_name} {$column_type} "; - - // For hexadecimal values do not use single quotes - if (!is_null($column_data[1]) && substr($column_type, -4) !== 'text' && substr($column_type, -4) !== 'blob') - { - $sql .= (strpos($column_data[1], '0x') === 0) ? "DEFAULT {$column_data[1]} " : "DEFAULT '{$column_data[1]}' "; - } - $sql .= 'NOT NULL'; - - if (isset($column_data[2])) - { - if ($column_data[2] == 'auto_increment') - { - $sql .= ' auto_increment'; - } - else if ($dbms === 'mysql_41' && $column_data[2] == 'true_sort') - { - $sql .= ' COLLATE utf8_unicode_ci'; - } - } - - $sql .= ",\n"; - break; - - case 'sqlite': - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $sql .= "\t{$column_name} INTEGER PRIMARY KEY "; - $generator = $column_name; - } - else - { - $sql .= "\t{$column_name} {$column_type} "; - } - - $sql .= 'NOT NULL '; - $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}'" : ''; - $sql .= ",\n"; - break; - - case 'firebird': - $sql .= "\t{$column_name} {$column_type} "; - - if (!is_null($column_data[1])) - { - $sql .= 'DEFAULT ' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ' '; - } - - $sql .= 'NOT NULL'; - - // This is a UNICODE column and thus should be given it's fair share - if (preg_match('/^X?STEXT_UNI|VCHAR_(CI|UNI:?)/', $column_data[0])) - { - $sql .= ' COLLATE UNICODE'; - } - - $sql .= ",\n"; - - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $generator = $column_name; - } - break; - - case 'mssql': - if ($column_type == '[text]') - { - $textimage = true; - } - - $sql .= "\t[{$column_name}] {$column_type} "; - - if (!is_null($column_data[1])) - { - // For hexadecimal values do not use single quotes - if (strpos($column_data[1], '0x') === 0) - { - $sql .= 'DEFAULT (' . $column_data[1] . ') '; - } - else - { - $sql .= 'DEFAULT (' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ') '; - } - } - - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $sql .= 'IDENTITY (1, 1) '; - } - - $sql .= 'NOT NULL'; - $sql .= " ,\n"; - break; - - case 'oracle': - $sql .= "\t{$column_name} {$column_type} "; - $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : ''; - - // In Oracle empty strings ('') are treated as NULL. - // Therefore in oracle we allow NULL's for all DEFAULT '' entries - $sql .= ($column_data[1] === '') ? ",\n" : "NOT NULL,\n"; - - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $generator = $column_name; - } - break; - - case 'postgres': - $sql .= "\t{$column_name} {$column_type} "; - - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $sql .= "DEFAULT nextval('{$table_name}_seq'),\n"; - - // Make sure the sequence will be created before creating the table - $sql = "CREATE SEQUENCE {$table_name}_seq;\n\n" . $sql; - } - else - { - $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : ''; - $sql .= "NOT NULL"; - - // Unsigned? Then add a CHECK contraint - if (in_array($orig_column_type, $unsigned_types)) - { - $sql .= " CHECK ({$column_name} >= 0)"; - } - - $sql .= ",\n"; - } - break; - } - } - - switch ($dbms) - { - case 'firebird': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n);;\n\n"; - break; - - case 'mssql': - $sql = substr($sql, 0, -2); - $sql .= "\n) ON [PRIMARY]" . (($textimage) ? ' TEXTIMAGE_ON [PRIMARY]' : '') . "\n"; - $sql .= "GO\n\n"; - break; - } - - // Write primary key - if (isset($table_data['PRIMARY_KEY'])) - { - if (!is_array($table_data['PRIMARY_KEY'])) - { - $table_data['PRIMARY_KEY'] = array($table_data['PRIMARY_KEY']); - } - - switch ($dbms) - { - case 'mysql_40': - case 'mysql_41': - case 'postgres': - $sql .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; - break; - - case 'firebird': - $sql .= "ALTER TABLE {$table_name} ADD PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . ");;\n\n"; - break; - - case 'sqlite': - if ($generator === false || !in_array($generator, $table_data['PRIMARY_KEY'])) - { - $sql .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; - } - break; - - case 'mssql': - $sql .= "ALTER TABLE [{$table_name}] WITH NOCHECK ADD \n"; - $sql .= "\tCONSTRAINT [PK_{$table_name}] PRIMARY KEY CLUSTERED \n"; - $sql .= "\t(\n"; - $sql .= "\t\t[" . implode("],\n\t\t[", $table_data['PRIMARY_KEY']) . "]\n"; - $sql .= "\t) ON [PRIMARY] \n"; - $sql .= "GO\n\n"; - break; - - case 'oracle': - $sql .= "\tCONSTRAINT pk_{$table_name} PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; - break; - } - } - - switch ($dbms) - { - case 'oracle': - // UNIQUE contrains to be added? - if (isset($table_data['KEYS'])) - { - foreach ($table_data['KEYS'] as $key_name => $key_data) - { - if (!is_array($key_data[1])) - { - $key_data[1] = array($key_data[1]); - } - - if ($key_data[0] == 'UNIQUE') - { - $sql .= "\tCONSTRAINT u_phpbb_{$key_name} UNIQUE (" . implode(', ', $key_data[1]) . "),\n"; - } - } - } - - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n)\n/\n\n"; - break; - - case 'postgres': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n);\n\n"; - break; - - case 'sqlite': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n);\n\n"; - break; - } - - // Write Keys - if (isset($table_data['KEYS'])) - { - foreach ($table_data['KEYS'] as $key_name => $key_data) - { - if (!is_array($key_data[1])) - { - $key_data[1] = array($key_data[1]); - } - - switch ($dbms) - { - case 'mysql_40': - case 'mysql_41': - $sql .= ($key_data[0] == 'INDEX') ? "\tKEY" : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? "\tUNIQUE" : ''; - foreach ($key_data[1] as $key => $col_name) - { - if (isset($modded_array[$col_name])) - { - switch ($modded_array[$col_name]) - { - case 'text': - case 'blob': - $key_data[1][$key] = $col_name . '(255)'; - break; - } - } - } - $sql .= ' ' . $key_name . ' (' . implode(', ', $key_data[1]) . "),\n"; - break; - - case 'firebird': - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; - - $sql .= ' ' . $table_name . '_' . $key_name . ' ON ' . $table_name . '(' . implode(', ', $key_data[1]) . ");;\n"; - break; - - case 'mssql': - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; - $sql .= " [{$key_name}] ON [{$table_name}]([" . implode('], [', $key_data[1]) . "]) ON [PRIMARY]\n"; - $sql .= "GO\n\n"; - break; - - case 'oracle': - if ($key_data[0] == 'UNIQUE') - { - continue; - } - - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - - $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ")\n"; - $sql .= "/\n"; - break; - - case 'sqlite': - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; - - $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n"; - break; - - case 'postgres': - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; - - $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n"; - break; - } - } - } - - switch ($dbms) - { - case 'mysql_40': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n);\n\n"; - break; - - case 'mysql_41': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n) CHARACTER SET utf8 COLLATE utf8_bin;\n\n"; - break; - - // Create Generator - case 'firebird': - if ($generator !== false) - { - $sql .= "\nCREATE GENERATOR {$table_name}_gen;;\n"; - $sql .= 'SET GENERATOR ' . $table_name . "_gen TO 0;;\n\n"; - - $sql .= 'CREATE TRIGGER t_' . $table_name . ' FOR ' . $table_name . "\n"; - $sql .= "BEFORE INSERT\nAS\nBEGIN\n"; - $sql .= "\tNEW.{$generator} = GEN_ID({$table_name}_gen, 1);\nEND;;\n\n"; - } - break; - - case 'oracle': - if ($generator !== false) - { - $sql .= "\nCREATE SEQUENCE {$table_name}_seq\n/\n\n"; - - $sql .= "CREATE OR REPLACE TRIGGER t_{$table_name}\n"; - $sql .= "BEFORE INSERT ON {$table_name}\n"; - $sql .= "FOR EACH ROW WHEN (\n"; - $sql .= "\tnew.{$generator} IS NULL OR new.{$generator} = 0\n"; - $sql .= ")\nBEGIN\n"; - $sql .= "\tSELECT {$table_name}_seq.nextval\n"; - $sql .= "\tINTO :new.{$generator}\n"; - $sql .= "\tFROM dual;\nEND;\n/\n\n"; - } - break; - } - - return $sql; - } - - /** - * Get the real table name - * By A_Jelly_Doughnut - * - * @param string $table_name The table name to get the real table name from - */ - function get_table_name(&$table_name) - { - // Use the global table prefix if a custom one is not specified - if ($this->table_prefix === false) - { - global $table_prefix; - } - else - { - $table_prefix = $this->table_prefix; - } - - static $constants = NULL; - - if (is_null($constants)) - { - $constants = get_defined_constants(); - } - - /** - * only do the replace if the table prefix is not already present - * this is required since UMIL supports specifying a table via phpbb_foo - * (where a replace would be needed) - * or by FOO_TABLE (where a replace is already done at constant-define time) - */ - if (!preg_match('#^' . preg_quote($table_prefix, '#') . '#', $table_name) || !in_array($table_name, $constants, true)) - { - $table_name = preg_replace('#^phpbb_#i', $table_prefix, $table_name); - } - } -} - -?> \ No newline at end of file diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 912a7b34ba..9f94273c63 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -45,10 +45,10 @@ class phpbb_db_migrator * @param string $phpbb_root_path * @param string $php_ext */ - function phpbb_db_migrator(&$db, &$db_tools, $table_prefix, $migrations_table, $phpbb_root_path, $php_ext) + function phpbb_db_migrator($db, $db_tools, $table_prefix, $migrations_table, $phpbb_root_path, $php_ext) { - $this->db = &$db; - $this->db_tools = &$db_tools; + $this->db = $db; + $this->db_tools = $db_tools; $this->table_prefix = $table_prefix; $this->migrations_table = $migrations_table; $this->migrations = array(); @@ -131,7 +131,7 @@ class phpbb_db_migrator return false; } - $migration =& new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); + $migration = new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); $state = (isset($this->migration_state[$name])) ? $this->migration_state[$name] : array( @@ -182,7 +182,7 @@ class phpbb_db_migrator return true; } - function process_data_step(&$migration) + function process_data_step($migration) { $continue = false; $steps = $migration->update_data(); @@ -199,7 +199,7 @@ class phpbb_db_migrator return $continue; } - function run_step(&$step) + function run_step($step) { } @@ -234,7 +234,7 @@ class phpbb_db_migrator return true; } - $migration =& new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); + $migration = new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); $depends = $migration->depends_on(); foreach ($depends as $depend) -- cgit v1.2.1 From 41de95bc11c0b64eafa294f03432f619d3d712d5 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 11 Nov 2012 12:12:05 +0100 Subject: [feature/migrations] Process migration steps and move to PHP5 code --- phpBB/includes/db/migration.php | 26 ++++----- phpBB/includes/db/migrator.php | 126 ++++++++++++++++++++++++++++++++++------ 2 files changed, 120 insertions(+), 32 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php index c98ac8728a..4e83d2570c 100644 --- a/phpBB/includes/db/migration.php +++ b/phpBB/includes/db/migration.php @@ -26,14 +26,14 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migration { - var $db; - var $db_tools; - var $table_prefix; + protected $db; + protected $db_tools; + protected $table_prefix; - var $phpbb_root_path; - var $php_ext; + protected $phpbb_root_path; + protected $php_ext; - var $errors; + protected $errors; /** * Migration constructor @@ -44,7 +44,7 @@ class phpbb_db_migration * @param string $phpbb_root_path * @param string $php_ext */ - function phpbb_db_migration($db, $db_tools, $table_prefix, $phpbb_root_path, $php_ext) + public function phpbb_db_migration($db, $db_tools, $table_prefix, $phpbb_root_path, $php_ext) { $this->db = $db; $this->db_tools = $db_tools; @@ -61,7 +61,7 @@ class phpbb_db_migration * * @return array An array of migration class names */ - function depends_on() + public function depends_on() { return array(); } @@ -71,24 +71,24 @@ class phpbb_db_migration * * @return array */ - function update_schema() + public function update_schema() { return array(); } /** - * Updates data + * Updates data by returning a list of instructions to be executed * - * @return null + * @return array */ - function update_data() + public function update_data() { } /** * Wrapper for running queries to generate user feedback on updates */ - function sql_query($sql) + protected function sql_query($sql) { if (defined('DEBUG_EXTRA')) { diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 9f94273c63..9187e09869 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -22,17 +22,17 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migrator { - var $db; - var $db_tools; - var $table_prefix; + protected $db; + protected $db_tools; + protected $table_prefix; - var $phpbb_root_path; - var $php_ext; + protected $phpbb_root_path; + protected $php_ext; - var $migrations_table; - var $migration_state; + protected $migrations_table; + protected $migration_state; - var $migrations; + protected $migrations; /** * Constructor of the database migrator @@ -45,7 +45,7 @@ class phpbb_db_migrator * @param string $phpbb_root_path * @param string $php_ext */ - function phpbb_db_migrator($db, $db_tools, $table_prefix, $migrations_table, $phpbb_root_path, $php_ext) + public function phpbb_db_migrator($db, $db_tools, $table_prefix, $migrations_table, $phpbb_root_path, $php_ext) { $this->db = $db; $this->db_tools = $db_tools; @@ -64,7 +64,7 @@ class phpbb_db_migrator * * @return null */ - function load_migration_state() + public function load_migration_state() { $sql = "SELECT * FROM " . $this->migrations_table; @@ -85,7 +85,7 @@ class phpbb_db_migrator * @param array $class_names An array of migration class names * @return null */ - function set_migrations($class_names) + public function set_migrations($class_names) { $this->migrations = $class_names; } @@ -98,7 +98,7 @@ class phpbb_db_migrator * * @return null */ - function update() + public function update() { foreach ($this->migrations as $name) { @@ -124,7 +124,7 @@ class phpbb_db_migrator * @param string The class name of the migration * @return bool Whether any update step was successfully run */ - function try_apply($name) + protected function try_apply($name) { if (!class_exists($name)) { @@ -182,7 +182,7 @@ class phpbb_db_migrator return true; } - function process_data_step($migration) + protected function process_data_step($migration) { $continue = false; $steps = $migration->update_data(); @@ -190,6 +190,7 @@ class phpbb_db_migrator foreach ($steps as $step) { $continue = $this->run_step($step); + if (!$continue) { return false; @@ -199,12 +200,99 @@ class phpbb_db_migrator return $continue; } - function run_step($step) + protected function run_step($step) { + try + { + $callable_and_parameters = $this->get_callable_from_step($step); + $callable = $callable_and_parameters[0]; + $parameters = $callable_and_parameters[1]; + + call_user_func_array($callable, $parameters); + + return false; + } + catch (phpbb_db_migration_exception $e) + { + echo $e;die(); + } + } + public function get_callable_from_step($step) + { + $type = $step[0]; + $parameters = $step[1]; + + $parts = explode('.', $type); + + $class = $parts[0]; + $method = false; + + if (isset($parts[1])) + { + $method = $parts[1]; + } + + switch ($class) + { + case 'if': + if (!isset($parameters[0])) + { + throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_MISSING_CONDITION', $step); + } + + if (!isset($parameters[1])) + { + throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_MISSING_STEP', $step); + } + + $condition = $parameters[0]; + $step = $parameters[1]; + + $callable_and_parameters = $this->get_callable_from_step($step); + $callable = $callable_and_parameters[0]; + $sub_parameters = $callable_and_parameters[1]; + return array( + function ($condition) use ($callable, $sub_parameters) { + return call_user_func_array($callable, $sub_parameters); + }, + array($condition) + ); + break; + case 'custom': + if (!is_callable($parameters[0])) + { + throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_CUSTOM_NOT_CALLABLE', $step); + } + + return array($parameters[0], array()); + break; + + default: + if (!$method) + { + throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_UNKNOWN_TYPE', $step); + } + + if (!isset($this->tools[$class])) + { + throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_UNDEFINED_TOOL', $step); + } + + if (!method_exists(get_class($this->tools[$class]), $method)) + { + throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_UNDEFINED_METHOD', $step); + } + + return array( + array($this->tools[$class], $method), + $parameters + ); + break; + } } - function insert_migration($name, $state) + protected function insert_migration($name, $state) { $migration_row = $state; $migration_row['migration_name'] = $name; @@ -222,7 +310,7 @@ class phpbb_db_migrator * @param string $name The class name of the migration * @return bool Whether the migration cannot be fulfilled */ - function unfulfillable($name) + public function unfulfillable($name) { if (isset($this->migration_state[$name])) { @@ -253,7 +341,7 @@ class phpbb_db_migrator * * @return bool Whether the migrations have been applied */ - function finished() + public function finished() { foreach ($this->migrations as $name) { @@ -279,7 +367,7 @@ class phpbb_db_migrator return true; } - function apply_schema_changes($schema_changes) + protected function apply_schema_changes($schema_changes) { $this->db_tools->perform_schema_changes($schema_changes); } -- cgit v1.2.1 From 6c44dadecbf50d6550f98dd1e1694519f39be680 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 8 Jan 2013 22:07:26 -0600 Subject: [feature/migrations] Move migrator to service container Version numbers 3.1 updates Restore database_update.php file to what it was in develop Get first forum to place global announcements in PHPBB3-9737 --- phpBB/includes/db/db_tools.php | 10 + phpBB/includes/db/migration.php | 20 +- phpBB/includes/db/migration/data/3_0_1.php | 3 + phpBB/includes/db/migration/data/3_0_10.php | 3 + phpBB/includes/db/migration/data/3_0_10_rc1.php | 2 + phpBB/includes/db/migration/data/3_0_10_rc2.php | 3 + phpBB/includes/db/migration/data/3_0_10_rc3.php | 3 + phpBB/includes/db/migration/data/3_0_11.php | 3 + phpBB/includes/db/migration/data/3_0_11_rc1.php | 2 + phpBB/includes/db/migration/data/3_0_11_rc2 | 31 --- phpBB/includes/db/migration/data/3_0_11_rc2.php | 34 +++ phpBB/includes/db/migration/data/3_0_12_rc1.php | 8 +- phpBB/includes/db/migration/data/3_0_1_rc1.php | 2 + phpBB/includes/db/migration/data/3_0_2.php | 3 + phpBB/includes/db/migration/data/3_0_2_rc1.php | 4 +- phpBB/includes/db/migration/data/3_0_2_rc2.php | 3 + phpBB/includes/db/migration/data/3_0_3.php | 5 +- phpBB/includes/db/migration/data/3_0_3_rc1.php | 2 + phpBB/includes/db/migration/data/3_0_4.php | 2 + phpBB/includes/db/migration/data/3_0_4_rc1.php | 2 + phpBB/includes/db/migration/data/3_0_5.php | 3 + .../includes/db/migration/data/3_0_5_rc1part2.php | 3 + phpBB/includes/db/migration/data/3_0_6.php | 3 + phpBB/includes/db/migration/data/3_0_6_rc1.php | 2 + phpBB/includes/db/migration/data/3_0_6_rc2.php | 3 + phpBB/includes/db/migration/data/3_0_6_rc3.php | 2 + phpBB/includes/db/migration/data/3_0_6_rc4.php | 3 + phpBB/includes/db/migration/data/3_0_7.php | 3 + phpBB/includes/db/migration/data/3_0_7_pl1.php | 3 + phpBB/includes/db/migration/data/3_0_7_rc1.php | 2 + phpBB/includes/db/migration/data/3_0_7_rc2.php | 2 + phpBB/includes/db/migration/data/3_0_8.php | 3 + phpBB/includes/db/migration/data/3_0_8_rc1.php | 2 + phpBB/includes/db/migration/data/3_0_9.php | 3 + phpBB/includes/db/migration/data/3_0_9_rc1.php | 2 + phpBB/includes/db/migration/data/3_0_9_rc2.php | 3 + phpBB/includes/db/migration/data/3_0_9_rc3.php | 3 + phpBB/includes/db/migration/data/3_0_9_rc4.php | 3 + phpBB/includes/db/migration/data/3_1_0_dev.php | 283 +++++++++++++++++++++ phpBB/includes/db/migration/data/extensions.php | 48 ++++ .../includes/db/migration/data/style_update_p1.php | 99 +++++++ .../includes/db/migration/data/style_update_p2.php | 83 ++++++ phpBB/includes/db/migration/data/timezone.php | 158 ++++++++++++ phpBB/includes/db/migration/tools/base.php | 47 ---- phpBB/includes/db/migration/tools/config.php | 26 +- phpBB/includes/db/migration/tools/module.php | 38 ++- phpBB/includes/db/migration/tools/permission.php | 26 +- phpBB/includes/db/migrator.php | 35 +-- phpBB/includes/update_helpers.php | 112 -------- 49 files changed, 906 insertions(+), 242 deletions(-) delete mode 100644 phpBB/includes/db/migration/data/3_0_11_rc2 create mode 100644 phpBB/includes/db/migration/data/3_0_11_rc2.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/db/migration/tools/base.php delete mode 100644 phpBB/includes/update_helpers.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index 2bb016cebd..5329d871c8 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -345,6 +345,16 @@ class phpbb_db_tools } } + /** + * Setter for {@link $return_statements return_statements}. + * + * @param bool $return_statements True if SQL should not be executed but returned as strings + */ + public function set_return_statements($return_statements) + { + $this->return_statements = $return_statements; + } + /** * Gets a list of tables in the database. * diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php index 4e83d2570c..1acef2d429 100644 --- a/phpBB/includes/db/migration.php +++ b/phpBB/includes/db/migration.php @@ -26,6 +26,7 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migration { + protected $config; protected $db; protected $db_tools; protected $table_prefix; @@ -38,20 +39,17 @@ class phpbb_db_migration /** * Migration constructor * - * @param dbal $db Connected database abstraction instance - * @param phpbb_db_tools $db_tools Instance of db schema manipulation tools - * @param string $table_prefix The prefix for all table names - * @param string $phpbb_root_path - * @param string $php_ext + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container Container supplying dependencies */ - public function phpbb_db_migration($db, $db_tools, $table_prefix, $phpbb_root_path, $php_ext) + public function phpbb_db_migration(\Symfony\Component\DependencyInjection\ContainerInterface $container) { - $this->db = $db; - $this->db_tools = $db_tools; - $this->table_prefix = $table_prefix; + $this->config = $this->container->get('config'); + $this->db = $this->container->get('dbal.conn'); + $this->db_tools = $this->container->get('dbal.tools'); + $this->table_prefix = $this->container->getParameters('core.table_prefix'); - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; + $this->phpbb_root_path = $this->container->getParameters('core.root_path'); + $this->php_ext = $this->container->getParameters('core.php_ext'); $this->errors = array(); } diff --git a/phpBB/includes/db/migration/data/3_0_1.php b/phpBB/includes/db/migration/data/3_0_1.php index 294db3d946..a2332c9b59 100644 --- a/phpBB/includes/db/migration/data/3_0_1.php +++ b/phpBB/includes/db/migration/data/3_0_1.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_1 extends phpbb_db_migration 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 6d39969d48..07410c5ba1 100644 --- a/phpBB/includes/db/migration/data/3_0_10.php +++ b/phpBB/includes/db/migration/data/3_0_10.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_10 extends phpbb_db_migration 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 06105c5b0d..daac50a631 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc1.php @@ -23,6 +23,8 @@ class phpbb_db_migration_data_3_0_10_rc1 extends phpbb_db_migration { 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 index 04161caf28..234e4c5fc7 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc2.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_10_rc2 extends phpbb_db_migration 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 539f0b8fec..075ce35e3e 100644 --- a/phpBB/includes/db/migration/data/3_0_10_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_10_rc3.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_10_rc3 extends phpbb_db_migration 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 3404272ef9..0bc9b6c4a5 100644 --- a/phpBB/includes/db/migration/data/3_0_11.php +++ b/phpBB/includes/db/migration/data/3_0_11.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_11 extends phpbb_db_migration 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 f44226df02..1509120f68 100644 --- a/phpBB/includes/db/migration/data/3_0_11_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_11_rc1.php @@ -24,6 +24,8 @@ class phpbb_db_migration_data_3_0_11_rc1 extends phpbb_db_migration 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')), ); } diff --git a/phpBB/includes/db/migration/data/3_0_11_rc2 b/phpBB/includes/db/migration/data/3_0_11_rc2 deleted file mode 100644 index 6add980c73..0000000000 --- a/phpBB/includes/db/migration/data/3_0_11_rc2 +++ /dev/null @@ -1,31 +0,0 @@ - array( - $this->table_prefix . 'profile_fields' => array( - 'field_show_novalue' => array('BOOL', 0), - ), - ), - ); - } - - function update_data() - { - } -} 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 index 734a57ecee..e5ff8c5814 100644 --- a/phpBB/includes/db/migration/data/3_0_12_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_12_rc1.php @@ -7,6 +7,9 @@ * */ +/** @todo DROP LOGIN_ATTEMPT_TABLE.attempt_id in 3.0.12-RC1 **/ + +/* class phpbb_db_migration_data_3_0_12_rc1 extends phpbb_db_migration { function depends_on() @@ -16,11 +19,14 @@ class phpbb_db_migration_data_3_0_12_rc1 extends phpbb_db_migration function update_schema() { - /** @todo DROP LOGIN_ATTEMPT_TABLE.attempt_id in 3.0.12-RC1 */ return array(); } function update_data() { + return array( + array('config.update', array('version', '3.0.12-rc1')), + ); } } +*/ \ No newline at end of file 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 1a696e0003..a3b4810d21 100644 --- a/phpBB/includes/db/migration/data/3_0_1_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_1_rc1.php @@ -44,6 +44,8 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration 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')), ); } diff --git a/phpBB/includes/db/migration/data/3_0_2.php b/phpBB/includes/db/migration/data/3_0_2.php index a5f94e644b..3469d8d178 100644 --- a/phpBB/includes/db/migration/data/3_0_2.php +++ b/phpBB/includes/db/migration/data/3_0_2.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_2 extends phpbb_db_migration 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 1b4d3bc2b8..d3c2200f14 100644 --- a/phpBB/includes/db/migration/data/3_0_2_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_2_rc1.php @@ -7,7 +7,7 @@ * */ -class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration +class phpbb_db_migration_data_3_0_2_rc1 extends phpbb_db_migration { function depends_on() { @@ -25,6 +25,8 @@ class phpbb_db_migration_data_3_0_1_rc1 extends phpbb_db_migration 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 index 9ddeb60a14..67fd1faec6 100644 --- a/phpBB/includes/db/migration/data/3_0_2_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_2_rc2.php @@ -48,5 +48,8 @@ class phpbb_db_migration_data_3_0_2_rc2 extends phpbb_db_migration 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 f989eea025..dff375f438 100644 --- a/phpBB/includes/db/migration/data/3_0_3.php +++ b/phpBB/includes/db/migration/data/3_0_3.php @@ -11,7 +11,7 @@ class phpbb_db_migration_data_3_0_3 extends phpbb_db_migration { function depends_on() { - return array('phpbb_db_migration_data_3_0_2_rc2'); + return array('phpbb_db_migration_data_3_0_3_rc1'); } function update_schema() @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_3 extends phpbb_db_migration 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 737eab4bd3..d5c110eb7d 100644 --- a/phpBB/includes/db/migration/data/3_0_3_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_3_rc1.php @@ -39,6 +39,8 @@ class phpbb_db_migration_data_3_0_3_rc1 extends phpbb_db_migration array('config.add', array('dbms_version', '')), array('permission.add', array('u_masspm_group', phpbb_auth::IS_GLOBAL), array('custom', array(array(&$this, 'correct_acp_email_permissions'))), + + array('config.update', array('version', '3.0.3-rc1')), )); } diff --git a/phpBB/includes/db/migration/data/3_0_4.php b/phpBB/includes/db/migration/data/3_0_4.php index cd34fda9ab..4965ac38d0 100644 --- a/phpBB/includes/db/migration/data/3_0_4.php +++ b/phpBB/includes/db/migration/data/3_0_4.php @@ -23,6 +23,8 @@ class phpbb_db_migration_data_3_0_4 extends phpbb_db_migration { return array( array('custom', array(array(&$this, 'rename_log_delete_topic'))), + + array('config.update', array('version', '3.0.4')), ); } 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 342f1fa910..2964dcebc9 100644 --- a/phpBB/includes/db/migration/data/3_0_4_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_4_rc1.php @@ -59,6 +59,8 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration { return array( array('custom', array(array(&$this, 'update_custom_profile_fields'))), + + array('config.update', array('version', '3.0.4-rc1')), ); } diff --git a/phpBB/includes/db/migration/data/3_0_5.php b/phpBB/includes/db/migration/data/3_0_5.php index 5671832a82..2f80970781 100644 --- a/phpBB/includes/db/migration/data/3_0_5.php +++ b/phpBB/includes/db/migration/data/3_0_5.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_5 extends phpbb_db_migration function update_data() { + return array( + array('config.update', array('version', '3.0.5')), + ); } } 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 6be8ea9845..1fab0f8873 100644 --- a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php +++ b/phpBB/includes/db/migration/data/3_0_5_rc1part2.php @@ -30,5 +30,8 @@ class phpbb_db_migration_data_3_0_5_rc1part2 extends phpbb_db_migration 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 c2cb59e62a..26176b9437 100644 --- a/phpBB/includes/db/migration/data/3_0_6.php +++ b/phpBB/includes/db/migration/data/3_0_6.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_6 extends phpbb_db_migration 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 eefdc1692d..a868d70684 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc1.php @@ -155,6 +155,8 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration )), 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')), ); } 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 07b31a53b9..4092a5fa61 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc2.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_6_rc2 extends phpbb_db_migration 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 c19a792bad..ec22d1da77 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc3.php @@ -23,6 +23,8 @@ class phpbb_db_migration_data_3_0_6_rc3 extends phpbb_db_migration { return array( array('custom', array(array(&$this, 'update_cp_fields'))), + + array('config.update', array('version', '3.0.6-rc3')), ); } 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 c48b1ca394..e748c7a4ff 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc4.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc4.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_6_rc4 extends phpbb_db_migration 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 05781b7b49..f27b56f778 100644 --- a/phpBB/includes/db/migration/data/3_0_7.php +++ b/phpBB/includes/db/migration/data/3_0_7.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_7 extends phpbb_db_migration 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 cee7a91a2e..5543d6437a 100644 --- a/phpBB/includes/db/migration/data/3_0_7_pl1.php +++ b/phpBB/includes/db/migration/data/3_0_7_pl1.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_7_pl1 extends phpbb_db_migration 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 b2d49cce63..71584382e8 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc1.php @@ -38,6 +38,8 @@ class phpbb_db_migration_data_3_0_7_rc1 extends phpbb_db_migration 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')), ); } 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 8a751328bf..e043f35705 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc2.php @@ -23,6 +23,8 @@ class phpbb_db_migration_data_3_0_7_rc2 extends phpbb_db_migration { return array( array('custom', array(array(&$this, 'update_email_hash'))), + + array('config.update', array('version', '3.0.7-rc2')), ); } diff --git a/phpBB/includes/db/migration/data/3_0_8.php b/phpBB/includes/db/migration/data/3_0_8.php index a714a3d2f6..a5defc8278 100644 --- a/phpBB/includes/db/migration/data/3_0_8.php +++ b/phpBB/includes/db/migration/data/3_0_8.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_8 extends phpbb_db_migration 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 73838d9d29..3f51806fd9 100644 --- a/phpBB/includes/db/migration/data/3_0_8_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_8_rc1.php @@ -37,6 +37,8 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration 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')), ); } diff --git a/phpBB/includes/db/migration/data/3_0_9.php b/phpBB/includes/db/migration/data/3_0_9.php index 4b2c08a256..eb359e2697 100644 --- a/phpBB/includes/db/migration/data/3_0_9.php +++ b/phpBB/includes/db/migration/data/3_0_9.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_9 extends phpbb_db_migration 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 98d3a26481..256426849c 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc1.php @@ -59,6 +59,8 @@ class phpbb_db_migration_data_3_0_9_rc1 extends phpbb_db_migration 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')), ); } 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 589047670a..e3c4716665 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc2.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_9_rc2 extends phpbb_db_migration 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 06061cbcb6..3cdecb96ae 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc3.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc3.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_9_rc3 extends phpbb_db_migration 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 04b3ae4b39..c2a92e618a 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc4.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc4.php @@ -21,5 +21,8 @@ class phpbb_db_migration_data_3_0_9_rc4 extends phpbb_db_migration 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 new file mode 100644 index 0000000000..987ab94646 --- /dev/null +++ b/phpBB/includes/db/migration/data/3_1_0_dev.php @@ -0,0 +1,283 @@ + 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('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( + 'acp', + 'UCP_PROFILE', + array( + 'module_basename' => 'ucp_profile', + 'modes' => array('autologin_keys'), + ), + )), + + array('module.remove', array( + 'acp', + 'ACP_CAT_STYLES', + array( + 'module_basename' => 'styles', + 'modes' => array('imageset', 'theme', 'template'), + ), + )), + + array('custom', array(array($this, 'rename_module_basenames'))), + array('custom', array(array($this, 'add_group_teampage'))), + array('custom', array(array($this, 'update_group_legend'))), + array('custom', array(array($this, 'localise_global_announcements'))), + ); + } + + 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..85d5511ef0 --- /dev/null +++ b/phpBB/includes/db/migration/data/extensions.php @@ -0,0 +1,48 @@ + 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( + array('module.add', array( + 'acp', + 'ACP_GENERAL_TASKS', + array( + 'module_basename' => 'extensions', + 'modes' => array('main'), + ), + )), + ); + } +} 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..d570caae04 --- /dev/null +++ b/phpBB/includes/db/migration/data/style_update_p1.php @@ -0,0 +1,99 @@ +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'], $errored, $error_ary); + $valid_styles[] = (int) $style_row['style_id']; + } + } + } +} 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..2c0991de59 --- /dev/null +++ b/phpBB/includes/db/migration/data/style_update_p2.php @@ -0,0 +1,83 @@ + 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( + array('custom', array(array($this, 'styles_update'))), + ); + } + + public function styles_update() + { + // 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 = 'INSERT INTO ' . STYLES_TABLE . " (style_name, style_copyright, style_active, style_path, bbcode_bitfield, style_parent_id, style_parent_tree) VALUES ('prosilver', '© phpBB Group', 1, 'prosilver', 'kNg=', 0, '')"; + $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), $errored, $error_ary); + + // Change default style + if (!in_array($config['default_style'], $valid_styles)) + { + set_config('default_style', $valid_styles[0]); + } + + // 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), $errored, $error_ary); + } + } +} diff --git a/phpBB/includes/db/migration/data/timezone.php b/phpBB/includes/db/migration/data/timezone.php new file mode 100644 index 0000000000..89fafbad28 --- /dev/null +++ b/phpBB/includes/db/migration/data/timezone.php @@ -0,0 +1,158 @@ + 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 + set_config('board_timezone', $this->convert_phpbb30_timezone($config['board_timezone'], $config['board_dst'])); + + // 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/db/migration/tools/base.php b/phpBB/includes/db/migration/tools/base.php deleted file mode 100644 index 61116d8b55..0000000000 --- a/phpBB/includes/db/migration/tools/base.php +++ /dev/null @@ -1,47 +0,0 @@ -db = $db; - $this->cache = $cache; - $this->template = $template; - $this->user = $user; - $this->auth = $auth; - $this->config = $config; - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - } -} \ No newline at end of file diff --git a/phpBB/includes/db/migration/tools/config.php b/phpBB/includes/db/migration/tools/config.php index 965ba1d136..2d58c8093c 100644 --- a/phpBB/includes/db/migration/tools/config.php +++ b/phpBB/includes/db/migration/tools/config.php @@ -7,20 +7,14 @@ * */ -class phpbb_db_migration_tools_config extends phpbb_db_migration_tools_base +class phpbb_db_migration_tools_config { - /** - * Config Exists - * - * This function is to check to see if a config variable exists or if it does not. - * - * @param string $config_name The name of the config setting you wish to check for. - * - * @return bool true/false if config exists - */ - public function exists($config_name) + /** @var phpbb_config */ + protected $config = null; + + public function __construct(phpbb_config $config) { - return (bool) $this->config->offsetExists($config_name); + $this->config = $config; } /** @@ -34,7 +28,7 @@ class phpbb_db_migration_tools_config extends phpbb_db_migration_tools_base */ public function add($config_name, $config_value = '', $is_dynamic = false) { - if ($this->config_exists($config_name)) + if (isset($this->config[$config_name])) { throw new phpbb_db_migration_exception('CONFIG_ALREADY_EXISTS', $config_name); } @@ -54,7 +48,7 @@ class phpbb_db_migration_tools_config extends phpbb_db_migration_tools_base */ public function update($config_name, $config_value = '') { - if (!$this->config_exists($config_name)) + if (!isset($this->config[$config_name])) { throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); } @@ -75,7 +69,7 @@ class phpbb_db_migration_tools_config extends phpbb_db_migration_tools_base */ public function update_if_equals($compare, $config_name, $config_value = '') { - if (!$this->config_exists($config_name)) + if (!isset($this->config[$config_name])) { throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); } @@ -94,7 +88,7 @@ class phpbb_db_migration_tools_config extends phpbb_db_migration_tools_base */ public function remove($config_name) { - if (!$this->config_exists($config_name)) + if (!isset($this->config[$config_name])) { throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); } diff --git a/phpBB/includes/db/migration/tools/module.php b/phpBB/includes/db/migration/tools/module.php index df1912a022..e17197d73e 100644 --- a/phpBB/includes/db/migration/tools/module.php +++ b/phpBB/includes/db/migration/tools/module.php @@ -7,8 +7,32 @@ * */ -class phpbb_db_migration_tools_module extends phpbb_db_migration_tools_base +class phpbb_db_migration_tools_module { + /** @var phpbb_cache_service */ + protected $cache = null; + + /** @var dbal */ + protected $db = null; + + /** @var phpbb_user */ + protected $user = null; + + /** @var string */ + protected $phpbb_root_path = null; + + /** @var string */ + protected $php_ext = null; + + public function __construct(dbal $db, phpbb_cache_driver_interface $cache, $user, $phpbb_root_path, $php_ext) + { + $this->db = $db; + $this->cache = $cache; + $this->user = $user; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + /** * Module Exists * @@ -117,11 +141,15 @@ class phpbb_db_migration_tools_module extends phpbb_db_migration_tools_base if (!isset($data['module_langname'])) { + /** + * @TODO does not work with 3.1 modules yet, but must continue for old 3.0 versions for + * upgrades from a 3.0.x version to 3.1 + */ // The "automatic" way $basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; $basename = str_replace(array('/', '\\'), '', $basename); $class = str_replace(array('/', '\\'), '', $class); - $info_file = "$class/info/{$class}_$basename.$this->phpEx"; + $info_file = "$class/info/{$class}_$basename.{$this->php_ext}"; // The manual and automatic ways both failed... if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file)) @@ -196,7 +224,7 @@ class phpbb_db_migration_tools_module extends phpbb_db_migration_tools_base if (!class_exists('acp_modules')) { - include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->phpEx); + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); $this->user->add_lang('acp/modules'); } $acp_modules = new acp_modules(); @@ -302,7 +330,7 @@ class phpbb_db_migration_tools_module extends phpbb_db_migration_tools_base // Automatic method $basename = str_replace(array('/', '\\'), '', $module['module_basename']); $class = str_replace(array('/', '\\'), '', $class); - $info_file = "$class/info/{$class}_$basename.$this->phpEx"; + $info_file = "$class/info/{$class}_$basename.{$this->php_ext}"; if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file)) { @@ -396,7 +424,7 @@ class phpbb_db_migration_tools_module extends phpbb_db_migration_tools_base if (!class_exists('acp_modules')) { - include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->phpEx); + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); $this->user->add_lang('acp/modules'); } $acp_modules = new acp_modules(); diff --git a/phpBB/includes/db/migration/tools/permission.php b/phpBB/includes/db/migration/tools/permission.php index 3fbe7c649c..7694bae0cb 100644 --- a/phpBB/includes/db/migration/tools/permission.php +++ b/phpBB/includes/db/migration/tools/permission.php @@ -9,6 +9,30 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base { + /** @var phpbb_auth */ + protected $auth = null; + + /** @var phpbb_cache_service */ + protected $cache = null; + + /** @var dbal */ + protected $db = null; + + /** @var string */ + protected $phpbb_root_path = null; + + /** @var string */ + protected $php_ext = null; + + public function __construct(dbal $db, phpbb_cache_driver_interface $cache, phpbb_auth $auth, $phpbb_root_path, $php_ext) + { + $this->db = $db; + $this->cache = $cache; + $this->auth = $auth; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + /** * Permission Exists * @@ -69,7 +93,7 @@ class phpbb_db_migration_tools_permission extends phpbb_db_migration_tools_base if (!class_exists('auth_admin')) { - include($this->phpbb_root_path . 'includes/acp/auth.' . $this->phpEx); + include($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext); } $auth_admin = new auth_admin(); diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 9187e09869..c9590fccf6 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -22,6 +22,7 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migrator { + protected $container; protected $db; protected $db_tools; protected $table_prefix; @@ -37,24 +38,26 @@ class phpbb_db_migrator /** * Constructor of the database migrator * - * @param dbal $db Connected database abstraction instance - * @param phpbb_db_tools $db_tools Instance of db schema manipulation tools - * @param string $table_prefix The prefix for all table names - * @param string $migrations_table The name of the db table storing - * information on applied migrations - * @param string $phpbb_root_path - * @param string $php_ext + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container Container supplying dependencies */ - public function phpbb_db_migrator($db, $db_tools, $table_prefix, $migrations_table, $phpbb_root_path, $php_ext) + public function phpbb_db_migrator(\Symfony\Component\DependencyInjection\ContainerInterface $container, $migrations) { - $this->db = $db; - $this->db_tools = $db_tools; - $this->table_prefix = $table_prefix; - $this->migrations_table = $migrations_table; - $this->migrations = array(); - - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; + $this->container = $container; + $this->db = $this->container->get('dbal.conn'); + $this->db_tools = $this->container->get('dbal.tools'); + $this->table_prefix = $this->container->getParameters('core.table_prefix'); + $this->migrations_table = $this->container->getParameters('tables.migrations'); + $this->migrations = $migrations; + + $this->phpbb_root_path = $this->container->getParameters('core.root_path'); + $this->php_ext = $this->container->getParameters('core.php_ext'); + + /** @todo replace with collection_pass when merged */ + $this->tools = array( + 'config' => new phpbb_db_migration_tools_config, + 'module' => new phpbb_db_migration_tools_module, + 'permission' => new phpbb_db_migration_tools_permission, + ); $this->load_migration_state(); } 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: Mon, 12 Nov 2012 16:41:02 -0500 Subject: [feature/migrations] Update phpbb_db_migration class for PHP 5.3.3 PHPBB3-9737 --- phpBB/includes/db/migration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php index 1acef2d429..fb030ded44 100644 --- a/phpBB/includes/db/migration.php +++ b/phpBB/includes/db/migration.php @@ -24,7 +24,7 @@ if (!defined('IN_PHPBB')) * * @package db */ -class phpbb_db_migration +abstract class phpbb_db_migration { protected $config; protected $db; @@ -88,7 +88,7 @@ class phpbb_db_migration */ protected function sql_query($sql) { - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { echo "
\n{$sql}\n
"; } -- cgit v1.2.1 From 61debcf14ca14afbb503b2535ef392a75002e8ae Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 12 Nov 2012 16:46:19 -0500 Subject: [feature/migrations] Update phpbb_db_migrator class for PHP 5.3.3 PHPBB3-9737 --- 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 c9590fccf6..216faf9866 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -40,7 +40,7 @@ class phpbb_db_migrator * * @param \Symfony\Component\DependencyInjection\ContainerInterface $container Container supplying dependencies */ - public function phpbb_db_migrator(\Symfony\Component\DependencyInjection\ContainerInterface $container, $migrations) + public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container, $migrations) { $this->container = $container; $this->db = $this->container->get('dbal.conn'); -- cgit v1.2.1 From 826607a40509d40ba5a85e5b0bc72a54f77d41d6 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 12 Nov 2012 16:54:10 -0500 Subject: [feature/migrations] Add method and property visibility, use __construct() PHPBB3-9737 --- phpBB/includes/db/migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php index fb030ded44..10f7b71551 100644 --- a/phpBB/includes/db/migration.php +++ b/phpBB/includes/db/migration.php @@ -41,7 +41,7 @@ abstract class phpbb_db_migration * * @param \Symfony\Component\DependencyInjection\ContainerInterface $container Container supplying dependencies */ - public function phpbb_db_migration(\Symfony\Component\DependencyInjection\ContainerInterface $container) + public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container) { $this->config = $this->container->get('config'); $this->db = $this->container->get('dbal.conn'); -- cgit v1.2.1 From 5c91e2569cb3a400acd20bf06cc0e609dd63a778 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 8 Jan 2013 22:09:14 -0600 Subject: [feature/migrations] Migrations now somewhat works PHPBB3-9737 --- phpBB/includes/db/driver/mysqli.php | 1 + phpBB/includes/db/migration.php | 122 - phpBB/includes/db/migration/data/3_0_11_rc1.php | 2 +- phpBB/includes/db/migration/data/3_0_12_rc1.php | 101 +- phpBB/includes/db/migration/data/3_0_3_rc1.php | 6 +- phpBB/includes/db/migration/data/3_0_4.php | 2 +- phpBB/includes/db/migration/data/3_0_4_rc1.php | 4 +- phpBB/includes/db/migration/data/3_0_5_rc1.php | 8 +- phpBB/includes/db/migration/data/3_0_6_rc1.php | 60 +- phpBB/includes/db/migration/data/3_0_7_rc2.php | 2 +- phpBB/includes/db/migration/data/3_0_8_rc1.php | 10 +- phpBB/includes/db/migration/data/3_0_9_rc1.php | 2 +- phpBB/includes/db/migration/data/3_1_0_dev.php | 100 +- phpBB/includes/db/migration/data/extensions.php | 3 +- .../includes/db/migration/data/style_update_p1.php | 62 +- .../includes/db/migration/data/style_update_p2.php | 43 +- phpBB/includes/db/migration/data/timezone.php | 5 +- phpBB/includes/db/migration/exception.php | 40 + phpBB/includes/db/migration/migration.php | 129 + phpBB/includes/db/migration/tool/config.php | 108 + phpBB/includes/db/migration/tool/interface.php | 18 + phpBB/includes/db/migration/tool/module.php | 471 +++ phpBB/includes/db/migration/tool/permission.php | 562 ++++ phpBB/includes/db/migration/tools/config.php | 100 - phpBB/includes/db/migration/tools/module.php | 447 --- phpBB/includes/db/migration/tools/permission.php | 504 ---- phpBB/includes/db/migration/tools/umil.php | 3037 -------------------- phpBB/includes/db/migrator.php | 113 +- phpBB/includes/functions.php | 3 +- 29 files changed, 1705 insertions(+), 4360 deletions(-) delete mode 100644 phpBB/includes/db/migration.php create mode 100644 phpBB/includes/db/migration/exception.php create mode 100644 phpBB/includes/db/migration/migration.php create mode 100644 phpBB/includes/db/migration/tool/config.php create mode 100644 phpBB/includes/db/migration/tool/interface.php create mode 100644 phpBB/includes/db/migration/tool/module.php create mode 100644 phpBB/includes/db/migration/tool/permission.php delete mode 100644 phpBB/includes/db/migration/tools/config.php delete mode 100644 phpBB/includes/db/migration/tools/module.php delete mode 100644 phpBB/includes/db/migration/tools/permission.php delete mode 100644 phpBB/includes/db/migration/tools/umil.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/driver/mysqli.php b/phpBB/includes/db/driver/mysqli.php index 7448bf1670..94921a22b7 100644 --- a/phpBB/includes/db/driver/mysqli.php +++ b/phpBB/includes/db/driver/mysqli.php @@ -24,6 +24,7 @@ if (!defined('IN_PHPBB')) class phpbb_db_driver_mysqli extends phpbb_db_driver { var $multi_insert = true; + var $connect_error = ''; /** diff --git a/phpBB/includes/db/migration.php b/phpBB/includes/db/migration.php deleted file mode 100644 index 10f7b71551..0000000000 --- a/phpBB/includes/db/migration.php +++ /dev/null @@ -1,122 +0,0 @@ -config = $this->container->get('config'); - $this->db = $this->container->get('dbal.conn'); - $this->db_tools = $this->container->get('dbal.tools'); - $this->table_prefix = $this->container->getParameters('core.table_prefix'); - - $this->phpbb_root_path = $this->container->getParameters('core.root_path'); - $this->php_ext = $this->container->getParameters('core.php_ext'); - - $this->errors = array(); - } - - /** - * Defines other migrationsto be applied first (abstract method) - * - * @return array An array of migration class names - */ - public function depends_on() - { - return array(); - } - - /** - * Updates the database schema by providing a set of change instructions - * - * @return array - */ - public function update_schema() - { - return array(); - } - - /** - * Updates data by returning a list of instructions to be executed - * - * @return array - */ - public function update_data() - { - } - - /** - * Wrapper for running queries to generate user feedback on updates - */ - protected function sql_query($sql) - { - if (defined('DEBUG')) - { - echo "
\n{$sql}\n
"; - } - - $this->db->sql_return_on_error(true); - - if ($sql === 'begin') - { - $result = $this->db->sql_transaction('begin'); - } - else if ($sql === 'commit') - { - $result = $this->db->sql_transaction('commit'); - } - else - { - $result = $this->db->sql_query($sql); - if ($this->db->sql_error_triggered) - { - $this->errors[] = array( - 'sql' => $this->db->sql_error_sql, - 'code' => $this->db->sql_error_returned, - ); - } - } - - $this->db->sql_return_on_error(false); - - return $result; - } -} 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 1509120f68..daf106accf 100644 --- a/phpBB/includes/db/migration/data/3_0_11_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_11_rc1.php @@ -80,7 +80,7 @@ class phpbb_db_migration_data_3_0_11_rc1 extends phpbb_db_migration { $delete_pms[] = (int) $row['msg_id']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if (!empty($delete_pms)) { 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 e5ff8c5814..0d8702f19e 100644 --- a/phpBB/includes/db/migration/data/3_0_12_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_12_rc1.php @@ -9,24 +9,115 @@ /** @todo DROP LOGIN_ATTEMPT_TABLE.attempt_id in 3.0.12-RC1 **/ -/* class phpbb_db_migration_data_3_0_12_rc1 extends phpbb_db_migration { - function depends_on() + public function depends_on() { return array('phpbb_db_migration_data_3_0_11'); } - function update_schema() + public function update_schema() { return array(); } - function update_data() + 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); + } + } + } + } } -*/ \ No newline at end of file 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 d5c110eb7d..2320c4ac4b 100644 --- a/phpBB/includes/db/migration/data/3_0_3_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_3_rc1.php @@ -36,12 +36,12 @@ class phpbb_db_migration_data_3_0_3_rc1 extends phpbb_db_migration 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', '')), - array('permission.add', array('u_masspm_group', phpbb_auth::IS_GLOBAL), + 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() diff --git a/phpBB/includes/db/migration/data/3_0_4.php b/phpBB/includes/db/migration/data/3_0_4.php index 4965ac38d0..1af4508331 100644 --- a/phpBB/includes/db/migration/data/3_0_4.php +++ b/phpBB/includes/db/migration/data/3_0_4.php @@ -30,7 +30,7 @@ class phpbb_db_migration_data_3_0_4 extends phpbb_db_migration function rename_log_delete_topic() { - if ($db->sql_layer == 'oracle') + if ($this->db->sql_layer == 'oracle') { // log_operation is CLOB - but we can change this later $sql = 'UPDATE ' . $this->table_prefix . "log 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 2964dcebc9..e9bb0e01f5 100644 --- a/phpBB/includes/db/migration/data/3_0_4_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_4_rc1.php @@ -69,7 +69,7 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration // 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->sql_query($sql); + $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { @@ -101,5 +101,7 @@ class phpbb_db_migration_data_3_0_4_rc1 extends phpbb_db_migration $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_rc1.php b/phpBB/includes/db/migration/data/3_0_5_rc1.php index 9205f0d5f8..cbf28c0be6 100644 --- a/phpBB/includes/db/migration/data/3_0_5_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_5_rc1.php @@ -32,7 +32,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration 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_refresh', 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')), @@ -47,7 +47,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration $sql = 'SELECT user_id, user_password FROM ' . $this->table_prefix . 'users WHERE user_pass_convert = 1'; - $result = $this->sql_query($sql); + $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { @@ -60,7 +60,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration $this->sql_query('UPDATE ' . $this->table_prefix . 'users SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $row['user_id']); } } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); } function update_ichiro_bot() @@ -99,7 +99,7 @@ class phpbb_db_migration_data_3_0_5_rc1 extends phpbb_db_migration 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->sql_query($sql); + $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); 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 a868d70684..35adcf52be 100644 --- a/phpBB/includes/db/migration/data/3_0_6_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_6_rc1.php @@ -35,7 +35,7 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration $this->table_prefix . 'reports' => array( 'pm_id' => array('UINT', 0), ), - $this->table_prefix . 'fields' => array( + $this->table_prefix . 'profile_fields' => array( 'field_show_on_vt' => array('BOOL', 0), ), $this->table_prefix . 'forums' => array( @@ -89,19 +89,19 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration 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.add', array('allow_avatar', 1)), + 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.add', array('allow_avatar_remote_upload', 1)), + array('config.update', array('allow_avatar_remote_upload', 1)), )), array('module.add', array( 'acp', 'ACP_BOARD_CONFIGURATION', array( - 'module_basename' => 'board', + 'module_basename' => 'acp_board', 'modes' => array('feed'), ), )), @@ -109,7 +109,7 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration 'acp', 'ACP_CAT_USERS', array( - 'module_basename' => 'users', + 'module_basename' => 'acp_users', 'modes' => array('warnings'), ), )), @@ -117,7 +117,7 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration 'acp', 'ACP_SERVER_CONFIGURATION', array( - 'module_basename' => 'send_statistics', + 'module_basename' => 'acp_send_statistics', 'modes' => array('send_statistics'), ), )), @@ -125,7 +125,7 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration 'acp', 'ACP_FORUM_BASED_PERMISSIONS', array( - 'module_basename' => 'permissions', + 'module_basename' => 'acp_permissions', 'modes' => array('setting_forum_copy'), ), )), @@ -133,24 +133,8 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration 'mcp', 'MCP_REPORTS', array( - 'module_basename' => 'pm_reports', - 'modes' => array('pm_reports'), - ), - )), - array('module.add', array( - 'mcp', - 'MCP_REPORTS', - array( - 'module_basename' => 'pm_reports', - 'modes' => array('pm_reports_closed'), - ), - )), - array('module.add', array( - 'mcp', - 'MCP_REPORTS', - array( - 'module_basename' => 'pm_reports', - 'modes' => array('pm_report_details'), + 'module_basename' => 'mcp_pm_reports', + 'modes' => array('pm_reports','pm_reports_closed','pm_report_details'), ), )), array('custom', array(array(&$this, 'add_newly_registered_group'))), @@ -209,17 +193,14 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration $this->sql_query($sql); $u_role = $this->db->sql_nextid(); - if (!$errored) - { - // 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); + // 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); - } + // 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 @@ -246,11 +227,8 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration $this->sql_query($sql); $f_role = $this->db->sql_nextid(); - if (!$errored) - { - $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); - } + $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) @@ -294,7 +272,7 @@ class phpbb_db_migration_data_3_0_6_rc1 extends phpbb_db_migration } // Clear permissions... - include_once($this->phpbb_root_path . 'includes/acp/auth.' . $this->phpEx); + 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_7_rc2.php b/phpBB/includes/db/migration/data/3_0_7_rc2.php index e043f35705..e2c6acce1e 100644 --- a/phpBB/includes/db/migration/data/3_0_7_rc2.php +++ b/phpBB/includes/db/migration/data/3_0_7_rc2.php @@ -59,7 +59,7 @@ class phpbb_db_migration_data_3_0_7_rc2 extends phpbb_db_migration $this->sql_query($sql); } } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); if ($i < $limit) { 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 3f51806fd9..b58b0966a5 100644 --- a/phpBB/includes/db/migration/data/3_0_8_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_8_rc1.php @@ -30,7 +30,7 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration 'acp', 'ACP_MESSAGES', array( - 'module_basename' => 'board', + 'module_basename' => 'acp_board', 'modes' => array('post'), ), )), @@ -60,9 +60,9 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration // 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->phpEx", - "{$this->phpbb_root_path}language/$lang_dir/install.$this->phpEx", - "{$this->phpbb_root_path}language/$lang_dir/acp/attachments.$this->phpEx", + "{$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) @@ -140,7 +140,7 @@ class phpbb_db_migration_data_3_0_8_rc1 extends phpbb_db_migration if (!function_exists('user_add')) { - include($this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx); + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); } $user_row = 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 256426849c..ea49cdbba9 100644 --- a/phpBB/includes/db/migration/data/3_0_9_rc1.php +++ b/phpBB/includes/db/migration/data/3_0_9_rc1.php @@ -44,7 +44,7 @@ class phpbb_db_migration_data_3_0_9_rc1 extends phpbb_db_migration ), ), 'change_columns' => array( - $this->table_prefix . 'bbcode' => array( + $this->table_prefix . 'bbcodes' => array( 'bbcode_id' => array('USINT', 0), ), ), 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 987ab94646..6eb5a6ddee 100644 --- a/phpBB/includes/db/migration/data/3_1_0_dev.php +++ b/phpBB/includes/db/migration/data/3_1_0_dev.php @@ -7,7 +7,7 @@ * */ -class phpbb_db_migration_data_extensions extends phpbb_db_migration +class phpbb_db_migration_data_3_1_0_dev extends phpbb_db_migration { public function depends_on() { @@ -78,6 +78,8 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration 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', @@ -103,7 +105,7 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration ), )), array('module.add', array( - 'acp', + 'ucp', 'UCP_PROFILE', array( 'module_basename' => 'ucp_profile', @@ -113,20 +115,104 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration array('module.remove', array( 'acp', - 'ACP_CAT_STYLES', - array( - 'module_basename' => 'styles', - 'modes' => array('imageset', 'theme', 'template'), - ), + 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 diff --git a/phpBB/includes/db/migration/data/extensions.php b/phpBB/includes/db/migration/data/extensions.php index 85d5511ef0..d28e0ebabb 100644 --- a/phpBB/includes/db/migration/data/extensions.php +++ b/phpBB/includes/db/migration/data/extensions.php @@ -39,10 +39,11 @@ class phpbb_db_migration_data_extensions extends phpbb_db_migration 'acp', 'ACP_GENERAL_TASKS', array( - 'module_basename' => 'extensions', + '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 index d570caae04..1c46e4147b 100644 --- a/phpBB/includes/db/migration/data/style_update_p1.php +++ b/phpBB/includes/db/migration/data/style_update_p1.php @@ -31,7 +31,7 @@ class phpbb_db_migration_data_style_update_p1 extends phpbb_db_migration // Get list of valid 3.1 styles $available_styles = array('prosilver'); - $iterator = new DirectoryIterator($phpbb_root_path . 'styles'); + $iterator = new DirectoryIterator($this->phpbb_root_path . 'styles'); $skip_dirs = array('.', '..', 'prosilver'); foreach ($iterator as $fileinfo) { @@ -91,9 +91,67 @@ class phpbb_db_migration_data_style_update_p1 extends phpbb_db_migration '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'], $errored, $error_ary); + $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' => 'kNg=', + '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 index 2c0991de59..db4b7f1753 100644 --- a/phpBB/includes/db/migration/data/style_update_p2.php +++ b/phpBB/includes/db/migration/data/style_update_p2.php @@ -37,47 +37,6 @@ class phpbb_db_migration_data_style_update_p2 extends phpbb_db_migration public function update_data() { - return array( - array('custom', array(array($this, 'styles_update'))), - ); - } - - public function styles_update() - { - // 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 = 'INSERT INTO ' . STYLES_TABLE . " (style_name, style_copyright, style_active, style_path, bbcode_bitfield, style_parent_id, style_parent_tree) VALUES ('prosilver', '© phpBB Group', 1, 'prosilver', 'kNg=', 0, '')"; - $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), $errored, $error_ary); - - // Change default style - if (!in_array($config['default_style'], $valid_styles)) - { - set_config('default_style', $valid_styles[0]); - } - - // 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), $errored, $error_ary); - } + return array(); } } diff --git a/phpBB/includes/db/migration/data/timezone.php b/phpBB/includes/db/migration/data/timezone.php index 89fafbad28..7734ed4b76 100644 --- a/phpBB/includes/db/migration/data/timezone.php +++ b/phpBB/includes/db/migration/data/timezone.php @@ -51,7 +51,10 @@ class phpbb_db_migration_data_timezone extends phpbb_db_migration $this->db->sql_freeresult($result); // Update board default timezone - set_config('board_timezone', $this->convert_phpbb30_timezone($config['board_timezone'], $config['board_dst'])); + $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'); diff --git a/phpBB/includes/db/migration/exception.php b/phpBB/includes/db/migration/exception.php new file mode 100644 index 0000000000..19fb39ab23 --- /dev/null +++ b/phpBB/includes/db/migration/exception.php @@ -0,0 +1,40 @@ +parameters = $parameters; + } + + public function __toString() + { + return $this->message . ': ' . var_export($this->parameters, true); + } +} diff --git a/phpBB/includes/db/migration/migration.php b/phpBB/includes/db/migration/migration.php new file mode 100644 index 0000000000..c2c6da855b --- /dev/null +++ b/phpBB/includes/db/migration/migration.php @@ -0,0 +1,129 @@ +config = $config; + $this->db = $db; + $this->db_tools = $db_tools; + $this->table_prefix = $table_prefix; + + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + + $this->errors = array(); + } + + /** + * Defines other migrationsto be applied first (abstract method) + * + * @return array An array of migration class names + */ + public function depends_on() + { + return array(); + } + + /** + * Updates the database schema by providing a set of change instructions + * + * @return array + */ + public function update_schema() + { + return array(); + } + + /** + * Updates data by returning a list of instructions to be executed + * + * @return array + */ + public function update_data() + { + } + + /** + * Wrapper for running queries to generate user feedback on updates + */ + protected function sql_query($sql) + { + $this->queries[] = $sql; + + $this->db->sql_return_on_error(true); + + if ($sql === 'begin') + { + $result = $this->db->sql_transaction('begin'); + } + else if ($sql === 'commit') + { + $result = $this->db->sql_transaction('commit'); + } + else + { + $result = $this->db->sql_query($sql); + if ($this->db->sql_error_triggered) + { + $this->errors[] = array( + 'sql' => $this->db->sql_error_sql, + 'code' => $this->db->sql_error_returned, + ); + } + } + + $this->db->sql_return_on_error(false); + + return $result; + } + + /** + * Get the list of queries run + * + * @return array + */ + public function get_queries() + { + return $this->queries; + } +} diff --git a/phpBB/includes/db/migration/tool/config.php b/phpBB/includes/db/migration/tool/config.php new file mode 100644 index 0000000000..35fa3ce566 --- /dev/null +++ b/phpBB/includes/db/migration/tool/config.php @@ -0,0 +1,108 @@ +config = $config; + } + + /** + * {@inheritdoc} + */ + public function get_name() + { + return 'config'; + } + + /** + * Config Add + * + * This function allows you to add a config setting. + * + * @param string $config_name The name of the config setting you would like to add + * @param mixed $config_value The value of the config setting + * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + */ + public function add($config_name, $config_value = '', $is_dynamic = false) + { + if (isset($this->config[$config_name])) + { + throw new phpbb_db_migration_exception('CONFIG_ALREADY_EXISTS', $config_name); + } + + $this->config->set($config_name, $config_value, !$is_dynamic); + + return false; + } + + /** + * Config Update + * + * This function allows you to update an existing config setting. + * + * @param string $config_name The name of the config setting you would like to update + * @param mixed $config_value The value of the config setting + */ + public function update($config_name, $config_value = '') + { + if (!isset($this->config[$config_name])) + { + throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); + } + + $this->config->set($config_name, $config_value); + + return false; + } + + /** + * Config Update If Equals + * + * This function allows you to update a config setting if the first argument equal to the current config value + * + * @param bool $compare If equal to the current config value, will be updated to the new config value, otherwise not + * @param string $config_name The name of the config setting you would like to update + * @param mixed $config_value The value of the config setting + */ + public function update_if_equals($compare, $config_name, $config_value = '') + { + if (!isset($this->config[$config_name])) + { + throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); + } + + $this->config->set_atomic($config_name, $compare, $config_value); + + return false; + } + + /** + * Config Remove + * + * This function allows you to remove an existing config setting. + * + * @param string $config_name The name of the config setting you would like to remove + */ + public function remove($config_name) + { + if (!isset($this->config[$config_name])) + { + throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); + } + + $this->config->delete($config_name); + + return false; + } +} diff --git a/phpBB/includes/db/migration/tool/interface.php b/phpBB/includes/db/migration/tool/interface.php new file mode 100644 index 0000000000..1815f5e8a2 --- /dev/null +++ b/phpBB/includes/db/migration/tool/interface.php @@ -0,0 +1,18 @@ +db = $db; + $this->cache = $cache; + $this->user = $user; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->modules_table = $modules_table; + } + + /** + * {@inheritdoc} + */ + public function get_name() + { + return 'module'; + } + + /** + * Module Exists + * + * Check if a module exists + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. + * @param int|string $module The module_id|module_langname you would like to check for to see if it exists + * + * @return bool true/false if module exists + */ + public function exists($class, $parent, $module) + { + // the main root directory should return true + if (!$module) + { + return true; + } + + $class = $this->db->sql_escape($class); + $module = $this->db->sql_escape($module); + + $parent_sql = ''; + if ($parent !== false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id + FROM ' . $this->modules_table . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + return false; + } + + $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + } + else + { + $parent_sql = 'AND parent_id = ' . (int) $parent; + } + } + + $sql = 'SELECT module_id + FROM ' . $this->modules_table . " + WHERE module_class = '$class' + $parent_sql + AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '$module'"); + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + return true; + } + + return false; + } + + /** + * Module Add + * + * Add a new module + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string $parent The parent module_id|module_langname (0 for no parent) + * @param array $data an array of the data on the new module. This can be setup in two different ways. + * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below, + * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode. + * array( + * 'module_enabled' => 1, + * 'module_display' => 1, + * 'module_basename' => '', + * 'module_class' => $class, + * 'parent_id' => (int) $parent, + * 'module_langname' => '', + * 'module_mode' => '', + * 'module_auth' => '', + * ) + * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file. + * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file): + * array( + * 'module_basename' => 'asacp', + * 'modes' => array('settings', 'log', 'flag'), + * ) + * Optionally you may not send 'modes' and it will insert all of the modules in that info file. + * @param string|bool $include_path If you would like to use a custom include path, specify that here + */ + public function add($class, $parent = 0, $data = array(), $include_path = false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + // allow sending the name as a string in $data to create a category + if (!is_array($data)) + { + $data = array('module_langname' => $data); + } + + if (!isset($data['module_langname'])) + { + /** + * @TODO does not work with 3.1 modules yet, but must continue for old 3.0 versions for + * upgrades from a 3.0.x version to 3.1 + */ + // The "automatic" way + $basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; + $basename = str_replace(array('/', '\\'), '', $basename); + $class = str_replace(array('/', '\\'), '', $class); + $info_file = "$class/info/$basename.{$this->php_ext}"; + + // The manual and automatic ways both failed... + if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $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)) + { + include((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file); + } + + $info = new $classname; + $module = $info->module(); + unset($info); + + $result = ''; + foreach ($module['modes'] as $mode => $module_info) + { + if (!isset($data['modes']) || in_array($mode, $data['modes'])) + { + $new_module = array( + 'module_basename' => $basename, + 'module_langname' => $module_info['title'], + 'module_mode' => $mode, + 'module_auth' => $module_info['auth'], + 'module_display' => (isset($module_info['display'])) ? $module_info['display'] : true, + 'before' => (isset($module_info['before'])) ? $module_info['before'] : false, + 'after' => (isset($module_info['after'])) ? $module_info['after'] : false, + ); + + // Run the "manual" way with the data we've collected. + $result .= ((isset($data['spacer'])) ? $data['spacer'] : '
') . $this->add($class, $parent, $new_module); + } + } + + return $result; + } + + // The "manual" way + add_log('admin', 'LOG_MODULE_ADD', ((isset($this->user->lang[$data['module_langname']])) ? $this->user->lang[$data['module_langname']] : $data['module_langname'])); + + $class = $this->db->sql_escape($class); + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id + FROM ' . $this->modules_table . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (!$row) + { + throw new phpbb_db_migration_exception('MODULE_PARENT_NOT_EXIST', $parent); + } + + $parent = $data['parent_id'] = $row['module_id']; + } + else if (!$this->exists($class, false, $parent)) + { + throw new phpbb_db_migration_exception('MODULE_PARENT_NOT_EXIST', $parent); + } + + if ($this->exists($class, $parent, $data['module_langname'])) + { + throw new phpbb_db_migration_exception('MODULE_ALREADY_EXIST', $data['module_langname']); + } + + if (!class_exists('acp_modules')) + { + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); + $this->user->add_lang('acp/modules'); + } + $acp_modules = new acp_modules(); + + $module_data = array( + 'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1, + 'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1, + 'module_basename' => (isset($data['module_basename'])) ? $data['module_basename'] : '', + 'module_class' => $class, + 'parent_id' => (int) $parent, + 'module_langname' => (isset($data['module_langname'])) ? $data['module_langname'] : '', + 'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '', + 'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '', + ); + $result = $acp_modules->update_module_data($module_data, true); + + // update_module_data can either return a string or an empty array... + if (is_string($result)) + { + // Error + throw new phpbb_db_migration_exception('MODULE_ERROR', $result); + } + else + { + // Success + + // Move the module if requested above/below an existing one + if (isset($data['before']) && $data['before']) + { + $sql = 'SELECT left_id + FROM ' . $this->modules_table . ' + WHERE module_class = \'' . $class . '\' + AND parent_id = ' . (int) $parent . ' + AND module_langname = \'' . $this->db->sql_escape($data['before']) . '\''; + $this->db->sql_query($sql); + $to_left = $this->db->sql_fetchfield('left_id'); + + $sql = 'UPDATE ' . $this->modules_table . " + SET left_id = left_id + 2, right_id = right_id + 2 + WHERE module_class = '$class' + AND left_id >= $to_left + AND left_id < {$module_data['left_id']}"; + $this->db->sql_query($sql); + + $sql = 'UPDATE ' . $this->modules_table . " + SET left_id = $to_left, right_id = " . ($to_left + 1) . " + WHERE module_class = '$class' + AND module_id = {$module_data['module_id']}"; + $this->db->sql_query($sql); + } + else if (isset($data['after']) && $data['after']) + { + $sql = 'SELECT right_id + FROM ' . $this->modules_table . ' + WHERE module_class = \'' . $class . '\' + AND parent_id = ' . (int) $parent . ' + AND module_langname = \'' . $this->db->sql_escape($data['after']) . '\''; + $this->db->sql_query($sql); + $to_right = $this->db->sql_fetchfield('right_id'); + + $sql = 'UPDATE ' . $this->modules_table . " + SET left_id = left_id + 2, right_id = right_id + 2 + WHERE module_class = '$class' + AND left_id >= $to_right + AND left_id < {$module_data['left_id']}"; + $this->db->sql_query($sql); + + $sql = 'UPDATE ' . $this->modules_table . ' + SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . " + WHERE module_class = '$class' + AND module_id = {$module_data['module_id']}"; + $this->db->sql_query($sql); + } + } + + // Clear the Modules Cache + $this->cache->destroy("_modules_$class"); + + return false; + } + + /** + * Module Remove + * + * Remove a module + * + * @param string $class The module class(acp|mcp|ucp) + * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. + * @param int|string $module The module id|module_langname + * @param string|bool $include_path If you would like to use a custom include path, specify that here + */ + public function remove($class, $parent = 0, $module = '', $include_path = false) + { + // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto + if (is_array($module)) + { + if (isset($module['module_langname'])) + { + // Manual Method + return $this->remove($class, $parent, $module['module_langname'], $include_path); + } + + // Failed. + if (!isset($module['module_basename'])) + { + throw new phpbb_db_migration_exception('MODULE_NOT_EXIST'); + } + + // Automatic method + $basename = str_replace(array('/', '\\'), '', $module['module_basename']); + $class = str_replace(array('/', '\\'), '', $class); + $info_file = "$class/info/$basename.{$this->php_ext}"; + + if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file)) + { + throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', $info_file); + } + + $classname = "{$basename}_info"; + + if (!class_exists($classname)) + { + include((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file); + } + + $info = new $classname; + $module_info = $info->module(); + unset($info); + + foreach ($module_info['modes'] as $mode => $info) + { + if (!isset($module['modes']) || in_array($mode, $module['modes'])) + { + $this->remove($class, $parent, $info['title']) . '
'; + } + } + return false; + } + else + { + $class = $this->db->sql_escape($class); + + if (!$this->exists($class, $parent, $module)) + { + throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', ((isset($this->user->lang[$module])) ? $this->user->lang[$module] : $module)); + } + + $parent_sql = ''; + if ($parent !== false) + { + // Allows '' to be sent as 0 + $parent = (!$parent) ? 0 : $parent; + + if (!is_numeric($parent)) + { + $sql = 'SELECT module_id + FROM ' . $this->modules_table . " + WHERE module_langname = '" . $this->db->sql_escape($parent) . "' + AND module_class = '$class'"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + // we know it exists from the module_exists check + $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + } + else + { + $parent_sql = 'AND parent_id = ' . (int) $parent; + } + } + + $module_ids = array(); + if (!is_numeric($module)) + { + $module = $this->db->sql_escape($module); + $sql = 'SELECT module_id + FROM ' . $this->modules_table . " + WHERE module_langname = '$module' + AND module_class = '$class' + $parent_sql"; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $module_ids[] = (int) $row['module_id']; + } + $this->db->sql_freeresult($result); + + $module_name = $module; + } + else + { + $module = (int) $module; + $sql = 'SELECT module_langname + FROM ' . $this->modules_table . " + WHERE module_id = $module + AND module_class = '$class' + $parent_sql"; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $module_name = $row['module_langname']; + $module_ids[] = $module; + } + + if (!class_exists('acp_modules')) + { + include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); + $this->user->add_lang('acp/modules'); + } + $acp_modules = new acp_modules(); + $acp_modules->module_class = $class; + + foreach ($module_ids as $module_id) + { + $result = $acp_modules->delete_module($module_id); + if (!empty($result)) + { + throw new phpbb_db_migration_exception('CANNOT_REMOVE_MODULE', $module_id); + } + } + + $this->cache->destroy("_modules_$class"); + + return false; + } + } +} diff --git a/phpBB/includes/db/migration/tool/permission.php b/phpBB/includes/db/migration/tool/permission.php new file mode 100644 index 0000000000..ebe404bc62 --- /dev/null +++ b/phpBB/includes/db/migration/tool/permission.php @@ -0,0 +1,562 @@ +db = $db; + $this->cache = $cache; + $this->auth = $auth; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + + /** + * {@inheritdoc} + */ + public function get_name() + { + return 'permission'; + } + + /** + * Permission Exists + * + * Check if a permission (auth) setting exists + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return bool true if it exists, false if not + */ + public function exists($auth_option, $global = true) + { + if ($global) + { + $type_sql = ' AND is_global = 1'; + } + else + { + $type_sql = ' AND is_local = 1'; + } + + $sql = 'SELECT auth_option_id + FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" + . $type_sql; + $result = $this->db->sql_query($sql); + + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row) + { + return true; + } + + return false; + } + + /** + * Permission Add + * + * Add a permission (auth) option + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return result + */ + public function add($auth_option, $global = true, $copy_from = false) + { + if ($this->exists($auth_option, $global)) + { + throw new phpbb_db_migration_exception('PERMISSION_ALREADY_EXISTS', $auth_option); + } + + // We've added permissions, so set to true to notify the user. + $this->permissions_added = true; + + if (!class_exists('auth_admin')) + { + include($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext); + } + $auth_admin = new auth_admin(); + + // We have to add a check to see if the !$global (if global, local, and if local, global) permission already exists. If it does, acl_add_option currently has a bug which would break the ACL system, so we are having a work-around here. + if ($this->exists($auth_option, !$global)) + { + $sql_ary = array( + 'is_global' => 1, + 'is_local' => 1, + ); + $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' + SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " + WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'"; + $this->db->sql_query($sql); + } + else + { + if ($global) + { + $auth_admin->acl_add_option(array('global' => array($auth_option))); + } + else + { + $auth_admin->acl_add_option(array('local' => array($auth_option))); + } + } + + // The permission has been added, now we can copy it if needed + if ($copy_from && isset($auth_admin->acl_options['id'][$copy_from])) + { + $old_id = $auth_admin->acl_options['id'][$copy_from]; + $new_id = $auth_admin->acl_options['id'][$auth_option]; + + $tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE); + + foreach ($tables as $table) + { + $sql = 'SELECT * + FROM ' . $table . ' + WHERE auth_option_id = ' . $old_id; + $result = $this->db->sql_query($sql); + + $sql_ary = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $row['auth_option_id'] = $new_id; + $sql_ary[] = $row; + } + $this->db->sql_freeresult($result); + + if (sizeof($sql_ary)) + { + $this->db->sql_multi_insert($table, $sql_ary); + } + } + + $auth_admin->acl_clear_prefetch(); + } + + return false; + } + + /** + * Permission Remove + * + * Remove a permission (auth) option + * + * @param string $auth_option The name of the permission (auth) option + * @param bool $global True for checking a global permission setting, False for a local permission setting + * + * @return result + */ + public function remove($auth_option, $global = true) + { + if (!$this->exists($auth_option, $global)) + { + throw new phpbb_db_migration_exception('PERMISSION_NOT_EXIST', $auth_option); + } + + if ($global) + { + $type_sql = ' AND is_global = 1'; + } + else + { + $type_sql = ' AND is_local = 1'; + } + $sql = 'SELECT auth_option_id, is_global, is_local + FROM ' . ACL_OPTIONS_TABLE . " + WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" . + $type_sql; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $id = $row['auth_option_id']; + + // If it is a local and global permission, do not remove the row! :P + if ($row['is_global'] && $row['is_local']) + { + $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' + SET ' . (($global) ? 'is_global = 0' : 'is_local = 0') . ' + WHERE auth_option_id = ' . $id; + $this->db->sql_query($sql); + } + else + { + // Delete time + $this->db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $id); + $this->db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $id); + } + + // Purge the auth cache + $this->cache->destroy('_acl_options'); + $this->auth->acl_clear_prefetch(); + + return false; + } + + /** + * Add a new permission role + * + * @param string $role_name The new role name + * @param sting $role_type The type (u_, m_, a_) + */ + public function role_add($role_name, $role_type = '', $role_description = '') + { + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = '" . $this->db->sql_escape($role_name) . "'"; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if ($role_id) + { + throw new phpbb_db_migration_exception('ROLE_ALREADY_EXISTS', $old_role_name); + } + + $sql = 'SELECT MAX(role_order) AS max + FROM ' . ACL_ROLES_TABLE . " + WHERE role_type = '" . $this->db->sql_escape($role_type) . "'"; + $this->db->sql_query($sql); + $role_order = $this->db->sql_fetchfield('max'); + $role_order = (!$role_order) ? 1 : $role_order + 1; + + $sql_ary = array( + 'role_name' => $role_name, + 'role_description' => $role_description, + 'role_type' => $role_type, + 'role_order' => $role_order, + ); + + $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->db->sql_query($sql); + + return false; + } + + /** + * Update the name on a permission role + * + * @param string $old_role_name The old role name + * @param string $new_role_name The new role name + */ + public function role_update($old_role_name, $new_role_name = '') + { + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = '" . $this->db->sql_escape($old_role_name) . "'"; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + throw new phpbb_db_migration_exception('ROLE_NOT_EXISTS', $old_role_name); + } + + $sql = 'UPDATE ' . ACL_ROLES_TABLE . " + SET role_name = '" . $this->db->sql_escape($new_role_name) . "' + WHERE role_name = '" . $this->db->sql_escape($old_role_name) . "'"; + $this->db->sql_query($sql); + + return false; + } + + /** + * Remove a permission role + * + * @param string $role_name The role name to remove + */ + public function role_remove($role_name) + { + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = '" . $this->db->sql_escape($role_name) . "'"; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $role_name); + } + + $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + + $sql = 'DELETE FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + + $this->auth->acl_clear_prefetch(); + + return false; + } + + /** + * Permission Set + * + * Allows you to set permissions for a certain group/role + * + * @param string $name The name of the role/group + * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string $type The type (role|group) + * @param bool $has_permission True if you want to give them permission, false if you want to deny them permission + */ + public function permission_set($name, $auth_option = array(), $type = 'role', $has_permission = true) + { + if (!is_array($auth_option)) + { + $auth_option = array($auth_option); + } + + $new_auth = array(); + $sql = 'SELECT auth_option_id + FROM ' . ACL_OPTIONS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $new_auth[] = $row['auth_option_id']; + } + $this->db->sql_freeresult($result); + + if (!sizeof($new_auth)) + { + return false; + } + + $current_auth = array(); + + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'role' : + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $name); + } + + $sql = 'SELECT auth_option_id, auth_setting + FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE role_id = ' . $role_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $current_auth[$row['auth_option_id']] = $row['auth_setting']; + } + $this->db->sql_freeresult($result); + break; + + case 'group' : + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . " + WHERE group_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + $group_id = $this->db->sql_fetchfield('group_id'); + + if (!$group_id) + { + throw new phpbb_db_migration_exception('GROUP_NOT_EXIST', $name); + } + + // If the group has a role set for them we will add the requested permissions to that role. + $sql = 'SELECT auth_role_id + FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id <> 0 + AND forum_id = 0'; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('auth_role_id'); + if ($role_id) + { + $sql = 'SELECT role_name + FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + $role_name = $this->db->sql_fetchfield('role_name'); + + return $this->set($role_name, $auth_option, 'role', $has_permission); + } + + $sql = 'SELECT auth_option_id, auth_setting + FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $current_auth[$row['auth_option_id']] = $row['auth_setting']; + } + $this->db->sql_freeresult($result); + break; + } + + $sql_ary = array(); + switch ($type) + { + case 'role' : + foreach ($new_auth as $auth_option_id) + { + if (!isset($current_auth[$auth_option_id])) + { + $sql_ary[] = array( + 'role_id' => $role_id, + 'auth_option_id' => $auth_option_id, + 'auth_setting' => $has_permission, + ); + } + } + + $this->db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary); + break; + + case 'group' : + foreach ($new_auth as $auth_option_id) + { + if (!isset($current_auth[$auth_option_id])) + { + $sql_ary[] = array( + 'group_id' => $group_id, + 'auth_option_id' => $auth_option_id, + 'auth_setting' => $has_permission, + ); + } + } + + $this->db->sql_multi_insert(ACL_GROUPS_TABLE, $sql_ary); + break; + } + + $this->auth->acl_clear_prefetch(); + + return false; + } + + /** + * Permission Unset + * + * Allows you to unset (remove) permissions for a certain group/role + * + * @param string $name The name of the role/group + * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string $type The type (role|group) + */ + public function permission_unset($name, $auth_option = array(), $type = 'role') + { + if (!is_array($auth_option)) + { + $auth_option = array($auth_option); + } + + $to_remove = array(); + $sql = 'SELECT auth_option_id + FROM ' . ACL_OPTIONS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $to_remove[] = $row['auth_option_id']; + } + $this->db->sql_freeresult($result); + + if (!sizeof($to_remove)) + { + return false; + } + + $type = (string) $type; // Prevent PHP bug. + + switch ($type) + { + case 'role' : + $sql = 'SELECT role_id + FROM ' . ACL_ROLES_TABLE . " + WHERE role_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('role_id'); + + if (!$role_id) + { + throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $name); + } + + $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); + $this->db->sql_query($sql); + break; + + case 'group' : + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . " + WHERE group_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + $group_id = $this->db->sql_fetchfield('group_id'); + + if (!$group_id) + { + throw new phpbb_db_migration_exception('GROUP_NOT_EXIST', $name); + } + + // If the group has a role set for them we will remove the requested permissions from that role. + $sql = 'SELECT auth_role_id + FROM ' . ACL_GROUPS_TABLE . ' + WHERE group_id = ' . $group_id . ' + AND auth_role_id <> 0'; + $this->db->sql_query($sql); + $role_id = $this->db->sql_fetchfield('auth_role_id'); + if ($role_id) + { + $sql = 'SELECT role_name + FROM ' . ACL_ROLES_TABLE . ' + WHERE role_id = ' . $role_id; + $this->db->sql_query($sql); + $role_name = $this->db->sql_fetchfield('role_name'); + + return $this->permission_unset($role_name, $auth_option, 'role'); + } + + $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . ' + WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); + $this->db->sql_query($sql); + break; + } + + $this->auth->acl_clear_prefetch(); + + return false; + } +} diff --git a/phpBB/includes/db/migration/tools/config.php b/phpBB/includes/db/migration/tools/config.php deleted file mode 100644 index 2d58c8093c..0000000000 --- a/phpBB/includes/db/migration/tools/config.php +++ /dev/null @@ -1,100 +0,0 @@ -config = $config; - } - - /** - * Config Add - * - * This function allows you to add a config setting. - * - * @param string $config_name The name of the config setting you would like to add - * @param mixed $config_value The value of the config setting - * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. - */ - public function add($config_name, $config_value = '', $is_dynamic = false) - { - if (isset($this->config[$config_name])) - { - throw new phpbb_db_migration_exception('CONFIG_ALREADY_EXISTS', $config_name); - } - - $this->config->set($config_name, $config_value, $is_dynamic); - - return false; - } - - /** - * Config Update - * - * This function allows you to update an existing config setting. - * - * @param string $config_name The name of the config setting you would like to update - * @param mixed $config_value The value of the config setting - */ - public function update($config_name, $config_value = '') - { - if (!isset($this->config[$config_name])) - { - throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); - } - - $this->config->set($config_name, $config_value); - - return false; - } - - /** - * Config Update If Equals - * - * This function allows you to update a config setting if the first argument equal to the current config value - * - * @param bool $compare If equal to the current config value, will be updated to the new config value, otherwise not - * @param string $config_name The name of the config setting you would like to update - * @param mixed $config_value The value of the config setting - */ - public function update_if_equals($compare, $config_name, $config_value = '') - { - if (!isset($this->config[$config_name])) - { - throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); - } - - $this->config->set_atomic($config_name, $compare, $config_value); - - return false; - } - - /** - * Config Remove - * - * This function allows you to remove an existing config setting. - * - * @param string $config_name The name of the config setting you would like to remove - */ - public function remove($config_name) - { - if (!isset($this->config[$config_name])) - { - throw new phpbb_db_migration_exception('CONFIG_NOT_EXIST', $config_name); - } - - $this->config->delete($config_name); - - return false; - } -} \ No newline at end of file diff --git a/phpBB/includes/db/migration/tools/module.php b/phpBB/includes/db/migration/tools/module.php deleted file mode 100644 index e17197d73e..0000000000 --- a/phpBB/includes/db/migration/tools/module.php +++ /dev/null @@ -1,447 +0,0 @@ -db = $db; - $this->cache = $cache; - $this->user = $user; - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - } - - /** - * Module Exists - * - * Check if a module exists - * - * @param string $class The module class(acp|mcp|ucp) - * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. - * @param int|string $module The module_id|module_langname you would like to check for to see if it exists - * - * @return bool true/false if module exists - */ - public function exists($class, $parent, $module) - { - // the main root directory should return true - if (!$module) - { - return true; - } - - $class = $this->db->sql_escape($class); - $module = $this->db->sql_escape($module); - - $parent_sql = ''; - if ($parent !== false) - { - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; - - if (!is_numeric($parent)) - { - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$row) - { - return false; - } - - $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; - } - else - { - $parent_sql = 'AND parent_id = ' . (int) $parent; - } - } - - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_class = '$class' - $parent_sql - AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '$module'"); - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if ($row) - { - return true; - } - - return false; - } - - /** - * Module Add - * - * Add a new module - * - * @param string $class The module class(acp|mcp|ucp) - * @param int|string $parent The parent module_id|module_langname (0 for no parent) - * @param array $data an array of the data on the new module. This can be setup in two different ways. - * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below, - * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode. - * array( - * 'module_enabled' => 1, - * 'module_display' => 1, - * 'module_basename' => '', - * 'module_class' => $class, - * 'parent_id' => (int) $parent, - * 'module_langname' => '', - * 'module_mode' => '', - * 'module_auth' => '', - * ) - * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file. - * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file): - * array( - * 'module_basename' => 'asacp', - * 'modes' => array('settings', 'log', 'flag'), - * ) - * Optionally you may not send 'modes' and it will insert all of the modules in that info file. - * @param string|bool $include_path If you would like to use a custom include path, specify that here - */ - public function add($class, $parent = 0, $data = array(), $include_path = false) - { - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; - - // allow sending the name as a string in $data to create a category - if (!is_array($data)) - { - $data = array('module_langname' => $data); - } - - if (!isset($data['module_langname'])) - { - /** - * @TODO does not work with 3.1 modules yet, but must continue for old 3.0 versions for - * upgrades from a 3.0.x version to 3.1 - */ - // The "automatic" way - $basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; - $basename = str_replace(array('/', '\\'), '', $basename); - $class = str_replace(array('/', '\\'), '', $class); - $info_file = "$class/info/{$class}_$basename.{$this->php_ext}"; - - // The manual and automatic ways both failed... - if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file)) - { - throw new phpbb_db_migration_exception('MODULE_ADD', $class, $info_file); - } - - $classname = "{$class}_{$basename}_info"; - - if (!class_exists($classname)) - { - include((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file); - } - - $info = new $classname; - $module = $info->module(); - unset($info); - - $result = ''; - foreach ($module['modes'] as $mode => $module_info) - { - if (!isset($data['modes']) || in_array($mode, $data['modes'])) - { - $new_module = array( - 'module_basename' => $basename, - 'module_langname' => $module_info['title'], - 'module_mode' => $mode, - 'module_auth' => $module_info['auth'], - 'module_display' => (isset($module_info['display'])) ? $module_info['display'] : true, - 'before' => (isset($module_info['before'])) ? $module_info['before'] : false, - 'after' => (isset($module_info['after'])) ? $module_info['after'] : false, - ); - - // Run the "manual" way with the data we've collected. - $result .= ((isset($data['spacer'])) ? $data['spacer'] : '
') . $this->add($class, $parent, $new_module); - } - } - - return $result; - } - - // The "manual" way - add_log('admin', 'LOG_MODULE_ADD', ((isset($this->user->lang[$data['module_langname']])) ? $this->user->lang[$data['module_langname']] : $data['module_langname'])); - - $class = $this->db->sql_escape($class); - - if (!is_numeric($parent)) - { - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$row) - { - throw new phpbb_db_migration_exception('MODULE_PARENT_NOT_EXIST', $parent); - } - - $parent = $data['parent_id'] = $row['module_id']; - } - else if (!$this->exists($class, false, $parent)) - { - throw new phpbb_db_migration_exception('MODULE_PARENT_NOT_EXIST', $parent); - } - - if ($this->exists($class, $parent, $data['module_langname'])) - { - throw new phpbb_db_migration_exception('MODULE_ALREADY_EXIST', $data['module_langname']); - } - - if (!class_exists('acp_modules')) - { - include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); - $this->user->add_lang('acp/modules'); - } - $acp_modules = new acp_modules(); - - $module_data = array( - 'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1, - 'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1, - 'module_basename' => (isset($data['module_basename'])) ? $data['module_basename'] : '', - 'module_class' => $class, - 'parent_id' => (int) $parent, - 'module_langname' => (isset($data['module_langname'])) ? $data['module_langname'] : '', - 'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '', - 'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '', - ); - $result = $acp_modules->update_module_data($module_data, true); - - // update_module_data can either return a string or an empty array... - if (is_string($result)) - { - // Error - throw new phpbb_db_migration_exception('MODULE_ERROR', $result); - } - else - { - // Success - - // Move the module if requested above/below an existing one - if (isset($data['before']) && $data['before']) - { - $sql = 'SELECT left_id FROM ' . MODULES_TABLE . ' - WHERE module_class = \'' . $class . '\' - AND parent_id = ' . (int) $parent . ' - AND module_langname = \'' . $this->db->sql_escape($data['before']) . '\''; - $this->db->sql_query($sql); - $to_left = $this->db->sql_fetchfield('left_id'); - - $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 - WHERE module_class = '$class' - AND left_id >= $to_left - AND left_id < {$module_data['left_id']}"; - $this->db->sql_query($sql); - - $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = $to_left, right_id = " . ($to_left + 1) . " - WHERE module_class = '$class' - AND module_id = {$module_data['module_id']}"; - $this->db->sql_query($sql); - } - else if (isset($data['after']) && $data['after']) - { - $sql = 'SELECT right_id FROM ' . MODULES_TABLE . ' - WHERE module_class = \'' . $class . '\' - AND parent_id = ' . (int) $parent . ' - AND module_langname = \'' . $this->db->sql_escape($data['after']) . '\''; - $this->db->sql_query($sql); - $to_right = $this->db->sql_fetchfield('right_id'); - - $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 - WHERE module_class = '$class' - AND left_id >= $to_right - AND left_id < {$module_data['left_id']}"; - $this->db->sql_query($sql); - - $sql = 'UPDATE ' . MODULES_TABLE . ' SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . " - WHERE module_class = '$class' - AND module_id = {$module_data['module_id']}"; - $this->db->sql_query($sql); - } - } - - // Clear the Modules Cache - $this->cache->destroy("_modules_$class"); - - return false; - } - - /** - * Module Remove - * - * Remove a module - * - * @param string $class The module class(acp|mcp|ucp) - * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. - * @param int|string $module The module id|module_langname - * @param string|bool $include_path If you would like to use a custom include path, specify that here - */ - public function remove($class, $parent = 0, $module = '', $include_path = false) - { - // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto - if (is_array($module)) - { - if (isset($module['module_langname'])) - { - // Manual Method - return $this->remove($class, $parent, $module['module_langname'], $include_path); - } - - // Failed. - if (!isset($module['module_basename'])) - { - throw new phpbb_db_migration_exception('MODULE_NOT_EXIST'); - } - - // Automatic method - $basename = str_replace(array('/', '\\'), '', $module['module_basename']); - $class = str_replace(array('/', '\\'), '', $class); - $info_file = "$class/info/{$class}_$basename.{$this->php_ext}"; - - if (!file_exists((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file)) - { - throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', $info_file); - } - - $classname = "{$class}_{$basename}_info"; - - if (!class_exists($classname)) - { - include((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file); - } - - $info = new $classname; - $module_info = $info->module(); - unset($info); - - foreach ($module_info['modes'] as $mode => $info) - { - if (!isset($module['modes']) || in_array($mode, $module['modes'])) - { - $this->remove($class, $parent, $info['title']) . '
'; - } - } - return false; - } - else - { - $class = $this->db->sql_escape($class); - - if (!$this->exists($class, $parent, $module)) - { - throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', ((isset($this->user->lang[$module])) ? $this->user->lang[$module] : $module)); - } - - $parent_sql = ''; - if ($parent !== false) - { - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; - - if (!is_numeric($parent)) - { - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - // we know it exists from the module_exists check - $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; - } - else - { - $parent_sql = 'AND parent_id = ' . (int) $parent; - } - } - - $module_ids = array(); - if (!is_numeric($module)) - { - $module = $this->db->sql_escape($module); - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '$module' - AND module_class = '$class' - $parent_sql"; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $module_ids[] = (int) $row['module_id']; - } - $this->db->sql_freeresult($result); - - $module_name = $module; - } - else - { - $module = (int) $module; - $sql = 'SELECT module_langname FROM ' . MODULES_TABLE . " - WHERE module_id = $module - AND module_class = '$class' - $parent_sql"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - $module_name = $row['module_langname']; - $module_ids[] = $module; - } - - if (!class_exists('acp_modules')) - { - include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); - $this->user->add_lang('acp/modules'); - } - $acp_modules = new acp_modules(); - $acp_modules->module_class = $class; - - foreach ($module_ids as $module_id) - { - $result = $acp_modules->delete_module($module_id); - if (!empty($result)) - { - throw new phpbb_db_migration_exception('CANNOT_REMOVE_MODULE', $module_id); - } - } - - $cache->destroy("_modules_$class"); - - return false; - } - } -} \ No newline at end of file diff --git a/phpBB/includes/db/migration/tools/permission.php b/phpBB/includes/db/migration/tools/permission.php deleted file mode 100644 index 7694bae0cb..0000000000 --- a/phpBB/includes/db/migration/tools/permission.php +++ /dev/null @@ -1,504 +0,0 @@ -db = $db; - $this->cache = $cache; - $this->auth = $auth; - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - } - - /** - * Permission Exists - * - * Check if a permission (auth) setting exists - * - * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return bool true if it exists, false if not - */ - public function exists($auth_option, $global = true) - { - if ($global) - { - $type_sql = ' AND is_global = 1'; - } - else - { - $type_sql = ' AND is_local = 1'; - } - - $sql = 'SELECT auth_option_id - FROM ' . ACL_OPTIONS_TABLE . " - WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" - . $type_sql; - $result = $this->db->sql_query($sql); - - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if ($row) - { - return true; - } - - return false; - } - - /** - * Permission Add - * - * Add a permission (auth) option - * - * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return result - */ - public function add($auth_option, $global = true) - { - if ($this->exists($auth_option, $global)) - { - throw new phpbb_db_migration_exception('PERMISSION_ALREADY_EXISTS', $auth_option); - } - - // We've added permissions, so set to true to notify the user. - $this->permissions_added = true; - - if (!class_exists('auth_admin')) - { - include($this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext); - } - $auth_admin = new auth_admin(); - - // We have to add a check to see if the !$global (if global, local, and if local, global) permission already exists. If it does, acl_add_option currently has a bug which would break the ACL system, so we are having a work-around here. - if ($this->exists($auth_option, !$global)) - { - $sql_ary = array( - 'is_global' => 1, - 'is_local' => 1, - ); - $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE auth_option = \'' . $this->db->sql_escape($auth_option) . "'"; - $this->db->sql_query($sql); - } - else - { - if ($global) - { - $auth_admin->acl_add_option(array('global' => array($auth_option))); - } - else - { - $auth_admin->acl_add_option(array('local' => array($auth_option))); - } - } - - return false; - } - - /** - * Permission Remove - * - * Remove a permission (auth) option - * - * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return result - */ - public function remove($auth_option, $global = true) - { - if (!$this->exists($auth_option, $global)) - { - throw new phpbb_db_migration_exception('PERMISSION_NOT_EXIST', $auth_option); - } - - if ($global) - { - $type_sql = ' AND is_global = 1'; - } - else - { - $type_sql = ' AND is_local = 1'; - } - $sql = 'SELECT auth_option_id, is_global, is_local FROM ' . ACL_OPTIONS_TABLE . " - WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" . - $type_sql; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - $id = $row['auth_option_id']; - - // If it is a local and global permission, do not remove the row! :P - if ($row['is_global'] && $row['is_local']) - { - $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' - SET ' . (($global) ? 'is_global = 0' : 'is_local = 0') . ' - WHERE auth_option_id = ' . $id; - $this->db->sql_query($sql); - } - else - { - // Delete time - $this->db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $id); - } - - // Purge the auth cache - $this->cache->destroy('_acl_options'); - $this->auth->acl_clear_prefetch(); - - return false; - } - - /** - * Add a new permission role - * - * @param string $role_name The new role name - * @param sting $role_type The type (u_, m_, a_) - */ - public function role_add($role_name, $role_type = '', $role_description = '') - { - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if ($role_id) - { - throw new phpbb_db_migration_exception('ROLE_ALREADY_EXISTS', $old_role_name); - } - - $sql = 'SELECT MAX(role_order) AS max FROM ' . ACL_ROLES_TABLE . ' - WHERE role_type = \'' . $this->db->sql_escape($role_type) . '\''; - $this->db->sql_query($sql); - $role_order = $this->db->sql_fetchfield('max'); - $role_order = (!$role_order) ? 1 : $role_order + 1; - - $sql_ary = array( - 'role_name' => $role_name, - 'role_description' => $role_description, - 'role_type' => $role_type, - 'role_order' => $role_order, - ); - - $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); - $this->db->sql_query($sql); - - return false; - } - - /** - * Update the name on a permission role - * - * @param string $old_role_name The old role name - * @param string $new_role_name The new role name - */ - public function role_update($old_role_name, $new_role_name = '') - { - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - throw new phpbb_db_migration_exception('ROLE_NOT_EXISTS', $old_role_name); - } - - $sql = 'UPDATE ' . ACL_ROLES_TABLE . ' - SET role_name = \'' . $this->db->sql_escape($new_role_name) . '\' - WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; - $this->db->sql_query($sql); - - return false; - } - - /** - * Remove a permission role - * - * @param string $role_name The role name to remove - */ - public function role_remove($role_name) - { - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $role_name); - } - - $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - - $sql = 'DELETE FROM ' . ACL_ROLES_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - - $this->auth->acl_clear_prefetch(); - - return false; - } - - /** - * Permission Set - * - * Allows you to set permissions for a certain group/role - * - * @param string $name The name of the role/group - * @param string|array $auth_option The auth_option or array of auth_options you would like to set - * @param string $type The type (role|group) - * @param bool $has_permission True if you want to give them permission, false if you want to deny them permission - */ - public function permission_set($name, $auth_option = array(), $type = 'role', $has_permission = true) - { - if (!is_array($auth_option)) - { - $auth_option = array($auth_option); - } - - $new_auth = array(); - $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $new_auth[] = $row['auth_option_id']; - } - $this->db->sql_freeresult($result); - - if (!sizeof($new_auth)) - { - return false; - } - - $current_auth = array(); - - $type = (string) $type; // Prevent PHP bug. - - switch ($type) - { - case 'role' : - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $name); - } - - $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_ROLES_DATA_TABLE . ' - WHERE role_id = ' . $role_id; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $current_auth[$row['auth_option_id']] = $row['auth_setting']; - } - $this->db->sql_freeresult($result); - break; - - case 'group' : - $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $group_id = $this->db->sql_fetchfield('group_id'); - - if (!$group_id) - { - throw new phpbb_db_migration_exception('GROUP_NOT_EXIST', $name); - } - - // If the group has a role set for them we will add the requested permissions to that role. - $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id . ' - AND auth_role_id <> 0 - AND forum_id = 0'; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('auth_role_id'); - if ($role_id) - { - $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - $role_name = $this->db->sql_fetchfield('role_name'); - - return $this->set($role_name, $auth_option, 'role', $has_permission); - } - - $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $current_auth[$row['auth_option_id']] = $row['auth_setting']; - } - $this->db->sql_freeresult($result); - break; - } - - $sql_ary = array(); - switch ($type) - { - case 'role' : - foreach ($new_auth as $auth_option_id) - { - if (!isset($current_auth[$auth_option_id])) - { - $sql_ary[] = array( - 'role_id' => $role_id, - 'auth_option_id' => $auth_option_id, - 'auth_setting' => $has_permission, - ); - } - } - - $this->db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary); - break; - - case 'group' : - foreach ($new_auth as $auth_option_id) - { - if (!isset($current_auth[$auth_option_id])) - { - $sql_ary[] = array( - 'group_id' => $group_id, - 'auth_option_id' => $auth_option_id, - 'auth_setting' => $has_permission, - ); - } - } - - $this->db->sql_multi_insert(ACL_GROUPS_TABLE, $sql_ary); - break; - } - - $this->auth->acl_clear_prefetch(); - - return false; - } - - /** - * Permission Unset - * - * Allows you to unset (remove) permissions for a certain group/role - * - * @param string $name The name of the role/group - * @param string|array $auth_option The auth_option or array of auth_options you would like to set - * @param string $type The type (role|group) - */ - public function permission_unset($name, $auth_option = array(), $type = 'role') - { - if (!is_array($auth_option)) - { - $auth_option = array($auth_option); - } - - $to_remove = array(); - $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $to_remove[] = $row['auth_option_id']; - } - $this->db->sql_freeresult($result); - - if (!sizeof($to_remove)) - { - return false; - } - - $type = (string) $type; // Prevent PHP bug. - - switch ($type) - { - case 'role' : - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $name); - } - - $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); - $this->db->sql_query($sql); - break; - - case 'group' : - $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' - WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $group_id = $this->db->sql_fetchfield('group_id'); - - if (!$group_id) - { - throw new phpbb_db_migration_exception('GROUP_NOT_EXIST', $name); - } - - // If the group has a role set for them we will remove the requested permissions from that role. - $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id . ' - AND auth_role_id <> 0'; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('auth_role_id'); - if ($role_id) - { - $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - $role_name = $this->db->sql_fetchfield('role_name'); - - return $this->permission_unset($role_name, $auth_option, 'role'); - } - - $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); - $this->db->sql_query($sql); - break; - } - - $this->auth->acl_clear_prefetch(); - - return false; - } -} \ No newline at end of file diff --git a/phpBB/includes/db/migration/tools/umil.php b/phpBB/includes/db/migration/tools/umil.php deleted file mode 100644 index ce7b8ff3be..0000000000 --- a/phpBB/includes/db/migration/tools/umil.php +++ /dev/null @@ -1,3037 +0,0 @@ -config_add(array( -* array('config_name', 'config_value'), -* array('config_name1', 'config_value1'), -* array('config_name2', 'config_value2', true), -* array('config_name3', 'config_value3', true), -* ); -*/ - -/** -* UMIL - Unified MOD Installation Library class -* -* Cache Functions -* cache_purge($type = '', $style_id = 0) -* -* Config Functions: -* config_exists($config_name, $return_result = false) -* config_add($config_name, $config_value = '', $is_dynamic = false) -* config_update($config_name, $config_value, $is_dynamic = false) -* config_remove($config_name) -* -* Module Functions -* module_exists($class, $parent, $module) -* module_add($class, $parent = 0, $data = array()) -* module_remove($class, $parent = 0, $module = '') -* -* Permissions/Auth Functions -* permission_exists($auth_option, $global = true) -* permission_add($auth_option, $global = true) -* permission_remove($auth_option, $global = true) -* permission_set($name, $auth_option = array(), $type = 'role', $global = true, $has_permission = true) -* permission_unset($name, $auth_option = array(), $type = 'role', $global = true) -* -* Table Functions -* table_exists($table_name) -* table_add($table_name, $table_data = array()) -* table_remove($table_name) -* -* Table Column Functions -* table_column_exists($table_name, $column_name) -* table_column_add($table_name, $column_name = '', $column_data = array()) -* table_column_update($table_name, $column_name = '', $column_data = array()) -* table_column_remove($table_name, $column_name = '') -* -* Table Key/Index Functions -* table_index_exists($table_name, $index_name) -* table_index_add($table_name, $index_name = '', $column = array()) -* table_index_remove($table_name, $index_name = '') -* -* Table Row Functions (note that these actions are not reversed automatically during uninstallation) -* table_row_insert($table_name, $data = array()) -* table_row_remove($table_name, $data = array()) -* table_row_update($table_name, $data = array(), $new_data = array()) -* -* Version Check Function -* version_check($url, $path, $file) -*/ -class umil -{ - /** - * This will hold the text output for the inputted command (if the mod author would like to display the command that was ran) - * - * @var string - */ - var $command = ''; - - /** - * This will hold the text output for the result of the command. $user->lang['SUCCESS'] if everything worked. - * - * @var string - */ - var $result = ''; - - /** - * Auto run $this->display_results after running a command - */ - var $auto_display_results = false; - - /** - * Stand Alone option (this makes it possible to just use the single umil file and not worry about any language stuff - */ - var $stand_alone = false; - - /** - * Were any new permissions added (used in umil_frontend)? - */ - var $permissions_added = false; - - /** - * Database Object - */ - var $db = false; - - /** - * Database Tools Object - */ - var $db_tools = false; - - /** - * Do we want a custom prefix besides the phpBB table prefix? You *probably* should not change this... - */ - var $table_prefix = false; - - /** - * Constructor - */ - function umil($stand_alone = false, $db = false) - { - // Setup $this->db - if ($db !== false) - { - if (!is_object($db) || !method_exists($db, 'sql_query')) - { - trigger_error('Invalid $db Object'); - } - - $this->db = $db; - } - else - { - global $db; - $this->db = $db; - } - - // Setup $this->db_tools - if (!class_exists('phpbb_db_tools')) - { - global $phpbb_root_path, $phpEx; - include($phpbb_root_path . 'includes/db/db_tools.' . $phpEx); - } - $this->db_tools = new phpbb_db_tools($this->db); - - $this->stand_alone = $stand_alone; - - if (!$stand_alone) - { - global $config, $user, $phpbb_root_path, $phpEx; - - /* Does not have the fall back option to use en/ if the user's language file does not exist, so we will not use it...unless that is changed. - if (method_exists('user', 'set_custom_lang_path')) - { - $user->set_custom_lang_path($phpbb_root_path . 'umil/language/'); - $user->add_lang('umil'); - $user->set_custom_lang_path($phpbb_root_path . 'language/'); - } - else - {*/ - // Include the umil language file. First we check if the language file for the user's language is available, if not we check if the board's default language is available, if not we use the english file. - if (isset($user->data['user_lang']) && file_exists("{$phpbb_root_path}umil/language/{$user->data['user_lang']}/umil.$phpEx")) - { - $path = $user->data['user_lang']; - } - else if (file_exists("{$phpbb_root_path}umil/language/" . basename($config['default_lang']) . "/umil.$phpEx")) - { - $path = basename($config['default_lang']); - } - else if (file_exists("{$phpbb_root_path}umil/language/en/umil.$phpEx")) - { - $path = 'en'; - } - else - { - trigger_error('Language Files Missing.

Please download the latest UMIL (Unified MOD Install Library) from: phpBB.com/mods/umil', E_USER_ERROR); - } - - $user->add_lang('./../../umil/language/' . $path . '/umil'); - //} - - $user->add_lang(array('acp/common', 'acp/permissions')); - - // Check to see if a newer version is available. - $info = $this->version_check('version.phpbb.com', '/umil', ((defined('PHPBB_QA')) ? 'umil_qa.txt' : 'umil.txt')); - if (is_array($info) && isset($info[0]) && isset($info[1])) - { - if (version_compare(UMIL_VERSION, $info[0], '<')) - { - global $template; - - // Make sure user->setup() has been called - if (empty($user->lang)) - { - $user->setup(); - } - - page_header('', false); - - $user->lang['UPDATE_UMIL'] = (isset($user->lang['UPDATE_UMIL'])) ? $user->lang['UPDATE_UMIL'] : 'This version of UMIL is outdated.

Please download the latest UMIL (Unified MOD Install Library) from: %1$s'; - $template->assign_vars(array( - 'S_BOARD_DISABLED' => true, - 'L_BOARD_DISABLED' => sprintf($user->lang['UPDATE_UMIL'], $info[1]), - )); - } - } - } - } - - /** - * umil_start - * - * A function which runs (almost) every time a function here is ran - */ - function umil_start() - { - global $user; - - // Set up the command. This will get the arguments sent to the function. - $args = func_get_args(); - $this->command = call_user_func_array(array($this, 'get_output_text'), $args); - - $this->result = (isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS'; - $this->db->sql_return_on_error(true); - - //$this->db->sql_transaction('begin'); - } - - /** - * umil_end - * - * A function which runs (almost) every time a function here is ran - */ - function umil_end() - { - global $user; - - // Set up the result. This will get the arguments sent to the function. - $args = func_get_args(); - $result = call_user_func_array(array($this, 'get_output_text'), $args); - $this->result = ($result) ? $result : $this->result; - - if ($this->db->sql_error_triggered) - { - if ($this->result == ((isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS')) - { - $this->result = 'SQL ERROR ' . $this->db->sql_error_returned['message']; - } - else - { - $this->result .= '

SQL ERROR ' . $this->db->sql_error_returned['message']; - } - - //$this->db->sql_transaction('rollback'); - } - else - { - //$this->db->sql_transaction('commit'); - } - - $this->db->sql_return_on_error(false); - - // Auto output if requested. - if ($this->auto_display_results && method_exists($this, 'display_results')) - { - $this->display_results(); - } - - return '' . $this->command . '
' . $this->result; - } - - /** - * Get text for output - * - * Takes the given arguments and prepares them for the UI - * - * First argument sent is used as the language key - * Further arguments (if send) are used on the language key through vsprintf() - * - * @return string Returns the prepared string for output - */ - function get_output_text() - { - global $user; - - // Set up the command. This will get the arguments sent to the function. - $args = func_get_args(); - if (sizeof($args)) - { - $lang_key = array_shift($args); - - if (sizeof($args)) - { - $lang_args = array(); - foreach ($args as $arg) - { - $lang_args[] = (isset($user->lang[$arg])) ? $user->lang[$arg] : $arg; - } - - return @vsprintf(((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key), $lang_args); - } - else - { - return ((isset($user->lang[$lang_key])) ? $user->lang[$lang_key] : $lang_key); - } - } - - return ''; - } - - /** - * Run Actions - * - * Do-It-All function that can do everything required for installing/updating/uninstalling a mod based on an array of actions and the versions. - * - * @param string $action The action. install|update|uninstall - * @param array $versions The array of versions and the actions for each - * @param string $version_config_name The name of the config setting which holds/will hold the currently installed version - * @param string $version_select Added for the UMIL Auto system to allow you to select the version you want to install/update/uninstall to. - */ - function run_actions($action, $versions, $version_config_name, $version_select = '') - { - // We will sort the actions to prevent issues from mod authors incorrectly listing the version numbers - uksort($versions, 'version_compare'); - - // Find the current version to install - $current_version = '0.0.0'; - foreach ($versions as $version => $actions) - { - $current_version = $version; - } - - $db_version = ''; - if ($this->config_exists($version_config_name)) - { - global $config; - $db_version = $config[$version_config_name]; - } - - // Set the action to install from update if nothing is currently installed - if ($action == 'update' && !$db_version) - { - $action = 'install'; - } - - if ($action == 'install' || $action == 'update') - { - $version_installed = $db_version; - foreach ($versions as $version => $version_actions) - { - // If we are updating - if ($db_version && version_compare($version, $db_version, '<=')) - { - continue; - } - - if ($version_select && version_compare($version, $version_select, '>')) - { - break; - } - - foreach ($version_actions as $method => $params) - { - if ($method == 'custom') - { - $this->_call_custom_function($params, $action, $version); - } - else - { - if (method_exists($this, $method)) - { - call_user_func(array($this, $method), $params); - } - } - } - - $version_installed = $version; - } - - // update the version number or add it - if ($this->config_exists($version_config_name)) - { - $this->config_update($version_config_name, $version_installed); - } - else - { - $this->config_add($version_config_name, $version_installed); - } - } - else if ($action == 'uninstall' && $db_version) - { - // reverse version list - $versions = array_reverse($versions); - - foreach ($versions as $version => $version_actions) - { - // Uninstalling and this listed version is newer than installed - if (version_compare($version, $db_version, '>')) - { - continue; - } - - // Version selection stuff - if ($version_select && version_compare($version, $version_select, '<=')) - { - // update the version number - $this->config_update($version_config_name, $version); - break; - } - - $cache_purge = false; - $version_actions = array_reverse($version_actions); - foreach ($version_actions as $method => $params) - { - if ($method == 'custom') - { - $this->_call_custom_function($params, $action, $version); - } - else - { - // This way we always run the cache purge at the end of the version (done for the uninstall because the instructions are reversed, which would cause the cache purge to be run at the beginning if it was meant to run at the end). - if ($method == 'cache_purge') - { - $cache_purge = $params; - continue; - } - - // A few things are not possible for uninstallations update actions and table_row actions - if (strpos($method, 'update') !== false || strpos($method, 'table_insert') !== false || strpos($method, 'table_row_') !== false) - { - continue; - } - - // reverse function call - $method = str_replace(array('add', 'remove', 'temp'), array('temp', 'add', 'remove'), $method); - $method = str_replace(array('set', 'unset', 'temp'), array('temp', 'set', 'unset'), $method); - - if (method_exists($this, $method)) - { - call_user_func(array($this, $method), ((is_array($params) ? array_reverse($params) : $params))); - } - } - } - - if ($cache_purge !== false) - { - $this->cache_purge($cache_purge); - } - } - - if (!$version_select) - { - // Unset the version number - $this->config_remove($version_config_name); - } - } - } - - /** - * Call custom function helper - */ - function _call_custom_function($functions, $action, $version) - { - if (!is_array($functions)) - { - $functions = array($functions); - } - - $return = ''; - - foreach ($functions as $function) - { - if (function_exists($function)) - { - // Must reset before calling the function - $this->umil_start(); - - $returned = call_user_func($function, $action, $version); - if (is_string($returned)) - { - $this->command = $this->get_output_text($returned); - } - else if (is_array($returned) && isset($returned['command'])) - { - if (is_array($returned['command'])) - { - $this->command = call_user_func_array(array($this, 'get_output_text'), $returned['command']); - } - else - { - $this->command = $this->get_output_text($returned['command']); - } - - if (isset($returned['result'])) - { - $this->result = $this->get_output_text($returned['result']); - } - } - else - { - $this->command = $this->get_output_text('UNKNOWN'); - } - - $return .= $this->umil_end() . '
'; - } - } - - return $return; - } - - /** - * Multicall Helper - * - * @param mixed $function Function name to call - * @param mixed $params The parameters array - * - * @return bool True if we have done a multicall ($params is an array), false if not ($params is not an array) - */ - function multicall($function, $params) - { - if (is_array($params) && !empty($params)) - { - foreach ($params as $param) - { - if (!is_array($param)) - { - call_user_func(array($this, $function), $param); - } - else - { - call_user_func_array(array($this, $function), $param); - } - } - return true; - } - - return false; - } - - /** - * Cache Purge - * - * This function is for purging either phpBB3’s data cache, authorization cache, or the styles cache. - * - * @param string $type The type of cache you want purged. Available types: auth, imageset, template, theme. Anything else sent will purge the forum's cache. - * @param int $style_id The id of the item you want purged (if the type selected is imageset/template/theme, 0 for all items in that section) - */ - function cache_purge($type = '', $style_id = 0) - { - global $auth, $cache, $user, $phpbb_root_path, $phpEx; - - // Multicall - if ($this->multicall(__FUNCTION__, $type)) - { - return; - } - - $style_id = (int) $style_id; - $type = (string) $type; // Prevent PHP bug. - - switch ($type) - { - case 'auth' : - $this->umil_start('AUTH_CACHE_PURGE'); - $cache->destroy('_acl_options'); - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - break; - - case 'imageset' : - if ($style_id == 0) - { - $return = array(); - $sql = 'SELECT imageset_id - FROM ' . STYLES_IMAGESET_TABLE; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $return[] = $this->cache_purge('imageset', $row['imageset_id']); - } - $this->db->sql_freeresult($result); - - return implode('

', $return); - } - else - { - $sql = 'SELECT * - FROM ' . STYLES_IMAGESET_TABLE . " - WHERE imageset_id = $style_id"; - $result = $this->db->sql_query($sql); - $imageset_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$imageset_row) - { - $this->umil_start('IMAGESET_CACHE_PURGE', 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - $this->umil_start('IMAGESET_CACHE_PURGE', $imageset_row['imageset_name']); - - // The following is from includes/acp/acp_styles.php (edited) - $sql_ary = array(); - - $cfg_data_imageset = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/imageset.cfg"); - - $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . ' - WHERE imageset_id = ' . $style_id; - $result = $this->db->sql_query($sql); - - foreach ($cfg_data_imageset as $image_name => $value) - { - if (strpos($value, '*') !== false) - { - if (substr($value, -1, 1) === '*') - { - list($image_filename, $image_height) = explode('*', $value); - $image_width = 0; - } - else - { - list($image_filename, $image_height, $image_width) = explode('*', $value); - } - } - else - { - $image_filename = $value; - $image_height = $image_width = 0; - } - - if (strpos($image_name, 'img_') === 0 && $image_filename) - { - $image_name = substr($image_name, 4); - - $sql_ary[] = array( - 'image_name' => (string) $image_name, - 'image_filename' => (string) $image_filename, - 'image_height' => (int) $image_height, - 'image_width' => (int) $image_width, - 'imageset_id' => (int) $style_id, - 'image_lang' => '', - ); - } - } - - $sql = 'SELECT lang_dir - FROM ' . LANG_TABLE; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { - if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg")) - { - $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg"); - foreach ($cfg_data_imageset_data as $image_name => $value) - { - if (strpos($value, '*') !== false) - { - if (substr($value, -1, 1) === '*') - { - list($image_filename, $image_height) = explode('*', $value); - $image_width = 0; - } - else - { - list($image_filename, $image_height, $image_width) = explode('*', $value); - } - } - else - { - $image_filename = $value; - $image_height = $image_width = 0; - } - - if (strpos($image_name, 'img_') === 0 && $image_filename) - { - $image_name = substr($image_name, 4); - $sql_ary[] = array( - 'image_name' => (string) $image_name, - 'image_filename' => (string) $image_filename, - 'image_height' => (int) $image_height, - 'image_width' => (int) $image_width, - 'imageset_id' => (int) $style_id, - 'image_lang' => (string) $row['lang_dir'], - ); - } - } - } - } - $this->db->sql_freeresult($result); - - $this->db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary); - - $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE); - - return $this->umil_end(); - } - break; - //case 'imageset' : - - case 'template' : - if ($style_id == 0) - { - $return = array(); - $sql = 'SELECT template_id - FROM ' . STYLES_TEMPLATE_TABLE; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $return[] = $this->cache_purge('template', $row['template_id']); - } - $this->db->sql_freeresult($result); - - return implode('

', $return); - } - else - { - $sql = 'SELECT * - FROM ' . STYLES_TEMPLATE_TABLE . " - WHERE template_id = $style_id"; - $result = $this->db->sql_query($sql); - $template_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$template_row) - { - $this->umil_start('TEMPLATE_CACHE_PURGE', 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - $this->umil_start('TEMPLATE_CACHE_PURGE', $template_row['template_name']); - - // The following is from includes/acp/acp_styles.php - if ($template_row['template_storedb'] && file_exists("{$phpbb_root_path}styles/{$template_row['template_path']}/template/")) - { - $filelist = array('' => array()); - - $sql = 'SELECT template_filename, template_mtime - FROM ' . STYLES_TEMPLATE_DATA_TABLE . " - WHERE template_id = $style_id"; - $result = $this->db->sql_query($sql); - - while ($row = $this->db->sql_fetchrow($result)) - { -// if (@filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}/template/" . $row['template_filename']) > $row['template_mtime']) -// { - // get folder info from the filename - if (($slash_pos = strrpos($row['template_filename'], '/')) === false) - { - $filelist[''][] = $row['template_filename']; - } - else - { - $filelist[substr($row['template_filename'], 0, $slash_pos + 1)][] = substr($row['template_filename'], $slash_pos + 1, strlen($row['template_filename']) - $slash_pos - 1); - } -// } - } - $this->db->sql_freeresult($result); - - $includes = array(); - foreach ($filelist as $pathfile => $file_ary) - { - foreach ($file_ary as $file) - { - if (!($fp = @fopen("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file", 'r'))) - { - return $this->umil_end('FILE_COULD_NOT_READ', "{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"); - } - $template_data = fread($fp, filesize("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file")); - fclose($fp); - - if (preg_match_all('##is', $template_data, $matches)) - { - foreach ($matches[1] as $match) - { - $includes[trim($match)][] = $file; - } - } - } - } - - foreach ($filelist as $pathfile => $file_ary) - { - foreach ($file_ary as $file) - { - // Skip index. - if (strpos($file, 'index.') === 0) - { - continue; - } - - // We could do this using extended inserts ... but that could be one - // heck of a lot of data ... - $sql_ary = array( - 'template_id' => (int) $style_id, - 'template_filename' => "$pathfile$file", - 'template_included' => (isset($includes[$file])) ? implode(':', $includes[$file]) . ':' : '', - 'template_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"), - 'template_data' => (string) file_get_contents("{$phpbb_root_path}styles/{$template_row['template_path']}$pathfile$file"), - ); - - $sql = 'UPDATE ' . STYLES_TEMPLATE_DATA_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " - WHERE template_id = $style_id - AND template_filename = '" . $this->db->sql_escape("$pathfile$file") . "'"; - $this->db->sql_query($sql); - } - } - unset($filelist); - } - - // Purge the forum's cache as well. - $cache->purge(); - - return $this->umil_end(); - } - break; - //case 'template' : - - case 'theme' : - if ($style_id == 0) - { - $return = array(); - $sql = 'SELECT theme_id - FROM ' . STYLES_THEME_TABLE; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $return[] = $this->cache_purge('theme', $row['theme_id']); - } - $this->db->sql_freeresult($result); - - return implode('

', $return); - } - else - { - $sql = 'SELECT * - FROM ' . STYLES_THEME_TABLE . " - WHERE theme_id = $style_id"; - $result = $this->db->sql_query($sql); - $theme_row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$theme_row) - { - $this->umil_start('THEME_CACHE_PURGE', 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - $this->umil_start('THEME_CACHE_PURGE', $theme_row['theme_name']); - - // The following is from includes/acp/acp_styles.php - if ($theme_row['theme_storedb'] && file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css")) - { - $stylesheet = file_get_contents($phpbb_root_path . 'styles/' . $theme_row['theme_path'] . '/theme/stylesheet.css'); - - // Match CSS imports - $matches = array(); - preg_match_all('/@import url\(["\'](.*)["\']\);/i', $stylesheet, $matches); - - if (sizeof($matches)) - { - foreach ($matches[0] as $idx => $match) - { - if (!file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}")) - { - continue; - } - - $content = trim(file_get_contents("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/{$matches[1][$idx]}")); - $stylesheet = str_replace($match, $content, $stylesheet); - } - } - - // adjust paths - $db_theme_data = str_replace('./', 'styles/' . $theme_row['theme_path'] . '/theme/', $stylesheet); - - // Save CSS contents - $sql_ary = array( - 'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"), - 'theme_data' => $db_theme_data, - ); - - $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " - WHERE theme_id = $style_id"; - $this->db->sql_query($sql); - - $cache->destroy('sql', STYLES_THEME_TABLE); - } - - return $this->umil_end(); - } - break; - //case 'theme' : - - default: - $this->umil_start('CACHE_PURGE'); - $cache->purge(); - - return $this->umil_end(); - break; - } - } - - /** - * Config Exists - * - * This function is to check to see if a config variable exists or if it does not. - * - * @param string $config_name The name of the config setting you wish to check for. - * @param bool $return_result - return the config value/default if true : default false. - * - * @return bool true/false if config exists - */ - function config_exists($config_name, $return_result = false) - { - global $config, $cache; - - $sql = 'SELECT * - FROM ' . CONFIG_TABLE . " - WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if ($row) - { - if (!isset($config[$config_name])) - { - $config[$config_name] = $row['config_value']; - - if (!$row['is_dynamic']) - { - $cache->destroy('config'); - } - } - - return ($return_result) ? $row : true; - } - - // this should never happen, but if it does, we need to remove the config from the array - if (isset($config[$config_name])) - { - unset($config[$config_name]); - $cache->destroy('config'); - } - - return false; - } - - /** - * Config Add - * - * This function allows you to add a config setting. - * - * @param string $config_name The name of the config setting you would like to add - * @param mixed $config_value The value of the config setting - * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. - * - * @return result - */ - function config_add($config_name, $config_value = '', $is_dynamic = false) - { - // Multicall - if ($this->multicall(__FUNCTION__, $config_name)) - { - return; - } - - $this->umil_start('CONFIG_ADD', $config_name); - - if ($this->config_exists($config_name)) - { - return $this->umil_end('CONFIG_ALREADY_EXISTS', $config_name); - } - - set_config($config_name, $config_value, $is_dynamic); - - return $this->umil_end(); - } - - /** - * Config Update - * - * This function allows you to update an existing config setting. - * - * @param string $config_name The name of the config setting you would like to update - * @param mixed $config_value The value of the config setting - * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. - * - * @return result - */ - function config_update($config_name, $config_value = '', $is_dynamic = false) - { - // Multicall - if ($this->multicall(__FUNCTION__, $config_name)) - { - return; - } - - $this->umil_start('CONFIG_UPDATE', $config_name); - - if (!$this->config_exists($config_name)) - { - return $this->umil_end('CONFIG_NOT_EXIST', $config_name); - } - - set_config($config_name, $config_value, $is_dynamic); - - return $this->umil_end(); - } - - /** - * Config Remove - * - * This function allows you to remove an existing config setting. - * - * @param string $config_name The name of the config setting you would like to remove - * - * @return result - */ - function config_remove($config_name) - { - global $cache, $config; - - // Multicall - if ($this->multicall(__FUNCTION__, $config_name)) - { - return; - } - - $this->umil_start('CONFIG_REMOVE', $config_name); - - if (!$this->config_exists($config_name)) - { - return $this->umil_end('CONFIG_NOT_EXIST', $config_name); - } - - $sql = 'DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; - $this->db->sql_query($sql); - - unset($config[$config_name]); - $cache->destroy('config'); - - return $this->umil_end(); - } - - /** - * Module Exists - * - * Check if a module exists - * - * @param string $class The module class(acp|mcp|ucp) - * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. - * @param int|string $module The module_id|module_langname you would like to check for to see if it exists - */ - function module_exists($class, $parent, $module) - { - // the main root directory should return true - if (!$module) - { - return true; - } - - $class = $this->db->sql_escape($class); - $module = $this->db->sql_escape($module); - - $parent_sql = ''; - if ($parent !== false) - { - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; - - if (!is_numeric($parent)) - { - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$row) - { - return false; - } - - $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; - } - else - { - $parent_sql = 'AND parent_id = ' . (int) $parent; - } - } - - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_class = '$class' - $parent_sql - AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '$module'"); - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if ($row) - { - return true; - } - - return false; - } - - /** - * Module Add - * - * Add a new module - * - * @param string $class The module class(acp|mcp|ucp) - * @param int|string $parent The parent module_id|module_langname (0 for no parent) - * @param array $data an array of the data on the new module. This can be setup in two different ways. - * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below, - * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode. - * array( - * 'module_enabled' => 1, - * 'module_display' => 1, - * 'module_basename' => '', - * 'module_class' => $class, - * 'parent_id' => (int) $parent, - * 'module_langname' => '', - * 'module_mode' => '', - * 'module_auth' => '', - * ) - * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file. - * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file): - * array( - * 'module_basename' => 'asacp', - * 'modes' => array('settings', 'log', 'flag'), - * ) - * Optionally you may not send 'modes' and it will insert all of the modules in that info file. - * @param string|bool $include_path If you would like to use a custom include path, specify that here - */ - function module_add($class, $parent = 0, $data = array(), $include_path = false) - { - global $cache, $user, $phpbb_root_path, $phpEx; - - // Multicall - if ($this->multicall(__FUNCTION__, $class)) - { - return; - } - - // Prevent stupid things like trying to add a module with no name or any data on it - if (empty($data)) - { - $this->umil_start('MODULE_ADD', $class, 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; - - // allow sending the name as a string in $data to create a category - if (!is_array($data)) - { - $data = array('module_langname' => $data); - } - - if (!isset($data['module_langname'])) - { - // The "automatic" way - $basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; - $basename = str_replace(array('/', '\\'), '', $basename); - $class = str_replace(array('/', '\\'), '', $class); - $info_file = "$class/info/{$class}_$basename.$phpEx"; - - // The manual and automatic ways both failed... - if (!file_exists((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file)) - { - $this->umil_start('MODULE_ADD', $class, $info_file); - return $this->umil_end('FAIL'); - } - - $classname = "{$class}_{$basename}_info"; - - if (!class_exists($classname)) - { - include((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file); - } - - $info = new $classname; - $module = $info->module(); - unset($info); - - $result = ''; - foreach ($module['modes'] as $mode => $module_info) - { - if (!isset($data['modes']) || in_array($mode, $data['modes'])) - { - $new_module = array( - 'module_basename' => $basename, - 'module_langname' => $module_info['title'], - 'module_mode' => $mode, - 'module_auth' => $module_info['auth'], - 'module_display' => (isset($module_info['display'])) ? $module_info['display'] : true, - 'before' => (isset($module_info['before'])) ? $module_info['before'] : false, - 'after' => (isset($module_info['after'])) ? $module_info['after'] : false, - ); - - // Run the "manual" way with the data we've collected. - $result .= ((isset($data['spacer'])) ? $data['spacer'] : '
') . $this->module_add($class, $parent, $new_module); - } - } - - return $result; - } - - // The "manual" way - $this->umil_start('MODULE_ADD', $class, ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname'])); - add_log('admin', 'LOG_MODULE_ADD', ((isset($user->lang[$data['module_langname']])) ? $user->lang[$data['module_langname']] : $data['module_langname'])); - - $class = $this->db->sql_escape($class); - - if (!is_numeric($parent)) - { - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if (!$row) - { - return $this->umil_end('PARENT_NOT_EXIST'); - } - - $parent = $data['parent_id'] = $row['module_id']; - } - else if (!$this->module_exists($class, false, $parent)) - { - return $this->umil_end('PARENT_NOT_EXIST'); - } - - if ($this->module_exists($class, $parent, $data['module_langname'])) - { - return $this->umil_end('MODULE_ALREADY_EXIST'); - } - - if (!class_exists('acp_modules')) - { - include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); - $user->add_lang('acp/modules'); - } - $acp_modules = new acp_modules(); - - $module_data = array( - 'module_enabled' => (isset($data['module_enabled'])) ? $data['module_enabled'] : 1, - 'module_display' => (isset($data['module_display'])) ? $data['module_display'] : 1, - 'module_basename' => (isset($data['module_basename'])) ? $data['module_basename'] : '', - 'module_class' => $class, - 'parent_id' => (int) $parent, - 'module_langname' => (isset($data['module_langname'])) ? $data['module_langname'] : '', - 'module_mode' => (isset($data['module_mode'])) ? $data['module_mode'] : '', - 'module_auth' => (isset($data['module_auth'])) ? $data['module_auth'] : '', - ); - $result = $acp_modules->update_module_data($module_data, true); - - // update_module_data can either return a string or an empty array... - if (is_string($result)) - { - // Error - $this->result = $this->get_output_text($result); - } - else - { - // Success - - // Move the module if requested above/below an existing one - if (isset($data['before']) && $data['before']) - { - $sql = 'SELECT left_id FROM ' . MODULES_TABLE . ' - WHERE module_class = \'' . $class . '\' - AND parent_id = ' . (int) $parent . ' - AND module_langname = \'' . $this->db->sql_escape($data['before']) . '\''; - $this->db->sql_query($sql); - $to_left = $this->db->sql_fetchfield('left_id'); - - $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 - WHERE module_class = '$class' - AND left_id >= $to_left - AND left_id < {$module_data['left_id']}"; - $this->db->sql_query($sql); - - $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = $to_left, right_id = " . ($to_left + 1) . " - WHERE module_class = '$class' - AND module_id = {$module_data['module_id']}"; - $this->db->sql_query($sql); - } - else if (isset($data['after']) && $data['after']) - { - $sql = 'SELECT right_id FROM ' . MODULES_TABLE . ' - WHERE module_class = \'' . $class . '\' - AND parent_id = ' . (int) $parent . ' - AND module_langname = \'' . $this->db->sql_escape($data['after']) . '\''; - $this->db->sql_query($sql); - $to_right = $this->db->sql_fetchfield('right_id'); - - $sql = 'UPDATE ' . MODULES_TABLE . " SET left_id = left_id + 2, right_id = right_id + 2 - WHERE module_class = '$class' - AND left_id >= $to_right - AND left_id < {$module_data['left_id']}"; - $this->db->sql_query($sql); - - $sql = 'UPDATE ' . MODULES_TABLE . ' SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . " - WHERE module_class = '$class' - AND module_id = {$module_data['module_id']}"; - $this->db->sql_query($sql); - } - } - - // Clear the Modules Cache - $cache->destroy("_modules_$class"); - - return $this->umil_end(); - } - - /** - * Module Remove - * - * Remove a module - * - * @param string $class The module class(acp|mcp|ucp) - * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. - * @param int|string $module The module id|module_langname - * @param string|bool $include_path If you would like to use a custom include path, specify that here - */ - function module_remove($class, $parent = 0, $module = '', $include_path = false) - { - global $cache, $user, $phpbb_root_path, $phpEx; - - // Multicall - if ($this->multicall(__FUNCTION__, $class)) - { - return; - } - - // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto - if (is_array($module)) - { - if (isset($module['module_langname'])) - { - // Manual Method - return $this->module_remove($class, $parent, $module['module_langname'], $include_path); - } - - // Failed. - if (!isset($module['module_basename'])) - { - $this->umil_start('MODULE_REMOVE', $class, 'UNKNOWN'); - return $this->umil_end('FAIL'); - } - - // Automatic method - $basename = str_replace(array('/', '\\'), '', $module['module_basename']); - $class = str_replace(array('/', '\\'), '', $class); - $info_file = "$class/info/{$class}_$basename.$phpEx"; - - if (!file_exists((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file)) - { - $this->umil_start('MODULE_REMOVE', $class, $info_file); - return $this->umil_end('FAIL'); - } - - $classname = "{$class}_{$basename}_info"; - - if (!class_exists($classname)) - { - include((($include_path === false) ? $phpbb_root_path . 'includes/' : $include_path) . $info_file); - } - - $info = new $classname; - $module_info = $info->module(); - unset($info); - - $result = ''; - foreach ($module_info['modes'] as $mode => $info) - { - if (!isset($module['modes']) || in_array($mode, $module['modes'])) - { - $result .= $this->module_remove($class, $parent, $info['title']) . '
'; - } - } - return $result; - } - else - { - $class = $this->db->sql_escape($class); - - if (!$this->module_exists($class, $parent, $module)) - { - $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module])) ? $user->lang[$module] : $module)); - return $this->umil_end('MODULE_NOT_EXIST'); - } - - $parent_sql = ''; - if ($parent !== false) - { - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; - - if (!is_numeric($parent)) - { - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - // we know it exists from the module_exists check - $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; - } - else - { - $parent_sql = 'AND parent_id = ' . (int) $parent; - } - } - - $module_ids = array(); - if (!is_numeric($module)) - { - $module = $this->db->sql_escape($module); - $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " - WHERE module_langname = '$module' - AND module_class = '$class' - $parent_sql"; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $module_ids[] = (int) $row['module_id']; - } - $this->db->sql_freeresult($result); - - $module_name = $module; - } - else - { - $module = (int) $module; - $sql = 'SELECT module_langname FROM ' . MODULES_TABLE . " - WHERE module_id = $module - AND module_class = '$class' - $parent_sql"; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - $module_name = $row['module_langname']; - $module_ids[] = $module; - } - - $this->umil_start('MODULE_REMOVE', $class, ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name)); - add_log('admin', 'LOG_MODULE_REMOVED', ((isset($user->lang[$module_name])) ? $user->lang[$module_name] : $module_name)); - - if (!class_exists('acp_modules')) - { - include($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); - $user->add_lang('acp/modules'); - } - $acp_modules = new acp_modules(); - $acp_modules->module_class = $class; - - foreach ($module_ids as $module_id) - { - $result = $acp_modules->delete_module($module_id); - if (!empty($result)) - { - if ($this->result == ((isset($user->lang['SUCCESS'])) ? $user->lang['SUCCESS'] : 'SUCCESS')) - { - $this->result = implode('
', $result); - } - else - { - $this->result .= '
' . implode('
', $result); - } - } - } - - $cache->destroy("_modules_$class"); - - return $this->umil_end(); - } - } - - /** - * Permission Exists - * - * Check if a permission (auth) setting exists - * - * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return bool true if it exists, false if not - */ - function permission_exists($auth_option, $global = true) - { - if ($global) - { - $type_sql = ' AND is_global = 1'; - } - else - { - $type_sql = ' AND is_local = 1'; - } - - $sql = 'SELECT auth_option_id - FROM ' . ACL_OPTIONS_TABLE . " - WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" - . $type_sql; - $result = $this->db->sql_query($sql); - - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - if ($row) - { - return true; - } - - return false; - } - - /** - * Permission Add - * - * Add a permission (auth) option - * - * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return result - */ - function permission_add($auth_option, $global = true) - { - // Multicall - if ($this->multicall(__FUNCTION__, $auth_option)) - { - return; - } - - $this->umil_start('PERMISSION_ADD', $auth_option); - - if ($this->permission_exists($auth_option, $global)) - { - return $this->umil_end('PERMISSION_ALREADY_EXISTS', $auth_option); - } - - // We've added permissions, so set to true to notify the user. - $this->permissions_added = true; - - if (!class_exists('auth_admin')) - { - global $phpbb_root_path, $phpEx; - - include($phpbb_root_path . 'includes/acp/auth.' . $phpEx); - } - $auth_admin = new auth_admin(); - - // We have to add a check to see if the !$global (if global, local, and if local, global) permission already exists. If it does, acl_add_option currently has a bug which would break the ACL system, so we are having a work-around here. - if ($this->permission_exists($auth_option, !$global)) - { - $sql_ary = array( - 'is_global' => 1, - 'is_local' => 1, - ); - $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' - SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE auth_option = \'' . $this->db->sql_escape($auth_option) . "'"; - $this->db->sql_query($sql); - } - else - { - if ($global) - { - $auth_admin->acl_add_option(array('global' => array($auth_option))); - } - else - { - $auth_admin->acl_add_option(array('local' => array($auth_option))); - } - } - - return $this->umil_end(); - } - - /** - * Permission Remove - * - * Remove a permission (auth) option - * - * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return result - */ - function permission_remove($auth_option, $global = true) - { - global $auth, $cache; - - // Multicall - if ($this->multicall(__FUNCTION__, $auth_option)) - { - return; - } - - $this->umil_start('PERMISSION_REMOVE', $auth_option); - - if (!$this->permission_exists($auth_option, $global)) - { - return $this->umil_end('PERMISSION_NOT_EXIST', $auth_option); - } - - if ($global) - { - $type_sql = ' AND is_global = 1'; - } - else - { - $type_sql = ' AND is_local = 1'; - } - $sql = 'SELECT auth_option_id, is_global, is_local FROM ' . ACL_OPTIONS_TABLE . " - WHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" . - $type_sql; - $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); - $this->db->sql_freeresult($result); - - $id = $row['auth_option_id']; - - // If it is a local and global permission, do not remove the row! :P - if ($row['is_global'] && $row['is_local']) - { - $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' - SET ' . (($global) ? 'is_global = 0' : 'is_local = 0') . ' - WHERE auth_option_id = ' . $id; - $this->db->sql_query($sql); - } - else - { - // Delete time - $this->db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $id); - } - - // Purge the auth cache - $cache->destroy('_acl_options'); - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - } - - /** - * Add a new permission role - * - * @param string $role_name The new role name - * @param sting $role_type The type (u_, m_, a_) - */ - function permission_role_add($role_name, $role_type = '', $role_description = '') - { - // Multicall - if ($this->multicall(__FUNCTION__, $role_name)) - { - return; - } - - $this->umil_start('PERMISSION_ROLE_ADD', $role_name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if ($role_id) - { - return $this->umil_end('ROLE_ALREADY_EXISTS', $old_role_name); - } - - $sql = 'SELECT MAX(role_order) AS max FROM ' . ACL_ROLES_TABLE . ' - WHERE role_type = \'' . $this->db->sql_escape($role_type) . '\''; - $this->db->sql_query($sql); - $role_order = $this->db->sql_fetchfield('max'); - $role_order = (!$role_order) ? 1 : $role_order + 1; - - $sql_ary = array( - 'role_name' => $role_name, - 'role_description' => $role_description, - 'role_type' => $role_type, - 'role_order' => $role_order, - ); - - $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); - $this->db->sql_query($sql); - - return $this->umil_end(); - } - - /** - * Update the name on a permission role - * - * @param string $old_role_name The old role name - * @param string $new_role_name The new role name - */ - function permission_role_update($old_role_name, $new_role_name = '') - { - // Multicall - if ($this->multicall(__FUNCTION__, $role_name)) - { - return; - } - - $this->umil_start('PERMISSION_ROLE_UPDATE', $old_role_name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - return $this->umil_end('ROLE_NOT_EXIST', $old_role_name); - } - - $sql = 'UPDATE ' . ACL_ROLES_TABLE . ' - SET role_name = \'' . $this->db->sql_escape($new_role_name) . '\' - WHERE role_name = \'' . $this->db->sql_escape($old_role_name) . '\''; - $this->db->sql_query($sql); - - return $this->umil_end(); - } - - /** - * Remove a permission role - * - * @param string $role_name The role name to remove - */ - function permission_role_remove($role_name) - { - global $auth; - - // Multicall - if ($this->multicall(__FUNCTION__, $role_name)) - { - return; - } - - $this->umil_start('PERMISSION_ROLE_REMOVE', $role_name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($role_name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - return $this->umil_end('ROLE_NOT_EXIST', $role_name); - } - - $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - - $sql = 'DELETE FROM ' . ACL_ROLES_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - } - - /** - * Permission Set - * - * Allows you to set permissions for a certain group/role - * - * @param string $name The name of the role/group - * @param string|array $auth_option The auth_option or array of auth_options you would like to set - * @param string $type The type (role|group) - * @param bool $has_permission True if you want to give them permission, false if you want to deny them permission - */ - function permission_set($name, $auth_option = array(), $type = 'role', $has_permission = true) - { - global $auth; - - // Multicall - if ($this->multicall(__FUNCTION__, $name)) - { - return; - } - - if (!is_array($auth_option)) - { - $auth_option = array($auth_option); - } - - $new_auth = array(); - $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $new_auth[] = $row['auth_option_id']; - } - $this->db->sql_freeresult($result); - - if (!sizeof($new_auth)) - { - return false; - } - - $current_auth = array(); - - $type = (string) $type; // Prevent PHP bug. - - switch ($type) - { - case 'role' : - $this->umil_start('PERMISSION_SET_ROLE', $name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - return $this->umil_end('ROLE_NOT_EXIST'); - } - - $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_ROLES_DATA_TABLE . ' - WHERE role_id = ' . $role_id; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $current_auth[$row['auth_option_id']] = $row['auth_setting']; - } - $this->db->sql_freeresult($result); - break; - - case 'group' : - $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $group_id = $this->db->sql_fetchfield('group_id'); - - if (!$group_id) - { - $this->umil_start('PERMISSION_SET_GROUP', $name); - return $this->umil_end('GROUP_NOT_EXIST'); - } - - // If the group has a role set for them we will add the requested permissions to that role. - $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id . ' - AND auth_role_id <> 0 - AND forum_id = 0'; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('auth_role_id'); - if ($role_id) - { - $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - $role_name = $this->db->sql_fetchfield('role_name'); - - return $this->permission_set($role_name, $auth_option, 'role', $has_permission); - } - - $this->umil_start('PERMISSION_SET_GROUP', $name); - - $sql = 'SELECT auth_option_id, auth_setting FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id; - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $current_auth[$row['auth_option_id']] = $row['auth_setting']; - } - $this->db->sql_freeresult($result); - break; - } - - $sql_ary = array(); - switch ($type) - { - case 'role' : - foreach ($new_auth as $auth_option_id) - { - if (!isset($current_auth[$auth_option_id])) - { - $sql_ary[] = array( - 'role_id' => $role_id, - 'auth_option_id' => $auth_option_id, - 'auth_setting' => $has_permission, - ); - } - } - - $this->db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary); - break; - - case 'group' : - foreach ($new_auth as $auth_option_id) - { - if (!isset($current_auth[$auth_option_id])) - { - $sql_ary[] = array( - 'group_id' => $group_id, - 'auth_option_id' => $auth_option_id, - 'auth_setting' => $has_permission, - ); - } - } - - $this->db->sql_multi_insert(ACL_GROUPS_TABLE, $sql_ary); - break; - } - - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - } - - /** - * Permission Unset - * - * Allows you to unset (remove) permissions for a certain group/role - * - * @param string $name The name of the role/group - * @param string|array $auth_option The auth_option or array of auth_options you would like to set - * @param string $type The type (role|group) - */ - function permission_unset($name, $auth_option = array(), $type = 'role') - { - global $auth; - - // Multicall - if ($this->multicall(__FUNCTION__, $name)) - { - return; - } - - if (!is_array($auth_option)) - { - $auth_option = array($auth_option); - } - - $to_remove = array(); - $sql = 'SELECT auth_option_id FROM ' . ACL_OPTIONS_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option', $auth_option); - $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) - { - $to_remove[] = $row['auth_option_id']; - } - $this->db->sql_freeresult($result); - - if (!sizeof($to_remove)) - { - return false; - } - - $type = (string) $type; // Prevent PHP bug. - - switch ($type) - { - case 'role' : - $this->umil_start('PERMISSION_UNSET_ROLE', $name); - - $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . ' - WHERE role_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); - - if (!$role_id) - { - return $this->umil_end('ROLE_NOT_EXIST'); - } - - $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); - $this->db->sql_query($sql); - break; - - case 'group' : - $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_name = \'' . $this->db->sql_escape($name) . '\''; - $this->db->sql_query($sql); - $group_id = $this->db->sql_fetchfield('group_id'); - - if (!$group_id) - { - $this->umil_start('PERMISSION_UNSET_GROUP', $name); - return $this->umil_end('GROUP_NOT_EXIST'); - } - - // If the group has a role set for them we will remove the requested permissions from that role. - $sql = 'SELECT auth_role_id FROM ' . ACL_GROUPS_TABLE . ' - WHERE group_id = ' . $group_id . ' - AND auth_role_id <> 0'; - $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('auth_role_id'); - if ($role_id) - { - $sql = 'SELECT role_name FROM ' . ACL_ROLES_TABLE . ' - WHERE role_id = ' . $role_id; - $this->db->sql_query($sql); - $role_name = $this->db->sql_fetchfield('role_name'); - - return $this->permission_unset($role_name, $auth_option, 'role'); - } - - $this->umil_start('PERMISSION_UNSET_GROUP', $name); - - $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . ' - WHERE ' . $this->db->sql_in_set('auth_option_id', $to_remove); - $this->db->sql_query($sql); - break; - } - - $auth->acl_clear_prefetch(); - - return $this->umil_end(); - } - - /** - * Table Exists - * - * Check if a table exists in the DB or not - * - * @param string $table_name The table name to check for - * - * @return bool true if the table exists, false if not - */ - function table_exists($table_name) - { - $this->get_table_name($table_name); - - // Use sql_table_exists if available - if (method_exists($this->db_tools, 'sql_table_exists')) - { - $roe = $this->db->return_on_error; - $result = $this->db_tools->sql_table_exists($table_name); - - // db_tools::sql_table_exists resets the return_on_error to false always after completing, so we must make sure we set it to true again if it was before - if ($roe) - { - $this->db->sql_return_on_error(true); - } - - return $result; - } - - if (!function_exists('get_tables')) - { - global $phpbb_root_path, $phpEx; - include($phpbb_root_path . 'includes/functions_install.' . $phpEx); - } - - $tables = get_tables($this->db); - - if (in_array($table_name, $tables)) - { - return true; - } - else - { - return false; - } - } - - /** - * Table Add - * - * This only supports input from the array format of db_tools or create_schema_files. - */ - function table_add($table_name, $table_data = array()) - { - global $dbms, $user; - - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - /** - * $table_data can be empty when uninstalling a mod and table_remove was used, but no 2rd argument was given. - * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 2rd argument) and skip this to prevent an error - */ - if (empty($table_data)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_ADD', $table_name); - - if ($this->table_exists($table_name)) - { - return $this->umil_end('TABLE_ALREADY_EXISTS', $table_name); - } - - if (!is_array($table_data)) - { - return $this->umil_end('NO_TABLE_DATA'); - } - - if (!function_exists('get_available_dbms')) - { - global $phpbb_root_path, $phpEx; - include("{$phpbb_root_path}includes/functions_install.$phpEx"); - } - - /* - * This function has had numerous problems and is currently broken, so until phpBB uses it I will not be anymore - if (method_exists($this->db_tools, 'sql_create_table')) - { - // Added in 3.0.5 - $this->db_tools->sql_create_table($table_name, $table_data); - } - else - {*/ - $available_dbms = get_available_dbms($dbms); - - $sql_query = $this->create_table_sql($table_name, $table_data); - $sql_query = split_sql_file($sql_query, $available_dbms[$dbms]['DELIM']); - - foreach ($sql_query as $sql) - { - $this->db->sql_query($sql); - } - //} - - return $this->umil_end(); - } - - /** - * Table Remove - * - * Delete/Drop a DB table - */ - function table_remove($table_name) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_REMOVE', $table_name); - - if (!$this->table_exists($table_name)) - { - return $this->umil_end('TABLE_NOT_EXIST', $table_name); - } - - if (method_exists($this->db_tools, 'sql_table_drop')) - { - // Added in 3.0.5 - $this->db_tools->sql_table_drop($table_name); - } - else - { - $this->db->sql_query('DROP TABLE ' . $table_name); - } - - return $this->umil_end(); - } - - /** - * Table Column Exists - * - * Check to see if a column exists in a table - */ - function table_column_exists($table_name, $column_name) - { - $this->get_table_name($table_name); - - return $this->db_tools->sql_column_exists($table_name, $column_name); - } - - /** - * Table Column Add - * - * Add a new column to a table. - */ - function table_column_add($table_name, $column_name = '', $column_data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - /** - * $column_data can be empty when uninstalling a mod and table_column_remove was used, but no 3rd argument was given. - * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 3rd argument) and skip this to prevent an error - */ - if (empty($column_data)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_COLUMN_ADD', $table_name, $column_name); - - if ($this->table_column_exists($table_name, $column_name)) - { - return $this->umil_end('TABLE_COLUMN_ALREADY_EXISTS', $table_name, $column_name); - } - - $this->db_tools->sql_column_add($table_name, $column_name, $column_data); - - return $this->umil_end(); - } - - /** - * Table Column Update - * - * Alter/Update a column in a table. You can not change a column name with this. - */ - function table_column_update($table_name, $column_name = '', $column_data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_COLUMN_UPDATE', $table_name, $column_name); - - if (!$this->table_column_exists($table_name, $column_name)) - { - return $this->umil_end('TABLE_COLUMN_NOT_EXIST', $table_name, $column_name); - } - - $this->db_tools->sql_column_change($table_name, $column_name, $column_data); - - return $this->umil_end(); - } - - /** - * Table Column Remove - * - * Remove a column from a table - */ - function table_column_remove($table_name, $column_name = '') - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_COLUMN_REMOVE', $table_name, $column_name); - - if (!$this->table_column_exists($table_name, $column_name)) - { - return $this->umil_end('TABLE_COLUMN_NOT_EXIST', $table_name, $column_name); - } - - $this->db_tools->sql_column_remove($table_name, $column_name); - - return $this->umil_end(); - } - - /** - * Table Index Exists - * - * Check if a table key/index exists on a table (can not check primary or unique) - */ - function table_index_exists($table_name, $index_name) - { - $this->get_table_name($table_name); - - $indexes = $this->db_tools->sql_list_index($table_name); - - if (in_array($index_name, $indexes)) - { - return true; - } - - return false; - } - - /** - * Table Index Add - * - * Add a new key/index to a table - */ - function table_index_add($table_name, $index_name = '', $column = array()) - { - global $config; - - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - // Let them skip the column field and just use the index name in that case as the column as well - if (empty($column)) - { - $column = array($index_name); - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_KEY_ADD', $table_name, $index_name); - - if ($this->table_index_exists($table_name, $index_name)) - { - return $this->umil_end('TABLE_KEY_ALREADY_EXIST', $table_name, $index_name); - } - - if (!is_array($column)) - { - $column = array($column); - } - - // remove index length if we are before 3.0.8 - // the feature (required for some types when using MySQL4) - // was added in that release (ticket PHPBB3-8944) - if (version_compare($config['version'], '3.0.7-pl1', '<=')) - { - $column = preg_replace('#:.*$#', '', $column); - } - - $this->db_tools->sql_create_index($table_name, $index_name, $column); - - return $this->umil_end(); - } - - /** - * Table Index Remove - * - * Remove a key/index from a table - */ - function table_index_remove($table_name, $index_name = '') - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_KEY_REMOVE', $table_name, $index_name); - - if (!$this->table_index_exists($table_name, $index_name)) - { - return $this->umil_end('TABLE_KEY_NOT_EXIST', $table_name, $index_name); - } - - $this->db_tools->sql_index_drop($table_name, $index_name); - - return $this->umil_end(); - } - - // Ignore, function was renamed to table_row_insert and keeping for backwards compatibility - function table_insert($table_name, $data = array()) { $this->table_row_insert($table_name, $data); } - - /** - * Table Insert - * - * Insert data into a table - */ - function table_row_insert($table_name, $data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_ROW_INSERT_DATA', $table_name); - - if (!$this->table_exists($table_name)) - { - return $this->umil_end('TABLE_NOT_EXIST', $table_name); - } - - $this->db->sql_multi_insert($table_name, $data); - - return $this->umil_end(); - } - - /** - * Table Row Update - * - * Update a row in a table - * - * $data should be an array with the column names as keys and values as the items to check for each column. Example: - * array('user_id' => 123, 'user_name' => 'test user') would become: - * WHERE user_id = 123 AND user_name = 'test user' - * - * $new_data is the new data it will be updated to (same format as you'd enter into $db->sql_build_array('UPDATE' ). - */ - function table_row_update($table_name, $data = array(), $new_data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - if (!sizeof($data)) - { - return $this->umil_end('FAIL'); - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_ROW_UPDATE_DATA', $table_name); - - if (!$this->table_exists($table_name)) - { - return $this->umil_end('TABLE_NOT_EXIST', $table_name); - } - - $sql = 'UPDATE ' . $table_name . ' - SET ' . $this->db->sql_build_array('UPDATE', $new_data) . ' - WHERE ' . $this->db->sql_build_array('SELECT', $data); - $this->db->sql_query($sql); - - return $this->umil_end(); - } - - /** - * Table Row Remove - * - * Remove a row from a table - * - * $data should be an array with the column names as keys and values as the items to check for each column. Example: - * array('user_id' => 123, 'user_name' => 'test user') would become: - * WHERE user_id = 123 AND user_name = 'test user' - */ - function table_row_remove($table_name, $data = array()) - { - // Multicall - if ($this->multicall(__FUNCTION__, $table_name)) - { - return; - } - - if (!sizeof($data)) - { - return $this->umil_end('FAIL'); - } - - $this->get_table_name($table_name); - - $this->umil_start('TABLE_ROW_REMOVE_DATA', $table_name); - - if (!$this->table_exists($table_name)) - { - return $this->umil_end('TABLE_NOT_EXIST', $table_name); - } - - $sql = 'DELETE FROM ' . $table_name . ' WHERE ' . $this->db->sql_build_array('SELECT', $data); - $this->db->sql_query($sql); - - return $this->umil_end(); - } - - /** - * Version Checker - * - * Format the file like the following: - * http://www.phpbb.com/updatecheck/30x.txt - * - * @param string $url The url to access (ex: www.phpbb.com) - * @param string $path The path to access (ex: /updatecheck) - * @param string $file The name of the file to access (ex: 30x.txt) - * - * @return array|string Error Message if there was any error, or an array (each line in the file as a value) - */ - function version_check($url, $path, $file, $timeout = 10, $port = 80) - { - if (!function_exists('get_remote_file')) - { - global $phpbb_root_path, $phpEx; - - include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); - } - - $errstr = $errno = ''; - - $info = get_remote_file($url, $path, $file, $errstr, $errno, $port, $timeout); - - if ($info === false) - { - return $errstr . ' [ ' . $errno . ' ]'; - } - - $info = str_replace("\r\n", "\n", $info); - $info = explode("\n", $info); - - return $info; - } - - /** - * Create table SQL - * - * Create the SQL query for the specified DBMS on the fly from a create_schema_files type of table array - * - * @param string $table_name The name of the table - * @param array $table_data The table data (formatted in the array format used by create_schema_files) - * @param string $dbms The dbms this will be built for (for testing only, leave blank to use the current DBMS) - * - * @return The sql query to run for the submitted dbms to insert the table - */ - function create_table_sql($table_name, $table_data, $dbms = '') - { - // To allow testing - $dbms = ($dbms) ? $dbms : $this->db_tools->sql_layer; - - // A list of types being unsigned for better reference in some db's - $unsigned_types = array('UINT', 'UINT:', 'USINT', 'BOOL', 'TIMESTAMP'); - $supported_dbms = array('firebird', 'mssql', 'mysql_40', 'mysql_41', 'oracle', 'postgres', 'sqlite'); - - $sql = ''; - - // Create Table statement - $generator = $textimage = false; - - switch ($dbms) - { - case 'mysql_40': - case 'mysql_41': - case 'firebird': - case 'oracle': - case 'sqlite': - case 'postgres': - $sql .= "CREATE TABLE {$table_name} (\n"; - break; - - case 'mssql': - $sql .= "CREATE TABLE [{$table_name}] (\n"; - break; - } - - // Table specific so we don't get overlap - $modded_array = array(); - - // Write columns one by one... - foreach ($table_data['COLUMNS'] as $column_name => $column_data) - { - // Get type - if (strpos($column_data[0], ':') !== false) - { - list($orig_column_type, $column_length) = explode(':', $column_data[0]); - if (!is_array($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'])) - { - $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'], $column_length); - } - else - { - if (isset($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'])) - { - switch ($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'][0]) - { - case 'div': - $column_length /= $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['rule'][1]; - $column_length = ceil($column_length); - $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length); - break; - } - } - - if (isset($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'])) - { - switch ($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][0]) - { - case 'mult': - $column_length *= $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][1]; - if ($column_length > $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][2]) - { - $column_type = $this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':']['limit'][3]; - $modded_array[$column_name] = $column_type; - } - else - { - $column_type = sprintf($this->db_tools->dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length); - } - break; - } - } - } - $orig_column_type .= ':'; - } - else - { - $orig_column_type = $column_data[0]; - $column_type = $this->db_tools->dbms_type_map[$dbms][$column_data[0]]; - if ($column_type == 'text' || $column_type == 'blob') - { - $modded_array[$column_name] = $column_type; - } - } - - // Adjust default value if db-dependant specified - if (is_array($column_data[1])) - { - $column_data[1] = (isset($column_data[1][$dbms])) ? $column_data[1][$dbms] : $column_data[1]['default']; - } - - switch ($dbms) - { - case 'mysql_40': - case 'mysql_41': - $sql .= "\t{$column_name} {$column_type} "; - - // For hexadecimal values do not use single quotes - if (!is_null($column_data[1]) && substr($column_type, -4) !== 'text' && substr($column_type, -4) !== 'blob') - { - $sql .= (strpos($column_data[1], '0x') === 0) ? "DEFAULT {$column_data[1]} " : "DEFAULT '{$column_data[1]}' "; - } - $sql .= 'NOT NULL'; - - if (isset($column_data[2])) - { - if ($column_data[2] == 'auto_increment') - { - $sql .= ' auto_increment'; - } - else if ($dbms === 'mysql_41' && $column_data[2] == 'true_sort') - { - $sql .= ' COLLATE utf8_unicode_ci'; - } - } - - $sql .= ",\n"; - break; - - case 'sqlite': - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $sql .= "\t{$column_name} INTEGER PRIMARY KEY "; - $generator = $column_name; - } - else - { - $sql .= "\t{$column_name} {$column_type} "; - } - - $sql .= 'NOT NULL '; - $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}'" : ''; - $sql .= ",\n"; - break; - - case 'firebird': - $sql .= "\t{$column_name} {$column_type} "; - - if (!is_null($column_data[1])) - { - $sql .= 'DEFAULT ' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ' '; - } - - $sql .= 'NOT NULL'; - - // This is a UNICODE column and thus should be given it's fair share - if (preg_match('/^X?STEXT_UNI|VCHAR_(CI|UNI:?)/', $column_data[0])) - { - $sql .= ' COLLATE UNICODE'; - } - - $sql .= ",\n"; - - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $generator = $column_name; - } - break; - - case 'mssql': - if ($column_type == '[text]') - { - $textimage = true; - } - - $sql .= "\t[{$column_name}] {$column_type} "; - - if (!is_null($column_data[1])) - { - // For hexadecimal values do not use single quotes - if (strpos($column_data[1], '0x') === 0) - { - $sql .= 'DEFAULT (' . $column_data[1] . ') '; - } - else - { - $sql .= 'DEFAULT (' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ') '; - } - } - - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $sql .= 'IDENTITY (1, 1) '; - } - - $sql .= 'NOT NULL'; - $sql .= " ,\n"; - break; - - case 'oracle': - $sql .= "\t{$column_name} {$column_type} "; - $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : ''; - - // In Oracle empty strings ('') are treated as NULL. - // Therefore in oracle we allow NULL's for all DEFAULT '' entries - $sql .= ($column_data[1] === '') ? ",\n" : "NOT NULL,\n"; - - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $generator = $column_name; - } - break; - - case 'postgres': - $sql .= "\t{$column_name} {$column_type} "; - - if (isset($column_data[2]) && $column_data[2] == 'auto_increment') - { - $sql .= "DEFAULT nextval('{$table_name}_seq'),\n"; - - // Make sure the sequence will be created before creating the table - $sql = "CREATE SEQUENCE {$table_name}_seq;\n\n" . $sql; - } - else - { - $sql .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : ''; - $sql .= "NOT NULL"; - - // Unsigned? Then add a CHECK contraint - if (in_array($orig_column_type, $unsigned_types)) - { - $sql .= " CHECK ({$column_name} >= 0)"; - } - - $sql .= ",\n"; - } - break; - } - } - - switch ($dbms) - { - case 'firebird': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n);;\n\n"; - break; - - case 'mssql': - $sql = substr($sql, 0, -2); - $sql .= "\n) ON [PRIMARY]" . (($textimage) ? ' TEXTIMAGE_ON [PRIMARY]' : '') . "\n"; - $sql .= "GO\n\n"; - break; - } - - // Write primary key - if (isset($table_data['PRIMARY_KEY'])) - { - if (!is_array($table_data['PRIMARY_KEY'])) - { - $table_data['PRIMARY_KEY'] = array($table_data['PRIMARY_KEY']); - } - - switch ($dbms) - { - case 'mysql_40': - case 'mysql_41': - case 'postgres': - $sql .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; - break; - - case 'firebird': - $sql .= "ALTER TABLE {$table_name} ADD PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . ");;\n\n"; - break; - - case 'sqlite': - if ($generator === false || !in_array($generator, $table_data['PRIMARY_KEY'])) - { - $sql .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; - } - break; - - case 'mssql': - $sql .= "ALTER TABLE [{$table_name}] WITH NOCHECK ADD \n"; - $sql .= "\tCONSTRAINT [PK_{$table_name}] PRIMARY KEY CLUSTERED \n"; - $sql .= "\t(\n"; - $sql .= "\t\t[" . implode("],\n\t\t[", $table_data['PRIMARY_KEY']) . "]\n"; - $sql .= "\t) ON [PRIMARY] \n"; - $sql .= "GO\n\n"; - break; - - case 'oracle': - $sql .= "\tCONSTRAINT pk_{$table_name} PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; - break; - } - } - - switch ($dbms) - { - case 'oracle': - // UNIQUE contrains to be added? - if (isset($table_data['KEYS'])) - { - foreach ($table_data['KEYS'] as $key_name => $key_data) - { - if (!is_array($key_data[1])) - { - $key_data[1] = array($key_data[1]); - } - - if ($key_data[0] == 'UNIQUE') - { - $sql .= "\tCONSTRAINT u_phpbb_{$key_name} UNIQUE (" . implode(', ', $key_data[1]) . "),\n"; - } - } - } - - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n)\n/\n\n"; - break; - - case 'postgres': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n);\n\n"; - break; - - case 'sqlite': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n);\n\n"; - break; - } - - // Write Keys - if (isset($table_data['KEYS'])) - { - foreach ($table_data['KEYS'] as $key_name => $key_data) - { - if (!is_array($key_data[1])) - { - $key_data[1] = array($key_data[1]); - } - - switch ($dbms) - { - case 'mysql_40': - case 'mysql_41': - $sql .= ($key_data[0] == 'INDEX') ? "\tKEY" : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? "\tUNIQUE" : ''; - foreach ($key_data[1] as $key => $col_name) - { - if (isset($modded_array[$col_name])) - { - switch ($modded_array[$col_name]) - { - case 'text': - case 'blob': - $key_data[1][$key] = $col_name . '(255)'; - break; - } - } - } - $sql .= ' ' . $key_name . ' (' . implode(', ', $key_data[1]) . "),\n"; - break; - - case 'firebird': - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; - - $sql .= ' ' . $table_name . '_' . $key_name . ' ON ' . $table_name . '(' . implode(', ', $key_data[1]) . ");;\n"; - break; - - case 'mssql': - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; - $sql .= " [{$key_name}] ON [{$table_name}]([" . implode('], [', $key_data[1]) . "]) ON [PRIMARY]\n"; - $sql .= "GO\n\n"; - break; - - case 'oracle': - if ($key_data[0] == 'UNIQUE') - { - continue; - } - - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - - $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ")\n"; - $sql .= "/\n"; - break; - - case 'sqlite': - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; - - $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n"; - break; - - case 'postgres': - $sql .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - $sql .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; - - $sql .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n"; - break; - } - } - } - - switch ($dbms) - { - case 'mysql_40': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n);\n\n"; - break; - - case 'mysql_41': - // Remove last line delimiter... - $sql = substr($sql, 0, -2); - $sql .= "\n) CHARACTER SET utf8 COLLATE utf8_bin;\n\n"; - break; - - // Create Generator - case 'firebird': - if ($generator !== false) - { - $sql .= "\nCREATE GENERATOR {$table_name}_gen;;\n"; - $sql .= 'SET GENERATOR ' . $table_name . "_gen TO 0;;\n\n"; - - $sql .= 'CREATE TRIGGER t_' . $table_name . ' FOR ' . $table_name . "\n"; - $sql .= "BEFORE INSERT\nAS\nBEGIN\n"; - $sql .= "\tNEW.{$generator} = GEN_ID({$table_name}_gen, 1);\nEND;;\n\n"; - } - break; - - case 'oracle': - if ($generator !== false) - { - $sql .= "\nCREATE SEQUENCE {$table_name}_seq\n/\n\n"; - - $sql .= "CREATE OR REPLACE TRIGGER t_{$table_name}\n"; - $sql .= "BEFORE INSERT ON {$table_name}\n"; - $sql .= "FOR EACH ROW WHEN (\n"; - $sql .= "\tnew.{$generator} IS NULL OR new.{$generator} = 0\n"; - $sql .= ")\nBEGIN\n"; - $sql .= "\tSELECT {$table_name}_seq.nextval\n"; - $sql .= "\tINTO :new.{$generator}\n"; - $sql .= "\tFROM dual;\nEND;\n/\n\n"; - } - break; - } - - return $sql; - } - - /** - * Get the real table name - * By A_Jelly_Doughnut - * - * @param string $table_name The table name to get the real table name from - */ - function get_table_name(&$table_name) - { - // Use the global table prefix if a custom one is not specified - if ($this->table_prefix === false) - { - global $table_prefix; - } - else - { - $table_prefix = $this->table_prefix; - } - - static $constants = NULL; - - if (is_null($constants)) - { - $constants = get_defined_constants(); - } - - /** - * only do the replace if the table prefix is not already present - * this is required since UMIL supports specifying a table via phpbb_foo - * (where a replace would be needed) - * or by FOO_TABLE (where a replace is already done at constant-define time) - */ - if (!preg_match('#^' . preg_quote($table_prefix, '#') . '#', $table_name) || !in_array($table_name, $constants, true)) - { - $table_name = preg_replace('#^phpbb_#i', $table_prefix, $table_name); - } - } -} - -?> \ No newline at end of file diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 216faf9866..2fd795b659 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -22,7 +22,7 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migrator { - protected $container; + protected $config; protected $db; protected $db_tools; protected $table_prefix; @@ -33,31 +33,31 @@ class phpbb_db_migrator protected $migrations_table; protected $migration_state; - protected $migrations; + protected $migrations = array(); + + /** @var string Name of the last migration run */ + public $last_run_migration = false; /** * Constructor of the database migrator - * - * @param \Symfony\Component\DependencyInjection\ContainerInterface $container Container supplying dependencies */ - public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container, $migrations) + public function __construct($config, phpbb_db_driver $db, $db_tools, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) { - $this->container = $container; - $this->db = $this->container->get('dbal.conn'); - $this->db_tools = $this->container->get('dbal.tools'); - $this->table_prefix = $this->container->getParameters('core.table_prefix'); - $this->migrations_table = $this->container->getParameters('tables.migrations'); - $this->migrations = $migrations; - - $this->phpbb_root_path = $this->container->getParameters('core.root_path'); - $this->php_ext = $this->container->getParameters('core.php_ext'); - - /** @todo replace with collection_pass when merged */ - $this->tools = array( - 'config' => new phpbb_db_migration_tools_config, - 'module' => new phpbb_db_migration_tools_module, - 'permission' => new phpbb_db_migration_tools_permission, - ); + $this->config = $config; + $this->db = $db; + $this->db_tools = $db_tools; + + $this->migrations_table = $migrations_table; + + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + + $this->table_prefix = $table_prefix; + + foreach ($tools as $tool) + { + $this->tools[$tool->get_name()] = $tool; + } $this->load_migration_state(); } @@ -93,13 +93,44 @@ class phpbb_db_migrator $this->migrations = $class_names; } + /** + * Load migration data files from a directory + * + * @param string $path + * @return array Array of migrations with names + */ + public function load_migrations($path) + { + $handle = opendir($path); + while (($file = readdir($handle)) !== false) + { + if (strpos($file, '_') !== 0 && strrpos($file, '.' . $this->php_ext) === (strlen($file) - strlen($this->php_ext) - 1)) + { + $name = 'phpbb_db_migration_data_' . substr($file, 0, -(strlen($this->php_ext) + 1)); + + if (!in_array($name, $this->migrations)) + { + $this->migrations[] = $name; + } + } + } + + foreach ($this->migrations as $name) + { + if ($this->unfulfillable($name)) + { + throw new phpbb_db_migration_exception('MIGRATION NOT FULFILLABLE', $name); + } + } + + return $this->migrations; + } + /** * Runs a single update step from the next migration to be applied. * * The update step can either be a schema or a (partial) data update. To * check if update() needs to be called again use the finished() method. - * - * @return null */ public function update() { @@ -134,7 +165,8 @@ class phpbb_db_migrator return false; } - $migration = new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); + $migration = $this->get_migration($name); + $state = (isset($this->migration_state[$name])) ? $this->migration_state[$name] : array( @@ -157,6 +189,11 @@ class phpbb_db_migrator } } + $this->last_run_migration = array( + 'name' => $name, + 'class' => $migration, + ); + if (!isset($this->migration_state[$name])) { $state['migration_start_time'] = time(); @@ -187,20 +224,20 @@ class phpbb_db_migrator protected function process_data_step($migration) { - $continue = false; + //$continue = false; $steps = $migration->update_data(); foreach ($steps as $step) { $continue = $this->run_step($step); - if (!$continue) + /*if ($continue === false) { return false; - } + }*/ } - return $continue; + //return $continue; } protected function run_step($step) @@ -211,13 +248,12 @@ class phpbb_db_migrator $callable = $callable_and_parameters[0]; $parameters = $callable_and_parameters[1]; - call_user_func_array($callable, $parameters); - - return false; + return call_user_func_array($callable, $parameters); } catch (phpbb_db_migration_exception $e) { - echo $e;die(); + echo $e; + die(); } } @@ -325,7 +361,7 @@ class phpbb_db_migrator return true; } - $migration = new $name($this->db, $this->db_tools, $this->table_prefix, $this->phpbb_root_path, $this->php_ext); + $migration = $this->get_migration($name); $depends = $migration->depends_on(); foreach ($depends as $depend) @@ -374,4 +410,15 @@ class phpbb_db_migrator { $this->db_tools->perform_schema_changes($schema_changes); } + + /** + * Helper to get a migration + * + * @param string $name Name of the migration + * @return phpbb_db_migration + */ + protected function get_migration($name) + { + return new $name($this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix); + } } diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index d0ef2759d5..057bdba0e3 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2868,6 +2868,7 @@ function send_status_line($code, $message) else { $version = phpbb_request_http_version(); + header("$version $code $message", true, $code); } } @@ -5582,7 +5583,7 @@ function phpbb_convert_30_dbms_to_31($dbms) /* $reflection = new \ReflectionClass($dbms); - + if ($reflection->isSubclassOf('phpbb_db_driver')) { return $dbms; -- cgit v1.2.1 From aceadfd77b620677a838c61085c88db4d28e4a8a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 8 Jan 2013 22:19:56 -0600 Subject: [feature/migrations] Remove migration data (separate PR) 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 | 98 ------ 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 | 79 ----- 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 | 225 ------------- 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 | 369 --------------------- phpBB/includes/db/migration/data/extensions.php | 49 --- .../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 --------- 41 files changed, 2887 deletions(-) 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/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 (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 deleted file mode 100644 index a2332c9b59..0000000000 --- a/phpBB/includes/db/migration/data/3_0_1.php +++ /dev/null @@ -1,28 +0,0 @@ -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 true; - } - else - { - 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 f2bed54085..0000000000 --- a/phpBB/includes/db/migration/data/3_0_11_rc2.php +++ /dev/null @@ -1,34 +0,0 @@ - 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 deleted file mode 100644 index 0d8702f19e..0000000000 --- a/phpBB/includes/db/migration/data/3_0_12_rc1.php +++ /dev/null @@ -1,123 +0,0 @@ -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 a3b4810d21..0000000000 --- a/phpBB/includes/db/migration/data/3_0_1_rc1.php +++ /dev/null @@ -1,79 +0,0 @@ - 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 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 deleted file mode 100644 index 3469d8d178..0000000000 --- a/phpBB/includes/db/migration/data/3_0_2.php +++ /dev/null @@ -1,28 +0,0 @@ - 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 deleted file mode 100644 index dff375f438..0000000000 --- a/phpBB/includes/db/migration/data/3_0_3.php +++ /dev/null @@ -1,28 +0,0 @@ - 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 deleted file mode 100644 index 1af4508331..0000000000 --- a/phpBB/includes/db/migration/data/3_0_4.php +++ /dev/null @@ -1,49 +0,0 @@ -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 e9bb0e01f5..0000000000 --- a/phpBB/includes/db/migration/data/3_0_4_rc1.php +++ /dev/null @@ -1,107 +0,0 @@ - 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 deleted file mode 100644 index 2f80970781..0000000000 --- a/phpBB/includes/db/migration/data/3_0_5.php +++ /dev/null @@ -1,28 +0,0 @@ - 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 deleted file mode 100644 index 1fab0f8873..0000000000 --- a/phpBB/includes/db/migration/data/3_0_5_rc1part2.php +++ /dev/null @@ -1,37 +0,0 @@ - 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 deleted file mode 100644 index 26176b9437..0000000000 --- a/phpBB/includes/db/migration/data/3_0_6.php +++ /dev/null @@ -1,28 +0,0 @@ - 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 deleted file mode 100644 index 4092a5fa61..0000000000 --- a/phpBB/includes/db/migration/data/3_0_6_rc2.php +++ /dev/null @@ -1,28 +0,0 @@ -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 e748c7a4ff..0000000000 --- a/phpBB/includes/db/migration/data/3_0_6_rc4.php +++ /dev/null @@ -1,28 +0,0 @@ - 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 deleted file mode 100644 index e2c6acce1e..0000000000 --- a/phpBB/includes/db/migration/data/3_0_7_rc2.php +++ /dev/null @@ -1,72 +0,0 @@ - ' . 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 false; - } - - 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 a5defc8278..0000000000 --- a/phpBB/includes/db/migration/data/3_0_8.php +++ /dev/null @@ -1,28 +0,0 @@ - '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 true; - } - else - { - 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 eb359e2697..0000000000 --- a/phpBB/includes/db/migration/data/3_0_9.php +++ /dev/null @@ -1,28 +0,0 @@ - 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 deleted file mode 100644 index e3c4716665..0000000000 --- a/phpBB/includes/db/migration/data/3_0_9_rc2.php +++ /dev/null @@ -1,28 +0,0 @@ - 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'), - ), - )), - - 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 d28e0ebabb..0000000000 --- a/phpBB/includes/db/migration/data/extensions.php +++ /dev/null @@ -1,49 +0,0 @@ - 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( - array('module.add', array( - 'acp', - 'ACP_GENERAL_TASKS', - 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 deleted file mode 100644 index 1c46e4147b..0000000000 --- a/phpBB/includes/db/migration/data/style_update_p1.php +++ /dev/null @@ -1,157 +0,0 @@ -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' => 'kNg=', - '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 db4b7f1753..0000000000 --- a/phpBB/includes/db/migration/data/style_update_p2.php +++ /dev/null @@ -1,42 +0,0 @@ - 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 deleted file mode 100644 index 7734ed4b76..0000000000 --- a/phpBB/includes/db/migration/data/timezone.php +++ /dev/null @@ -1,161 +0,0 @@ - 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'; - } - } -} -- cgit v1.2.1 From e9bcea5d82fd086ebcf7634ab386623f34ea8d03 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 8 Jan 2013 22:22:44 -0600 Subject: [feature/migrations] Restore update_helpers.php file This should be removed by the data branch PHPBB3-9737 --- phpBB/includes/update_helpers.php | 112 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 phpBB/includes/update_helpers.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/update_helpers.php b/phpBB/includes/update_helpers.php new file mode 100644 index 0000000000..69d678b2f8 --- /dev/null +++ b/phpBB/includes/update_helpers.php @@ -0,0 +1,112 @@ + Date: Wed, 9 Jan 2013 14:27:01 -0600 Subject: [feature/migrations] Fixing returns of callables and handling data state Lots of comments and some other miscellaneous fixes. PHPBB3-9737 --- phpBB/includes/db/db_tools.php | 1 + phpBB/includes/db/driver/mysqli.php | 1 - phpBB/includes/db/migration/exception.php | 10 ++ phpBB/includes/db/migration/migration.php | 35 ++++- phpBB/includes/db/migration/tool/config.php | 40 +++--- phpBB/includes/db/migration/tool/interface.php | 5 + phpBB/includes/db/migration/tool/module.php | 177 ++++++++++++------------ phpBB/includes/db/migration/tool/permission.php | 106 +++++++------- phpBB/includes/db/migrator.php | 158 ++++++++++++++++----- 9 files changed, 329 insertions(+), 204 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index 5329d871c8..1d6823d37a 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -349,6 +349,7 @@ class phpbb_db_tools * Setter for {@link $return_statements return_statements}. * * @param bool $return_statements True if SQL should not be executed but returned as strings + * @return null */ public function set_return_statements($return_statements) { diff --git a/phpBB/includes/db/driver/mysqli.php b/phpBB/includes/db/driver/mysqli.php index 94921a22b7..7448bf1670 100644 --- a/phpBB/includes/db/driver/mysqli.php +++ b/phpBB/includes/db/driver/mysqli.php @@ -24,7 +24,6 @@ if (!defined('IN_PHPBB')) class phpbb_db_driver_mysqli extends phpbb_db_driver { var $multi_insert = true; - var $connect_error = ''; /** diff --git a/phpBB/includes/db/migration/exception.php b/phpBB/includes/db/migration/exception.php index 19fb39ab23..bd46a4e064 100644 --- a/phpBB/includes/db/migration/exception.php +++ b/phpBB/includes/db/migration/exception.php @@ -22,8 +22,15 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migration_exception extends \Exception { + /** @var array Extra parameters sent to exception to aid in debugging */ protected $parameters; + /** + * Throw an exception. + * + * First argument is the error message. + * Additional arguments will be output with the error message. + */ public function __construct() { $parameters = func_get_args(); @@ -33,6 +40,9 @@ class phpbb_db_migration_exception extends \Exception $this->parameters = $parameters; } + /** + * Output the error as a string + */ public function __toString() { return $this->message . ': ' . var_export($this->parameters, true); diff --git a/phpBB/includes/db/migration/migration.php b/phpBB/includes/db/migration/migration.php index c2c6da855b..5f1f0443db 100644 --- a/phpBB/includes/db/migration/migration.php +++ b/phpBB/includes/db/migration/migration.php @@ -26,22 +26,41 @@ if (!defined('IN_PHPBB')) */ abstract class phpbb_db_migration { + /** @var phpbb_config */ protected $config; + + /** @var phpbb_db_driver */ protected $db; + + /** @var phpbb_db_tools */ protected $db_tools; + + /** @var string */ protected $table_prefix; + /** @var string */ protected $phpbb_root_path; + + /** @var string */ protected $php_ext; + /** @var array Errors, if any occured */ protected $errors; - private $queries = array(); + /** @var array List of queries executed through $this->sql_query() */ + protected $queries = array(); /** - * Migration constructor + * Constructor + * + * @param phpbb_config $config + * @param phpbb_db_driver $db + * @param phpbb_db_tools $db_tools + * @param string $phpbb_root_path + * @param string $php_ext + * @param string $table_prefix */ - public function __construct($config, phpbb_db_driver $db, $db_tools, $phpbb_root_path, $php_ext, $table_prefix) + public function __construct(phpbb_config $config, phpbb_db_driver $db, phpbb_db_tools $db_tools, $phpbb_root_path, $php_ext, $table_prefix) { $this->config = $config; $this->db = $db; @@ -55,7 +74,7 @@ abstract class phpbb_db_migration } /** - * Defines other migrationsto be applied first (abstract method) + * Defines other migrations to be applied first (abstract method) * * @return array An array of migration class names */ @@ -67,7 +86,7 @@ abstract class phpbb_db_migration /** * Updates the database schema by providing a set of change instructions * - * @return array + * @return array Array of schema changes (compatible with db_tools->perform_schema_changes()) */ public function update_schema() { @@ -77,14 +96,18 @@ abstract class phpbb_db_migration /** * Updates data by returning a list of instructions to be executed * - * @return array + * @return array Array of data update instructions */ public function update_data() { + return array(); } /** * Wrapper for running queries to generate user feedback on updates + * + * @param string $sql SQL query to run on the database + * @return mixed Query result from db->sql_query() */ protected function sql_query($sql) { diff --git a/phpBB/includes/db/migration/tool/config.php b/phpBB/includes/db/migration/tool/config.php index 35fa3ce566..e7239436d2 100644 --- a/phpBB/includes/db/migration/tool/config.php +++ b/phpBB/includes/db/migration/tool/config.php @@ -7,11 +7,21 @@ * */ +/** +* Migration config tool +* +* @package db +*/ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interface { /** @var phpbb_config */ - protected $config = null; + protected $config; + /** + * Constructor + * + * @param phpbb_config $config + */ public function __construct(phpbb_config $config) { $this->config = $config; @@ -26,13 +36,12 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac } /** - * Config Add - * - * This function allows you to add a config setting. + * Add a config setting. * * @param string $config_name The name of the config setting you would like to add * @param mixed $config_value The value of the config setting * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + * @return null */ public function add($config_name, $config_value = '', $is_dynamic = false) { @@ -42,17 +51,14 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac } $this->config->set($config_name, $config_value, !$is_dynamic); - - return false; } /** - * Config Update - * - * This function allows you to update an existing config setting. + * Update an existing config setting. * * @param string $config_name The name of the config setting you would like to update * @param mixed $config_value The value of the config setting + * @return null */ public function update($config_name, $config_value = '') { @@ -62,18 +68,15 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac } $this->config->set($config_name, $config_value); - - return false; } /** - * Config Update If Equals - * - * This function allows you to update a config setting if the first argument equal to the current config value + * Update a config setting if the first argument equal to the current config value * * @param bool $compare If equal to the current config value, will be updated to the new config value, otherwise not * @param string $config_name The name of the config setting you would like to update * @param mixed $config_value The value of the config setting + * @return null */ public function update_if_equals($compare, $config_name, $config_value = '') { @@ -83,16 +86,13 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac } $this->config->set_atomic($config_name, $compare, $config_value); - - return false; } /** - * Config Remove - * - * This function allows you to remove an existing config setting. + * Remove an existing config setting. * * @param string $config_name The name of the config setting you would like to remove + * @return null */ public function remove($config_name) { @@ -102,7 +102,5 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac } $this->config->delete($config_name); - - return false; } } diff --git a/phpBB/includes/db/migration/tool/interface.php b/phpBB/includes/db/migration/tool/interface.php index 1815f5e8a2..5d10246ba1 100644 --- a/phpBB/includes/db/migration/tool/interface.php +++ b/phpBB/includes/db/migration/tool/interface.php @@ -7,6 +7,11 @@ * */ +/** +* Migration tool interface +* +* @package db +*/ interface phpbb_db_migration_tool_interface { /** diff --git a/phpBB/includes/db/migration/tool/module.php b/phpBB/includes/db/migration/tool/module.php index a503f08c01..f1b527bf21 100644 --- a/phpBB/includes/db/migration/tool/module.php +++ b/phpBB/includes/db/migration/tool/module.php @@ -7,27 +7,42 @@ * */ +/** +* Migration module management tool +* +* @package db +*/ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interface { /** @var phpbb_cache_service */ - protected $cache = null; + protected $cache; /** @var dbal */ - 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 $modules_table = null; + protected $modules_table; - public function __construct(phpbb_db_driver $db, $cache, $user, $phpbb_root_path, $php_ext, $modules_table) + /** + * Constructor + * + * @param phpbb_db_driver $db + * @param mixed $cache + * @param phpbb_user $user + * @param string $phpbb_root_path + * @param string $php_ext + * @param string $modules_table + */ + public function __construct(phpbb_db_driver $db, phpbb_cache_service $cache, phpbb_user $user, $phpbb_root_path, $php_ext, $modules_table) { $this->db = $db; $this->cache = $cache; @@ -53,7 +68,6 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac * @param string $class The module class(acp|mcp|ucp) * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. * @param int|string $module The module_id|module_langname you would like to check for to see if it exists - * * @return bool true/false if module exists */ public function exists($class, $parent, $module) @@ -64,31 +78,28 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac return true; } - $class = $this->db->sql_escape($class); - $module = $this->db->sql_escape($module); - $parent_sql = ''; if ($parent !== false) { // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; + $parent = $parent ?: 0; if (!is_numeric($parent)) { $sql = 'SELECT module_id FROM ' . $this->modules_table . " WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; + AND module_class = '" . $this->db->sql_escape($class) . "'"; $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); + $module_id = $this->db->sql_fetchfield('module_id'); $this->db->sql_freeresult($result); - if (!$row) + if (!$module_id) { return false; } - $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + $parent_sql = 'AND parent_id = ' . (int) $module_id; } else { @@ -98,14 +109,14 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac $sql = 'SELECT module_id FROM ' . $this->modules_table . " - WHERE module_class = '$class' + WHERE module_class = '" . $this->db->sql_escape($class) . "' $parent_sql - AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '$module'"); + AND " . ((is_numeric($module)) ? 'module_id = ' . (int) $module : "module_langname = '" . $this->db->sql_escape($module) . "'"); $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); + $module_id = $this->db->sql_fetchfield('module_id'); $this->db->sql_freeresult($result); - if ($row) + if ($module_id) { return true; } @@ -123,29 +134,30 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac * @param array $data an array of the data on the new module. This can be setup in two different ways. * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below, * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode. - * array( - * 'module_enabled' => 1, - * 'module_display' => 1, - * 'module_basename' => '', - * 'module_class' => $class, - * 'parent_id' => (int) $parent, - * 'module_langname' => '', - * 'module_mode' => '', - * 'module_auth' => '', - * ) + * array( + * 'module_enabled' => 1, + * 'module_display' => 1, + * 'module_basename' => '', + * 'module_class' => $class, + * 'parent_id' => (int) $parent, + * 'module_langname' => '', + * 'module_mode' => '', + * 'module_auth' => '', + * ) * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file. * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file): - * array( - * 'module_basename' => 'asacp', - * 'modes' => array('settings', 'log', 'flag'), - * ) + * array( + * 'module_basename' => 'asacp', + * 'modes' => array('settings', 'log', 'flag'), + * ) * Optionally you may not send 'modes' and it will insert all of the modules in that info file. - * @param string|bool $include_path If you would like to use a custom include path, specify that here + * @param string|bool $include_path If you would like to use a custom include path, specify that here + * @return null */ public function add($class, $parent = 0, $data = array(), $include_path = false) { - // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; + // Allows '' to be sent as 0 + $parent = $parent ?: 0; // allow sending the name as a string in $data to create a category if (!is_array($data)) @@ -155,18 +167,16 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac if (!isset($data['module_langname'])) { - /** - * @TODO does not work with 3.1 modules yet, but must continue for old 3.0 versions for - * upgrades from a 3.0.x version to 3.1 - */ // The "automatic" way $basename = (isset($data['module_basename'])) ? $data['module_basename'] : ''; $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 === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file)) + if (!file_exists($include_path . $info_file)) { throw new phpbb_db_migration_exception('MODULE_INFO_FILE_NOT_EXIST', $class, $info_file); } @@ -175,7 +185,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac if (!class_exists($classname)) { - include((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file); + include($include_path . $info_file); } $info = new $classname; @@ -206,26 +216,25 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac } // The "manual" way - add_log('admin', 'LOG_MODULE_ADD', ((isset($this->user->lang[$data['module_langname']])) ? $this->user->lang[$data['module_langname']] : $data['module_langname'])); - - $class = $this->db->sql_escape($class); + $module_log_name = ((isset($this->user->lang[$data['module_langname']])) ? $this->user->lang[$data['module_langname']] : $data['module_langname']); + add_log('admin', 'LOG_MODULE_ADD', $module_log_name); if (!is_numeric($parent)) { $sql = 'SELECT module_id FROM ' . $this->modules_table . " WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; + AND module_class = '" . $this->db->sql_escape($class) . "'"; $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); + $module_id = $this->db->sql_fetchfield('module_id'); $this->db->sql_freeresult($result); - if (!$row) + if (!$module_id) { throw new phpbb_db_migration_exception('MODULE_PARENT_NOT_EXIST', $parent); } - $parent = $data['parent_id'] = $row['module_id']; + $parent = $data['parent_id'] = $module_id; } else if (!$this->exists($class, false, $parent)) { @@ -270,46 +279,46 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac if (isset($data['before']) && $data['before']) { $sql = 'SELECT left_id - FROM ' . $this->modules_table . ' - WHERE module_class = \'' . $class . '\' - AND parent_id = ' . (int) $parent . ' - AND module_langname = \'' . $this->db->sql_escape($data['before']) . '\''; + FROM ' . $this->modules_table . " + WHERE module_class = '" . $this->db->sql_escape($class) . "' + AND parent_id = " . (int) $parent . " + AND module_langname = '" . $this->db->sql_escape($data['before']) . "'"; $this->db->sql_query($sql); - $to_left = $this->db->sql_fetchfield('left_id'); + $to_left = (int) $this->db->sql_fetchfield('left_id'); $sql = 'UPDATE ' . $this->modules_table . " SET left_id = left_id + 2, right_id = right_id + 2 - WHERE module_class = '$class' + WHERE module_class = '" . $this->db->sql_escape($class) . "' AND left_id >= $to_left AND left_id < {$module_data['left_id']}"; $this->db->sql_query($sql); $sql = 'UPDATE ' . $this->modules_table . " SET left_id = $to_left, right_id = " . ($to_left + 1) . " - WHERE module_class = '$class' + WHERE module_class = '" . $this->db->sql_escape($class) . "' AND module_id = {$module_data['module_id']}"; $this->db->sql_query($sql); } else if (isset($data['after']) && $data['after']) { $sql = 'SELECT right_id - FROM ' . $this->modules_table . ' - WHERE module_class = \'' . $class . '\' - AND parent_id = ' . (int) $parent . ' - AND module_langname = \'' . $this->db->sql_escape($data['after']) . '\''; + FROM ' . $this->modules_table . " + WHERE module_class = '" . $this->db->sql_escape($class) . "' + AND parent_id = " . (int) $parent . " + AND module_langname = '" . $this->db->sql_escape($data['after']) . "'"; $this->db->sql_query($sql); - $to_right = $this->db->sql_fetchfield('right_id'); + $to_right = (int) $this->db->sql_fetchfield('right_id'); $sql = 'UPDATE ' . $this->modules_table . " SET left_id = left_id + 2, right_id = right_id + 2 - WHERE module_class = '$class' + WHERE module_class = '" . $this->db->sql_escape($class) . "' AND left_id >= $to_right AND left_id < {$module_data['left_id']}"; $this->db->sql_query($sql); $sql = 'UPDATE ' . $this->modules_table . ' SET left_id = ' . ($to_right + 1) . ', right_id = ' . ($to_right + 2) . " - WHERE module_class = '$class' + WHERE module_class = '" . $this->db->sql_escape($class) . "' AND module_id = {$module_data['module_id']}"; $this->db->sql_query($sql); } @@ -317,8 +326,6 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac // Clear the Modules Cache $this->cache->destroy("_modules_$class"); - - return false; } /** @@ -330,6 +337,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. * @param int|string $module The module id|module_langname * @param string|bool $include_path If you would like to use a custom include path, specify that here + * @return null */ public function remove($class, $parent = 0, $module = '', $include_path = false) { @@ -351,9 +359,11 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac // Automatic method $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 === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file)) + if (!file_exists($include_path . $info_file)) { throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', $info_file); } @@ -362,7 +372,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac if (!class_exists($classname)) { - include((($include_path === false) ? $this->phpbb_root_path . 'includes/' : $include_path) . $info_file); + include($include_path . $info_file); } $info = new $classname; @@ -376,12 +386,9 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac $this->remove($class, $parent, $info['title']) . '
'; } } - return false; } else { - $class = $this->db->sql_escape($class); - if (!$this->exists($class, $parent, $module)) { throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', ((isset($this->user->lang[$module])) ? $this->user->lang[$module] : $module)); @@ -391,20 +398,20 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac if ($parent !== false) { // Allows '' to be sent as 0 - $parent = (!$parent) ? 0 : $parent; + $parent = ($parent) ?: 0; if (!is_numeric($parent)) { $sql = 'SELECT module_id FROM ' . $this->modules_table . " WHERE module_langname = '" . $this->db->sql_escape($parent) . "' - AND module_class = '$class'"; + AND module_class = '" . $this->db->sql_escape($class) . "'"; $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); + $module_id = $this->db->sql_fetchfield('module_id'); $this->db->sql_freeresult($result); // we know it exists from the module_exists check - $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; + $parent_sql = 'AND parent_id = ' . (int) $module_id; } else { @@ -415,16 +422,15 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac $module_ids = array(); if (!is_numeric($module)) { - $module = $this->db->sql_escape($module); $sql = 'SELECT module_id FROM ' . $this->modules_table . " - WHERE module_langname = '$module' - AND module_class = '$class' - $parent_sql"; + WHERE module_langname = '" . $this->db->sql_escape($module) . "' + AND module_class = '" . $this->db->sql_escape($class) . "' + $parent_sql"; $result = $this->db->sql_query($sql); - while ($row = $this->db->sql_fetchrow($result)) + while ($module_id = $this->db->sql_fetchfield('module_id')) { - $module_ids[] = (int) $row['module_id']; + $module_ids[] = (int) $module_id; } $this->db->sql_freeresult($result); @@ -436,13 +442,12 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac $sql = 'SELECT module_langname FROM ' . $this->modules_table . " WHERE module_id = $module - AND module_class = '$class' - $parent_sql"; + AND module_class = '" . $this->db->sql_escape($class) . "' + $parent_sql"; $result = $this->db->sql_query($sql); - $row = $this->db->sql_fetchrow($result); + $module_name = $this->db->sql_fetchfield('module_id'); $this->db->sql_freeresult($result); - $module_name = $row['module_langname']; $module_ids[] = $module; } @@ -464,8 +469,6 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac } $this->cache->destroy("_modules_$class"); - - return false; } } } diff --git a/phpBB/includes/db/migration/tool/permission.php b/phpBB/includes/db/migration/tool/permission.php index ebe404bc62..97fdbc0df9 100644 --- a/phpBB/includes/db/migration/tool/permission.php +++ b/phpBB/includes/db/migration/tool/permission.php @@ -7,24 +7,38 @@ * */ +/** +* Migration permission management tool +* +* @package db +*/ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_interface { /** @var phpbb_auth */ - protected $auth = null; + protected $auth; /** @var phpbb_cache_service */ - protected $cache = null; + protected $cache; /** @var dbal */ - protected $db = null; + protected $db; /** @var string */ - protected $phpbb_root_path = null; + protected $phpbb_root_path; /** @var string */ - protected $php_ext = null; + protected $php_ext; - public function __construct(phpbb_db_driver $db, $cache, phpbb_auth $auth, $phpbb_root_path, $php_ext) + /** + * Constructor + * + * @param phpbb_db_driver $db + * @param mixed $cache + * @param phpbb_auth $auth + * @param string $phpbb_root_path + * @param string $php_ext + */ + public function __construct(phpbb_db_driver $db, phpbb_cache_service $cache, phpbb_auth $auth, $phpbb_root_path, $php_ext) { $this->db = $db; $this->cache = $cache; @@ -48,7 +62,6 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * * @param string $auth_option The name of the permission (auth) option * @param bool $global True for checking a global permission setting, False for a local permission setting - * * @return bool true if it exists, false if not */ public function exists($auth_option, $global = true) @@ -86,8 +99,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * * @param string $auth_option The name of the permission (auth) option * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return result + * @return null */ public function add($auth_option, $global = true, $copy_from = false) { @@ -152,7 +164,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte } $this->db->sql_freeresult($result); - if (sizeof($sql_ary)) + if (!empty($sql_ary)) { $this->db->sql_multi_insert($table, $sql_ary); } @@ -160,8 +172,6 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $auth_admin->acl_clear_prefetch(); } - - return false; } /** @@ -171,8 +181,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * * @param string $auth_option The name of the permission (auth) option * @param bool $global True for checking a global permission setting, False for a local permission setting - * - * @return result + * @return null */ public function remove($auth_option, $global = true) { @@ -197,7 +206,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); - $id = $row['auth_option_id']; + $id = (int) $row['auth_option_id']; // If it is a local and global permission, do not remove the row! :P if ($row['is_global'] && $row['is_local']) @@ -210,17 +219,17 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte else { // Delete time - $this->db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id = ' . $id); - $this->db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id = ' . $id); + $tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE, ACL_OPTIONS_TABLE); + foreach ($tables as $table) + { + $this->db->sql_query('DELETE FROM ' . $table . ' + WHERE auth_option_id = ' . $id); + } } // Purge the auth cache $this->cache->destroy('_acl_options'); $this->auth->acl_clear_prefetch(); - - return false; } /** @@ -228,6 +237,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * * @param string $role_name The new role name * @param sting $role_type The type (u_, m_, a_) + * @return null */ public function role_add($role_name, $role_type = '', $role_description = '') { @@ -235,18 +245,18 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte FROM ' . ACL_ROLES_TABLE . " WHERE role_name = '" . $this->db->sql_escape($role_name) . "'"; $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); + $role_id = (int) $this->db->sql_fetchfield('role_id'); if ($role_id) { throw new phpbb_db_migration_exception('ROLE_ALREADY_EXISTS', $old_role_name); } - $sql = 'SELECT MAX(role_order) AS max + $sql = 'SELECT MAX(role_order) AS max_role_order FROM ' . ACL_ROLES_TABLE . " WHERE role_type = '" . $this->db->sql_escape($role_type) . "'"; $this->db->sql_query($sql); - $role_order = $this->db->sql_fetchfield('max'); + $role_order = (int) $this->db->sql_fetchfield('max_role_order'); $role_order = (!$role_order) ? 1 : $role_order + 1; $sql_ary = array( @@ -258,8 +268,6 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); - - return false; } /** @@ -267,6 +275,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * * @param string $old_role_name The old role name * @param string $new_role_name The new role name + * @return null */ public function role_update($old_role_name, $new_role_name = '') { @@ -274,7 +283,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte FROM ' . ACL_ROLES_TABLE . " WHERE role_name = '" . $this->db->sql_escape($old_role_name) . "'"; $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); + $role_id = (int) $this->db->sql_fetchfield('role_id'); if (!$role_id) { @@ -285,14 +294,13 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte SET role_name = '" . $this->db->sql_escape($new_role_name) . "' WHERE role_name = '" . $this->db->sql_escape($old_role_name) . "'"; $this->db->sql_query($sql); - - return false; } /** * Remove a permission role * * @param string $role_name The role name to remove + * @return null */ public function role_remove($role_name) { @@ -300,7 +308,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte FROM ' . ACL_ROLES_TABLE . " WHERE role_name = '" . $this->db->sql_escape($role_name) . "'"; $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); + $role_id = (int) $this->db->sql_fetchfield('role_id'); if (!$role_id) { @@ -316,8 +324,6 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $this->db->sql_query($sql); $this->auth->acl_clear_prefetch(); - - return false; } /** @@ -329,6 +335,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * @param string|array $auth_option The auth_option or array of auth_options you would like to set * @param string $type The type (role|group) * @param bool $has_permission True if you want to give them permission, false if you want to deny them permission + * @return null */ public function permission_set($name, $auth_option = array(), $type = 'role', $has_permission = true) { @@ -344,13 +351,13 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - $new_auth[] = $row['auth_option_id']; + $new_auth[] = (int) $row['auth_option_id']; } $this->db->sql_freeresult($result); - if (!sizeof($new_auth)) + if (empty($new_auth)) { - return false; + return; } $current_auth = array(); @@ -364,7 +371,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte FROM ' . ACL_ROLES_TABLE . " WHERE role_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); + $role_id = (int) $this->db->sql_fetchfield('role_id'); if (!$role_id) { @@ -387,7 +394,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte FROM ' . GROUPS_TABLE . " WHERE group_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); - $group_id = $this->db->sql_fetchfield('group_id'); + $group_id = (int) $this->db->sql_fetchfield('group_id'); if (!$group_id) { @@ -401,7 +408,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte AND auth_role_id <> 0 AND forum_id = 0'; $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('auth_role_id'); + $role_id = (int) $this->db->sql_fetchfield('auth_role_id'); if ($role_id) { $sql = 'SELECT role_name @@ -437,7 +444,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte 'role_id' => $role_id, 'auth_option_id' => $auth_option_id, 'auth_setting' => $has_permission, - ); + ); } } @@ -453,7 +460,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte 'group_id' => $group_id, 'auth_option_id' => $auth_option_id, 'auth_setting' => $has_permission, - ); + ); } } @@ -462,8 +469,6 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte } $this->auth->acl_clear_prefetch(); - - return false; } /** @@ -474,6 +479,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * @param string $name The name of the role/group * @param string|array $auth_option The auth_option or array of auth_options you would like to set * @param string $type The type (role|group) + * @return null */ public function permission_unset($name, $auth_option = array(), $type = 'role') { @@ -489,13 +495,13 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { - $to_remove[] = $row['auth_option_id']; + $to_remove[] = (int) $row['auth_option_id']; } $this->db->sql_freeresult($result); - if (!sizeof($to_remove)) + if (empty($to_remove)) { - return false; + return; } $type = (string) $type; // Prevent PHP bug. @@ -507,11 +513,11 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte FROM ' . ACL_ROLES_TABLE . " WHERE role_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('role_id'); + $role_id = (int) $this->db->sql_fetchfield('role_id'); if (!$role_id) { - throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $name); + throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $name); } $sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . ' @@ -524,7 +530,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte FROM ' . GROUPS_TABLE . " WHERE group_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); - $group_id = $this->db->sql_fetchfield('group_id'); + $group_id = (int) $this->db->sql_fetchfield('group_id'); if (!$group_id) { @@ -537,7 +543,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte WHERE group_id = ' . $group_id . ' AND auth_role_id <> 0'; $this->db->sql_query($sql); - $role_id = $this->db->sql_fetchfield('auth_role_id'); + $role_id = (int) $this->db->sql_fetchfield('auth_role_id'); if ($role_id) { $sql = 'SELECT role_name @@ -556,7 +562,5 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte } $this->auth->acl_clear_prefetch(); - - return false; } } diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 2fd795b659..2ba1eba427 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -22,26 +22,40 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migrator { + /** @var phpbb_config */ protected $config; + + /** @var phpbb_db_driver */ protected $db; + + /** @var phpbb_db_tools */ protected $db_tools; + + /** @var string */ protected $table_prefix; + /** @var string */ protected $phpbb_root_path; + + /** @var string */ protected $php_ext; + /** @var string */ protected $migrations_table; + + /** @var array State of all migrations (SELECT * FROM migrations table) */ protected $migration_state; + /** @var array Array of all migrations available to be run */ protected $migrations = array(); - /** @var string Name of the last migration run */ + /** @var array 'name' and 'class' of the last migration run */ public $last_run_migration = false; /** * Constructor of the database migrator */ - public function __construct($config, phpbb_db_driver $db, $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, $migrations_table, $phpbb_root_path, $php_ext, $table_prefix, $tools) { $this->config = $config; $this->db = $db; @@ -96,17 +110,42 @@ class phpbb_db_migrator /** * Load migration data files from a directory * - * @param string $path + * This does not loop through sub-directories. + * Migration data files loaded with this function MUST contain + * ONLY ONE class in them (or an exception will be thrown). + * + * @param string $path Path to migration data files + * @param bool $check_fulfillable If TRUE (default), we will check + * if all of the migrations are fulfillable after loading them. + * 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). * @return array Array of migrations with names */ - public function load_migrations($path) + public function load_migrations($path, $check_fulfillable = true) { $handle = opendir($path); while (($file = readdir($handle)) !== false) { if (strpos($file, '_') !== 0 && strrpos($file, '.' . $this->php_ext) === (strlen($file) - strlen($this->php_ext) - 1)) { - $name = 'phpbb_db_migration_data_' . substr($file, 0, -(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 ( + // The phpbb_db_migrations class may not have been loaded until now, so make sure to ignore it. + !(sizeof($added_classes) == 2 && in_array('phpbb_db_migration', $added_classes)) && + 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)) { @@ -115,11 +154,14 @@ class phpbb_db_migrator } } - foreach ($this->migrations as $name) + if ($check_fulfillable) { - if ($this->unfulfillable($name)) + foreach ($this->migrations as $name) { - throw new phpbb_db_migration_exception('MIGRATION NOT FULFILLABLE', $name); + if ($this->unfulfillable($name)) + { + throw new phpbb_db_migration_exception('MIGRATION NOT FULFILLABLE', $name); + } } } @@ -131,6 +173,8 @@ class phpbb_db_migrator * * The update step can either be a schema or a (partial) data update. To * check if update() needs to be called again use the finished() method. + * + * @return null */ public function update() { @@ -207,9 +251,11 @@ class phpbb_db_migrator } else { - $this->process_data_step($migration); - $state['migration_data_done'] = true; - $state['migration_end_time'] = time(); + $state = $this->process_data_step($migration); + + $state['migration_data_state'] = $state; + $state['migration_data_done'] = ($state === true); + $state['migration_end_time'] = ($state === true) ? time() : 0; } $sql = 'UPDATE ' . $this->migrations_table . ' @@ -222,41 +268,74 @@ class phpbb_db_migrator return true; } + /** + * Apply schema changes from a migration + * + * Just calls db_tools->perform_schema_changes + * + * @param array $schema_changes from migration + */ + protected function apply_schema_changes($schema_changes) + { + $this->db_tools->perform_schema_changes($schema_changes); + } + + /** + * Process the data step of the migration + * + * @param phpbb_db_migration $migration + * @return mixed migration status or bool true if everything completed successfully + */ protected function process_data_step($migration) { - //$continue = false; $steps = $migration->update_data(); foreach ($steps as $step) { - $continue = $this->run_step($step); - - /*if ($continue === false) + try { - return false; - }*/ + // Result will be null or true if everything completed correctly + $result = $this->run_step($step); + if ($result !== null && $result !== true) + { + return $result; + } + } + catch (phpbb_db_migration_exception $e) + { + // We should try rolling back here + + echo $e; + die(); + } } - //return $continue; + return true; } + /** + * Run a single step + * + * An exception should be thrown if an error occurs + * + * @param mixed $step + * @return null + */ protected function run_step($step) { - try - { - $callable_and_parameters = $this->get_callable_from_step($step); - $callable = $callable_and_parameters[0]; - $parameters = $callable_and_parameters[1]; + $callable_and_parameters = $this->get_callable_from_step($step); + $callable = $callable_and_parameters[0]; + $parameters = $callable_and_parameters[1]; - return call_user_func_array($callable, $parameters); - } - catch (phpbb_db_migration_exception $e) - { - echo $e; - die(); - } + return call_user_func_array($callable, $parameters); } + /** + * Get a callable statement from a data step + * + * @param mixed $step Data step from migration + * @return array Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters + */ public function get_callable_from_step($step) { $type = $step[0]; @@ -291,6 +370,7 @@ class phpbb_db_migrator $callable_and_parameters = $this->get_callable_from_step($step); $callable = $callable_and_parameters[0]; $sub_parameters = $callable_and_parameters[1]; + return array( function ($condition) use ($callable, $sub_parameters) { return call_user_func_array($callable, $sub_parameters); @@ -325,12 +405,19 @@ class phpbb_db_migrator return array( array($this->tools[$class], $method), - $parameters + $parameters, ); break; } } + /** + * Insert migration row into the database + * + * @param string $name Name of the migration + * @param array $state + * @return null + */ protected function insert_migration($name, $state) { $migration_row = $state; @@ -346,8 +433,8 @@ class phpbb_db_migrator /** * Checks if a migration's dependencies can even theoretically be satisfied. * - * @param string $name The class name of the migration - * @return bool Whether the migration cannot be fulfilled + * @param string $name The class name of the migration + * @return bool Whether the migration cannot be fulfilled */ public function unfulfillable($name) { @@ -406,11 +493,6 @@ class phpbb_db_migrator return true; } - protected function apply_schema_changes($schema_changes) - { - $this->db_tools->perform_schema_changes($schema_changes); - } - /** * Helper to get a migration * -- cgit v1.2.1 From edf693e3bd4352ab75c62311b34f12fc98e7ef63 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 15:28:08 -0600 Subject: [feature/migrations] Store state properly and send past result to callable Fix return on module add PHPBB3-9737 --- phpBB/includes/db/migration/tool/module.php | 4 +-- phpBB/includes/db/migrator.php | 56 +++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 16 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/tool/module.php b/phpBB/includes/db/migration/tool/module.php index f1b527bf21..70a246849a 100644 --- a/phpBB/includes/db/migration/tool/module.php +++ b/phpBB/includes/db/migration/tool/module.php @@ -208,11 +208,11 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac ); // Run the "manual" way with the data we've collected. - $result .= ((isset($data['spacer'])) ? $data['spacer'] : '
') . $this->add($class, $parent, $new_module); + $this->add($class, $parent, $new_module); } } - return $result; + return; } // The "manual" way diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 2ba1eba427..7aa4cfa719 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -251,11 +251,11 @@ class phpbb_db_migrator } else { - $state = $this->process_data_step($migration); + $result = $this->process_data_step($migration, $state['migration_data_state']); - $state['migration_data_state'] = $state; - $state['migration_data_done'] = ($state === true); - $state['migration_end_time'] = ($state === true) ? time() : 0; + $state['migration_data_state'] = ($result === true) ? '' : $result; + $state['migration_data_done'] = ($result === true); + $state['migration_end_time'] = ($result === true) ? time() : 0; } $sql = 'UPDATE ' . $this->migrations_table . ' @@ -284,27 +284,50 @@ class phpbb_db_migrator * Process the data step of the migration * * @param phpbb_db_migration $migration - * @return mixed migration status or bool true if everything completed successfully + * @param bool|string $state Current state of the migration + * @return bool|string migration state. True if completed, serialized array if not finished */ - protected function process_data_step($migration) + protected function process_data_step($migration, $state) { + $state = ($state) ? unserialize($state) : false; + $steps = $migration->update_data(); foreach ($steps as $step) { + $last_result = false; + if ($state) + { + // Continue until we reach the step that matches the last step called + if ($state['step'] != $step) + { + continue; + } + + // We send the result from last time to the callable function + $last_result = $state['result']; + + // Set state to false since we reached the point we were at + $state = false; + } + try { // Result will be null or true if everything completed correctly - $result = $this->run_step($step); + $result = $this->run_step($step, $last_result); if ($result !== null && $result !== true) { - return $result; + return serialize(array( + 'result' => $result, + 'step' => $step, + )); } } catch (phpbb_db_migration_exception $e) { // We should try rolling back here + var_dump($step); echo $e; die(); } @@ -318,12 +341,13 @@ class phpbb_db_migrator * * An exception should be thrown if an error occurs * - * @param mixed $step + * @param mixed $step Data step from migration + * @param mixed $last_result Result to pass to the callable (only for 'custom' method) * @return null */ - protected function run_step($step) + protected function run_step($step, $last_result = false) { - $callable_and_parameters = $this->get_callable_from_step($step); + $callable_and_parameters = $this->get_callable_from_step($step, $last_result); $callable = $callable_and_parameters[0]; $parameters = $callable_and_parameters[1]; @@ -334,9 +358,10 @@ class phpbb_db_migrator * Get a callable statement from a data step * * @param mixed $step Data step from migration + * @param mixed $last_result Result to pass to the callable (only for 'custom' method) * @return array Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters */ - public function get_callable_from_step($step) + public function get_callable_from_step($step, $last_result = false) { $type = $step[0]; $parameters = $step[1]; @@ -375,7 +400,7 @@ class phpbb_db_migrator function ($condition) use ($callable, $sub_parameters) { return call_user_func_array($callable, $sub_parameters); }, - array($condition) + array($condition), ); break; case 'custom': @@ -384,7 +409,10 @@ class phpbb_db_migrator throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_CUSTOM_NOT_CALLABLE', $step); } - return array($parameters[0], array()); + return array( + $parameters[0], + array($last_result), + ); break; default: -- cgit v1.2.1 From f56e400cd36b6d17ffde90a91e6e221cb83d2dbd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 15:41:04 -0600 Subject: [feature/migrations] Comments PHPBB3-9737 --- phpBB/includes/db/migration/tool/permission.php | 12 +++++------ phpBB/includes/db/migrator.php | 28 +++++++++++++++++++------ 2 files changed, 28 insertions(+), 12 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/tool/permission.php b/phpBB/includes/db/migration/tool/permission.php index 97fdbc0df9..7b45b24361 100644 --- a/phpBB/includes/db/migration/tool/permission.php +++ b/phpBB/includes/db/migration/tool/permission.php @@ -366,7 +366,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte switch ($type) { - case 'role' : + case 'role': $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . " WHERE role_name = '" . $this->db->sql_escape($name) . "'"; @@ -389,7 +389,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $this->db->sql_freeresult($result); break; - case 'group' : + case 'group': $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . " WHERE group_name = '" . $this->db->sql_escape($name) . "'"; @@ -435,7 +435,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $sql_ary = array(); switch ($type) { - case 'role' : + case 'role': foreach ($new_auth as $auth_option_id) { if (!isset($current_auth[$auth_option_id])) @@ -451,7 +451,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $this->db->sql_multi_insert(ACL_ROLES_DATA_TABLE, $sql_ary); break; - case 'group' : + case 'group': foreach ($new_auth as $auth_option_id) { if (!isset($current_auth[$auth_option_id])) @@ -508,7 +508,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte switch ($type) { - case 'role' : + case 'role': $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . " WHERE role_name = '" . $this->db->sql_escape($name) . "'"; @@ -525,7 +525,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $this->db->sql_query($sql); break; - case 'group' : + case 'group': $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . " WHERE group_name = '" . $this->db->sql_escape($name) . "'"; diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 7aa4cfa719..5d8dc12f58 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -43,13 +43,27 @@ class phpbb_db_migrator /** @var string */ protected $migrations_table; - /** @var array State of all migrations (SELECT * FROM migrations table) */ - protected $migration_state; + /** + * State of all migrations + * + * (SELECT * FROM migrations table) + * + * @var array + */ + protected $migration_state = array(); - /** @var array Array of all migrations available to be run */ + /** + * Array of all migrations available to be run + * + * @var array + */ protected $migrations = array(); - /** @var array 'name' and 'class' of the last migration run */ + /** + * 'name' and 'class' of the last migration run + * + * @var array + */ public $last_run_migration = false; /** @@ -83,11 +97,12 @@ class phpbb_db_migrator */ public function load_migration_state() { + $this->migration_state = array(); + $sql = "SELECT * FROM " . $this->migrations_table; $result = $this->db->sql_query($sql); - $this->migration_state = array(); while ($migration = $this->db->sql_fetchrow($result)) { $this->migration_state[$migration['migration_name']] = $migration; @@ -137,8 +152,9 @@ class phpbb_db_migrator $added_classes = array_diff(get_declared_classes(), $declared_classes); if ( - // The phpbb_db_migrations class may not have been loaded until now, so make sure to ignore it. + // 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 ) { -- cgit v1.2.1 From 445667a62e80c42b5406c981d1116ef99a23df3b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 16:31:56 -0600 Subject: [feature/migrations] Fix if method (and create a test for it) PHPBB3-9737 --- phpBB/includes/db/migrator.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 5d8dc12f58..1042b767e8 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -364,6 +364,12 @@ class phpbb_db_migrator protected function run_step($step, $last_result = false) { $callable_and_parameters = $this->get_callable_from_step($step, $last_result); + + if ($callable_and_parameters === false) + { + return; + } + $callable = $callable_and_parameters[0]; $parameters = $callable_and_parameters[1]; @@ -377,7 +383,7 @@ class phpbb_db_migrator * @param mixed $last_result Result to pass to the callable (only for 'custom' method) * @return array Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters */ - public function get_callable_from_step($step, $last_result = false) + protected function get_callable_from_step($step, $last_result = false) { $type = $step[0]; $parameters = $step[1]; @@ -406,6 +412,12 @@ class phpbb_db_migrator } $condition = $parameters[0]; + + if (!$condition) + { + return false; + } + $step = $parameters[1]; $callable_and_parameters = $this->get_callable_from_step($step); @@ -413,10 +425,8 @@ class phpbb_db_migrator $sub_parameters = $callable_and_parameters[1]; return array( - function ($condition) use ($callable, $sub_parameters) { - return call_user_func_array($callable, $sub_parameters); - }, - array($condition), + $callable, + $sub_parameters, ); break; case 'custom': -- cgit v1.2.1 From 5f9e1f1e89f8df5420fd82b5256a461de0f98604 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 16:56:26 -0600 Subject: [feature/migrations] Make sure the path sent to load_migrations is a directory Prevent a lot++ of errors PHPBB3-9737 --- phpBB/includes/db/migrator.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 1042b767e8..359c34bf5d 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -139,6 +139,11 @@ class phpbb_db_migrator */ 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) { -- cgit v1.2.1 From 3d4c00619f1c96df7a4c6f8bc1c03eb21abf49d7 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 18:24:32 -0600 Subject: [feature/migrations] Reverse data functionality If data step fails, attempt to roll back any previous calls from the migration that failed. Fix some failing tests PHPBB3-9737 --- phpBB/includes/db/migration/tool/config.php | 42 +++++++++++++++++++ phpBB/includes/db/migration/tool/interface.php | 10 +++++ phpBB/includes/db/migration/tool/module.php | 31 ++++++++++++++ phpBB/includes/db/migration/tool/permission.php | 55 +++++++++++++++++++++++++ phpBB/includes/db/migrator.php | 37 ++++++++++++----- 5 files changed, 164 insertions(+), 11 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/tool/config.php b/phpBB/includes/db/migration/tool/config.php index e7239436d2..6ae419d5e7 100644 --- a/phpBB/includes/db/migration/tool/config.php +++ b/phpBB/includes/db/migration/tool/config.php @@ -103,4 +103,46 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac $this->config->delete($config_name); } + + /** + * Reverse an original install action + * + * First argument is the original call to the class (e.g. add, remove) + * After the first argument, send the original arguments to the function in the original call + * + * @return null + */ + public function reverse() + { + $arguments = func_get_args(); + $original_call = array_shift($arguments); + + $call = false; + switch ($original_call) + { + case 'add': + $call = 'remove'; + break; + + case 'remove': + $call = 'add'; + break; + + case 'update_if_equals': + $call = 'update_if_equals'; + + // Set to the original value if the current value is what we compared to originally + $arguments = array( + $arguments[2], + $arguments[1], + $arguments[0], + ); + break; + } + + if ($call) + { + return call_user_func_array(array(&$this, $call), $arguments); + } + } } diff --git a/phpBB/includes/db/migration/tool/interface.php b/phpBB/includes/db/migration/tool/interface.php index 5d10246ba1..ced53b2023 100644 --- a/phpBB/includes/db/migration/tool/interface.php +++ b/phpBB/includes/db/migration/tool/interface.php @@ -20,4 +20,14 @@ interface phpbb_db_migration_tool_interface * @return string short name */ public function get_name(); + + /** + * Reverse an original install action + * + * First argument is the original call to the class (e.g. add, remove) + * After the first argument, send the original arguments to the function in the original call + * + * @return null + */ + public function reverse(); } diff --git a/phpBB/includes/db/migration/tool/module.php b/phpBB/includes/db/migration/tool/module.php index 70a246849a..561faac552 100644 --- a/phpBB/includes/db/migration/tool/module.php +++ b/phpBB/includes/db/migration/tool/module.php @@ -471,4 +471,35 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac $this->cache->destroy("_modules_$class"); } } + + /** + * Reverse an original install action + * + * First argument is the original call to the class (e.g. add, remove) + * After the first argument, send the original arguments to the function in the original call + * + * @return null + */ + public function reverse() + { + $arguments = func_get_args(); + $original_call = array_shift($arguments); + + $call = false; + switch ($original_call) + { + case 'add': + $call = 'remove'; + break; + + case 'remove': + $call = 'add'; + break; + } + + if ($call) + { + return call_user_func_array(array(&$this, $call), $arguments); + } + } } diff --git a/phpBB/includes/db/migration/tool/permission.php b/phpBB/includes/db/migration/tool/permission.php index 7b45b24361..a25fdb345e 100644 --- a/phpBB/includes/db/migration/tool/permission.php +++ b/phpBB/includes/db/migration/tool/permission.php @@ -563,4 +563,59 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte $this->auth->acl_clear_prefetch(); } + + /** + * Reverse an original install action + * + * First argument is the original call to the class (e.g. add, remove) + * After the first argument, send the original arguments to the function in the original call + * + * @return null + */ + public function reverse() + { + $arguments = func_get_args(); + $original_call = array_shift($arguments); + + $call = false; + switch ($original_call) + { + case 'add': + $call = 'remove'; + break; + + case 'remove': + $call = 'add'; + break; + + case 'permission_set': + $call = 'permission_unset'; + break; + + case 'permission_unset': + $call = 'permission_set'; + break; + + case 'role_add': + $call = 'role_remove'; + break; + + case 'role_remove': + $call = 'role_add'; + break; + + case 'role_update': + // Set to the original value if the current value is what we compared to originally + $arguments = array( + $arguments[1], + $arguments[0], + ); + break; + } + + if ($call) + { + return call_user_func_array(array(&$this, $call), $arguments); + } + } } diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 359c34bf5d..dc2c746559 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -347,6 +347,17 @@ class phpbb_db_migrator catch (phpbb_db_migration_exception $e) { // We should try rolling back here + foreach ($steps as $reverse_step) + { + // Reverse the step that was run + $result = $this->run_step($step, false, true); + + // If we've reached the current step we can break because we reversed everything that was run + if ($reverse_step === $step) + { + break; + } + } var_dump($step); echo $e; @@ -364,11 +375,12 @@ class phpbb_db_migrator * * @param mixed $step Data step from migration * @param mixed $last_result Result to pass to the callable (only for 'custom' method) + * @param bool $reverse False to install, True to attempt uninstallation by reversing the call * @return null */ - protected function run_step($step, $last_result = false) + protected function run_step($step, $last_result = false, $reverse = false) { - $callable_and_parameters = $this->get_callable_from_step($step, $last_result); + $callable_and_parameters = $this->get_callable_from_step($step, $last_result, $reverse); if ($callable_and_parameters === false) { @@ -386,9 +398,10 @@ class phpbb_db_migrator * * @param mixed $step Data step from migration * @param mixed $last_result Result to pass to the callable (only for 'custom' method) + * @param bool $reverse False to install, True to attempt uninstallation by reversing the call * @return array Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters */ - protected function get_callable_from_step($step, $last_result = false) + protected function get_callable_from_step($step, $last_result = false, $reverse = false) { $type = $step[0]; $parameters = $step[1]; @@ -425,14 +438,7 @@ class phpbb_db_migrator $step = $parameters[1]; - $callable_and_parameters = $this->get_callable_from_step($step); - $callable = $callable_and_parameters[0]; - $sub_parameters = $callable_and_parameters[1]; - - return array( - $callable, - $sub_parameters, - ); + return $this->get_callable_from_step($step); break; case 'custom': if (!is_callable($parameters[0])) @@ -462,6 +468,15 @@ class phpbb_db_migrator throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_UNDEFINED_METHOD', $step); } + // Attempt to reverse operations + if ($reverse) + { + return array( + array($this->tools[$class], 'reverse'), + array_unshift($parameters, $method), + ); + } + return array( array($this->tools[$class], $method), $parameters, -- cgit v1.2.1 From 595246f9bf17f1bef69c285ba8e78534cd91054a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 18:55:55 -0600 Subject: [feature/migrations] Some comments in db_tools PHPBB3-9737 --- phpBB/includes/db/db_tools.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index 1d6823d37a..b13d4fe978 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -685,6 +685,8 @@ class phpbb_db_tools * Handle passed database update array. * Expected structure... * Key being one of the following + * drop_tables: Drop tables + * add_tables: Add tables * change_columns: Column changes (only type, not name) * add_columns: Add columns to a table * drop_keys: Dropping keys -- cgit v1.2.1 From 44c10f661ee548ae08fe81ba76f47f1c8134b96f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 18:59:15 -0600 Subject: [feature/migrations] Creating revert method to attempt reverting a migration This code is in progress PHPBB3-9737 --- phpBB/includes/db/migration/migration.php | 23 +++++++ phpBB/includes/db/migrator.php | 100 ++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/migration.php b/phpBB/includes/db/migration/migration.php index 5f1f0443db..61fbf04320 100644 --- a/phpBB/includes/db/migration/migration.php +++ b/phpBB/includes/db/migration/migration.php @@ -93,6 +93,16 @@ abstract class phpbb_db_migration return array(); } + /** + * Reverts the database schema by providing a set of change instructions + * + * @return array Array of schema changes (compatible with db_tools->perform_schema_changes()) + */ + public function revert_schema() + { + return array(); + } + /** * Updates data by returning a list of instructions to be executed * @@ -103,6 +113,19 @@ abstract class phpbb_db_migration return array(); } + /** + * Reverts data by returning a list of instructions to be executed + * + * @return array Array of data instructions that will be performed on revert + * NOTE: calls to tools (such as config.add) are automatically reverted when + * possible, so you should not attempt to revert those, this is mostly for + * otherwise unrevertable calls (custom functions for example) + */ + public function revert_data() + { + return array(); + } + /** * Wrapper for running queries to generate user feedback on updates * diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index dc2c746559..e8d3735974 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -289,6 +289,91 @@ class phpbb_db_migrator return true; } + /** + * Runs a single revert step from the last migration installed + * + * The revert step can either be a schema or a (partial) data revert. To + * check if revert() needs to be called again use the migration_installed() method. + * + * @param string $migration String migration name to revert (including any that depend on this migration) + * @return null + */ + public function revert($migration) + { + if (!isset($this->migration_state[$name])) + { + // Not installed + return; + } + + // Iterate through all installed migrations and make sure any dependencies are removed first + foreach ($this->migration_state as $name => $state) + { + $migration_class = $this->get_migration($name); + + if (in_array($migration, $migration_class->depends_on())) + { + $this->revert($name); + } + } + + $this->try_revert($migration); + } + + /** + * Attempts to apply a step of the given migration or one of its dependencies + * + * @param string The class name of the migration + * @return bool Whether any update step was successfully run + */ + protected function try_revert($name) + { + if (!class_exists($name)) + { + return false; + } + + $migration = $this->get_migration($name); + + $state = $this->migration_state[$name]; + + $this->last_run_migration = array( + 'name' => $name, + 'class' => $migration, + ); + + // Left off here + + if (!isset($this->migration_state[$name])) + { + $state['migration_start_time'] = time(); + $this->insert_migration($name, $state); + } + + if (!$state['migration_schema_done']) + { + $this->apply_schema_changes($migration->update_schema()); + $state['migration_schema_done'] = true; + } + else + { + $result = $this->process_data_step($migration, $state['migration_data_state']); + + $state['migration_data_state'] = ($result === true) ? '' : $result; + $state['migration_data_done'] = ($result === true); + $state['migration_end_time'] = ($result === true) ? time() : 0; + } + + $sql = 'UPDATE ' . $this->migrations_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $state) . " + WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + + $this->migration_state[$name] = $state; + + return true; + } + /** * Apply schema changes from a migration * @@ -359,6 +444,7 @@ class phpbb_db_migrator } } + /** TODO Revert Schema **/ var_dump($step); echo $e; die(); @@ -567,6 +653,20 @@ class phpbb_db_migrator return true; } + /** + * Checks whether a migration is installed + * + * @param string $migration String migration name to check if it is installed + * @return bool Whether the migrations have been applied + */ + public function migration_installed($migration) + { + if (isset($this->migration_state[$migration])) + { + return true; + } + } + /** * Helper to get a migration * -- cgit v1.2.1 From dbe71bb170dc684311174bb025696c81f1d50883 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 13:53:09 -0600 Subject: [feature/migrations] Revert method completed PHPBB3-9737 --- phpBB/includes/db/migrator.php | 74 +++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 33 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index e8d3735974..13114e7df1 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -272,7 +272,7 @@ class phpbb_db_migrator } else { - $result = $this->process_data_step($migration, $state['migration_data_state']); + $result = $this->process_data_step($migration->update_data(), $state['migration_data_state']); $state['migration_data_state'] = ($result === true) ? '' : $result; $state['migration_data_done'] = ($result === true); @@ -300,7 +300,7 @@ class phpbb_db_migrator */ public function revert($migration) { - if (!isset($this->migration_state[$name])) + if (!isset($this->migration_state[$migration])) { // Not installed return; @@ -342,34 +342,39 @@ class phpbb_db_migrator 'class' => $migration, ); - // Left off here - - if (!isset($this->migration_state[$name])) + if ($state['migration_data_done']) { - $state['migration_start_time'] = time(); - $this->insert_migration($name, $state); - } + if ($state['migration_data_state'] !== 'revert_data') + { + $result = $this->process_data_step($migration->update_data(), $state['migration_data_state'], true); - if (!$state['migration_schema_done']) - { - $this->apply_schema_changes($migration->update_schema()); - $state['migration_schema_done'] = true; + $state['migration_data_state'] = ($result === true) ? 'revert_data' : $result; + } + else + { + $result = $this->process_data_step($migration->revert_data(), $state['migration_data_state'], false); + + $state['migration_data_state'] = ($result === true) ? '' : $result; + $state['migration_data_done'] = ($result === true) ? false : true; + } + + $sql = 'UPDATE ' . $this->migrations_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $state) . " + WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + + $this->migration_state[$name] = $state; } else { - $result = $this->process_data_step($migration, $state['migration_data_state']); - - $state['migration_data_state'] = ($result === true) ? '' : $result; - $state['migration_data_done'] = ($result === true); - $state['migration_end_time'] = ($result === true) ? time() : 0; - } + $this->apply_schema_changes($migration->revert_schema()); - $sql = 'UPDATE ' . $this->migrations_table . ' - SET ' . $this->db->sql_build_array('UPDATE', $state) . " - WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; - $this->db->sql_query($sql); + $sql = 'DELETE FROM ' . $this->migrations_table . " + WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); - $this->migration_state[$name] = $state; + unset($this->migration_state[$name]); + } return true; } @@ -389,23 +394,22 @@ class phpbb_db_migrator /** * Process the data step of the migration * - * @param phpbb_db_migration $migration + * @param array $steps The steps to run * @param bool|string $state Current state of the migration + * @param bool $revert true to revert a data step * @return bool|string migration state. True if completed, serialized array if not finished */ - protected function process_data_step($migration, $state) + protected function process_data_step($steps, $state, $revert = false) { $state = ($state) ? unserialize($state) : false; - $steps = $migration->update_data(); - - foreach ($steps as $step) + foreach ($steps as $step_identifier => $step) { $last_result = false; if ($state) { // Continue until we reach the step that matches the last step called - if ($state['step'] != $step) + if ($state['step'] != $step_identifier) { continue; } @@ -420,12 +424,12 @@ class phpbb_db_migrator try { // Result will be null or true if everything completed correctly - $result = $this->run_step($step, $last_result); + $result = $this->run_step($step, $last_result, $revert); if ($result !== null && $result !== true) { return serialize(array( 'result' => $result, - 'step' => $step, + 'step' => $step_identifier, )); } } @@ -435,7 +439,7 @@ class phpbb_db_migrator foreach ($steps as $reverse_step) { // Reverse the step that was run - $result = $this->run_step($step, false, true); + $result = $this->run_step($step, false, !$revert); // If we've reached the current step we can break because we reversed everything that was run if ($reverse_step === $step) @@ -557,9 +561,11 @@ class phpbb_db_migrator // Attempt to reverse operations if ($reverse) { + array_unshift($parameters, $method); + return array( array($this->tools[$class], 'reverse'), - array_unshift($parameters, $method), + $parameters, ); } @@ -665,6 +671,8 @@ class phpbb_db_migrator { return true; } + + return false; } /** -- cgit v1.2.1 From d50500860fe44a78c8f29e0f2382b96da17c0b62 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 15:09:51 -0600 Subject: [feature/migrations] Store depends on in the database (serialized) This is required so that when migrations are reverted we can check through all installed migrations and make sure that all dependencies are handled properly and so that we are only required to load the migrations files that could be dependent on the ones installed. I believe in normal proper use the old way might have worked, but in case something happens and an unrelated migration file is installed, but cannot be loaded, this makes sure we do not stop everything unless we absolutely must (one of those files is dependent on something we want to revert). PHPBB3-9737 --- phpBB/includes/db/migrator.php | 79 ++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 33 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 13114e7df1..2ec44a5a45 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -106,6 +106,8 @@ class phpbb_db_migrator 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->db->sql_freeresult($result); @@ -235,16 +237,15 @@ class phpbb_db_migrator $state = (isset($this->migration_state[$name])) ? $this->migration_state[$name] : array( + 'migration_depends_on' => $migration->depends_on(), 'migration_schema_done' => false, - 'migration_data_done' => false, - 'migration_data_state' => '', - 'migration_start_time' => 0, - 'migration_end_time' => 0, + 'migration_data_done' => false, + 'migration_data_state' => '', + 'migration_start_time' => 0, + 'migration_end_time' => 0, ); - $depends = $migration->depends_on(); - - foreach ($depends as $depend) + foreach ($state['migration_depends_on'] as $depend) { if (!isset($this->migration_state[$depend]) || !$this->migration_state[$depend]['migration_schema_done'] || @@ -272,15 +273,28 @@ class phpbb_db_migrator } else { - $result = $this->process_data_step($migration->update_data(), $state['migration_data_state']); + try + { + $result = $this->process_data_step($migration->update_data(), $state['migration_data_state']); + + $state['migration_data_state'] = ($result === true) ? '' : $result; + $state['migration_data_done'] = ($result === true); + $state['migration_end_time'] = ($result === true) ? time() : 0; + } + catch (phpbb_db_migration_exception $e) + { + // Revert the schema changes + $this->revert($name); - $state['migration_data_state'] = ($result === true) ? '' : $result; - $state['migration_data_done'] = ($result === true); - $state['migration_end_time'] = ($result === true) ? time() : 0; + // Rethrow exception + throw $e; + } } + $insert = $state; + $insert['migration_depends_on'] = serialize($state['migration_depends_on']); $sql = 'UPDATE ' . $this->migrations_table . ' - SET ' . $this->db->sql_build_array('UPDATE', $state) . " + SET ' . $this->db->sql_build_array('UPDATE', $insert) . " WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); @@ -292,8 +306,9 @@ class phpbb_db_migrator /** * Runs a single revert step from the last migration installed * + * YOU MUST ADD/SET ALL MIGRATIONS THAT COULD BE DEPENDENT ON THE MIGRATION TO REVERT TO BEFORE CALLING THIS METHOD! * The revert step can either be a schema or a (partial) data revert. To - * check if revert() needs to be called again use the migration_installed() method. + * check if revert() needs to be called again use the migration_state() method. * * @param string $migration String migration name to revert (including any that depend on this migration) * @return null @@ -306,12 +321,9 @@ class phpbb_db_migrator return; } - // Iterate through all installed migrations and make sure any dependencies are removed first foreach ($this->migration_state as $name => $state) { - $migration_class = $this->get_migration($name); - - if (in_array($migration, $migration_class->depends_on())) + if (!empty($state['migration_depends_on']) && in_array($migration, $state['migration_depends_on'])) { $this->revert($name); } @@ -358,8 +370,10 @@ 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', $state) . " + SET ' . $this->db->sql_build_array('UPDATE', $insert) . " WHERE migration_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); @@ -436,22 +450,20 @@ class phpbb_db_migrator catch (phpbb_db_migration_exception $e) { // We should try rolling back here - foreach ($steps as $reverse_step) + foreach ($steps as $reverse_step_identifier => $reverse_step) { - // Reverse the step that was run - $result = $this->run_step($step, false, !$revert); - // If we've reached the current step we can break because we reversed everything that was run - if ($reverse_step === $step) + if ($reverse_step_identifier == $step_identifier) { break; } + + // Reverse the step that was run + $result = $this->run_step($reverse_step, false, !$revert); } - /** TODO Revert Schema **/ - var_dump($step); - echo $e; - die(); + // rethrow the exception + throw $e; } } @@ -588,6 +600,7 @@ class phpbb_db_migrator { $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); @@ -660,19 +673,19 @@ class phpbb_db_migrator } /** - * Checks whether a migration is installed + * Gets a migration state (whether it is installed and to what extent) * * @param string $migration String migration name to check if it is installed - * @return bool Whether the migrations have been applied + * @return bool|array False if the migration has not at all been installed, array */ - public function migration_installed($migration) + public function migration_state($migration) { - if (isset($this->migration_state[$migration])) + if (!isset($this->migration_state[$migration])) { - return true; + return false; } - return false; + return $this->migration_state[$migration]; } /** -- cgit v1.2.1 From db4fcab3bb4aefcabe93dd4acd1f12e8517cf340 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 22:29:49 -0600 Subject: [feature/migrations] Make depends_on static to call it without dependencies PHPBB3-11318 --- phpBB/includes/db/migration/migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/migration.php b/phpBB/includes/db/migration/migration.php index 61fbf04320..4271751362 100644 --- a/phpBB/includes/db/migration/migration.php +++ b/phpBB/includes/db/migration/migration.php @@ -78,7 +78,7 @@ abstract class phpbb_db_migration * * @return array An array of migration class names */ - public function depends_on() + static public function depends_on() { return array(); } -- cgit v1.2.1 From 9affd6f7e7b95442f1ef14894858d8213f3fbd2a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 11 Jan 2013 00:41:03 +0100 Subject: [ticket/11201] Remove MSN/WLM fields WLM will be shutdown in March 2013. Skype is the new replacement. But as Skype uses a different login ID and service, the values in this field are useless. So we can safely remove the field and the links/functions we create. PHPBB3-11201 --- phpBB/includes/acp/acp_users.php | 4 ---- phpBB/includes/ucp/ucp_pm_viewmessage.php | 1 - phpBB/includes/ucp/ucp_profile.php | 4 ---- 3 files changed, 9 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 82d8ef5cbb..2bdbf1441a 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1352,7 +1352,6 @@ class acp_users $data = array( 'icq' => request_var('icq', $user_row['user_icq']), 'aim' => request_var('aim', $user_row['user_aim']), - 'msn' => request_var('msn', $user_row['user_msnm']), 'yim' => request_var('yim', $user_row['user_yim']), 'jabber' => utf8_normalize_nfc(request_var('jabber', $user_row['user_jabber'], true)), 'website' => request_var('website', $user_row['user_website']), @@ -1382,7 +1381,6 @@ class acp_users array('string', true, 3, 15), array('match', true, '#^[0-9]+$#i')), 'aim' => array('string', true, 3, 255), - 'msn' => array('string', true, 5, 255), 'jabber' => array( array('string', true, 5, 255), array('jabber')), @@ -1416,7 +1414,6 @@ class acp_users $sql_ary = array( 'user_icq' => $data['icq'], 'user_aim' => $data['aim'], - 'user_msnm' => $data['msn'], 'user_yim' => $data['yim'], 'user_jabber' => $data['jabber'], 'user_website' => $data['website'], @@ -1469,7 +1466,6 @@ class acp_users 'ICQ' => $data['icq'], 'YIM' => $data['yim'], 'AIM' => $data['aim'], - 'MSN' => $data['msn'], 'JABBER' => $data['jabber'], 'WEBSITE' => $data['website'], 'LOCATION' => $data['location'], diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index c85b05f144..a1001cfa74 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -241,7 +241,6 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) 'U_ICQ' => ($user_info['user_icq']) ? 'http://www.icq.com/people/' . urlencode($user_info['user_icq']) . '/' : '', 'U_AIM' => ($user_info['user_aim'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=aim&u=' . $author_id) : '', 'U_YIM' => ($user_info['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($user_info['user_yim']) . '&.src=pg' : '', - 'U_MSN' => ($user_info['user_msnm'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=msnm&u=' . $author_id) : '', 'U_JABBER' => ($user_info['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=jabber&u=' . $author_id) : '', 'U_DELETE' => ($auth->acl_get('u_pm_delete')) ? "$url&mode=compose&action=delete&f=$folder_id&p=" . $message_row['msg_id'] : '', diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index e7cea06a45..c1ad9955b6 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -266,7 +266,6 @@ class ucp_profile $data = array( 'icq' => request_var('icq', $user->data['user_icq']), 'aim' => request_var('aim', $user->data['user_aim']), - 'msn' => request_var('msn', $user->data['user_msnm']), 'yim' => request_var('yim', $user->data['user_yim']), 'jabber' => utf8_normalize_nfc(request_var('jabber', $user->data['user_jabber'], true)), 'website' => request_var('website', $user->data['user_website']), @@ -299,7 +298,6 @@ class ucp_profile array('string', true, 3, 15), array('match', true, '#^[0-9]+$#i')), 'aim' => array('string', true, 3, 255), - 'msn' => array('string', true, 5, 255), 'jabber' => array( array('string', true, 5, 255), array('jabber')), @@ -351,7 +349,6 @@ class ucp_profile $sql_ary = array( 'user_icq' => $data['icq'], 'user_aim' => $data['aim'], - 'user_msnm' => $data['msn'], 'user_yim' => $data['yim'], 'user_jabber' => $data['jabber'], 'user_website' => $data['website'], @@ -423,7 +420,6 @@ class ucp_profile 'ICQ' => $data['icq'], 'YIM' => $data['yim'], 'AIM' => $data['aim'], - 'MSN' => $data['msn'], 'JABBER' => $data['jabber'], 'WEBSITE' => $data['website'], 'LOCATION' => $data['location'], -- cgit v1.2.1 From 93f9ebbb258a06e34198cffda0f5fd8dfdf29597 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 12 Jan 2013 18:27:33 -0600 Subject: [feature/migrations] Make load_migrations recursive (optionally) PHPBB3-9737 --- phpBB/includes/db/migrator.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 2ec44a5a45..6b249e3ee0 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -127,7 +127,6 @@ class phpbb_db_migrator /** * Load migration data files from a directory * - * This does not loop through sub-directories. * Migration data files loaded with this function MUST contain * ONLY ONE class in them (or an exception will be thrown). * @@ -137,9 +136,10 @@ 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). - * @return array Array of migrations with names + * @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) + public function load_migrations($path, $check_fulfillable = true, $recursive = true) { if (!is_dir($path)) { @@ -149,6 +149,17 @@ class phpbb_db_migrator $handle = opendir($path); while (($file = readdir($handle)) !== false) { + if ($file == '.' || $file == '..') + { + continue; + } + + // Recursion through subdirectories + if (is_dir($path . $file) && $recursive) + { + $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. -- cgit v1.2.1 From 26c16559c3496f5496ad6e83e55c40f03edda5bd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 13 Jan 2013 12:39:08 -0600 Subject: [feature/migrations] Function effectively_installed() in migrations Allows you to check if the migration is effectively installed (entirely optionall) This function is intended to help moving to migrations from a previous database updater, where some migrations may have been installed already even though they are not yet listed in the migrations table. PHPBB3-9737 --- phpBB/includes/db/migration/migration.php | 15 +++++++++++++++ phpBB/includes/db/migrator.php | 20 +++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/migration.php b/phpBB/includes/db/migration/migration.php index 4271751362..cf1e97b3b1 100644 --- a/phpBB/includes/db/migration/migration.php +++ b/phpBB/includes/db/migration/migration.php @@ -83,6 +83,21 @@ abstract class phpbb_db_migration return array(); } + /** + * Allows you to check if the migration is effectively installed (entirely optionall) + * + * This is checked when a migration is installed. If true is returned, the migration will be set as + * installed without performing the database changes. + * This function is intended to help moving to migrations from a previous database updater, where some + * migrations may have been installed already even though they are not yet listed in the migrations table. + * + * @return bool True if this migration is installed, False if this migration is not installed (checked on install) + */ + public function effectively_installed() + { + return false; + } + /** * Updates the database schema by providing a set of change instructions * diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 6b249e3ee0..b56da95b1a 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -271,10 +271,24 @@ class phpbb_db_migrator 'class' => $migration, ); - if (!isset($this->migration_state[$name])) + if ($migration->effectively_installed()) { - $state['migration_start_time'] = time(); - $this->insert_migration($name, $state); + $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])) + { + $state['migration_start_time'] = time(); + $this->insert_migration($name, $state); + } } if (!$state['migration_schema_done']) -- cgit v1.2.1 From 000b8fefd2788c7f9f6aa6efc1d93658a00e48bd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 13 Jan 2013 13:21:01 -0600 Subject: [feature/migrations] Function to populate the migrations table (for install) PHPBB3-9737 --- phpBB/includes/db/migrator.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index b56da95b1a..69a5a4dd9c 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -124,6 +124,42 @@ class phpbb_db_migrator $this->migrations = $class_names; } + /** + * This function adds all migrations in a specified directory to the migrations table + * + * THIS SHOULD NOT GENERALLY BE USED! THIS IS FOR THE PHPBB INSTALLER. + * THIS WILL THROW ERRORS IF MIGRATIONS ALREADY EXIST IN THE TABLE, DO NOT CALL MORE THAN ONCE! + * + * @param string $path Path to migration data files + * @param bool $recursive Set to true to also load data files from subdirectories + * @return null + */ + public function populate_migrations_from_directory($path, $recursive = true) + { + $existing_migrations = $this->migrations; + + $this->migrations = array(); + $this->load_migrations($path, true, $recursive); + + foreach ($this->migrations as $name) + { + if ($this->migration_state($name) === false) + { + $state = array( + 'migration_depends_on' => $name::depends_on(), + 'migration_schema_done' => true, + 'migration_data_done' => true, + 'migration_data_state' => '', + 'migration_start_time' => time(), + 'migration_end_time' => time(), + ); + $this->insert_migration($name, $state); + } + } + + $this->migrations = $existing_migrations; + } + /** * Load migration data files from a directory * -- cgit v1.2.1 From ccd08e21f6ae97ff0ff628ff29935a70bdd7a58d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 13 Jan 2013 13:34:16 -0600 Subject: [feature/migrations] Make sure migration data not done before running data step PHPBB3-9737 --- 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 69a5a4dd9c..d95283ae01 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -332,7 +332,7 @@ class phpbb_db_migrator $this->apply_schema_changes($migration->update_schema()); $state['migration_schema_done'] = true; } - else + else if (!$state['migration_data_done']) { try { -- 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 3122aeff263b5fee51440ff49274897ccb6ea46f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Jan 2013 14:32:15 +0100 Subject: [ticket/9492] Retain custom ranks and avatars when setting users default group PHPBB3-9492 --- phpBB/includes/functions_user.php | 83 +++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 30 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 6abcdee8f2..22272b20f3 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3208,8 +3208,8 @@ function remove_default_avatar($group_id, $user_ids) user_avatar_width = 0, user_avatar_height = 0 WHERE group_id = " . (int) $group_id . " - AND user_avatar = '" . $db->sql_escape($row['group_avatar']) . "' - AND " . $db->sql_in_set('user_id', $user_ids); + AND user_avatar = '" . $db->sql_escape($row['group_avatar']) . "' + AND " . $db->sql_in_set('user_id', $user_ids); $db->sql_query($sql); } @@ -3246,9 +3246,9 @@ function remove_default_rank($group_id, $user_ids) $sql = 'UPDATE ' . USERS_TABLE . ' SET user_rank = 0 WHERE group_id = ' . (int)$group_id . ' - AND user_rank <> 0 - AND user_rank = ' . (int)$row['group_rank'] . ' - AND ' . $db->sql_in_set('user_id', $user_ids); + AND user_rank <> 0 + AND user_rank = ' . (int)$row['group_rank'] . ' + AND ' . $db->sql_in_set('user_id', $user_ids); $db->sql_query($sql); } @@ -3277,7 +3277,8 @@ function group_user_attributes($action, $group_id, $user_id_ary = false, $userna case 'demote': case 'promote': - $sql = 'SELECT user_id FROM ' . USER_GROUP_TABLE . " + $sql = 'SELECT user_id + FROM ' . USER_GROUP_TABLE . " WHERE group_id = $group_id AND user_pending = 1 AND " . $db->sql_in_set('user_id', $user_id_ary); @@ -3375,7 +3376,8 @@ function group_user_attributes($action, $group_id, $user_id_ary = false, $userna return 'NO_USERS'; } - $sql = 'SELECT user_id, group_id FROM ' . USERS_TABLE . ' + $sql = 'SELECT user_id, group_id + FROM ' . USERS_TABLE . ' WHERE ' . $db->sql_in_set('user_id', $user_id_ary, false, true); $result = $db->sql_query($sql); @@ -3509,45 +3511,63 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal } } - // Before we update the user attributes, we will make a list of those having now the group avatar assigned + $updated_sql_ary = $sql_ary; + + // Before we update the user attributes, we will update the rank for users that don't have a custom rank + if (isset($sql_ary['user_rank'])) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', array('user_rank' => $sql_ary['user_rank'])) . ' + WHERE user_rank = 0 + AND ' . $db->sql_in_set('user_id', $user_id_ary); + $db->sql_query($sql); + unset($sql_ary['user_rank']); + } + + // Before we update the user attributes, we will update the avatar for users that don't have a custom avatar if (isset($sql_ary['user_avatar'])) { - // Ok, get the original avatar data from users having an uploaded one (we need to remove these from the filesystem) - $sql = 'SELECT user_id, group_id, user_avatar - FROM ' . USERS_TABLE . ' - WHERE ' . $db->sql_in_set('user_id', $user_id_ary) . ' - AND user_avatar_type = ' . AVATAR_UPLOAD; - $result = $db->sql_query($sql); + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', array( + 'user_avatar' => $sql_ary['user_avatar'], + 'user_avatar_type' => $sql_ary['user_avatar_type'], + 'user_avatar_height' => $sql_ary['user_avatar_height'], + 'user_avatar_width' => $sql_ary['user_avatar_width'], + )) . " + WHERE user_avatar = '' + AND " . $db->sql_in_set('user_id', $user_id_ary); + $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - avatar_delete('user', $row); - } - $db->sql_freeresult($result); + unset($sql_ary['user_avatar']); } - else + + unset($sql_ary['user_avatar_type']); + unset($sql_ary['user_avatar_height']); + unset($sql_ary['user_avatar_width']); + + if (!empty($sql_ary)) { - unset($sql_ary['user_avatar_type']); - unset($sql_ary['user_avatar_height']); - unset($sql_ary['user_avatar_width']); + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' + WHERE ' . $db->sql_in_set('user_id', $user_id_ary); + $db->sql_query($sql); } - $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE ' . $db->sql_in_set('user_id', $user_id_ary); - $db->sql_query($sql); - if (isset($sql_ary['user_colour'])) { // Update any cached colour information for these users - $sql = 'UPDATE ' . FORUMS_TABLE . " SET forum_last_poster_colour = '" . $db->sql_escape($sql_ary['user_colour']) . "' + $sql = 'UPDATE ' . FORUMS_TABLE . " + SET forum_last_poster_colour = '" . $db->sql_escape($sql_ary['user_colour']) . "' WHERE " . $db->sql_in_set('forum_last_poster_id', $user_id_ary); $db->sql_query($sql); - $sql = 'UPDATE ' . TOPICS_TABLE . " SET topic_first_poster_colour = '" . $db->sql_escape($sql_ary['user_colour']) . "' + $sql = 'UPDATE ' . TOPICS_TABLE . " + SET topic_first_poster_colour = '" . $db->sql_escape($sql_ary['user_colour']) . "' WHERE " . $db->sql_in_set('topic_poster', $user_id_ary); $db->sql_query($sql); - $sql = 'UPDATE ' . TOPICS_TABLE . " SET topic_last_poster_colour = '" . $db->sql_escape($sql_ary['user_colour']) . "' + $sql = 'UPDATE ' . TOPICS_TABLE . " + SET topic_last_poster_colour = '" . $db->sql_escape($sql_ary['user_colour']) . "' WHERE " . $db->sql_in_set('topic_last_poster_id', $user_id_ary); $db->sql_query($sql); @@ -3559,6 +3579,9 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal } } + // Make all values available for the event + $sql_ary = $updated_sql_ary; + /** * Event when the default group is set for an array of users * -- cgit v1.2.1 From 64c27013d4835f9bede202f208679e34fb0ec7bf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Jan 2013 14:40:58 +0100 Subject: [ticket/9492] Fix undefined user_avatar_* values when updating the group avatar PHPBB3-9492 --- phpBB/includes/functions_user.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 22272b20f3..3b7c9eea92 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3525,25 +3525,31 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal } // Before we update the user attributes, we will update the avatar for users that don't have a custom avatar + $avatar_options = array('user_avatar', 'user_avatar_type', 'user_avatar_height', 'user_avatar_width'); + if (isset($sql_ary['user_avatar'])) { + $avatar_sql_ary = array(); + foreach ($avatar_options as $avatar_option) + { + if (isset($sql_ary[$avatar_option])) + { + $avatar_sql_ary[$avatar_option] = $sql_ary[$avatar_option]; + } + } + $sql = 'UPDATE ' . USERS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', array( - 'user_avatar' => $sql_ary['user_avatar'], - 'user_avatar_type' => $sql_ary['user_avatar_type'], - 'user_avatar_height' => $sql_ary['user_avatar_height'], - 'user_avatar_width' => $sql_ary['user_avatar_width'], - )) . " + SSET ' . $db->sql_build_array('UPDATE', $avatar_sql_ary) . " WHERE user_avatar = '' AND " . $db->sql_in_set('user_id', $user_id_ary); $db->sql_query($sql); - - unset($sql_ary['user_avatar']); } - unset($sql_ary['user_avatar_type']); - unset($sql_ary['user_avatar_height']); - unset($sql_ary['user_avatar_width']); + // Remove the avatar options, as we already updated them + foreach ($avatar_options as $avatar_option) + { + unset($sql_ary[$avatar_option]); + } if (!empty($sql_ary)) { -- cgit v1.2.1 From bd87b068587a519b4a6275209525e069e7690ded Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Jan 2013 14:43:00 +0100 Subject: [ticket/9492] Ensure to update all avatar values when the avatar is changed PHPBB3-9492 --- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/ucp/ucp_groups.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index b604e20094..9145a20400 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -439,7 +439,7 @@ class acp_groups foreach ($test_variables as $test => $type) { - if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test] || in_array($test, $set_attributes))) + if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test] || isset($group_attributes['group_avatar']) && strpos($test, 'avatar') === 0 || in_array($test, $set_attributes))) { settype($submit_ary[$test], $type); $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test]; diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index d92aea91f8..b9a06bc3b4 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -618,7 +618,7 @@ class ucp_groups foreach ($test_variables as $test => $type) { - if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test])) + if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test] || isset($group_attributes['group_avatar']) && strpos($test, 'avatar') === 0)) { settype($submit_ary[$test], $type); $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test]; -- cgit v1.2.1 From 9a6219d8b391eedbbd5626f845b00c3acd738e12 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Jan 2013 14:45:40 +0100 Subject: [ticket/9492] Ensure to delete the avatar/rank data when we change it PHPBB3-9492 --- phpBB/includes/functions_user.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 3b7c9eea92..d47e04cbe5 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2698,12 +2698,12 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow } $db->sql_freeresult($result); - if (isset($sql_ary['group_avatar']) && !$sql_ary['group_avatar']) + if (isset($sql_ary['group_avatar'])) { remove_default_avatar($group_id, $user_ary); } - if (isset($sql_ary['group_rank']) && !$sql_ary['group_rank']) + if (isset($sql_ary['group_rank'])) { remove_default_rank($group_id, $user_ary); } -- cgit v1.2.1 From 6a972da4c7d0cc8008ff95d41b5fb71cb17e107e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 20 Jan 2013 20:58:46 +0100 Subject: [ticket/9492] Fix typo in SQL query PHPBB3-9492 --- phpBB/includes/functions_user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index d47e04cbe5..b7878ddfc7 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3539,7 +3539,7 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal } $sql = 'UPDATE ' . USERS_TABLE . ' - SSET ' . $db->sql_build_array('UPDATE', $avatar_sql_ary) . " + SET ' . $db->sql_build_array('UPDATE', $avatar_sql_ary) . " WHERE user_avatar = '' AND " . $db->sql_in_set('user_id', $user_id_ary); $db->sql_query($sql); -- cgit v1.2.1 From dfabdbca508a3fbd60c8df57ea756a974f4f135b Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 22 Jan 2013 13:19:49 -0600 Subject: [ticket/9737] Fix a few minor things in migrations PHPBB3-9737 --- phpBB/includes/db/migration/exception.php | 7 ++++++- phpBB/includes/db/migrator.php | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/exception.php b/phpBB/includes/db/migration/exception.php index bd46a4e064..ffdcd97780 100644 --- a/phpBB/includes/db/migration/exception.php +++ b/phpBB/includes/db/migration/exception.php @@ -22,7 +22,10 @@ if (!defined('IN_PHPBB')) */ class phpbb_db_migration_exception extends \Exception { - /** @var array Extra parameters sent to exception to aid in debugging */ + /** + * Extra parameters sent to exception to aid in debugging + * @var array + */ protected $parameters; /** @@ -42,6 +45,8 @@ class phpbb_db_migration_exception extends \Exception /** * Output the error as a string + * + * @return string */ public function __toString() { diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index d95283ae01..4456600b0a 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -394,7 +394,7 @@ class phpbb_db_migrator } /** - * Attempts to apply a step of the given migration or one of its dependencies + * Attempts to revert a step of the given migration or one of its dependencies * * @param string The class name of the migration * @return bool Whether any update step was successfully run @@ -559,12 +559,12 @@ class phpbb_db_migrator /** * Get a callable statement from a data step * - * @param mixed $step Data step from migration + * @param array $step Data step from migration * @param mixed $last_result Result to pass to the callable (only for 'custom' method) * @param bool $reverse False to install, True to attempt uninstallation by reversing the call * @return array Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters */ - protected function get_callable_from_step($step, $last_result = false, $reverse = false) + protected function get_callable_from_step(array $step, $last_result = false, $reverse = false) { $type = $step[0]; $parameters = $step[1]; -- cgit v1.2.1 From 7338bfe3f08b829b97a2045b6bb029dd6b3ba54a Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 23 Jan 2013 09:45:20 -0600 Subject: [ticket/9737] Fix some comments PHPBB3-9737 --- phpBB/includes/db/migration/migration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/migration.php b/phpBB/includes/db/migration/migration.php index cf1e97b3b1..5f14a6953c 100644 --- a/phpBB/includes/db/migration/migration.php +++ b/phpBB/includes/db/migration/migration.php @@ -74,7 +74,7 @@ abstract class phpbb_db_migration } /** - * Defines other migrations to be applied first (abstract method) + * Defines other migrations to be applied first * * @return array An array of migration class names */ @@ -84,7 +84,7 @@ abstract class phpbb_db_migration } /** - * Allows you to check if the migration is effectively installed (entirely optionall) + * Allows you to check if the migration is effectively installed (entirely optional) * * This is checked when a migration is installed. If true is returned, the migration will be set as * installed without performing the database changes. -- cgit v1.2.1 From 305b2b8f4876e9a11c30a36b10a92b112db47864 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 25 Jan 2013 19:49:02 +0100 Subject: [ticket/11343] Use === when checking stored user_actkey against user input. Use strict comparison when checking whether stored user_actkey is equal to user input. PHPBB3-11343 --- phpBB/includes/ucp/ucp_activate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_activate.php b/phpBB/includes/ucp/ucp_activate.php index 82c1937919..1177d55c12 100644 --- a/phpBB/includes/ucp/ucp_activate.php +++ b/phpBB/includes/ucp/ucp_activate.php @@ -51,7 +51,7 @@ class ucp_activate trigger_error('ALREADY_ACTIVATED'); } - if (($user_row['user_inactive_reason'] == INACTIVE_MANUAL) || $user_row['user_actkey'] != $key) + if (($user_row['user_inactive_reason'] == INACTIVE_MANUAL) || $user_row['user_actkey'] !== $key) { trigger_error('WRONG_ACTIVATION'); } -- cgit v1.2.1 From 8421aa0b0e5607765593126de959bab113427272 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 25 Jan 2013 19:51:17 +0100 Subject: [ticket/11343] Remove spare space. PHPBB3-11343 --- phpBB/includes/ucp/ucp_activate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_activate.php b/phpBB/includes/ucp/ucp_activate.php index 1177d55c12..9e545cd747 100644 --- a/phpBB/includes/ucp/ucp_activate.php +++ b/phpBB/includes/ucp/ucp_activate.php @@ -51,7 +51,7 @@ class ucp_activate trigger_error('ALREADY_ACTIVATED'); } - if (($user_row['user_inactive_reason'] == INACTIVE_MANUAL) || $user_row['user_actkey'] !== $key) + if (($user_row['user_inactive_reason'] == INACTIVE_MANUAL) || $user_row['user_actkey'] !== $key) { trigger_error('WRONG_ACTIVATION'); } -- cgit v1.2.1 From 5a146df07f62f9963b3ec313ef27a72183f295db Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 25 Jan 2013 19:52:02 +0100 Subject: [ticket/11343] Remove spare parentheses. PHPBB3-11343 --- phpBB/includes/ucp/ucp_activate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_activate.php b/phpBB/includes/ucp/ucp_activate.php index 9e545cd747..b262dc5c1c 100644 --- a/phpBB/includes/ucp/ucp_activate.php +++ b/phpBB/includes/ucp/ucp_activate.php @@ -51,7 +51,7 @@ class ucp_activate trigger_error('ALREADY_ACTIVATED'); } - if (($user_row['user_inactive_reason'] == INACTIVE_MANUAL) || $user_row['user_actkey'] !== $key) + if ($user_row['user_inactive_reason'] == INACTIVE_MANUAL || $user_row['user_actkey'] !== $key) { trigger_error('WRONG_ACTIVATION'); } -- cgit v1.2.1 From 36b7d7560e55ee570a2e2f5991982be6c8e66487 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 28 Jan 2013 22:26:20 +0530 Subject: [ticket/11233] prohibit selecting anonymous user as a PM recipient While composing pm, it should not be allowed to add anonymous user as a PM recipient PHPBB3-11233 --- phpBB/includes/ucp/ucp_pm_compose.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_pm_compose.php b/phpBB/includes/ucp/ucp_pm_compose.php index d1786dd9ba..8e82188aff 100644 --- a/phpBB/includes/ucp/ucp_pm_compose.php +++ b/phpBB/includes/ucp/ucp_pm_compose.php @@ -359,7 +359,7 @@ function compose_pm($id, $mode, $action, $user_folders = array()) $message_attachment = 0; $message_text = $message_subject = ''; - if ($to_user_id && $action == 'post') + if ($to_user_id && $to_user_id != ANONYMOUS && $action == 'post') { $address_list['u'][$to_user_id] = 'to'; } -- cgit v1.2.1 From 75244eafd946bb157ec5e54d5ec2ba3a309ae3ab Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 30 Jan 2013 16:20:50 -0600 Subject: [feature/migrations] Revert unrelated changes to functions.php PHPBB3-9737 --- phpBB/includes/functions.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 057bdba0e3..d0ef2759d5 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2868,7 +2868,6 @@ function send_status_line($code, $message) else { $version = phpbb_request_http_version(); - header("$version $code $message", true, $code); } } @@ -5583,7 +5582,7 @@ function phpbb_convert_30_dbms_to_31($dbms) /* $reflection = new \ReflectionClass($dbms); - + if ($reflection->isSubclassOf('phpbb_db_driver')) { return $dbms; -- cgit v1.2.1 From 336187151a2010197ddda1bcdabc311fd10c1c87 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 4 Feb 2013 01:30:04 +0100 Subject: [ticket/11201] Revert WLM dropping because it is still used in China. Windows Live Messenger is still in use in china which accounts for ~20% of world population. Revert WLM dropping which has been merged under the assumption that WLM data and features are completely useless. This commit reverts commits - 460470229d972b93ef5a98b0d1d97a2a970d684f - 9affd6f7e7b95442f1ef14894858d8213f3fbd2a which have been merged by d59431691c27c73fba8ae9934b84b34a13280dd2. PHPBB3-11201 --- phpBB/includes/acp/acp_users.php | 4 ++++ phpBB/includes/ucp/ucp_pm_viewmessage.php | 1 + phpBB/includes/ucp/ucp_profile.php | 4 ++++ 3 files changed, 9 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 2bdbf1441a..82d8ef5cbb 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1352,6 +1352,7 @@ class acp_users $data = array( 'icq' => request_var('icq', $user_row['user_icq']), 'aim' => request_var('aim', $user_row['user_aim']), + 'msn' => request_var('msn', $user_row['user_msnm']), 'yim' => request_var('yim', $user_row['user_yim']), 'jabber' => utf8_normalize_nfc(request_var('jabber', $user_row['user_jabber'], true)), 'website' => request_var('website', $user_row['user_website']), @@ -1381,6 +1382,7 @@ class acp_users array('string', true, 3, 15), array('match', true, '#^[0-9]+$#i')), 'aim' => array('string', true, 3, 255), + 'msn' => array('string', true, 5, 255), 'jabber' => array( array('string', true, 5, 255), array('jabber')), @@ -1414,6 +1416,7 @@ class acp_users $sql_ary = array( 'user_icq' => $data['icq'], 'user_aim' => $data['aim'], + 'user_msnm' => $data['msn'], 'user_yim' => $data['yim'], 'user_jabber' => $data['jabber'], 'user_website' => $data['website'], @@ -1466,6 +1469,7 @@ class acp_users 'ICQ' => $data['icq'], 'YIM' => $data['yim'], 'AIM' => $data['aim'], + 'MSN' => $data['msn'], 'JABBER' => $data['jabber'], 'WEBSITE' => $data['website'], 'LOCATION' => $data['location'], diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index a1001cfa74..c85b05f144 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -241,6 +241,7 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) 'U_ICQ' => ($user_info['user_icq']) ? 'http://www.icq.com/people/' . urlencode($user_info['user_icq']) . '/' : '', 'U_AIM' => ($user_info['user_aim'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=aim&u=' . $author_id) : '', 'U_YIM' => ($user_info['user_yim']) ? 'http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($user_info['user_yim']) . '&.src=pg' : '', + 'U_MSN' => ($user_info['user_msnm'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=msnm&u=' . $author_id) : '', 'U_JABBER' => ($user_info['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=jabber&u=' . $author_id) : '', 'U_DELETE' => ($auth->acl_get('u_pm_delete')) ? "$url&mode=compose&action=delete&f=$folder_id&p=" . $message_row['msg_id'] : '', diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index c1ad9955b6..e7cea06a45 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -266,6 +266,7 @@ class ucp_profile $data = array( 'icq' => request_var('icq', $user->data['user_icq']), 'aim' => request_var('aim', $user->data['user_aim']), + 'msn' => request_var('msn', $user->data['user_msnm']), 'yim' => request_var('yim', $user->data['user_yim']), 'jabber' => utf8_normalize_nfc(request_var('jabber', $user->data['user_jabber'], true)), 'website' => request_var('website', $user->data['user_website']), @@ -298,6 +299,7 @@ class ucp_profile array('string', true, 3, 15), array('match', true, '#^[0-9]+$#i')), 'aim' => array('string', true, 3, 255), + 'msn' => array('string', true, 5, 255), 'jabber' => array( array('string', true, 5, 255), array('jabber')), @@ -349,6 +351,7 @@ class ucp_profile $sql_ary = array( 'user_icq' => $data['icq'], 'user_aim' => $data['aim'], + 'user_msnm' => $data['msn'], 'user_yim' => $data['yim'], 'user_jabber' => $data['jabber'], 'user_website' => $data['website'], @@ -420,6 +423,7 @@ class ucp_profile 'ICQ' => $data['icq'], 'YIM' => $data['yim'], 'AIM' => $data['aim'], + 'MSN' => $data['msn'], 'JABBER' => $data['jabber'], 'WEBSITE' => $data['website'], 'LOCATION' => $data['location'], -- cgit v1.2.1 From 77df9109b61ec93c28a8120a8d81a045961b24ac Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Mon, 4 Feb 2013 13:46:23 -0600 Subject: [feature/migrations] Remove default values from necessary parameters Clean up some comments PHPBB3-9737 --- phpBB/includes/db/migration/tool/config.php | 34 ++++++++++--------- phpBB/includes/db/migration/tool/module.php | 44 +++++++++++++++---------- phpBB/includes/db/migration/tool/permission.php | 33 ++++++++++--------- 3 files changed, 61 insertions(+), 50 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/tool/config.php b/phpBB/includes/db/migration/tool/config.php index 6ae419d5e7..d9cc20053e 100644 --- a/phpBB/includes/db/migration/tool/config.php +++ b/phpBB/includes/db/migration/tool/config.php @@ -38,12 +38,14 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac /** * Add a config setting. * - * @param string $config_name The name of the config setting you would like to add + * @param string $config_name The name of the config setting + * you would like to add * @param mixed $config_value The value of the config setting - * @param bool $is_dynamic True if it is dynamic (changes very often) and should not be stored in the cache, false if not. + * @param bool $is_dynamic True if it is dynamic (changes very often) + * and should not be stored in the cache, false if not. * @return null */ - public function add($config_name, $config_value = '', $is_dynamic = false) + public function add($config_name, $config_value, $is_dynamic = false) { if (isset($this->config[$config_name])) { @@ -56,11 +58,12 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac /** * Update an existing config setting. * - * @param string $config_name The name of the config setting you would like to update + * @param string $config_name The name of the config setting you would + * like to update * @param mixed $config_value The value of the config setting * @return null */ - public function update($config_name, $config_value = '') + public function update($config_name, $config_value) { if (!isset($this->config[$config_name])) { @@ -71,14 +74,17 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac } /** - * Update a config setting if the first argument equal to the current config value + * Update a config setting if the first argument equal to the + * current config value * - * @param bool $compare If equal to the current config value, will be updated to the new config value, otherwise not - * @param string $config_name The name of the config setting you would like to update + * @param string $compare If equal to the current config value, will be + * updated to the new config value, otherwise not + * @param string $config_name The name of the config setting you would + * like to update * @param mixed $config_value The value of the config setting * @return null */ - public function update_if_equals($compare, $config_name, $config_value = '') + public function update_if_equals($compare, $config_name, $config_value) { if (!isset($this->config[$config_name])) { @@ -91,7 +97,8 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac /** * Remove an existing config setting. * - * @param string $config_name The name of the config setting you would like to remove + * @param string $config_name The name of the config setting you would + * like to remove * @return null */ public function remove($config_name) @@ -105,12 +112,7 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac } /** - * Reverse an original install action - * - * First argument is the original call to the class (e.g. add, remove) - * After the first argument, send the original arguments to the function in the original call - * - * @return null + * {@inheritdoc} */ public function reverse() { diff --git a/phpBB/includes/db/migration/tool/module.php b/phpBB/includes/db/migration/tool/module.php index 561faac552..afe1f21ec5 100644 --- a/phpBB/includes/db/migration/tool/module.php +++ b/phpBB/includes/db/migration/tool/module.php @@ -66,8 +66,10 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac * Check if a module exists * * @param string $class The module class(acp|mcp|ucp) - * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. - * @param int|string $module The module_id|module_langname you would like to check for to see if it exists + * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). + * Use false to ignore the parent check and check class wide. + * @param int|string $module The module_id|module_langname you would like to + * check for to see if it exists * @return bool true/false if module exists */ public function exists($class, $parent, $module) @@ -131,10 +133,14 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac * * @param string $class The module class(acp|mcp|ucp) * @param int|string $parent The parent module_id|module_langname (0 for no parent) - * @param array $data an array of the data on the new module. This can be setup in two different ways. - * 1. The "manual" way. For inserting a category or one at a time. It will be merged with the base array shown a bit below, - * but at the least requires 'module_langname' to be sent, and, if you want to create a module (instead of just a category) you must send module_basename and module_mode. - * array( + * @param array $data an array of the data on the new module. + * This can be setup in two different ways. + * 1. The "manual" way. For inserting a category or one at a time. + * It will be merged with the base array shown a bit below, + * but at the least requires 'module_langname' to be sent, and, + * if you want to create a module (instead of just a category) you must + * send module_basename and module_mode. + * array( * 'module_enabled' => 1, * 'module_display' => 1, * 'module_basename' => '', @@ -144,14 +150,19 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac * 'module_mode' => '', * 'module_auth' => '', * ) - * 2. The "automatic" way. For inserting multiple at a time based on the specs in the info file for the module(s). For this to work the modules must be correctly setup in the info file. - * An example follows (this would insert the settings, log, and flag modes from the includes/acp/info/acp_asacp.php file): + * 2. The "automatic" way. For inserting multiple at a time based on the + * specs in the info file for the module(s). For this to work the + * modules must be correctly setup in the info file. + * An example follows (this would insert the settings, log, and flag + * modes from the includes/acp/info/acp_asacp.php file): * array( * 'module_basename' => 'asacp', * 'modes' => array('settings', 'log', 'flag'), * ) - * Optionally you may not send 'modes' and it will insert all of the modules in that info file. - * @param string|bool $include_path If you would like to use a custom include path, specify that here + * Optionally you may not send 'modes' and it will insert all of the + * modules in that info file. + * @param string|bool $include_path If you would like to use a custom include + * path, specify that here * @return null */ public function add($class, $parent = 0, $data = array(), $include_path = false) @@ -334,9 +345,11 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac * Remove a module * * @param string $class The module class(acp|mcp|ucp) - * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. + * @param int|string|bool $parent The parent module_id|module_langname(0 for no parent). + * Use false to ignore the parent check and check class wide. * @param int|string $module The module id|module_langname - * @param string|bool $include_path If you would like to use a custom include path, specify that here + * @param string|bool $include_path If you would like to use a custom include path, + * specify that here * @return null */ public function remove($class, $parent = 0, $module = '', $include_path = false) @@ -473,12 +486,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac } /** - * Reverse an original install action - * - * First argument is the original call to the class (e.g. add, remove) - * After the first argument, send the original arguments to the function in the original call - * - * @return null + * {@inheritdoc} */ public function reverse() { diff --git a/phpBB/includes/db/migration/tool/permission.php b/phpBB/includes/db/migration/tool/permission.php index a25fdb345e..001d090f5a 100644 --- a/phpBB/includes/db/migration/tool/permission.php +++ b/phpBB/includes/db/migration/tool/permission.php @@ -61,7 +61,8 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * Check if a permission (auth) setting exists * * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting + * @param bool $global True for checking a global permission setting, + * False for a local permission setting * @return bool true if it exists, false if not */ public function exists($auth_option, $global = true) @@ -98,7 +99,8 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * Add a permission (auth) option * * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting + * @param bool $global True for checking a global permission setting, + * False for a local permission setting * @return null */ public function add($auth_option, $global = true, $copy_from = false) @@ -180,7 +182,8 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * Remove a permission (auth) option * * @param string $auth_option The name of the permission (auth) option - * @param bool $global True for checking a global permission setting, False for a local permission setting + * @param bool $global True for checking a global permission setting, + * False for a local permission setting * @return null */ public function remove($auth_option, $global = true) @@ -239,7 +242,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * @param sting $role_type The type (u_, m_, a_) * @return null */ - public function role_add($role_name, $role_type = '', $role_description = '') + public function role_add($role_name, $role_type, $role_description = '') { $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . " @@ -277,7 +280,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * @param string $new_role_name The new role name * @return null */ - public function role_update($old_role_name, $new_role_name = '') + public function role_update($old_role_name, $new_role_name) { $sql = 'SELECT role_id FROM ' . ACL_ROLES_TABLE . " @@ -332,12 +335,14 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * Allows you to set permissions for a certain group/role * * @param string $name The name of the role/group - * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string|array $auth_option The auth_option or array of + * auth_options you would like to set * @param string $type The type (role|group) - * @param bool $has_permission True if you want to give them permission, false if you want to deny them permission + * @param bool $has_permission True if you want to give them permission, + * false if you want to deny them permission * @return null */ - public function permission_set($name, $auth_option = array(), $type = 'role', $has_permission = true) + public function permission_set($name, $auth_option, $type = 'role', $has_permission = true) { if (!is_array($auth_option)) { @@ -477,11 +482,12 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte * Allows you to unset (remove) permissions for a certain group/role * * @param string $name The name of the role/group - * @param string|array $auth_option The auth_option or array of auth_options you would like to set + * @param string|array $auth_option The auth_option or array of + * auth_options you would like to set * @param string $type The type (role|group) * @return null */ - public function permission_unset($name, $auth_option = array(), $type = 'role') + public function permission_unset($name, $auth_option, $type = 'role') { if (!is_array($auth_option)) { @@ -565,12 +571,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte } /** - * Reverse an original install action - * - * First argument is the original call to the class (e.g. add, remove) - * After the first argument, send the original arguments to the function in the original call - * - * @return null + * {@inheritdoc} */ public function reverse() { -- cgit v1.2.1 From 293b65e3efbf94f6521acebe1b9f3e7bbca20286 Mon Sep 17 00:00:00 2001 From: David Tobin Date: Thu, 5 Jul 2012 02:47:49 +0100 Subject: [ticket/10896] Adds email validation to email settings in ACP Adds a new validation type to the ACP validate_config_vars function and implements it on the board_contact and board_email settings. PHPBB3-10896 --- phpBB/includes/acp/acp_board.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index f437dca8f9..ebbf66657e 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -408,8 +408,8 @@ class acp_board 'board_email_form' => array('lang' => 'BOARD_EMAIL_FORM', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true), 'email_function_name' => array('lang' => 'EMAIL_FUNCTION_NAME', 'validate' => 'string', 'type' => 'text:20:50', 'explain' => true), 'email_package_size' => array('lang' => 'EMAIL_PACKAGE_SIZE', 'validate' => 'int:0', 'type' => 'text:5:5', 'explain' => true), - 'board_contact' => array('lang' => 'CONTACT_EMAIL', 'validate' => 'string', 'type' => 'text:25:100', 'explain' => true), - 'board_email' => array('lang' => 'ADMIN_EMAIL', 'validate' => 'string', 'type' => 'text:25:100', 'explain' => true), + 'board_contact' => array('lang' => 'CONTACT_EMAIL', 'validate' => 'email', 'type' => 'text:25:100', 'explain' => true), + 'board_email' => array('lang' => 'ADMIN_EMAIL', 'validate' => 'email', 'type' => 'text:25:100', 'explain' => true), 'board_email_sig' => array('lang' => 'EMAIL_SIG', 'validate' => 'string', 'type' => 'textarea:5:30', 'explain' => true), 'board_hide_emails' => array('lang' => 'BOARD_HIDE_EMAILS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), -- cgit v1.2.1 From 8d3a82a4fa8ced50fbc1d1019ef439d1d5c81e71 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 19:32:39 -0600 Subject: [feature/migrations] Make the container available to extension installers This allows extensions to load and install migrations easily as per their needs. PHPBB3-11318 --- phpBB/includes/extension/base.php | 15 +++++++++++++++ phpBB/includes/extension/manager.php | 13 ++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/base.php b/phpBB/includes/extension/base.php index 9d076eb6c5..d51589d719 100644 --- a/phpBB/includes/extension/base.php +++ b/phpBB/includes/extension/base.php @@ -15,6 +15,8 @@ if (!defined('IN_PHPBB')) exit; } +use Symfony\Component\DependencyInjection\ContainerInterface; + /** * A base class for extensions without custom enable/disable/purge code. * @@ -22,6 +24,19 @@ if (!defined('IN_PHPBB')) */ class phpbb_extension_base implements phpbb_extension_interface { + /** @var ContainerInterface */ + protected $container; + + /** + * Constructor + * + * @param ContainerInterface $container Container object + */ + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + /** * Single enable step that does nothing * diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index de6f364320..8136dfa90b 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -15,6 +15,8 @@ if (!defined('IN_PHPBB')) exit; } +use Symfony\Component\DependencyInjection\ContainerInterface; + /** * The extension manager provides means to activate/deactivate extensions. * @@ -22,6 +24,9 @@ if (!defined('IN_PHPBB')) */ class phpbb_extension_manager { + /** @var ContainerInterface */ + protected $container; + protected $db; protected $config; protected $cache; @@ -34,6 +39,7 @@ class phpbb_extension_manager /** * Creates a manager and loads information from database * + * @param ContainerInterface $container A container * @param phpbb_db_driver $db A database connection * @param phpbb_config $config phpbb_config * @param string $extension_table The name of the table holding extensions @@ -42,8 +48,9 @@ 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(phpbb_db_driver $db, phpbb_config $config, $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; @@ -126,11 +133,11 @@ class phpbb_extension_manager if (class_exists($extension_class_name)) { - return new $extension_class_name; + return new $extension_class_name($this->container); } else { - return new phpbb_extension_base; + return new phpbb_extension_base($this->container); } } -- cgit v1.2.1 From aa67fa6dd83e329c3b6edbb356eae3eeda1ba69f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 31 Jan 2013 13:53:33 -0600 Subject: [feature/migrations] Automatically install/revert migrations for extensions Migrations from ext/ext_name/migrations/ are automatically installed when enabling the extension and automatically reverted when the extension is purged. PHPBB3-11318 --- phpBB/includes/extension/manager.php | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 8136dfa90b..018324d5d6 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -173,6 +173,12 @@ class phpbb_extension_manager $old_state = (isset($this->extensions[$name]['ext_state'])) ? unserialize($this->extensions[$name]['ext_state']) : false; + // Returns false if not completed + if (!$this->handle_migrations($name, 'enable')) + { + return true; + } + $extension = $this->get_extension($name); $state = $extension->enable_step($old_state); @@ -324,6 +330,12 @@ class phpbb_extension_manager $old_state = unserialize($this->extensions[$name]['ext_state']); + // Returns false if not completed + if (!$this->handle_migrations($name, 'purge')) + { + return true; + } + $extension = $this->get_extension($name); $state = $extension->purge_step($old_state); @@ -497,4 +509,54 @@ class phpbb_extension_manager { return new phpbb_extension_finder($this, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder'); } + + /** + * Handle installing/reverting migrations + * + * @param string $extension_name Name of the extension + * @param string $mode enable or purge + * @return bool True if completed, False if not completed + */ + protected function handle_migrations($extension_name, $mode) + { + $migrator = $this->container->get('migrator'); + $migrations_path = $this->get_extension_path($extension_name) . 'migrations'; + if (file_exists($migrations_path) && is_dir($migrations_path)) + { + $migrator->load_migrations($migrations_path); + } + + // What is a safe limit of execution time? Half the max execution time should be safe. + $safe_time_limit = (ini_get('max_execution_time') / 2); + $start_time = time(); + + if ($mode == 'enable') + { + while (!$migrator->finished()) + { + $migrator->update(); + + // Are we approaching the time limit? If so we want to pause the update and continue after refreshing + if ((time() - $start_time) >= $safe_time_limit) + { + return false; + } + } + } + else if ($mode == 'purge') + { + while ($migrator->migration_state() !== false) + { + $migrator->revert(); + + // Are we approaching the time limit? If so we want to pause the update and continue after refreshing + if ((time() - $start_time) >= $safe_time_limit) + { + return false; + } + } + } + + return true; + } } -- 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 daf243026a1c6bcd369381433b556732674c41f6 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 6 Feb 2013 13:08:35 -0600 Subject: [ticket/11350] Do not pass $db by reference; typehint phpbb_db_driver PHPBB3-11350 --- phpBB/includes/db/db_tools.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/db_tools.php b/phpBB/includes/db/db_tools.php index a4bf40fcd7..9235317958 100644 --- a/phpBB/includes/db/db_tools.php +++ b/phpBB/includes/db/db_tools.php @@ -303,7 +303,7 @@ class phpbb_db_tools * @param phpbb_db_driver $db Database connection * @param bool $return_statements True if only statements should be returned and no SQL being executed */ - function phpbb_db_tools(&$db, $return_statements = false) + function phpbb_db_tools(phpbb_db_driver $db, $return_statements = false) { $this->db = $db; $this->return_statements = $return_statements; -- cgit v1.2.1 From 5705c3d377d097ef8bf7b99863eabc08fe3276e7 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 6 Feb 2013 13:14:40 -0600 Subject: [feature/migrations] Fix path to extension migrations PHPBB3-11318 --- phpBB/includes/extension/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 018324d5d6..008bd35376 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -520,7 +520,7 @@ class phpbb_extension_manager protected function handle_migrations($extension_name, $mode) { $migrator = $this->container->get('migrator'); - $migrations_path = $this->get_extension_path($extension_name) . 'migrations'; + $migrations_path = $this->phpbb_root_path . $this->get_extension_path($extension_name) . 'migrations/'; if (file_exists($migrations_path) && is_dir($migrations_path)) { $migrator->load_migrations($migrations_path); -- cgit v1.2.1 From a8da6b89e9da1d3b4e16317c21fc88fa1173d0f1 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 9 Feb 2013 20:01:40 -0600 Subject: [feature/migrations] Inject Migrator instead of using the container to fetch PHPBB3-11318 --- phpBB/includes/extension/manager.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 008bd35376..926cc015de 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -29,6 +29,7 @@ class phpbb_extension_manager protected $db; protected $config; + protected $migrator; protected $cache; protected $php_ext; protected $extensions; @@ -48,12 +49,13 @@ 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, $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, phpbb_db_migrator $migrator, $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; @@ -519,11 +521,10 @@ class phpbb_extension_manager */ protected function handle_migrations($extension_name, $mode) { - $migrator = $this->container->get('migrator'); $migrations_path = $this->phpbb_root_path . $this->get_extension_path($extension_name) . 'migrations/'; if (file_exists($migrations_path) && is_dir($migrations_path)) { - $migrator->load_migrations($migrations_path); + $this->migrator->load_migrations($migrations_path); } // What is a safe limit of execution time? Half the max execution time should be safe. @@ -532,9 +533,9 @@ class phpbb_extension_manager if ($mode == 'enable') { - while (!$migrator->finished()) + while (!$this->migrator->finished()) { - $migrator->update(); + $this->migrator->update(); // Are we approaching the time limit? If so we want to pause the update and continue after refreshing if ((time() - $start_time) >= $safe_time_limit) @@ -545,9 +546,9 @@ class phpbb_extension_manager } else if ($mode == 'purge') { - while ($migrator->migration_state() !== false) + while ($this->migrator->migration_state() !== false) { - $migrator->revert(); + $this->migrator->revert(); // Are we approaching the time limit? If so we want to pause the update and continue after refreshing if ((time() - $start_time) >= $safe_time_limit) -- cgit v1.2.1 From fc4d5f74c0b82989370e899939d6f31e9a85723d Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 9 Feb 2013 20:05:39 -0600 Subject: [feature/migrations] Call revert correctly when purging an extension PHPBB3-11318 --- phpBB/includes/extension/manager.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 926cc015de..21a9ec1370 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -522,11 +522,13 @@ class phpbb_extension_manager protected function handle_migrations($extension_name, $mode) { $migrations_path = $this->phpbb_root_path . $this->get_extension_path($extension_name) . 'migrations/'; - if (file_exists($migrations_path) && is_dir($migrations_path)) + if (!file_exists($migrations_path) || !is_dir($migrations_path)) { - $this->migrator->load_migrations($migrations_path); + return true; } + $migrations = $this->migrator->load_migrations($migrations_path); + // What is a safe limit of execution time? Half the max execution time should be safe. $safe_time_limit = (ini_get('max_execution_time') / 2); $start_time = time(); @@ -546,14 +548,17 @@ class phpbb_extension_manager } else if ($mode == 'purge') { - while ($this->migrator->migration_state() !== false) + foreach ($migrations as $migration) { - $this->migrator->revert(); - - // Are we approaching the time limit? If so we want to pause the update and continue after refreshing - if ((time() - $start_time) >= $safe_time_limit) + while ($this->migrator->migration_state($migration) !== false) { - return false; + $this->migrator->revert($migration); + + // Are we approaching the time limit? If so we want to pause the update and continue after refreshing + if ((time() - $start_time) >= $safe_time_limit) + { + return false; + } } } } -- cgit v1.2.1 From cacaffee6e013e43b75212d49960922f88f9f69a Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 9 Feb 2013 20:56:42 -0600 Subject: [feature/migrations] Add language strings for migrations errors Unfulfillable returns string of the missing dependency name now if the migration is unfulfillable (this is significantly more helpful). PHPBB3-11351 --- phpBB/includes/db/migration/tool/config.php | 2 +- phpBB/includes/db/migration/tool/module.php | 6 +++--- phpBB/includes/db/migration/tool/permission.php | 6 +++--- phpBB/includes/db/migrator.php | 16 +++++++++------- 4 files changed, 16 insertions(+), 14 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/tool/config.php b/phpBB/includes/db/migration/tool/config.php index d9cc20053e..458a25fb66 100644 --- a/phpBB/includes/db/migration/tool/config.php +++ b/phpBB/includes/db/migration/tool/config.php @@ -49,7 +49,7 @@ class phpbb_db_migration_tool_config implements phpbb_db_migration_tool_interfac { if (isset($this->config[$config_name])) { - throw new phpbb_db_migration_exception('CONFIG_ALREADY_EXISTS', $config_name); + throw new phpbb_db_migration_exception('CONFIG_ALREADY_EXIST', $config_name); } $this->config->set($config_name, $config_value, !$is_dynamic); diff --git a/phpBB/includes/db/migration/tool/module.php b/phpBB/includes/db/migration/tool/module.php index afe1f21ec5..4d7fae2bb0 100644 --- a/phpBB/includes/db/migration/tool/module.php +++ b/phpBB/includes/db/migration/tool/module.php @@ -242,14 +242,14 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac if (!$module_id) { - throw new phpbb_db_migration_exception('MODULE_PARENT_NOT_EXIST', $parent); + throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', $parent); } $parent = $data['parent_id'] = $module_id; } else if (!$this->exists($class, false, $parent)) { - throw new phpbb_db_migration_exception('MODULE_PARENT_NOT_EXIST', $parent); + throw new phpbb_db_migration_exception('MODULE_NOT_EXIST', $parent); } if ($this->exists($class, $parent, $data['module_langname'])) @@ -477,7 +477,7 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac $result = $acp_modules->delete_module($module_id); if (!empty($result)) { - throw new phpbb_db_migration_exception('CANNOT_REMOVE_MODULE', $module_id); + throw new phpbb_db_migration_exception('MODULE_NOT_REMOVABLE', $module_id, $result); } } diff --git a/phpBB/includes/db/migration/tool/permission.php b/phpBB/includes/db/migration/tool/permission.php index 001d090f5a..4231fbe1dd 100644 --- a/phpBB/includes/db/migration/tool/permission.php +++ b/phpBB/includes/db/migration/tool/permission.php @@ -107,7 +107,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte { if ($this->exists($auth_option, $global)) { - throw new phpbb_db_migration_exception('PERMISSION_ALREADY_EXISTS', $auth_option); + throw new phpbb_db_migration_exception('PERMISSION_ALREADY_EXIST', $auth_option); } // We've added permissions, so set to true to notify the user. @@ -252,7 +252,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte if ($role_id) { - throw new phpbb_db_migration_exception('ROLE_ALREADY_EXISTS', $old_role_name); + return; } $sql = 'SELECT MAX(role_order) AS max_role_order @@ -290,7 +290,7 @@ class phpbb_db_migration_tool_permission implements phpbb_db_migration_tool_inte if (!$role_id) { - throw new phpbb_db_migration_exception('ROLE_NOT_EXISTS', $old_role_name); + throw new phpbb_db_migration_exception('ROLE_NOT_EXIST', $old_role_name); } $sql = 'UPDATE ' . ACL_ROLES_TABLE . " diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php index 4456600b0a..3c311e96d7 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -228,9 +228,10 @@ class phpbb_db_migrator { foreach ($this->migrations as $name) { - if ($this->unfulfillable($name)) + $unfulfillable = $this->unfulfillable($name); + if ($unfulfillable !== false) { - throw new phpbb_db_migration_exception('MIGRATION NOT FULFILLABLE', $name); + throw new phpbb_db_migration_exception('MIGRATION_NOT_FULFILLABLE', $name, $unfulfillable); } } } @@ -674,13 +675,13 @@ class phpbb_db_migrator * Checks if a migration's dependencies can even theoretically be satisfied. * * @param string $name The class name of the migration - * @return bool Whether the migration cannot be fulfilled + * @return bool|string False if fulfillable, string of missing migration name if unfulfillable */ public function unfulfillable($name) { if (isset($this->migration_state[$name])) { - return false; + return $name; } if (!class_exists($name)) @@ -693,9 +694,10 @@ class phpbb_db_migrator foreach ($depends as $depend) { - if ($this->unfulfillable($depend)) + $unfulfillable = $this->unfulfillable($depend); + if ($unfulfillable !== false) { - return true; + return $unfulfillable; } } @@ -715,7 +717,7 @@ class phpbb_db_migrator { // skip unfulfillable migrations, but fulfillables mean we // are not finished yet - if ($this->unfulfillable($name)) + if ($this->unfulfillable($name) !== false) { continue; } -- cgit v1.2.1 From b398fa2050ab720d9a3ae2b809bb3cdf4f153dc6 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 9 Feb 2013 21:09:29 -0600 Subject: [feature/migrations] Catch and display errors from the migrator PHPBB3-11318 --- phpBB/includes/acp/acp_extensions.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index a0bcf62ecc..17ab4f3169 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -37,7 +37,7 @@ class acp_extensions $this->template = $template; $this->user = $user; - $user->add_lang(array('install', 'acp/extensions')); + $user->add_lang(array('install', 'acp/extensions', 'migrator')); $this->page_title = 'ACP_EXTENSIONS'; @@ -103,11 +103,18 @@ class acp_extensions trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action)); } - if ($phpbb_extension_manager->enable_step($ext_name)) + try { - $template->assign_var('S_NEXT_STEP', true); + if ($phpbb_extension_manager->enable_step($ext_name)) + { + $template->assign_var('S_NEXT_STEP', true); - meta_refresh(0, $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name)); + meta_refresh(0, $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name)); + } + } + catch (phpbb_db_migration_exception $e) + { + $template->assign_var('MIGRATOR_ERROR', $user->lang($e->getMessage(), $e->getParameters())); } $this->tpl_name = 'acp_ext_enable'; @@ -156,11 +163,18 @@ class acp_extensions break; case 'purge': - if ($phpbb_extension_manager->purge_step($ext_name)) + try { - $template->assign_var('S_NEXT_STEP', true); + if ($phpbb_extension_manager->purge_step($ext_name)) + { + $template->assign_var('S_NEXT_STEP', true); - meta_refresh(0, $this->u_action . '&action=purge&ext_name=' . urlencode($ext_name)); + meta_refresh(0, $this->u_action . '&action=purge&ext_name=' . urlencode($ext_name)); + } + } + catch (phpbb_db_migration_exception $e) + { + $template->assign_var('MIGRATOR_ERROR', $user->lang($e->getMessage(), $e->getParameters())); } $this->tpl_name = 'acp_ext_purge'; -- cgit v1.2.1 From f18b096df945648aa3ecc2b8b914869871b1823f Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 9 Feb 2013 21:10:56 -0600 Subject: [feature/migrations] getParameters function for migration exception PHPBB3-11351 --- phpBB/includes/db/migration/exception.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/exception.php b/phpBB/includes/db/migration/exception.php index ffdcd97780..b3abcdb5e5 100644 --- a/phpBB/includes/db/migration/exception.php +++ b/phpBB/includes/db/migration/exception.php @@ -52,4 +52,14 @@ class phpbb_db_migration_exception extends \Exception { return $this->message . ': ' . var_export($this->parameters, true); } + + /** + * Get the parameters + * + * @return array + */ + public function getParameters() + { + return $this->parameters; + } } -- cgit v1.2.1 From f9a1b27a99e30a41db4facd415b39a690614d6c6 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 9 Feb 2013 21:16:39 -0600 Subject: [feature/migrations] Fix unfulfillable function Returned unfulfillable name in the wrong place previously PHPBB3-11351 --- 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 3c311e96d7..41d996b1e3 100644 --- a/phpBB/includes/db/migrator.php +++ b/phpBB/includes/db/migrator.php @@ -681,12 +681,12 @@ class phpbb_db_migrator { if (isset($this->migration_state[$name])) { - return $name; + return false; } if (!class_exists($name)) { - return true; + return $name; } $migration = $this->get_migration($name); -- cgit v1.2.1 From 8ec55b062dbaf40f5ad3aec49bf987a14b34dfe8 Mon Sep 17 00:00:00 2001 From: erangamapa Date: Mon, 11 Feb 2013 15:29:12 +0530 Subject: [ticket/11196] Changed 401 response message in session.php. In session.php 401 response message was "Not Authorized". I changed it to "Unauthorized". PHPBB3-11196 --- phpBB/includes/session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index 496c12a0d1..d980f50e05 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -325,7 +325,7 @@ class session // if no session id is set, redirect to index.php if (defined('NEED_SID') && (!isset($_GET['sid']) || $this->session_id !== $_GET['sid'])) { - send_status_line(401, 'Not authorized'); + send_status_line(401, 'Unauthorized'); redirect(append_sid("{$phpbb_root_path}index.$phpEx")); } -- 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 f6bb14569b0a777d3511b732201af9d1a415f2ed Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 15 Feb 2013 22:19:24 -0600 Subject: [feature/migrations] getLocalisedMessage function for migration exception PHPBB3-11351 --- phpBB/includes/db/migration/exception.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/db/migration/exception.php b/phpBB/includes/db/migration/exception.php index b3abcdb5e5..e84330dd71 100644 --- a/phpBB/includes/db/migration/exception.php +++ b/phpBB/includes/db/migration/exception.php @@ -62,4 +62,18 @@ class phpbb_db_migration_exception extends \Exception { return $this->parameters; } + + /** + * Get localised message (with $user->lang()) + * + * @param phpbb_user $user + * @return string + */ + public function getLocalisedMessage(phpbb_user $user) + { + $parameters = $this->getParameters(); + array_unshift($parameters, $this->getMessage()); + + return call_user_func_array(array($user, 'lang'), $parameters); + } } -- cgit v1.2.1 From 872773a21897ccad754a53d7c8ad7899bcc05796 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 15 Feb 2013 22:22:13 -0600 Subject: [feature/migrations] Use getLocalisedMessage() function to get error message PHPBB3-11318 --- phpBB/includes/acp/acp_extensions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 17ab4f3169..24211196bd 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -114,7 +114,7 @@ class acp_extensions } catch (phpbb_db_migration_exception $e) { - $template->assign_var('MIGRATOR_ERROR', $user->lang($e->getMessage(), $e->getParameters())); + $template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($user)); } $this->tpl_name = 'acp_ext_enable'; @@ -174,7 +174,7 @@ class acp_extensions } catch (phpbb_db_migration_exception $e) { - $template->assign_var('MIGRATOR_ERROR', $user->lang($e->getMessage(), $e->getParameters())); + $template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($user)); } $this->tpl_name = 'acp_ext_purge'; -- cgit v1.2.1 From 5b99f0c113390959f693222055715413addef34e Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 18 Feb 2013 14:01:46 +0530 Subject: [ticket/11359] close span PHPBB3-11359 --- phpBB/includes/search/fulltext_sphinx.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 4bacf74f93..07bcbdadc1 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -878,7 +878,7 @@ class phpbb_search_fulltext_sphinx
' . $this->user->lang['MIB'] . '
-

' . $this->user->lang['FULLTEXT_SPHINX_CONFIG_FILE_EXPLAIN'] . '
+

' . $this->user->lang['FULLTEXT_SPHINX_CONFIG_FILE_EXPLAIN'] . '
' . (($this->config_generate()) ? '' : $this->config_file_data) . '
'; -- cgit v1.2.1 From 3c6256b3e7489b9aca1e153b3e3bb754f3dd6a7d Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 18 Feb 2013 14:05:25 +0530 Subject: [ticket/11359] add id attribute to textarea PHPBB3-11359 --- phpBB/includes/search/fulltext_sphinx.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 07bcbdadc1..6c66499d21 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -879,7 +879,7 @@ class phpbb_search_fulltext_sphinx

' . $this->user->lang['FULLTEXT_SPHINX_CONFIG_FILE_EXPLAIN'] . '
-
' . (($this->config_generate()) ? '' : $this->config_file_data) . '
+
' . (($this->config_generate()) ? '' : $this->config_file_data) . '
'; -- cgit v1.2.1 From 38360c71f298efee54396118b8afb5c642c79db3 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 18 Feb 2013 14:13:31 +0530 Subject: [ticket/11359] html escape sphinx config data PHPBB3-11359 --- phpBB/includes/search/fulltext_sphinx.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 6c66499d21..7304e70ff8 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -879,7 +879,7 @@ class phpbb_search_fulltext_sphinx

' . $this->user->lang['FULLTEXT_SPHINX_CONFIG_FILE_EXPLAIN'] . '
-
' . (($this->config_generate()) ? '' : $this->config_file_data) . '
+
' . (($this->config_generate()) ? '' : $this->config_file_data) . '
'; -- cgit v1.2.1 From 737b99966de8e12ffa13d762b7065043a39399d7 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 03:39:51 +0530 Subject: [ticket/11179] add search query in case initial one fails changes the start parameter according to the total search results and executes the search query again to get the results. PHPBB3-11179 --- phpBB/includes/search/fulltext_mysql.php | 34 ++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 324c214e91..acb1a7bde8 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -381,7 +381,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base { return $result_count; } - $id_ary = array(); $join_topic = ($type == 'posts') ? false : true; @@ -490,7 +489,38 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if (!sizeof($id_ary)) { - return false; + $sql_count = "SELECT COUNT(*) as result_count + FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p + WHERE MATCH ($sql_match) AGAINST ('" . $this->db->sql_escape(htmlspecialchars_decode($this->search_query)) . "' IN BOOLEAN MODE) + $sql_where_options + ORDER BY $sql_sort"; + $result = $this->db->sql_query($sql_count); + $total_match_count = (int) $this->db->sql_fetchfield('result_count'); + + if ($total_match_count) + { + if ($start < 0) + { + $start = 0; + } + else if ($start >= $total_match_count) + { + $start = floor(($total_match_count - 1) / $per_page) * $per_page; + } + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = (int) $row[$field]; + } + $this->db->sql_freeresult($result); + + $id_ary = array_unique($id_ary); + } + + if (!sizeof($id_ary)) + { + return false; + } } // if the total result count is not cached yet, retrieve it from the db -- cgit v1.2.1 From 00d34617ccb6a53185f0e872a735b4dd2f65009b Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 13:36:14 +0100 Subject: [ticket/11179] correct the start parameter while retrieving from cache Start parameter if not between 0 and the total result count of the cached search results is changed accordingly PHPBB3-11179 --- phpBB/includes/search/base.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/base.php b/phpBB/includes/search/base.php index b364dead9a..11e5535979 100644 --- a/phpBB/includes/search/base.php +++ b/phpBB/includes/search/base.php @@ -97,7 +97,6 @@ class phpbb_search_base function obtain_ids($search_key, &$result_count, &$id_ary, $start, $per_page, $sort_dir) { global $cache; - if (!($stored_ids = $cache->get('_search_results_' . $search_key))) { // no search results cached for this search_key @@ -109,6 +108,19 @@ class phpbb_search_base $reverse_ids = ($stored_ids[-2] != $sort_dir) ? true : false; $complete = true; + // change start parameter in case out of bounds + if ($result_count) + { + if ($start < 0) + { + $start = 0; + } + else if ($start >= $result_count) + { + $start = floor(($result_count - 1) / $per_page) * $per_page; + } + } + // change the start to the actual end of the current request if the sort direction differs // from the dirction in the cache and reverse the ids later if ($reverse_ids) -- cgit v1.2.1 From 3e5ef8ab2cc1d8c6e0850e36ddb546489cc5ab12 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 13:39:40 +0100 Subject: [ticket/11179] pass start parameter by reference start parameter is passed by reference so that in case it is not in bounds the changes made to it are reflected back to the phpBB/search.php file PHPBB3-11179 --- phpBB/includes/search/base.php | 2 +- phpBB/includes/search/fulltext_mysql.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/base.php b/phpBB/includes/search/base.php index 11e5535979..2047742367 100644 --- a/phpBB/includes/search/base.php +++ b/phpBB/includes/search/base.php @@ -94,7 +94,7 @@ class phpbb_search_base * * @return int SEARCH_RESULT_NOT_IN_CACHE or SEARCH_RESULT_IN_CACHE or SEARCH_RESULT_INCOMPLETE */ - function obtain_ids($search_key, &$result_count, &$id_ary, $start, $per_page, $sort_dir) + function obtain_ids($search_key, &$result_count, &$id_ary, &$start, $per_page, $sort_dir) { global $cache; if (!($stored_ids = $cache->get('_search_results_' . $search_key))) diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index acb1a7bde8..749353b2ee 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -353,7 +353,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No keywords? No posts if (!$this->search_query) -- cgit v1.2.1 From 1c9c666ef193942a2d88ec59741ddc49900e92e9 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 14:17:38 +0100 Subject: [ticket/11179] use FOUND_ROWS query to re-search with changed start param PHPBB3-11179 --- phpBB/includes/search/fulltext_mysql.php | 60 ++++++++++++-------------------- 1 file changed, 22 insertions(+), 38 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 749353b2ee..3ecc2cd39d 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -375,6 +375,11 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base implode(',', $author_ary) ))); + if ($start < 0) + { + $start = 0; + } + // try reading the results from cache $result_count = 0; if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) @@ -487,47 +492,11 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $id_ary = array_unique($id_ary); - if (!sizeof($id_ary)) - { - $sql_count = "SELECT COUNT(*) as result_count - FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p - WHERE MATCH ($sql_match) AGAINST ('" . $this->db->sql_escape(htmlspecialchars_decode($this->search_query)) . "' IN BOOLEAN MODE) - $sql_where_options - ORDER BY $sql_sort"; - $result = $this->db->sql_query($sql_count); - $total_match_count = (int) $this->db->sql_fetchfield('result_count'); - - if ($total_match_count) - { - if ($start < 0) - { - $start = 0; - } - else if ($start >= $total_match_count) - { - $start = floor(($total_match_count - 1) / $per_page) * $per_page; - } - $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $this->db->sql_fetchrow($result)) - { - $id_ary[] = (int) $row[$field]; - } - $this->db->sql_freeresult($result); - - $id_ary = array_unique($id_ary); - } - - if (!sizeof($id_ary)) - { - return false; - } - } - // if the total result count is not cached yet, retrieve it from the db if (!$result_count) { - $sql = 'SELECT FOUND_ROWS() as result_count'; - $result = $this->db->sql_query($sql); + $sql_found_rows = 'SELECT FOUND_ROWS() as result_count'; + $result = $this->db->sql_query($sql_found_rows); $result_count = (int) $this->db->sql_fetchfield('result_count'); $this->db->sql_freeresult($result); @@ -537,6 +506,21 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base } } + if ($start >= $result_count) + { + $start = floor(($result_count - 1) / $per_page) * $per_page; + } + + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = (int) $row[$field]; + } + $this->db->sql_freeresult($result); + + $id_ary = array_unique($id_ary); + // store the ids, from start on then delete anything that isn't on the current page because we only need ids for one page $this->save_ids($search_key, implode(' ', $this->split_words), $author_ary, $result_count, $id_ary, $start, $sort_dir); $id_ary = array_slice($id_ary, 0, (int) $per_page); -- cgit v1.2.1 From 2601411a9cfb79de1c45523005e91f00a8583ad1 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 14:28:29 +0100 Subject: [ticket/11179] correct start parameter for author search PHPBB3-11179 --- phpBB/includes/search/fulltext_mysql.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 3ecc2cd39d..54e2007da3 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -571,6 +571,11 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $author_name, ))); + if ($start < 0) + { + $start = 0; + } + // try reading the results from cache $result_count = 0; if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) @@ -676,8 +681,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base // retrieve the total result count if needed if (!$result_count) { - $sql = 'SELECT FOUND_ROWS() as result_count'; - $result = $this->db->sql_query($sql); + $sql_found_rows = 'SELECT FOUND_ROWS() as result_count'; + $result = $this->db->sql_query($sql_found_rows); $result_count = (int) $this->db->sql_fetchfield('result_count'); $this->db->sql_freeresult($result); @@ -687,6 +692,20 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base } } + if ($start >= $result_count) + { + $start = floor(($result_count - 1) / $per_page) * $per_page; + } + + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = (int) $row[$field]; + } + $this->db->sql_freeresult($result); + + $id_ary = array_unique($id_ary); + if (sizeof($id_ary)) { $this->save_ids($search_key, '', $author_ary, $result_count, $id_ary, $start, $sort_dir); -- cgit v1.2.1 From 80f8e3abceabab658a5a935e5a6079e73f663698 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 14:29:39 +0100 Subject: [ticket/11179] pass start param by reference in author search PHPBB3-11179 --- phpBB/includes/search/fulltext_mysql.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 54e2007da3..69f76ba99e 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -547,7 +547,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No author? No posts if (!sizeof($author_ary)) @@ -578,7 +578,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base // try reading the results from cache $result_count = 0; - if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) + if ($this->obtain_ids($search_key, $result_count, $id_ary, &$start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) { return $result_count; } -- cgit v1.2.1 From 2cb48f034153038d71d89ab58904cd048b8524d9 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 15:35:05 +0100 Subject: [ticket/11179] correct start parameter in psql keyword search PHPBB3-11179 --- phpBB/includes/search/fulltext_postgres.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index 1475cc31d0..d968a934f4 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -371,6 +371,11 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base implode(',', $author_ary) ))); + if ($start < 0) + { + $start = 0; + } + // try reading the results from cache $result_count = 0; if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) @@ -495,11 +500,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $id_ary = array_unique($id_ary); - if (!sizeof($id_ary)) - { - return false; - } - // if the total result count is not cached yet, retrieve it from the db if (!$result_count) { @@ -518,6 +518,21 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $this->db->sql_transaction('commit'); + if ($start >= $result_count) + { + $start = floor(($result_count - 1) / $per_page) * $per_page; + } + + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = $row[$field]; + } + $this->db->sql_freeresult($result); + + $id_ary = array_unique($id_ary); + // store the ids, from start on then delete anything that isn't on the current page because we only need ids for one page $this->save_ids($search_key, implode(' ', $this->split_words), $author_ary, $result_count, $id_ary, $start, $sort_dir); $id_ary = array_slice($id_ary, 0, (int) $per_page); -- cgit v1.2.1 From ef88edbcf69541bd79e220c87c444b33a6751c67 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 15:44:16 +0100 Subject: [ticket/11179] correct start param in author search of postgres PHPBB3-11179 --- phpBB/includes/search/fulltext_postgres.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index d968a934f4..e8a5353b05 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -583,6 +583,11 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $author_name, ))); + if ($start < 0) + { + $start = 0; + } + // try reading the results from cache $result_count = 0; if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) @@ -725,6 +730,20 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $this->db->sql_transaction('commit'); + if ($start >= $result_count) + { + $start = floor(($result_count - 1) / $per_page) * $per_page; + } + + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = (int) $row[$field]; + } + $this->db->sql_freeresult($result); + + $id_ary = array_unique($id_ary); + if (sizeof($id_ary)) { $this->save_ids($search_key, '', $author_ary, $result_count, $id_ary, $start, $sort_dir); -- cgit v1.2.1 From bc77ca4d4eb6a5bcf3e47706c6b6fd2b0fe33f82 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 15:45:15 +0100 Subject: [ticket/11179] pass start param by reference in postgres PHPBB3-11179 --- phpBB/includes/search/fulltext_postgres.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index e8a5353b05..bdc2fa4f19 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -343,7 +343,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No keywords? No posts if (!$this->search_query) @@ -559,7 +559,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No author? No posts if (!sizeof($author_ary)) -- cgit v1.2.1 From 16bbdf4a52b2cb2fa4aa2cd607ae726ea1c7af67 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 11 Nov 2012 10:11:58 +0100 Subject: [ticket/11179] minor fixes Amends comments to start with capitals. Reinsert blank lines which were not supposed to be removed PHPBB3-11179 --- phpBB/includes/search/base.php | 3 ++- phpBB/includes/search/fulltext_mysql.php | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/base.php b/phpBB/includes/search/base.php index 2047742367..914cef9167 100644 --- a/phpBB/includes/search/base.php +++ b/phpBB/includes/search/base.php @@ -97,6 +97,7 @@ class phpbb_search_base function obtain_ids($search_key, &$result_count, &$id_ary, &$start, $per_page, $sort_dir) { global $cache; + if (!($stored_ids = $cache->get('_search_results_' . $search_key))) { // no search results cached for this search_key @@ -108,7 +109,7 @@ class phpbb_search_base $reverse_ids = ($stored_ids[-2] != $sort_dir) ? true : false; $complete = true; - // change start parameter in case out of bounds + // Change start parameter in case out of bounds if ($result_count) { if ($start < 0) diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 69f76ba99e..ad5119f67c 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -386,6 +386,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base { return $result_count; } + $id_ary = array(); $join_topic = ($type == 'posts') ? false : true; -- cgit v1.2.1 From f0d63594e68fa7a165b8ba90d0fcf35f38e42de9 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 2 Dec 2012 14:15:04 +0530 Subject: [ticket/11179] fix success query path for mysql Additional query to check start parameter executed only incase of no results. PHPBB3-11179 --- phpBB/includes/search/fulltext_mysql.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index ad5119f67c..4dc62753aa 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -510,17 +510,17 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if ($start >= $result_count) { $start = floor(($result_count - 1) / $per_page) * $per_page; - } - $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $this->db->sql_fetchrow($result)) - { - $id_ary[] = (int) $row[$field]; - } - $this->db->sql_freeresult($result); + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = (int) $row[$field]; + } + $this->db->sql_freeresult($result); - $id_ary = array_unique($id_ary); + $id_ary = array_unique($id_ary); + } // store the ids, from start on then delete anything that isn't on the current page because we only need ids for one page $this->save_ids($search_key, implode(' ', $this->split_words), $author_ary, $result_count, $id_ary, $start, $sort_dir); @@ -696,16 +696,16 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if ($start >= $result_count) { $start = floor(($result_count - 1) / $per_page) * $per_page; - } - $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $this->db->sql_fetchrow($result)) - { - $id_ary[] = (int) $row[$field]; - } - $this->db->sql_freeresult($result); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = (int) $row[$field]; + } + $this->db->sql_freeresult($result); - $id_ary = array_unique($id_ary); + $id_ary = array_unique($id_ary); + } if (sizeof($id_ary)) { -- cgit v1.2.1 From 8b7f306897cddcb16cbed50488848ee357c26f39 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 2 Dec 2012 14:31:12 +0530 Subject: [ticket/11179] fix success query path for postgres Additional query to check start parameter executed only incase of no results. PHPBB3-11179 --- phpBB/includes/search/fulltext_postgres.php | 32 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index bdc2fa4f19..eeb628b18f 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -521,17 +521,17 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base if ($start >= $result_count) { $start = floor(($result_count - 1) / $per_page) * $per_page; - } - $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $this->db->sql_fetchrow($result)) - { - $id_ary[] = $row[$field]; - } - $this->db->sql_freeresult($result); + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = $row[$field]; + } + $this->db->sql_freeresult($result); - $id_ary = array_unique($id_ary); + $id_ary = array_unique($id_ary); + } // store the ids, from start on then delete anything that isn't on the current page because we only need ids for one page $this->save_ids($search_key, implode(' ', $this->split_words), $author_ary, $result_count, $id_ary, $start, $sort_dir); @@ -733,16 +733,16 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base if ($start >= $result_count) { $start = floor(($result_count - 1) / $per_page) * $per_page; - } - $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $this->db->sql_fetchrow($result)) - { - $id_ary[] = (int) $row[$field]; - } - $this->db->sql_freeresult($result); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = (int) $row[$field]; + } + $this->db->sql_freeresult($result); - $id_ary = array_unique($id_ary); + $id_ary = array_unique($id_ary); + } if (sizeof($id_ary)) { -- cgit v1.2.1 From a0ae223ef46e30c9413350ed7c4e52eaab5bb159 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 21 Dec 2012 19:10:48 +0530 Subject: [ticket/11179] correct start parameter in native keyword search PHPBB3-11179 --- phpBB/includes/search/fulltext_native.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index 53df8348ae..fccdcd855e 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -516,7 +516,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No keywords? No posts. if (empty($this->search_query)) @@ -855,10 +855,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base } $this->db->sql_freeresult($result); - if (!sizeof($id_ary)) - { - return false; - } // if we use mysql and the total result count is not cached yet, retrieve it from the db if (!$total_results && $is_mysql) @@ -867,14 +863,14 @@ class phpbb_search_fulltext_native extends phpbb_search_base $sql_array_copy = $sql_array; $sql_array_copy['SELECT'] = 'SQL_CALC_FOUND_ROWS p.post_id '; - $sql = $this->db->sql_build_query('SELECT', $sql_array_copy); + $sql_calc = $this->db->sql_build_query('SELECT', $sql_array_copy); unset($sql_array_copy); - $this->db->sql_query($sql); + $this->db->sql_query($sql_calc); $this->db->sql_freeresult($result); - $sql = 'SELECT FOUND_ROWS() as total_results'; - $result = $this->db->sql_query($sql); + $sql_count = 'SELECT FOUND_ROWS() as total_results'; + $result = $this->db->sql_query($sql_count); $total_results = (int) $this->db->sql_fetchfield('total_results'); $this->db->sql_freeresult($result); @@ -884,6 +880,20 @@ class phpbb_search_fulltext_native extends phpbb_search_base } } + if ($start >= $total_results) + { + $start = floor(($total_results - 1) / $per_page) * $per_page; + + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = (int) $row[(($type == 'posts') ? 'post_id' : 'topic_id')]; + } + $this->db->sql_freeresult($result); + + } + // store the ids, from start on then delete anything that isn't on the current page because we only need ids for one page $this->save_ids($search_key, $this->search_query, $author_ary, $total_results, $id_ary, $start, $sort_dir); $id_ary = array_slice($id_ary, 0, (int) $per_page); -- cgit v1.2.1 From 2ff874fe930d458382212cfe5495080231ec76e6 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 21 Dec 2012 19:11:20 +0530 Subject: [ticket/11179] correct start parameter in native author search PHPBB3-11179 --- phpBB/includes/search/fulltext_native.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index fccdcd855e..c9f33054fc 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -920,7 +920,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No author? No posts if (!sizeof($author_ary)) @@ -1106,13 +1106,13 @@ class phpbb_search_fulltext_native extends phpbb_search_base if (!$total_results && $is_mysql) { // Count rows for the executed queries. Replace $select within $sql with SQL_CALC_FOUND_ROWS, and run it. - $sql = str_replace('SELECT ' . $select, 'SELECT DISTINCT SQL_CALC_FOUND_ROWS p.post_id', $sql); + $sql_calc = str_replace('SELECT ' . $select, 'SELECT DISTINCT SQL_CALC_FOUND_ROWS p.post_id', $sql); - $this->db->sql_query($sql); + $this->db->sql_query($sql_calc); $this->db->sql_freeresult($result); - $sql = 'SELECT FOUND_ROWS() as total_results'; - $result = $this->db->sql_query($sql); + $sql_count = 'SELECT FOUND_ROWS() as total_results'; + $result = $this->db->sql_query($sql_count); $total_results = (int) $this->db->sql_fetchfield('total_results'); $this->db->sql_freeresult($result); @@ -1122,6 +1122,19 @@ class phpbb_search_fulltext_native extends phpbb_search_base } } + if ($start >= $total_results) + { + $start = floor(($total_results - 1) / $per_page) * $per_page; + + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = (int) $row[$field]; + } + $this->db->sql_freeresult($result); + } + if (sizeof($id_ary)) { $this->save_ids($search_key, '', $author_ary, $total_results, $id_ary, $start, $sort_dir); -- cgit v1.2.1 From 38bb7dca31740f9d4f188b75167f736ee6666c2f Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 21 Dec 2012 21:54:41 +0530 Subject: [ticket/11179] correct start parameter in sphinx search PHPBB3-11179 --- phpBB/includes/search/fulltext_sphinx.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_sphinx.php b/phpBB/includes/search/fulltext_sphinx.php index 7304e70ff8..48445d0794 100644 --- a/phpBB/includes/search/fulltext_sphinx.php +++ b/phpBB/includes/search/fulltext_sphinx.php @@ -454,7 +454,7 @@ class phpbb_search_fulltext_sphinx * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No keywords? No posts. if (!strlen($this->search_query) && !sizeof($author_ary)) @@ -609,6 +609,25 @@ class phpbb_search_fulltext_sphinx } } + $result_count = $result['total_found']; + + if ($start >= $result_count) + { + $start = floor(($result_count - 1) / $per_page) * $per_page; + + $this->sphinx->SetLimits((int) $start, (int) $per_page, SPHINX_MAX_MATCHES); + $result = $this->sphinx->Query($search_query_prefix . str_replace('"', '"', $this->search_query), $this->indexes); + + // Could be connection to localhost:9312 failed (errno=111, + // msg=Connection refused) during rotate, retry if so + $retries = SPHINX_CONNECT_RETRIES; + while (!$result && (strpos($this->sphinx->GetLastError(), "errno=111,") !== false) && $retries--) + { + usleep(SPHINX_CONNECT_WAIT_TIME); + $result = $this->sphinx->Query($search_query_prefix . str_replace('"', '"', $this->search_query), $this->indexes); + } + } + $id_ary = array(); if (isset($result['matches'])) { @@ -629,8 +648,6 @@ class phpbb_search_fulltext_sphinx return false; } - $result_count = $result['total_found']; - $id_ary = array_slice($id_ary, 0, (int) $per_page); return $result_count; -- cgit v1.2.1 From 1ee4702ec51ecfc7d40c8768ba7927439c73002c Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 25 Jan 2013 18:15:55 +0530 Subject: [ticket/11179] remove extra & in function call PHPBB3-11179 --- phpBB/includes/search/fulltext_mysql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 4dc62753aa..adaf025730 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -579,7 +579,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base // try reading the results from cache $result_count = 0; - if ($this->obtain_ids($search_key, $result_count, $id_ary, &$start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) + if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) { return $result_count; } -- cgit v1.2.1 From ae3a22bd0c06bd6098c229963402d660572a0598 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 23 Feb 2013 11:06:48 +0100 Subject: [ticket/11361] Make sure that array passed to strtr() has the proper format. The array $date_cache[$format]['lang'] passed to strtr() contains a sub-array which results in an E_NOTICE being thrown for 'Array to string conversion' on PHP 5.4. Ensure that the array passed to strtr() is one-dimensional by filtering out non-string values. PHPBB3-11361 --- phpBB/includes/session.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index d980f50e05..b93f2ff65e 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -2156,7 +2156,8 @@ class user extends session 'is_short' => strpos($format, '|'), 'format_short' => substr($format, 0, strpos($format, '|')) . '||' . substr(strrchr($format, '|'), 1), 'format_long' => str_replace('|', '', $format), - 'lang' => $this->lang['datetime'], + // Filter out values that are not strings (e.g. arrays) for strtr(). + 'lang' => array_filter($this->lang['datetime'], 'is_string'), ); // Short representation of month in format? Some languages use different terms for the long and short format of May -- cgit v1.2.1 From b7a222cdd593edb3e61183d9e28707ac9005aa82 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 23 Feb 2013 14:20:56 -0500 Subject: [ticket/11298] Fix typo in language key; EXTENSIONS -> EXTENSION PHPBB3-11298 --- phpBB/includes/acp/info/acp_extensions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/info/acp_extensions.php b/phpBB/includes/acp/info/acp_extensions.php index 03d7059165..174b365af0 100644 --- a/phpBB/includes/acp/info/acp_extensions.php +++ b/phpBB/includes/acp/info/acp_extensions.php @@ -16,10 +16,10 @@ class acp_extensions_info { return array( 'filename' => 'acp_extensions', - 'title' => 'ACP_EXTENSIONS_MANAGEMENT', + 'title' => 'ACP_EXTENSION_MANAGEMENT', 'version' => '1.0.0', 'modes' => array( - 'main' => array('title' => 'ACP_EXTENSIONS', 'auth' => 'acl_a_extensions', 'cat' => array('ACP_EXTENSIONS_MANAGEMENT')), + 'main' => array('title' => 'ACP_EXTENSIONS', 'auth' => 'acl_a_extensions', 'cat' => array('ACP_EXTENSION_MANAGEMENT')), ), ); } -- 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 e8b3e8498d9842296a905fdaad8c0c32e31bceb4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 24 Feb 2013 12:54:05 +0100 Subject: [ticket/7262] Backport set_config() and set_config_count() docs from develop. PHPBB3-7262 --- phpBB/includes/functions.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 571c863839..04b69f8c69 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -137,7 +137,14 @@ function request_var($var_name, $default, $multibyte = false, $cookie = false) } /** -* Set config value. Creates missing config entry. +* Sets a configuration option's value. +* +* @param string $config_name The configuration option's name +* @param string $config_value New configuration value +* @param bool $is_dynamic Whether this variable should be cached or if it +* changes too frequently to be efficiently cached. +* +* @return null */ function set_config($config_name, $config_value, $is_dynamic = false) { @@ -166,7 +173,14 @@ function set_config($config_name, $config_value, $is_dynamic = false) } /** -* Set dynamic config value with arithmetic operation. +* Increments an integer config value directly in the database. +* +* @param string $config_name The configuration option's name +* @param int $increment Amount to increment by +* @param bool $is_dynamic Whether this variable should be cached or if it +* changes too frequently to be efficiently cached. +* +* @return null */ function set_config_count($config_name, $increment, $is_dynamic = false) { -- cgit v1.2.1 From a9037a68c177d396b2ed4b9bfcaad64536a01aaa Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 24 Feb 2013 13:03:48 +0100 Subject: [ticket/7262] Add $is_dynamic example to set_config() and set_config_count(). The logic is the other way around here in comparison to develop's phpbb_config_db class, so add examples to make things more clear. PHPBB3-7262 --- phpBB/includes/functions.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 04b69f8c69..2ca7d7f898 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -141,8 +141,9 @@ function request_var($var_name, $default, $multibyte = false, $cookie = false) * * @param string $config_name The configuration option's name * @param string $config_value New configuration value -* @param bool $is_dynamic Whether this variable should be cached or if it -* changes too frequently to be efficiently cached. +* @param bool $is_dynamic Whether this variable should be cached (false) or +* if it changes too frequently (true) to be +* efficiently cached. * * @return null */ @@ -177,8 +178,9 @@ function set_config($config_name, $config_value, $is_dynamic = false) * * @param string $config_name The configuration option's name * @param int $increment Amount to increment by -* @param bool $is_dynamic Whether this variable should be cached or if it -* changes too frequently to be efficiently cached. +* @param bool $is_dynamic Whether this variable should be cached (false) or +* if it changes too frequently (true) to be +* efficiently cached. * * @return null */ -- cgit v1.2.1 From 6bf64d5620b1b9f165a65b50042c391a29ef151c Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 24 Feb 2013 13:37:52 +0100 Subject: [ticket/7262] Add note about set_config() not updating is_dynamic. PHPBB3-7262 --- phpBB/includes/functions.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 2ca7d7f898..ccd2d3147c 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -139,6 +139,9 @@ function request_var($var_name, $default, $multibyte = false, $cookie = false) /** * Sets a configuration option's value. * +* Please note that this function does not update the is_dynamic value for +* an already existing config option. +* * @param string $config_name The configuration option's name * @param string $config_value New configuration value * @param bool $is_dynamic Whether this variable should be cached (false) or -- cgit v1.2.1 From d2a15d9afe06509ff3e9fe5b6463800f66813783 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 24 Feb 2013 17:42:53 +0100 Subject: [ticket/10896] Add missing email validation lost in develop merge Fix incomplete merge, by adding a piece of code moved to another file in olympus back. PHPBB3-10896 --- phpBB/includes/functions_acp.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index 32fd76e74d..d6bd9e35dd 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -443,6 +443,13 @@ function validate_config_vars($config_vars, &$cfg_array, &$error) } break; + case 'email': + if (!preg_match('/^' . get_preg_expression('email') . '$/i', $cfg_array[$config_name])) + { + $error[] = $user->lang['EMAIL_INVALID_EMAIL']; + } + break; + // Absolute path case 'script_path': if (!$cfg_array[$config_name]) -- cgit v1.2.1 From f8e184c54e85dc55a803b76a6ccefb769ef38e17 Mon Sep 17 00:00:00 2001 From: erangamapa Date: Mon, 18 Feb 2013 11:04:14 +0530 Subject: [ticket/11355] Wrong error message when no user is selected. In ACP group membership management, if you select 'remove member from group' without selecting any users and submit,it will display a wrong error after confirmbox. Since no users are selected, this should not go even until confirmbox. Added a new condition to check weather any users are selected when the action is 'deleteusers' in acp_groups.php and disply a correct error. PHPBB3-11355 --- phpBB/includes/acp/acp_groups.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 486616c33d..ec44f4fc0c 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -179,6 +179,10 @@ class acp_groups break; case 'deleteusers': + if (!$name_ary) + { + trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); + } case 'delete': if (!$group_id) { @@ -795,4 +799,4 @@ class acp_groups } } -?> \ No newline at end of file +?> -- cgit v1.2.1 From ab530a999ed64a2e1fcc10252bdae6d9139d7538 Mon Sep 17 00:00:00 2001 From: erangamapa Date: Thu, 21 Feb 2013 22:47:42 +0530 Subject: [ticket/11355] Referred proper variable when validating selection. Earlier PR was referring wrong variable $name_ary. Changed it to $mark_ary which actually contains selected user ids. PHPBB3-11355 --- phpBB/includes/acp/acp_groups.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index ec44f4fc0c..bbe85f8038 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -179,7 +179,7 @@ class acp_groups break; case 'deleteusers': - if (!$name_ary) + if (empty($mark_ary)) { trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); } -- cgit v1.2.1 From 373c9a3f4ea92f1bcbe63404a2b3bf356fe5abcb Mon Sep 17 00:00:00 2001 From: erangamapa Date: Mon, 18 Feb 2013 11:17:27 +0530 Subject: [ticket/11358] Success message even without selecting a user. In group membership management, if you perform the action 'Make group default for member' without selecting any user, a confirm box will be displayed and will show a success message after confirming. Added a new condition to fix this issue in acp_groups.php. It will check weather any users are selected before performing above action. PHPBB3-11358 --- phpBB/includes/acp/acp_groups.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index bbe85f8038..dbe692aee0 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -120,6 +120,10 @@ class acp_groups { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } + else if (!$name_ary) + { + trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); + } if (confirm_box(true)) { -- cgit v1.2.1 From 880786d68610aff0c30573dc599af9e5b3ad56cf Mon Sep 17 00:00:00 2001 From: erangamapa Date: Thu, 21 Feb 2013 22:25:12 +0530 Subject: [ticket/11358] Removed redundant code and referred proper variable. Error was thrown when no users are selected before executing the code chunk which manually adds all the user to make the group default. Removed this code and referred $mark_ary instead of $name_ary which will not have selected user ids. PHPBB3-11358 --- phpBB/includes/acp/acp_groups.php | 42 ++------------------------------------- 1 file changed, 2 insertions(+), 40 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index dbe692aee0..af25d9d014 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -120,7 +120,7 @@ class acp_groups { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } - else if (!$name_ary) + else if (empty($mark_ary)) { trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); } @@ -128,45 +128,7 @@ class acp_groups if (confirm_box(true)) { $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; - - if (!sizeof($mark_ary)) - { - $start = 0; - - do - { - $sql = 'SELECT user_id - FROM ' . USER_GROUP_TABLE . " - WHERE group_id = $group_id - ORDER BY user_id"; - $result = $db->sql_query_limit($sql, 200, $start); - - $mark_ary = array(); - if ($row = $db->sql_fetchrow($result)) - { - do - { - $mark_ary[] = $row['user_id']; - } - while ($row = $db->sql_fetchrow($result)); - - group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); - - $start = (sizeof($mark_ary) < 200) ? 0 : $start + 200; - } - else - { - $start = 0; - } - $db->sql_freeresult($result); - } - while ($start); - } - else - { - group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); - } - + group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); } else -- cgit v1.2.1 From 538b09ba6115a1f90821a18d045f2056e66b5178 Mon Sep 17 00:00:00 2001 From: erangamapa Date: Fri, 22 Feb 2013 00:31:55 +0530 Subject: [ticket/11358] Enabled link making all users default for a group. Detect whether link is clicked or form is posted for making users default for a group. If form is posted and no users are selected, validation happens and displays an error message. When the link is clicked, all the users will be default users for that group. PHPBB3-11358 --- phpBB/includes/acp/acp_groups.php | 42 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index af25d9d014..c70327c6f1 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -120,7 +120,7 @@ class acp_groups { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } - else if (empty($mark_ary)) + else if (empty($mark_ary) && $request->is_set_post('default')) { trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); } @@ -128,7 +128,45 @@ class acp_groups if (confirm_box(true)) { $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; - group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); + + if (!sizeof($mark_ary)) + { + $start = 0; + + do + { + $sql = 'SELECT user_id + FROM ' . USER_GROUP_TABLE . " + WHERE group_id = $group_id + ORDER BY user_id"; + $result = $db->sql_query_limit($sql, 200, $start); + + $mark_ary = array(); + if ($row = $db->sql_fetchrow($result)) + { + do + { + $mark_ary[] = $row['user_id']; + } + while ($row = $db->sql_fetchrow($result)); + + group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); + + $start = (sizeof($mark_ary) < 200) ? 0 : $start + 200; + } + else + { + $start = 0; + } + $db->sql_freeresult($result); + } + while ($start); + } + else + { + group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); + } + trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); } else -- cgit v1.2.1 From c0a39537e38c350365c0baa74be31c000b1e9381 Mon Sep 17 00:00:00 2001 From: erangamapa Date: Fri, 22 Feb 2013 09:53:49 +0530 Subject: [ticket/11358] Changed the action parameter value to represent the link. Changed the action parameter value to recognize whether 'Make default group for every member' is clicked. If so execute a seperate code block under switch statement for $action and add all the users as default for the group. PHPBB3-11358 --- phpBB/includes/acp/acp_groups.php | 50 +++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 20 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index c70327c6f1..33d5c16ed0 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -120,7 +120,7 @@ class acp_groups { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } - else if (empty($mark_ary) && $request->is_set_post('default')) + else if (empty($mark_ary)) { trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); } @@ -128,9 +128,26 @@ class acp_groups if (confirm_box(true)) { $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; - - if (!sizeof($mark_ary)) + group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); + trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); + } + else + { + confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( + 'mark' => $mark_ary, + 'g' => $group_id, + 'i' => $id, + 'mode' => $mode, + 'action' => $action)) + ); + } + + break; + case 'defaultbylink': + if (confirm_box(true)) { + $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; + $start = 0; do @@ -161,27 +178,20 @@ class acp_groups $db->sql_freeresult($result); } while ($start); + + trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); } else { - group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); + confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( + 'mark' => $mark_ary, + 'g' => $group_id, + 'i' => $id, + 'mode' => $mode, + 'action' => $action)) + ); } - - trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); - } - else - { - confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array( - 'mark' => $mark_ary, - 'g' => $group_id, - 'i' => $id, - 'mode' => $mode, - 'action' => $action)) - ); - } - break; - case 'deleteusers': if (empty($mark_ary)) { @@ -691,7 +701,7 @@ class acp_groups 'U_ACTION' => $this->u_action . "&g=$group_id", 'U_BACK' => $this->u_action, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=list&field=usernames'), - 'U_DEFAULT_ALL' => "{$this->u_action}&action=default&g=$group_id", + 'U_DEFAULT_ALL' => "{$this->u_action}&action=defaultbylink&g=$group_id", )); // Grab the members -- cgit v1.2.1 From 1b39d6d65e2af632e6ad2ccba7fa2e61ab36c30c Mon Sep 17 00:00:00 2001 From: erangamapa Date: Sun, 24 Feb 2013 21:34:29 +0530 Subject: [ticket/11358] Changed the name of post parameter. Replaced the parameter name 'defaultbylink' to a meaningful name 'set_default_on_all'. Parameter is used for making all users default for selected group in acp_groups.php. PHPBB3-11358 --- phpBB/includes/acp/acp_groups.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 33d5c16ed0..00ca26dfa6 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -143,7 +143,7 @@ class acp_groups } break; - case 'defaultbylink': + case 'set_default_on_all': if (confirm_box(true)) { $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; @@ -701,7 +701,7 @@ class acp_groups 'U_ACTION' => $this->u_action . "&g=$group_id", 'U_BACK' => $this->u_action, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=list&field=usernames'), - 'U_DEFAULT_ALL' => "{$this->u_action}&action=defaultbylink&g=$group_id", + 'U_DEFAULT_ALL' => "{$this->u_action}&action=set_default_on_all&g=$group_id", )); // Grab the members -- cgit v1.2.1 From 4615698807e17c55d5ab93e872f7efefb1e6acd7 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 24 Feb 2013 19:07:24 +0100 Subject: [ticket/10986] message.id fallback to SERVER_NAME or phpbb.generated Rather than send invalid message ids with a missing domain part we try to read one from $_SERVER and otherwise use phpbb.generated PHPBB3-10986 --- phpBB/includes/functions_messenger.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index e837811c86..db2dea33e8 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -389,6 +389,28 @@ class messenger } } + /** + * Generates a valid message id to be used in emails + * + * @return string message id + */ + function generate_message_id() + { + global $config; + + $domain = 'phpbb.generated'; + if ($config['server_name']) + { + $domain = $config['server_name']; + } + else if (!empty($_SERVER['SERVER_NAME'])) + { + $domain = $_SERVER['SERVER_NAME']; + } + + return md5(unique_id(time())) . '@' . $domain; + } + /** * Return email header */ @@ -415,7 +437,7 @@ class messenger $headers[] = 'Return-Path: <' . $config['board_email'] . '>'; $headers[] = 'Sender: <' . $config['board_email'] . '>'; $headers[] = 'MIME-Version: 1.0'; - $headers[] = 'Message-ID: <' . md5(unique_id(time())) . '@' . $config['server_name'] . '>'; + $headers[] = 'Message-ID: <' . $this->generate_message_id() . '>'; $headers[] = 'Date: ' . date('r', time()); $headers[] = 'Content-Type: text/plain; charset=UTF-8'; // format=flowed $headers[] = 'Content-Transfer-Encoding: 8bit'; // 7bit -- 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