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/DataAccess/ArchiveTableCreator.php50
-rw-r--r--core/DataTable/Manager.php2
-rw-r--r--core/Db/Schema/Myisam.php3
-rw-r--r--core/TablePartitioning.php135
-rw-r--r--plugins/Actions/API.php2
-rw-r--r--plugins/DevicesDetection/Controller.php2
-rw-r--r--plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php2
-rw-r--r--plugins/PrivacyManager/PrivacyManager.php2
-rw-r--r--tests/PHPUnit/Core/TablePartitioningTest.php70
-rw-r--r--tests/PHPUnit/DatabaseTestCase.php2
-rwxr-xr-xtests/PHPUnit/IntegrationTestCase.php4
-rwxr-xr-xtests/PHPUnit/Plugins/PrivacyManagerTest.php2
12 files changed, 56 insertions, 220 deletions
diff --git a/core/DataAccess/ArchiveTableCreator.php b/core/DataAccess/ArchiveTableCreator.php
index f5f1c44287..c932639fdb 100644
--- a/core/DataAccess/ArchiveTableCreator.php
+++ b/core/DataAccess/ArchiveTableCreator.php
@@ -11,20 +11,62 @@
class Piwik_DataAccess_ArchiveTableCreator
{
+ const NUMERIC_TABLE = "numeric";
+
+ const BLOB_TABLE = "blob";
+
+ static public $tablesAlreadyInstalled = null;
+
static public function getNumericTable(Piwik_Date $date)
{
- return self::getTable($date, "numeric");
+ return self::getTable($date, self::NUMERIC_TABLE);
}
static public function getBlobTable(Piwik_Date $date)
{
- return self::getTable($date, "blob");
+ return self::getTable($date, self::BLOB_TABLE);
}
static protected function getTable(Piwik_Date $date, $type)
{
- Piwik_TablePartitioning_Monthly::createArchiveTablesIfAbsent($date);
+ $tableNamePrefix = "archive_" . $type;
+ $tableName = $tableNamePrefix . "_" . $date->toString('Y_m');
+ $tableName = Piwik_Common::prefixTable($tableName);
+ self::createArchiveTablesIfAbsent($tableName, $tableNamePrefix);
+ return $tableName;
+ }
+
+ static protected function createArchiveTablesIfAbsent($tableName, $tableNamePrefix)
+ {
+ if (is_null(self::$tablesAlreadyInstalled)) {
+ self::refreshTableList();
+ }
- return Piwik_Common::prefixTable("archive_" . $type . "_" . $date->toString('Y_m'));
+ if (!in_array($tableName, self::$tablesAlreadyInstalled)) {
+ $db = Zend_Registry::get('db');
+ $sql = Piwik::getTableCreateSql($tableNamePrefix);
+
+ // replace table name template by real name
+ $tableNamePrefix = Piwik_Common::prefixTable($tableNamePrefix);
+ $sql = str_replace($tableNamePrefix, $tableName, $sql);
+ try {
+ $db->query($sql);
+ } catch (Exception $e) {
+ // accept mysql error 1050: table already exists, throw otherwise
+ if (!$db->isErrNo($e, '1050')) {
+ throw $e;
+ }
+ }
+ self::$tablesAlreadyInstalled[] = $tableName;
+ }
+ }
+
+ static public function clear()
+ {
+ self::$tablesAlreadyInstalled = null;
+ }
+ static public function refreshTableList($forceReload = false)
+ {
+ self::$tablesAlreadyInstalled = Piwik::getTablesInstalled($forceReload);
}
} \ No newline at end of file
diff --git a/core/DataTable/Manager.php b/core/DataTable/Manager.php
index b091ec6466..eab94df8f8 100644
--- a/core/DataTable/Manager.php
+++ b/core/DataTable/Manager.php
@@ -136,7 +136,7 @@ class Piwik_DataTable_Manager
foreach ($this->tables as $id => $table) {
if (!($table instanceof Piwik_DataTable)) {
echo "Error table $id is not instance of datatable<br />";
- var_dump($table);
+ var_export($table);
} else {
echo "<hr />";
echo "Table (index=$id) TableId = " . $table->getId() . "<br />";
diff --git a/core/Db/Schema/Myisam.php b/core/Db/Schema/Myisam.php
index 959ea056d8..55cd20e715 100644
--- a/core/Db/Schema/Myisam.php
+++ b/core/Db/Schema/Myisam.php
@@ -458,8 +458,7 @@ class Piwik_Db_Schema_Myisam implements Piwik_Db_Schema_Interface
// we get the intersection between all the tables in the DB and the tables to be installed
$tablesInstalled = array_intersect($allMyTables, $allTables);
- // at this point we have only the piwik tables which is good
- // but we still miss the piwik generated tables (using the class Piwik_TablePartitioning)
+ // at this point we have the static list of core tables, but let's add the monthly archive tables
$allArchiveNumeric = $db->fetchCol("SHOW TABLES LIKE '" . $prefixTables . "archive_numeric%'");
$allArchiveBlob = $db->fetchCol("SHOW TABLES LIKE '" . $prefixTables . "archive_blob%'");
diff --git a/core/TablePartitioning.php b/core/TablePartitioning.php
deleted file mode 100644
index 330c9f168a..0000000000
--- a/core/TablePartitioning.php
+++ /dev/null
@@ -1,135 +0,0 @@
-<?php
-/**
- * Piwik - Open source web analytics
- *
- * @link http://piwik.org
- * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- *
- * @category Piwik
- * @package Piwik
- */
-
-/**
- * FIXMEA: simplify/delete this code
- *
- * @package Piwik
- * @subpackage Piwik_TablePartitioning
- */
-abstract class Piwik_TablePartitioning
-{
- protected $tableName = null;
- protected $generatedTableName = null;
- protected $timestamp = null;
-
- static public $tablesAlreadyInstalled = null;
-
- public function __construct($tableName)
- {
- $this->tableName = $tableName;
- }
-
- abstract protected function generateTableName();
-
- public function setTimestamp($timestamp)
- {
- $this->timestamp = $timestamp;
- $this->generatedTableName = null;
- $this->getTableName();
- }
-
- public function getTableName()
- {
- // table name already processed
- if (!is_null($this->generatedTableName)) {
- return $this->generatedTableName;
- }
-
- if (is_null($this->timestamp)) {
- throw new Exception("You have to specify a timestamp for a Table Partitioning by date.");
- }
-
- // generate table name
- $this->generatedTableName = $this->generateTableName();
-
- // we make sure the table already exists
- $this->checkTableExists();
- }
-
- protected function checkTableExists()
- {
- if (is_null(self::$tablesAlreadyInstalled)) {
- self::$tablesAlreadyInstalled = Piwik::getTablesInstalled($forceReload = false);
- }
-
- if (!in_array($this->generatedTableName, self::$tablesAlreadyInstalled)) {
- $db = Zend_Registry::get('db');
- $sql = Piwik::getTableCreateSql($this->tableName);
-
- $config = Piwik_Config::getInstance();
- $prefixTables = $config->database['tables_prefix'];
- $sql = str_replace($prefixTables . $this->tableName, $this->generatedTableName, $sql);
- try {
- $db->query($sql);
- } catch (Exception $e) {
- // mysql error 1050: table already exists
- if (!$db->isErrNo($e, '1050')) {
- // failed for some other reason
- throw $e;
- }
- }
-
- self::$tablesAlreadyInstalled[] = $this->generatedTableName;
- }
- }
-
- public function __toString()
- {
- return $this->getTableName();
- }
-}
-
-/**
- *
- * @package Piwik
- * @subpackage Piwik_TablePartitioning
- */
-class Piwik_TablePartitioning_Monthly extends Piwik_TablePartitioning
-{
- private static $blobArchiveTable = null;
- private static $numericArchiveTable = null;
-
- public function __construct($tableName)
- {
- parent::__construct($tableName);
- }
-
- protected function generateTableName()
- {
- $config = Piwik_Config::getInstance();
- return $config->database['tables_prefix'] . $this->tableName . "_" . date("Y_m", $this->timestamp);
- }
-
- /**
- * Creates archive_blob & archive_numeric tables for a period if they don't already exist.
- *
- * @param Piwik_Date
- */
- public static function createArchiveTablesIfAbsent(Piwik_Date $dateInMonth)
- {
- $timestamp = $dateInMonth->getTimestamp();
-
- self::$blobArchiveTable->setTimestamp($timestamp);
- self::$blobArchiveTable->getTableName();
-
- self::$numericArchiveTable->setTimestamp($timestamp);
- self::$numericArchiveTable->getTableName();
- }
-
- public static function init()
- {
- self::$blobArchiveTable = new Piwik_TablePartitioning_Monthly('archive_blob');
- self::$numericArchiveTable = new Piwik_TablePartitioning_Monthly('archive_numeric');
- }
-}
-
-Piwik_TablePartitioning_Monthly::init();
diff --git a/plugins/Actions/API.php b/plugins/Actions/API.php
index 4815f05cce..8eec6d2d1b 100644
--- a/plugins/Actions/API.php
+++ b/plugins/Actions/API.php
@@ -346,7 +346,7 @@ class Piwik_Actions_API
$dataTable = new Piwik_DataTable();
// Handle case where date=last30&period=day
- // TODO: this logic should really be refactored somewhere, this is ugly!
+ // FIXMEA: this logic should really be refactored somewhere, this is ugly!
if ($customVariables instanceof Piwik_DataTable_Array) {
$dataTable = $customVariables->getEmptyClone();
diff --git a/plugins/DevicesDetection/Controller.php b/plugins/DevicesDetection/Controller.php
index 4ac0644f5b..22681f1a6c 100644
--- a/plugins/DevicesDetection/Controller.php
+++ b/plugins/DevicesDetection/Controller.php
@@ -140,7 +140,7 @@ class Piwik_DevicesDetection_Controller extends Piwik_Controller
echo "Processing idvisit = " . $rec['idvisit'] . "<br/>";
echo "UserAgent string: " . $rec['config_debug_ua'] . "<br/> Decoded values:";
$uaDetails = $this->getArray($UAParser);
- var_dump($uaDetails);
+ var_export($uaDetails);
echo "<hr/>";
$this->updateVisit($rec['idvisit'], $uaDetails);
unset($UAParser);
diff --git a/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php b/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php
index 5691033bf5..911c751221 100644
--- a/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php
+++ b/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php
@@ -362,7 +362,7 @@ class UserAgentParserEnhanced
$this->device = array_search('desktop', self::$deviceTypes);
}
if ($this->debug) {
- var_dump($this->brand, $this->model, $this->device);
+ var_export($this->brand, $this->model, $this->device);
}
}
diff --git a/plugins/PrivacyManager/PrivacyManager.php b/plugins/PrivacyManager/PrivacyManager.php
index a505b54e57..9065c4678d 100644
--- a/plugins/PrivacyManager/PrivacyManager.php
+++ b/plugins/PrivacyManager/PrivacyManager.php
@@ -385,7 +385,7 @@ class Piwik_PrivacyManager extends Piwik_Plugin
$deleteIntervalSeconds = $this->getDeleteIntervalInSeconds($deleteIntervalDays);
if ($lastDelete === false ||
- ($lastDelete !== false && ((int)$lastDelete + $deleteIntervalSeconds) <= time())
+ ((int)$lastDelete + $deleteIntervalSeconds) <= time()
) {
return true;
} else // not time to run data purge
diff --git a/tests/PHPUnit/Core/TablePartitioningTest.php b/tests/PHPUnit/Core/TablePartitioningTest.php
deleted file mode 100644
index 8c8695f184..0000000000
--- a/tests/PHPUnit/Core/TablePartitioningTest.php
+++ /dev/null
@@ -1,70 +0,0 @@
-<?php
-/**
- * Piwik - Open source web analytics
- *
- * @link http://piwik.org
- * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- */
-class TablePartitioningTest extends DatabaseTestCase
-{
- /**
- * test no timestamp => exception
- * @group Core
- * @group TablePartitioning
- */
- public function testNoTimestamp()
- {
- try {
- $p = new Piwik_TablePartitioning_Monthly('testtable');
- $p->getTableName();
- } catch (Exception $e) {
- return;
- }
- $this->fail('Expected exception not raised');
- }
-
- /**
- * test table absent => create
- * @group Core
- * @group TablePartitioning
- */
- public function testNoTable()
- {
- $tableName = 'archive_numeric';
- $p = new Piwik_TablePartitioning_Monthly($tableName);
- $timestamp = strtotime("10 September 2000");
- $suffixShouldBe = "_2000_09";
- $prefixTables = Piwik_Config::getInstance()->database['tables_prefix'];
- $tablename = $prefixTables . $tableName . $suffixShouldBe;
-
- $p->setTimestamp($timestamp);
-
- $allTablesInstalled = Piwik::getTablesInstalled($forceReload = true);
-
- $this->assertContains($tablename, $allTablesInstalled);
- $this->assertEquals($tablename, $p->getTableName());
- $this->assertEquals($tablename, (string)$p->__toString());
- }
-
- /**
- * test monthly
- * @group Core
- * @group TablePartitioning
- */
- public function testMonthlyPartition()
- {
- $tableName = 'archive_numeric';
- $p = new Piwik_TablePartitioning_Monthly($tableName);
- $timestamp = strtotime("10 September 2000");
- $suffixShouldBe = "_2000_09";
- $prefixTables = Piwik_Config::getInstance()->database['tables_prefix'];
- $tablename = $prefixTables . $tableName . $suffixShouldBe;
-
- $p->setTimestamp($timestamp);
-
- $allTablesInstalled = Piwik::getTablesInstalled($forceReload = true);
- $this->assertContains($tablename, $allTablesInstalled);
- $this->assertEquals($tablename, $p->getTableName());
- $this->assertEquals($tablename, (string)$p->__toString());
- }
-}
diff --git a/tests/PHPUnit/DatabaseTestCase.php b/tests/PHPUnit/DatabaseTestCase.php
index db4186ffb4..35a2c8f050 100644
--- a/tests/PHPUnit/DatabaseTestCase.php
+++ b/tests/PHPUnit/DatabaseTestCase.php
@@ -68,7 +68,7 @@ class DatabaseTestCase extends PHPUnit_Framework_TestCase
Piwik_Site::clearCache();
Piwik_Tracker_Cache::deleteTrackerCache();
Piwik_Config::getInstance()->clear();
- Piwik_TablePartitioning::$tablesAlreadyInstalled = null;
+ Piwik_DataAccess_ArchiveTableCreator::clear();
Zend_Registry::_unsetInstance();
}
diff --git a/tests/PHPUnit/IntegrationTestCase.php b/tests/PHPUnit/IntegrationTestCase.php
index 17356d6175..d87c1970a2 100755
--- a/tests/PHPUnit/IntegrationTestCase.php
+++ b/tests/PHPUnit/IntegrationTestCase.php
@@ -207,7 +207,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
Piwik_Site::clearCache();
Piwik_Tracker_Cache::deleteTrackerCache();
Piwik_Config::getInstance()->clear();
- Piwik_TablePartitioning::$tablesAlreadyInstalled = null;
+ Piwik_DataAccess_ArchiveTableCreator::clear();
Piwik_PDFReports_API::$cache = array();
Zend_Registry::_unsetInstance();
@@ -1109,7 +1109,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
Piwik_Query("DROP TABLE IF EXISTS $table");
}
- Piwik_TablePartitioning::$tablesAlreadyInstalled = Piwik::getTablesInstalled($forceReload = true);
+ Piwik_DataAccess_ArchiveTableCreator::refreshTableList($forceReload = true);
}
}
diff --git a/tests/PHPUnit/Plugins/PrivacyManagerTest.php b/tests/PHPUnit/Plugins/PrivacyManagerTest.php
index 1c2f86a686..bc9d653551 100755
--- a/tests/PHPUnit/Plugins/PrivacyManagerTest.php
+++ b/tests/PHPUnit/Plugins/PrivacyManagerTest.php
@@ -104,7 +104,7 @@ class PrivacyManagerTest extends IntegrationTestCase
Piwik_Option::getInstance()->clearCache();
Piwik_Site::clearCache();
Piwik_Tracker_Cache::deleteTrackerCache();
- Piwik_TablePartitioning::$tablesAlreadyInstalled = null;
+ Piwik_DataAccess_ArchiveTableCreator::clear();
$tempTableName = Piwik_Common::prefixTable(Piwik_PrivacyManager_LogDataPurger::TEMP_TABLE_NAME);
Piwik_Query("DROP TABLE IF EXISTS " . $tempTableName);