From d3afd6ec68b0c90b28e020dd2b9035e2bf7dd41d Mon Sep 17 00:00:00 2001 From: 3D-I <480857+3D-I@users.noreply.github.com> Date: Mon, 2 Nov 2020 17:40:06 +0100 Subject: [PATCH 1/4] [ticket/16629] Fix ACP get_database_size() for MySql 8 PHPBB3-16629 --- phpBB/includes/functions_admin.php | 42 +++++++++++------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index b190fcf899..08e275a0ed 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2832,15 +2832,13 @@ function view_warned_users(&$users, &$user_count, $limit = 0, $offset = 0, $limi /** * Get database size -* Currently only mysql and mssql are supported */ function get_database_size() { - global $db, $user, $table_prefix; + global $db, $user; $database_size = false; - // This code is heavily influenced by a similar routine in phpMyAdmin 2.2.0 switch ($db->get_sql_layer()) { case 'mysqli': @@ -2853,35 +2851,25 @@ function get_database_size() { $version = $row['mysql_version']; - if (preg_match('#(3\.23|[45]\.|10\.[0-9]\.[0-9]{1,2}-+Maria)#', $version)) + $db_name = $db->get_db_name(); + + $sql = 'SHOW TABLE STATUS + FROM ' . $db_name; + $result = $db->sql_query($sql, 7200); + + while ($row = $db->sql_fetchrow($result)) { - $db_name = (preg_match('#^(?:3\.23\.(?:[6-9]|[1-9]{2}))|[45]\.|10\.[0-9]\.[0-9]{1,2}-+Maria#', $version)) ? "`{$db->get_db_name()}`" : $db->get_db_name(); - - $sql = 'SHOW TABLE STATUS - FROM ' . $db_name; - $result = $db->sql_query($sql, 7200); - - $database_size = 0; - while ($row = $db->sql_fetchrow($result)) + if (isset($row['Engine']) + && ($row['Engine'] == ('MyISAM' || 'InnoDB' || 'Aria')) + ) { - if ((isset($row['Type']) && $row['Type'] != 'MRG_MyISAM') || (isset($row['Engine']) && ($row['Engine'] == 'MyISAM' || $row['Engine'] == 'InnoDB' || $row['Engine'] == 'Aria'))) - { - if ($table_prefix != '') - { - if (strpos($row['Name'], $table_prefix) !== false) - { - $database_size += $row['Data_length'] + $row['Index_length']; - } - } - else - { - $database_size += $row['Data_length'] + $row['Index_length']; - } - } + $database_size += $row['Data_length'] + $row['Index_length']; } - $db->sql_freeresult($result); } + + $db->sql_freeresult($result); } + break; case 'sqlite3': From 4b2c25342755cd0dd9cefe2abdfaf14e0b4f4882 Mon Sep 17 00:00:00 2001 From: 3D-I <480857+3D-I@users.noreply.github.com> Date: Thu, 5 Nov 2020 05:07:54 +0100 Subject: [PATCH 2/4] [ticket/16629] Fix ACP get_database_size() for MySql 8 PHPBB3-16629 --- phpBB/includes/functions_admin.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 08e275a0ed..60eb7b616d 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2849,9 +2849,9 @@ function get_database_size() if ($row) { - $version = $row['mysql_version']; - - $db_name = $db->get_db_name(); + $version = $row['mysql_version']; + $mysql_engine = ['MyISAM', 'InnoDB', 'Aria']; + $db_name = $db->get_db_name(); $sql = 'SHOW TABLE STATUS FROM ' . $db_name; @@ -2860,7 +2860,7 @@ function get_database_size() while ($row = $db->sql_fetchrow($result)) { if (isset($row['Engine']) - && ($row['Engine'] == ('MyISAM' || 'InnoDB' || 'Aria')) + && in_array($row['Engine'], $mysql_engine) ) { $database_size += $row['Data_length'] + $row['Index_length']; From 3521d2e9fa6f6ceaeba3886936ff8417d60537a4 Mon Sep 17 00:00:00 2001 From: 3D-I <480857+3D-I@users.noreply.github.com> Date: Thu, 12 Nov 2020 08:16:46 +0100 Subject: [PATCH 3/4] [ticket/16629] Fix ACP get_database_size() for MySql 8 Add functional test (thanks rxu) PHPBB3-16629 --- tests/functional/acp_main_test.php | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/functional/acp_main_test.php diff --git a/tests/functional/acp_main_test.php b/tests/functional/acp_main_test.php new file mode 100644 index 0000000000..d392102e1a --- /dev/null +++ b/tests/functional/acp_main_test.php @@ -0,0 +1,31 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_acp_main_test extends phpbb_functional_test_case +{ + public function test_acp_database_size() + { + $this->add_lang(['acp/common', 'acp/board']); + $this->login(); + $this->admin_login(); + + $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid); + $this->assertContainsLang('WELCOME_PHPBB', $this->get_content()); + $this->assertContainsLang('ADMIN_INTRO', $this->get_content()); + $this->assertContainsLang('DATABASE_SIZE', $crawler->filter('tbody > tr')->eq(2)->filter('td[class="tabled"]')->eq(0)->text()); + $this->assertNotContainsLang('NOT_AVAILABLE', $crawler->filter('tbody > tr')->eq(2)->filter('td[class="tabled"]')->eq(1)->text()); + } +} From cd235dfd428afe001fc0e5ae191136566ec3fbe0 Mon Sep 17 00:00:00 2001 From: 3D-I <480857+3D-I@users.noreply.github.com> Date: Sun, 15 Nov 2020 22:59:47 +0100 Subject: [PATCH 4/4] [ticket/16629] Fix ACP get_database_size() for MySql 8 PHPBB3-16629 --- phpBB/includes/functions_admin.php | 34 +++++++++++------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 60eb7b616d..07bf9f9192 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -2842,34 +2842,24 @@ function get_database_size() switch ($db->get_sql_layer()) { case 'mysqli': - $sql = 'SELECT VERSION() AS mysql_version'; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + $mysql_engine = ['MyISAM', 'InnoDB', 'Aria']; - if ($row) + $db_name = $db->get_db_name(); + + $sql = 'SHOW TABLE STATUS + FROM ' . $db_name; + $result = $db->sql_query($sql, 7200); + + while ($row = $db->sql_fetchrow($result)) { - $version = $row['mysql_version']; - $mysql_engine = ['MyISAM', 'InnoDB', 'Aria']; - $db_name = $db->get_db_name(); - - $sql = 'SHOW TABLE STATUS - FROM ' . $db_name; - $result = $db->sql_query($sql, 7200); - - while ($row = $db->sql_fetchrow($result)) + if (isset($row['Engine']) && in_array($row['Engine'], $mysql_engine)) { - if (isset($row['Engine']) - && in_array($row['Engine'], $mysql_engine) - ) - { - $database_size += $row['Data_length'] + $row['Index_length']; - } + $database_size += $row['Data_length'] + $row['Index_length']; } - - $db->sql_freeresult($result); } + $db->sql_freeresult($result); + break; case 'sqlite3':