diff --git a/phpunit/functional/Glpi/System/Requirement/DbTimezonesTest.php b/phpunit/functional/Glpi/System/Requirement/DbTimezonesTest.php index 810feb74490..cfe8fd358f2 100644 --- a/phpunit/functional/Glpi/System/Requirement/DbTimezonesTest.php +++ b/phpunit/functional/Glpi/System/Requirement/DbTimezonesTest.php @@ -45,12 +45,12 @@ public function testCheckWithUnavailableMysqlDb() ->getMock(); $db->method('request')->willReturnCallback( - function ($query) { + function ($criteria) { $result = $this->getMockBuilder(\DBmysqlIterator::class) ->setConstructorArgs([null]) ->onlyMethods(['count']) ->getMock(); - if ($query === "SHOW DATABASES LIKE 'mysql'") { + if ($criteria['FROM'] == 'information_schema.schemata' && $criteria['WHERE']['schema_name'] == 'mysql') { $result->method('count')->willReturn(0); } return $result; @@ -73,14 +73,14 @@ public function testCheckWithUnavailableTimezonenameTable() ->getMock(); $db->method('request')->willReturnCallback( - function ($query) { + function ($criteria) { $result = $this->getMockBuilder(\DBmysqlIterator::class) ->setConstructorArgs([null]) ->onlyMethods(['count']) ->getMock(); - if ($query === "SHOW DATABASES LIKE 'mysql'") { + if ($criteria['FROM'] == 'information_schema.schemata' && $criteria['WHERE']['schema_name'] == 'mysql') { $result->method('count')->willReturn(1); - } else if ($query === "SHOW TABLES FROM `mysql` LIKE 'time_zone_name'") { + } elseif ($criteria['FROM'] == 'information_schema.tables' && $criteria['WHERE']['table_schema'] == 'mysql') { $result->method('count')->willReturn(0); } return $result; @@ -103,14 +103,14 @@ public function testCheckWithTimezonenameEmptyTable() ->getMock(); $db->method('request')->willReturnCallback( - function ($query) { + function ($criteria) { $result = $this->getMockBuilder(\DBmysqlIterator::class) ->setConstructorArgs([null]) ->onlyMethods(['count', 'current']) ->getMock(); - if ($query === "SHOW DATABASES LIKE 'mysql'") { + if ($criteria['FROM'] == 'information_schema.schemata' && $criteria['WHERE']['schema_name'] == 'mysql') { $result->method('count')->willReturn(1); - } else if ($query === "SHOW TABLES FROM `mysql` LIKE 'time_zone_name'") { + } elseif ($criteria['FROM'] == 'information_schema.tables' && $criteria['WHERE']['table_schema'] == 'mysql') { $result->method('count')->willReturn(1); } else { $result->method('current')->willReturn(['cpt' => 0]); @@ -135,14 +135,14 @@ public function testCheckWithAvailableData() ->getMock(); $db->method('request')->willReturnCallback( - function ($query) { + function ($criteria) { $result = $this->getMockBuilder(\DBmysqlIterator::class) ->setConstructorArgs([null]) ->onlyMethods(['count', 'current']) ->getMock(); - if ($query === "SHOW DATABASES LIKE 'mysql'") { + if ($criteria['FROM'] == 'information_schema.schemata' && $criteria['WHERE']['schema_name'] == 'mysql') { $result->method('count')->willReturn(1); - } else if ($query === "SHOW TABLES FROM `mysql` LIKE 'time_zone_name'") { + } elseif ($criteria['FROM'] == 'information_schema.tables' && $criteria['WHERE']['table_schema'] == 'mysql') { $result->method('count')->willReturn(1); } else { $result->method('current')->willReturn(['cpt' => 30]); diff --git a/src/Glpi/System/Requirement/DbTimezones.php b/src/Glpi/System/Requirement/DbTimezones.php index 4d3c840a0d3..ba305da9422 100644 --- a/src/Glpi/System/Requirement/DbTimezones.php +++ b/src/Glpi/System/Requirement/DbTimezones.php @@ -60,20 +60,27 @@ public function __construct(\DBmysql $db) protected function check() { - $mysql_db_res = $this->db->doQuery('SHOW DATABASES LIKE ' . $this->db->quoteValue('mysql')); - if ($this->db->numrows($mysql_db_res) === 0) { + $mysql_db_res = $this->db->request([ + 'FROM' => 'information_schema.schemata', + 'WHERE' => [ + 'schema_name' => 'mysql' + ] + ]); + if ($mysql_db_res->count() === 0) { $this->validated = false; $this->validation_messages[] = __('Access to timezone database (mysql) is not allowed.'); return; } - $tz_table_res = $this->db->doQuery( - 'SHOW TABLES FROM ' - . $this->db->quoteName('mysql') - . ' LIKE ' - . $this->db->quoteValue('time_zone_name') - ); - if ($this->db->numrows($tz_table_res) === 0) { + $tz_table_res = $this->db->request([ + 'FROM' => 'information_schema.tables', + 'WHERE' => [ + 'table_schema' => 'mysql', + 'table_type' => 'BASE TABLE', + 'table_name' => ['LIKE', 'time_zone_name'] + ] + ]); + if ($tz_table_res->count() === 0) { $this->validated = false; $this->validation_messages[] = __('Access to timezone table (mysql.time_zone_name) is not allowed.'); return;