diff options
author | mattab <matthieu.aubry@gmail.com> | 2013-03-28 03:42:39 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2013-03-28 03:42:40 +0400 |
commit | ae4b03163792f0b6e933933e5d37df87dc3fd566 (patch) | |
tree | d1d7510a9728f587d3d63ebd03e4ecf3d904838b /core/TablePartitioning.php | |
parent | 158c2150f5f2e13ece459b8d131244c11b763997 (diff) |
Mass conversion of all files to the newly agreed coding standard: PSR 1/2
Converting Piwik core source files, PHP, JS, TPL, CSS
More info: http://piwik.org/participate/coding-standards/
Diffstat (limited to 'core/TablePartitioning.php')
-rw-r--r-- | core/TablePartitioning.php | 195 |
1 files changed, 96 insertions, 99 deletions
diff --git a/core/TablePartitioning.php b/core/TablePartitioning.php index 0f4df6b777..40bcec40d0 100644 --- a/core/TablePartitioning.php +++ b/core/TablePartitioning.php @@ -1,133 +1,130 @@ <?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 */ /** - * + * * NB: When a new table is partitionned using this class, we have to update the method * Piwik::getTablesInstalled() to add the new table to the list of tablename_* to fetch - * + * * @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(); - } + 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 { - 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); - } - + 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); + } + } /** - * + * * @package Piwik * @subpackage Piwik_TablePartitioning */ class Piwik_TablePartitioning_Daily extends Piwik_TablePartitioning { - public function __construct( $tableName ) - { - parent::__construct($tableName); - } - protected function generateTableName() - { - $config = Piwik_Config::getInstance(); - return $config->database['tables_prefix'] . $this->tableName . "_" . date("Y_m_d", $this->timestamp); - } + public function __construct($tableName) + { + parent::__construct($tableName); + } + + protected function generateTableName() + { + $config = Piwik_Config::getInstance(); + return $config->database['tables_prefix'] . $this->tableName . "_" . date("Y_m_d", $this->timestamp); + } } |