update Piwik to version 2.16 (fixes #91)
This commit is contained in:
parent
296343bf3b
commit
d885a4baa9
5833 changed files with 418860 additions and 226988 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -11,8 +11,13 @@ namespace Piwik\Tracker;
|
|||
use Exception;
|
||||
use PDOStatement;
|
||||
use Piwik\Common;
|
||||
use Piwik\Config;
|
||||
use Piwik\Piwik;
|
||||
use Piwik\Timer;
|
||||
use Piwik\Tracker;
|
||||
use Piwik\Tracker\Db\DbException;
|
||||
use Piwik\Tracker\Db\Mysqli;
|
||||
use Piwik\Tracker\Db\Pdo\Mysql;
|
||||
|
||||
/**
|
||||
* Simple database wrapper.
|
||||
|
|
@ -77,10 +82,14 @@ abstract class Db
|
|||
*/
|
||||
protected function recordQueryProfile($query, $timer)
|
||||
{
|
||||
if (!isset($this->queriesProfiling[$query])) $this->queriesProfiling[$query] = array('sum_time_ms' => 0, 'count' => 0);
|
||||
$time = $timer->getTimeMs(2);
|
||||
if (!isset($this->queriesProfiling[$query])) {
|
||||
$this->queriesProfiling[$query] = array('sum_time_ms' => 0, 'count' => 0);
|
||||
}
|
||||
|
||||
$time = $timer->getTimeMs(2);
|
||||
$time += $this->queriesProfiling[$query]['sum_time_ms'];
|
||||
$count = $this->queriesProfiling[$query]['count'] + 1;
|
||||
|
||||
$this->queriesProfiling[$query] = array('sum_time_ms' => $time, 'count' => $count);
|
||||
}
|
||||
|
||||
|
|
@ -97,13 +106,13 @@ abstract class Db
|
|||
self::$profiling = false;
|
||||
|
||||
foreach ($this->queriesProfiling as $query => $info) {
|
||||
$time = $info['sum_time_ms'];
|
||||
$time = $info['sum_time_ms'];
|
||||
$time = Common::forceDotAsSeparatorForDecimalPoint($time);
|
||||
$count = $info['count'];
|
||||
|
||||
$queryProfiling = "INSERT INTO " . Common::prefixTable('log_profiling') . "
|
||||
(query,count,sum_time_ms) VALUES (?,$count,$time)
|
||||
ON DUPLICATE KEY
|
||||
UPDATE count=count+$count,sum_time_ms=sum_time_ms+$time";
|
||||
ON DUPLICATE KEY UPDATE count=count+$count,sum_time_ms=sum_time_ms+$time";
|
||||
$this->query($queryProfiling, array($query));
|
||||
}
|
||||
|
||||
|
|
@ -222,4 +231,63 @@ abstract class Db
|
|||
* @return bool True if error number matches; false otherwise
|
||||
*/
|
||||
abstract public function isErrNo($e, $errno);
|
||||
|
||||
/**
|
||||
* Factory to create database objects
|
||||
*
|
||||
* @param array $configDb Database configuration
|
||||
* @throws Exception
|
||||
* @return \Piwik\Tracker\Db\Mysqli|\Piwik\Tracker\Db\Pdo\Mysql
|
||||
*/
|
||||
public static function factory($configDb)
|
||||
{
|
||||
/**
|
||||
* Triggered before a connection to the database is established by the Tracker.
|
||||
*
|
||||
* This event can be used to change the database connection settings used by the Tracker.
|
||||
*
|
||||
* @param array $dbInfos Reference to an array containing database connection info,
|
||||
* including:
|
||||
*
|
||||
* - **host**: The host name or IP address to the MySQL database.
|
||||
* - **username**: The username to use when connecting to the
|
||||
* database.
|
||||
* - **password**: The password to use when connecting to the
|
||||
* database.
|
||||
* - **dbname**: The name of the Piwik MySQL database.
|
||||
* - **port**: The MySQL database port to use.
|
||||
* - **adapter**: either `'PDO\MYSQL'` or `'MYSQLI'`
|
||||
* - **type**: The MySQL engine to use, for instance 'InnoDB'
|
||||
*/
|
||||
Piwik::postEvent('Tracker.getDatabaseConfig', array(&$configDb));
|
||||
|
||||
switch ($configDb['adapter']) {
|
||||
case 'PDO\MYSQL':
|
||||
case 'PDO_MYSQL': // old format pre Piwik 2
|
||||
require_once PIWIK_INCLUDE_PATH . '/core/Tracker/Db/Pdo/Mysql.php';
|
||||
return new Mysql($configDb);
|
||||
|
||||
case 'MYSQLI':
|
||||
require_once PIWIK_INCLUDE_PATH . '/core/Tracker/Db/Mysqli.php';
|
||||
return new Mysqli($configDb);
|
||||
}
|
||||
|
||||
throw new Exception('Unsupported database adapter ' . $configDb['adapter']);
|
||||
}
|
||||
|
||||
public static function connectPiwikTrackerDb()
|
||||
{
|
||||
$db = null;
|
||||
$configDb = Config::getInstance()->database;
|
||||
|
||||
if (!isset($configDb['port'])) {
|
||||
// before 0.2.4 there is no port specified in config file
|
||||
$configDb['port'] = '3306';
|
||||
}
|
||||
|
||||
$db = self::factory($configDb);
|
||||
$db->connect();
|
||||
|
||||
return $db;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue