From 0ced93ccd5cb3de54f51ead46d4ab87a0ce67dd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 28 Apr 2017 04:04:36 +0200 Subject: [PATCH 1/7] [ticket/15201] Set user style to default style when it is disabled or uninstalled PHPBB3-15201 --- phpBB/includes/acp/acp_styles.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index b954f90451..a57c509abe 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -398,7 +398,7 @@ class acp_styles // Reset default style for users who use selected styles $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_style = 0 + SET user_style = ' . $this->default_style . ' WHERE user_style IN (' . implode(', ', $ids) . ')'; $this->db->sql_query($sql); @@ -1249,7 +1249,7 @@ class acp_styles // Change default style for users $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_style = 0 + SET user_style = ' . $this->default_style . ' WHERE user_style = ' . $id; $this->db->sql_query($sql); From b0a22163261075932a92c6c46b36c57c104c3493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 28 Apr 2017 12:01:51 +0200 Subject: [PATCH 2/7] [ticket/15201] Castings PHPBB3-15201 --- phpBB/includes/acp/acp_styles.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index a57c509abe..fc6cf26f70 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -398,7 +398,9 @@ class acp_styles // Reset default style for users who use selected styles $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_style = ' . $this->default_style . ' + SET user_style = ' . (int) $this->default_style +. +' WHERE user_style IN (' . implode(', ', $ids) . ')'; $this->db->sql_query($sql); @@ -1249,7 +1251,9 @@ class acp_styles // Change default style for users $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_style = ' . $this->default_style . ' + SET user_style = ' . (int) $this->default_style +. +' WHERE user_style = ' . $id; $this->db->sql_query($sql); From 48a3bd1a9e1fe9c6a761b43a1058b4d3c1b6641b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 28 Apr 2017 12:03:52 +0200 Subject: [PATCH 3/7] [ticket/15201] Fix PHPBB3-15201 --- phpBB/includes/acp/acp_styles.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index fc6cf26f70..5b31417b83 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -398,9 +398,7 @@ class acp_styles // Reset default style for users who use selected styles $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_style = ' . (int) $this->default_style -. -' + SET user_style = ' . (int) $this->default_style . ' WHERE user_style IN (' . implode(', ', $ids) . ')'; $this->db->sql_query($sql); @@ -1251,9 +1249,7 @@ class acp_styles // Change default style for users $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_style = ' . (int) $this->default_style -. -' + SET user_style = ' . (int) $this->default_style . ' WHERE user_style = ' . $id; $this->db->sql_query($sql); From 4719f94cecd8a3f585c9ca1c75336aa109849844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 28 Apr 2017 22:41:07 +0200 Subject: [PATCH 4/7] [ticket/15201] Remove wrong user style check PHPBB3-15201 --- .../db/migration/data/v310/style_update_p1.php | 8 ++++---- phpBB/phpbb/user.php | 18 ------------------ 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/phpBB/phpbb/db/migration/data/v310/style_update_p1.php b/phpBB/phpbb/db/migration/data/v310/style_update_p1.php index 2c7b7edf2e..dcf031a7a7 100644 --- a/phpBB/phpbb/db/migration/data/v310/style_update_p1.php +++ b/phpBB/phpbb/db/migration/data/v310/style_update_p1.php @@ -165,7 +165,7 @@ class style_update_p1 extends \phpbb\db\migration\migration $this->config->set('default_style', $default_style); - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0'; + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = ' . $default_style; $this->sql_query($sql); } else @@ -183,9 +183,9 @@ class style_update_p1 extends \phpbb\db\migration\migration } // 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)); + $this->sql_query('UPDATE ' . USERS_TABLE . " + SET user_style = '" . $valid_styles[0] . "' + WHERE " . $this->db->sql_in_set('user_style', $valid_styles, true)); } } } diff --git a/phpBB/phpbb/user.php b/phpBB/phpbb/user.php index d4097f53ee..5899dff2f5 100644 --- a/phpBB/phpbb/user.php +++ b/phpBB/phpbb/user.php @@ -278,24 +278,6 @@ class user extends \phpbb\session $db->sql_freeresult($result); } - // User has wrong style - if (!$this->style && $style_id == $this->data['user_style']) - { - $style_id = $this->data['user_style'] = $config['default_style']; - - $sql = 'UPDATE ' . USERS_TABLE . " - SET user_style = $style_id - WHERE user_id = {$this->data['user_id']}"; - $db->sql_query($sql); - - $sql = 'SELECT * - FROM ' . STYLES_TABLE . " s - WHERE s.style_id = $style_id"; - $result = $db->sql_query($sql, 3600); - $this->style = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - } - if (!$this->style) { trigger_error('NO_STYLE_DATA', E_USER_ERROR); From 13b0f399612bf3c3f6ce04bda46429dab572e590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Sat, 29 Apr 2017 09:47:48 +0200 Subject: [PATCH 5/7] [ticket/15201] Migration to fix current invalid styles PHPBB3-15201 --- .../migration/data/v32x/fix_user_styles.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 phpBB/phpbb/db/migration/data/v32x/fix_user_styles.php diff --git a/phpBB/phpbb/db/migration/data/v32x/fix_user_styles.php b/phpBB/phpbb/db/migration/data/v32x/fix_user_styles.php new file mode 100644 index 0000000000..e0caae812a --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v32x/fix_user_styles.php @@ -0,0 +1,50 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\db\migration\data\v32x; + +class fix_user_styles extends \phpbb\db\migration\migration +{ + + static public function depends_on() + { + return array( + '\phpbb\db\migration\data\v320\v320', + ); + } + + public function update_data() + { + return array( + array('custom', array(array($this, 'styles_fix'))), + ); + } + + public function styles_fix() + { + $default_style = (int) $this->config['default_style']; + + // Get enabled styles + $sql = 'SELECT style_id + FROM ' . STYLES_TABLE . ' + WHERE style_active = 1'; + $result = $this->db->sql_query($sql); + $enabled_styles = $result->fetch_array(); + $this->db->sql_freeresult($result); + + // Set the default style to users who have an invalid style + $this->sql_query('UPDATE ' . USERS_TABLE . " + SET user_style = $default_style + WHERE " . $this->db->sql_in_set('user_style', $enabled_styles, true)); + } +} From 4b1ec6abb7b2d2daa320ac5e2872e055bc5b07d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 8 Sep 2017 10:59:47 +0200 Subject: [PATCH 6/7] [ticket/15201] Fix tests PHPBB3-15201 --- phpBB/phpbb/db/migration/data/v310/style_update_p1.php | 4 ++-- tests/test_framework/phpbb_functional_test_case.php | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/db/migration/data/v310/style_update_p1.php b/phpBB/phpbb/db/migration/data/v310/style_update_p1.php index dcf031a7a7..3e28e8747d 100644 --- a/phpBB/phpbb/db/migration/data/v310/style_update_p1.php +++ b/phpBB/phpbb/db/migration/data/v310/style_update_p1.php @@ -160,7 +160,7 @@ class style_update_p1 extends \phpbb\db\migration\migration FROM ' . STYLES_TABLE . " WHERE style_name = 'prosilver'"; $result = $this->sql_query($sql); - $default_style = $this->db->sql_fetchfield('style_id'); + $default_style = (int) $this->db->sql_fetchfield('style_id'); $this->db->sql_freeresult($result); $this->config->set('default_style', $default_style); @@ -184,7 +184,7 @@ class style_update_p1 extends \phpbb\db\migration\migration // Reset styles for users $this->sql_query('UPDATE ' . USERS_TABLE . " - SET user_style = '" . $valid_styles[0] . "' + SET user_style = '" . (int) $valid_styles[0] . "' WHERE " . $this->db->sql_in_set('user_style', $valid_styles, true)); } } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index eb56049515..c9943c4302 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -572,6 +572,9 @@ class phpbb_functional_test_case extends phpbb_test_case $config['rand_seed'] = ''; $config['rand_seed_last_update'] = time() + 600; + // Prevent new user to have an invalid style + $config['default_style'] = 1; + // Required by user_add global $db, $cache, $phpbb_dispatcher, $phpbb_container; $db = $this->get_db(); From bace8dd31f0a5c2f95ae612e7e1b2e6d3083613b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 8 Sep 2017 15:02:29 +0200 Subject: [PATCH 7/7] [ticket/15201] Add casting PHPBB3-15201 --- phpBB/phpbb/db/migration/data/v310/style_update_p1.php | 2 +- phpBB/phpbb/db/migration/data/v32x/fix_user_styles.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/phpbb/db/migration/data/v310/style_update_p1.php b/phpBB/phpbb/db/migration/data/v310/style_update_p1.php index 3e28e8747d..f50ab33830 100644 --- a/phpBB/phpbb/db/migration/data/v310/style_update_p1.php +++ b/phpBB/phpbb/db/migration/data/v310/style_update_p1.php @@ -165,7 +165,7 @@ class style_update_p1 extends \phpbb\db\migration\migration $this->config->set('default_style', $default_style); - $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = ' . $default_style; + $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = ' . (int) $default_style; $this->sql_query($sql); } else diff --git a/phpBB/phpbb/db/migration/data/v32x/fix_user_styles.php b/phpBB/phpbb/db/migration/data/v32x/fix_user_styles.php index e0caae812a..282c6bef2f 100644 --- a/phpBB/phpbb/db/migration/data/v32x/fix_user_styles.php +++ b/phpBB/phpbb/db/migration/data/v32x/fix_user_styles.php @@ -43,8 +43,8 @@ class fix_user_styles extends \phpbb\db\migration\migration $this->db->sql_freeresult($result); // Set the default style to users who have an invalid style - $this->sql_query('UPDATE ' . USERS_TABLE . " - SET user_style = $default_style - WHERE " . $this->db->sql_in_set('user_style', $enabled_styles, true)); + $this->sql_query('UPDATE ' . USERS_TABLE . ' + SET user_style = ' . (int) $default_style . ' + WHERE ' . $this->db->sql_in_set('user_style', $enabled_styles, true)); } }