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:
Diffstat (limited to 'core')
-rw-r--r--core/DataAccess/RawLogDao.php109
-rw-r--r--core/Db.php40
-rw-r--r--core/Tracker.php10
3 files changed, 149 insertions, 10 deletions
diff --git a/core/DataAccess/RawLogDao.php b/core/DataAccess/RawLogDao.php
new file mode 100644
index 0000000000..28f2a07978
--- /dev/null
+++ b/core/DataAccess/RawLogDao.php
@@ -0,0 +1,109 @@
+<?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\DataAccess;
+
+use Piwik\Common;
+use Piwik\Db;
+
+/**
+ * DAO that queries log tables.
+ */
+class RawLogDao
+{
+ /**
+ * @param array $values
+ * @param string $idVisit
+ */
+ public function updateVisits(array $values, $idVisit)
+ {
+ $sql = "UPDATE " . Common::prefixTable('log_visit')
+ . " SET " . $this->getColumnSetExpressions(array_keys($values))
+ . " WHERE idvisit = ?";
+
+ $this->update($sql, $values, $idVisit);
+ }
+
+ /**
+ * @param array $values
+ * @param string $idVisit
+ */
+ public function updateConversions(array $values, $idVisit)
+ {
+ $sql = "UPDATE " . Common::prefixTable('log_conversion')
+ . " SET " . $this->getColumnSetExpressions(array_keys($values))
+ . " WHERE idvisit = ?";
+
+ $this->update($sql, $values, $idVisit);
+ }
+
+ /**
+ * @param string $from
+ * @param string $to
+ * @param array $fields
+ * @param int $fromId
+ * @param int $limit
+ * @return array[]
+ */
+ public function getVisitsWithDatesLimit($from, $to, $fields = array(), $fromId = 0, $limit = 1000)
+ {
+ $sql = "SELECT " . implode(', ', $fields)
+ . " FROM " . Common::prefixTable('log_visit')
+ . " WHERE visit_first_action_time >= ? AND visit_last_action_time < ?"
+ . " AND idvisit > ?"
+ . sprintf(" LIMIT %d", $limit);
+
+ $bind = array($from, $to, $fromId);
+
+ return Db::fetchAll($sql, $bind);
+ }
+
+ /**
+ * @param string $from
+ * @param string $to
+ * @return int
+ */
+ public function countVisitsWithDatesLimit($from, $to)
+ {
+ $sql = "SELECT COUNT(*) AS num_rows"
+ . " FROM " . Common::prefixTable('log_visit')
+ . " WHERE visit_first_action_time >= ? AND visit_last_action_time < ?";
+
+ $bind = array($from, $to);
+
+ return (int) Db::fetchOne($sql, $bind);
+ }
+
+ /**
+ * @param array $columnsToSet
+ * @return string
+ */
+ protected function getColumnSetExpressions(array $columnsToSet)
+ {
+ $columnsToSet = array_map(
+ function ($column) {
+ return $column . ' = ?';
+ },
+ $columnsToSet
+ );
+
+ return implode(', ', $columnsToSet);
+ }
+
+ /**
+ * @param array $values
+ * @param $idVisit
+ * @param $sql
+ * @return \Zend_Db_Statement
+ * @throws \Exception
+ */
+ protected function update($sql, array $values, $idVisit)
+ {
+ return Db::query($sql, array_merge(array_values($values), array($idVisit)));
+ }
+} \ No newline at end of file
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/core/Tracker.php b/core/Tracker.php
index 5bf6a9b4e1..bdc04462ee 100644
--- a/core/Tracker.php
+++ b/core/Tracker.php
@@ -225,6 +225,16 @@ class Tracker
}
}
+ // for tests
+ public static function disconnectCachedDbConnection()
+ {
+ // code redundancy w/ above is on purpose; above disconnectDatabase depends on method that can potentially be overridden
+ if (!is_null(self::$db)) {
+ self::$db->disconnect();
+ self::$db = null;
+ }
+ }
+
public static function setTestEnvironment($args = null, $requestMethod = null)
{
if (is_null($args)) {