Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authordiosmosis <benaka@piwik.pro>2014-10-01 11:46:17 +0400
committerdiosmosis <benaka@piwik.pro>2014-10-02 06:10:31 +0400
commit420f2306ac60c1331691e9ca3ddc748eed90d0d1 (patch)
tree75ec318ba5943989c4f2e0f35c002d47867df186 /core
parent860839e3b05cc08cbbe2021e8597dd4267025305 (diff)
Refactor DbHelper::truncateAllTables() to truncate non-core tables, and tweaks to DatabaseTestCase tests.
Diffstat (limited to 'core')
-rw-r--r--core/Db/Schema/Mysql.php28
1 files changed, 21 insertions, 7 deletions
diff --git a/core/Db/Schema/Mysql.php b/core/Db/Schema/Mysql.php
index 43a42f167d..45ff75b685 100644
--- a/core/Db/Schema/Mysql.php
+++ b/core/Db/Schema/Mysql.php
@@ -341,12 +341,9 @@ class Mysql implements SchemaInterface
|| $forceReload === true
) {
$db = Db::get();
- $prefixTables = $this->getTablePrefix();
+ $prefixTables = $this->getTablePrefixEscaped();
- // '_' matches any character; force it to be literal
- $prefixTables = str_replace('_', '\_', $prefixTables);
-
- $allTables = $db->fetchCol("SHOW TABLES LIKE '" . $prefixTables . "%'");
+ $allTables = $this->getAllExistingTables($prefixTables);
// all the tables to be installed
$allMyTables = $this->getTablesNames();
@@ -461,8 +458,8 @@ class Mysql implements SchemaInterface
*/
public function truncateAllTables()
{
- $tablesAlreadyInstalled = $this->getTablesInstalled($forceReload = true);
- foreach ($tablesAlreadyInstalled as $table) {
+ $tables = $this->getAllExistingTables();
+ foreach ($tables as $table) {
Db::query("TRUNCATE `$table`");
}
}
@@ -489,4 +486,21 @@ class Mysql implements SchemaInterface
return $dbName;
}
+
+ private function getAllExistingTables($prefixTables = false)
+ {
+ if (empty($prefixTables)) {
+ $prefixTables = $this->getTablePrefixEscaped();
+ }
+
+ return Db::get()->fetchCol("SHOW TABLES LIKE '" . $prefixTables . "%'");
+ }
+
+ private function getTablePrefixEscaped()
+ {
+ $prefixTables = $this->getTablePrefix();
+ // '_' matches any character; force it to be literal
+ $prefixTables = str_replace('_', '\_', $prefixTables);
+ return $prefixTables;
+ }
}