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
diff options
context:
space:
mode:
-rw-r--r--core/Db.php40
-rw-r--r--tests/PHPUnit/Unit/DbTest.php39
2 files changed, 69 insertions, 10 deletions
diff --git a/core/Db.php b/core/Db.php
index a96786e1e3..8c718ceac5 100644
--- a/core/Db.php
+++ b/core/Db.php
@@ -324,7 +324,7 @@ class Db
$optimize = Config::getInstance()->General['enable_sql_optimize_queries'];
if (empty($optimize)) {
- return;
+ return false;
}
if (empty($tables)) {
@@ -335,22 +335,26 @@ class Db
$tables = array($tables);
}
- // filter out all InnoDB tables
- $myisamDbTables = array();
- foreach (self::getTableStatus() as $row) {
- if (strtolower($row['Engine']) == 'myisam'
- && in_array($row['Name'], $tables)
- ) {
- $myisamDbTables[] = $row['Name'];
+ if (!self::isOptimizeInnoDBSupported()) {
+ // filter out all InnoDB tables
+ $myisamDbTables = array();
+ foreach (self::getTableStatus() as $row) {
+ if (strtolower($row['Engine']) == 'myisam'
+ && in_array($row['Name'], $tables)
+ ) {
+ $myisamDbTables[] = $row['Name'];
+ }
}
+
+ $tables = $myisamDbTables;
}
- if (empty($myisamDbTables)) {
+ if (empty($tables)) {
return false;
}
// optimize the tables
- return self::query("OPTIMIZE TABLE " . implode(',', $myisamDbTables));
+ return self::query("OPTIMIZE TABLE " . implode(',', $tables));
}
private static function getTableStatus()
@@ -731,4 +735,20 @@ class Db
{
return self::$logQueries;
}
+
+ public static function isOptimizeInnoDBSupported($version = null)
+ {
+ if (empty($version)) {
+ $version = Db::fetchOne("SELECT VERSION()");
+ }
+
+ $version = strtolower($version);
+
+ if (strpos($version, "mariadb") === false) {
+ return false;
+ }
+
+ $semanticVersion = strstr($version, '-', $beforeNeedle = true);
+ return version_compare($semanticVersion, '10.1.1', '>=');
+ }
}
diff --git a/tests/PHPUnit/Unit/DbTest.php b/tests/PHPUnit/Unit/DbTest.php
new file mode 100644
index 0000000000..70b4338866
--- /dev/null
+++ b/tests/PHPUnit/Unit/DbTest.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+namespace Piwik\Tests\Unit\Db;
+
+use Piwik\Db;
+
+class DbTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @dataProvider getIsOptimizeInnoDBTestData
+ */
+ public function test_isOptimizeInnoDBSupported_ReturnsCorrectResult($version, $expectedResult)
+ {
+ $result = Db::isOptimizeInnoDBSupported($version);
+ $this->assertEquals($expectedResult, $result);
+ }
+
+ public function getIsOptimizeInnoDBTestData()
+ {
+ return array(
+ array("10.0.17-MariaDB-1~trusty", false),
+ array("10.1.1-MariaDB-1~trusty", true),
+ array("10.2.0-MariaDB-1~trusty", true),
+ array("10.6.19-0ubuntu0.14.04.1", false),
+
+ // for sanity. maybe not ours.
+ array("", false),
+ array(0, false),
+ array(false, false),
+ array("slkdf(@*#lkesjfMariaDB", false),
+ array("slkdfjq3rujlkv", false),
+ );
+ }
+} \ No newline at end of file