From 52080c92e5dc61d064989740879f5df6fa4fb445 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 26 May 2021 13:08:34 -0100 Subject: [PATCH 1/3] fix getTableNamesWithoutPrefix() Signed-off-by: Maxence Lange --- lib/private/DB/SchemaWrapper.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/private/DB/SchemaWrapper.php b/lib/private/DB/SchemaWrapper.php index 20ae5b6faa..9b92418850 100644 --- a/lib/private/DB/SchemaWrapper.php +++ b/lib/private/DB/SchemaWrapper.php @@ -59,15 +59,14 @@ class SchemaWrapper implements ISchemaWrapper { * * @return array */ - public function getTableNamesWithoutPrefix() { - $tableNames = $this->schema->getTableNames(); + public function getTableNamesWithoutPrefix(): array { return array_map(function ($tableName) { if (strpos($tableName, $this->connection->getPrefix()) === 0) { return substr($tableName, strlen($this->connection->getPrefix())); } return $tableName; - }, $tableNames); + }, $this->getTableNames()); } // Overwritten methods @@ -75,8 +74,15 @@ class SchemaWrapper implements ISchemaWrapper { /** * @return array */ - public function getTableNames() { - return $this->schema->getTableNames(); + public function getTableNames(): array { + return array_map(function (string $fullName) { + $pos = strpos($fullName, '.'); + if ($pos === false) { + return $fullName; + } + + return substr($fullName, $pos+1); + }, $this->schema->getTableNames()); } /** From 704f002bd4d67d7ebf144a6c1e56864be171535d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 1 Jun 2021 10:48:54 +0200 Subject: [PATCH 2/3] Add a unit test to check all DBs Signed-off-by: Joas Schilling --- lib/private/DB/SchemaWrapper.php | 2 +- tests/lib/DB/SchemaWrapperTest.php | 57 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/lib/DB/SchemaWrapperTest.php diff --git a/lib/private/DB/SchemaWrapper.php b/lib/private/DB/SchemaWrapper.php index 9b92418850..5f70cbd775 100644 --- a/lib/private/DB/SchemaWrapper.php +++ b/lib/private/DB/SchemaWrapper.php @@ -75,7 +75,7 @@ class SchemaWrapper implements ISchemaWrapper { * @return array */ public function getTableNames(): array { - return array_map(function (string $fullName) { + return array_map(static function (string $fullName) { $pos = strpos($fullName, '.'); if ($pos === false) { return $fullName; diff --git a/tests/lib/DB/SchemaWrapperTest.php b/tests/lib/DB/SchemaWrapperTest.php new file mode 100644 index 0000000000..df3b5d0014 --- /dev/null +++ b/tests/lib/DB/SchemaWrapperTest.php @@ -0,0 +1,57 @@ + + * + * @author Joas Schilling + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace Test\DB; + +use OC\DB\Connection; +use OC\DB\SchemaWrapper; + +/** + * Class SchemaWrapperTest + * + * @group DB + * + * @package Test\DB + */ +class SchemaWrapperTest extends \Test\TestCase { + /** @var \Doctrine\DBAL\Connection $connection */ + private $connection; + + protected function setUp(): void { + parent::setUp(); + + $this->connection = \OC::$server->get(Connection::class); + } + + public function testGetTableNames(): void { + $schema = new SchemaWrapper($this->connection); + self::assertContains('oc_share', $schema->getTableNames()); + } + + public function testGetTableNamesWithoutPrefix(): void { + $schema = new SchemaWrapper($this->connection); + self::assertContains('share', $schema->getTableNamesWithoutPrefix()); + } +} From 2eab957ec95963df2c75541b7fed66faafa0c7d7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 1 Jun 2021 10:50:41 +0200 Subject: [PATCH 3/3] Fix PHP CS Signed-off-by: Joas Schilling --- lib/private/DB/SchemaWrapper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/DB/SchemaWrapper.php b/lib/private/DB/SchemaWrapper.php index 5f70cbd775..dfac3ed97a 100644 --- a/lib/private/DB/SchemaWrapper.php +++ b/lib/private/DB/SchemaWrapper.php @@ -81,7 +81,7 @@ class SchemaWrapper implements ISchemaWrapper { return $fullName; } - return substr($fullName, $pos+1); + return substr($fullName, $pos + 1); }, $this->schema->getTableNames()); }