From 4f171ac1b6c3c47688ede41e8dc9af1fe24b5ee5 Mon Sep 17 00:00:00 2001 From: sebbbbauer Date: Thu, 28 Sep 2017 15:37:33 +0200 Subject: [PATCH] OXDEV-46 Clean up & small refactorings for readability --- library/UnitTestCase.php | 2 ++ library/helpers/oxDatabaseHelper.php | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/library/UnitTestCase.php b/library/UnitTestCase.php index 71cc4e21..d56fda6f 100644 --- a/library/UnitTestCase.php +++ b/library/UnitTestCase.php @@ -24,6 +24,7 @@ use modOXID; use modOxUtilsDate; +use oxDatabaseHelper; use OxidEsales\Eshop\Core\DatabaseProvider; use OxidEsales\EshopCommunity\Core\Database\Adapter\DatabaseInterface; use OxidEsales\EshopCommunity\Core\Database; @@ -38,6 +39,7 @@ use ReflectionClass; use Exception; +require_once TEST_LIBRARY_HELPERS_PATH . 'oxDatabaseHelper.php'; require_once TEST_LIBRARY_HELPERS_PATH . 'modOxUtilsDate.php'; /** diff --git a/library/helpers/oxDatabaseHelper.php b/library/helpers/oxDatabaseHelper.php index 7e196b4b..479c03ac 100644 --- a/library/helpers/oxDatabaseHelper.php +++ b/library/helpers/oxDatabaseHelper.php @@ -1,5 +1,4 @@ database->getOne($sql); } + /** + * @param string $tableName The name of the table we want to assure to exist. + * + * @return bool Does the database table with the given name exists? + */ + public function existsTable($tableName) + { + $database = DatabaseProvider::getDb(); + $sql = "SELECT COUNT(TABLE_NAME) FROM information_schema.TABLES WHERE TABLE_NAME = '$tableName'"; + + $count = $database->getOne($sql); + + return $count > 0; + } + public function adjustTemplateBlocksOxModuleColumn() { $sql = "ALTER TABLE `oxtplblocks`