From ae4b03163792f0b6e933933e5d37df87dc3fd566 Mon Sep 17 00:00:00 2001 From: mattab Date: Thu, 28 Mar 2013 12:42:39 +1300 Subject: 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/ --- core/TablePartitioning.php | 195 ++++++++++++++++++++++----------------------- 1 file changed, 96 insertions(+), 99 deletions(-) (limited to 'core/TablePartitioning.php') 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 @@ 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); + } } -- cgit v1.2.3