diff --git a/config/global.ini.php b/config/global.ini.php index 7e3b83bfaa523e12c6d59b8e664f848c20d6ee45..5db6d8160eb481d7cfcd9ea15c50f118124e796e 100755 --- a/config/global.ini.php +++ b/config/global.ini.php @@ -32,7 +32,8 @@ adapter = PDO_MYSQL [Debug] ; if set to 1, the archiving process will always be triggered, even if the archive has already been computed ; this is useful when making changes to the archiving code so we can force the archiving process -always_archive_data = 0 +always_archive_data_period = 0; +always_archive_data_day = 0; ; if set to 1, all the SQL queries will be recorded by the profiler ; and a profiling summary will be printed at the end of the request @@ -183,6 +184,7 @@ download_redirect_var_name = redirect logger_message[] = screen logger_error[] = screen logger_exception[] = screen + ; if configured to log in files, log files will be created in this relative path ; eg. if the value is tmp/logs files will be created in /path/to/piwik/tmp/logs/ logger_file_path = tmp/logs/ @@ -209,7 +211,6 @@ error_reporting = E_ALL|E_NOTICE ; allow smarty debugging using {debug} debugging = 1 - [Plugins] Plugins[] = CorePluginsAdmin Plugins[] = CoreAdminHome diff --git a/core/Archive/Single.php b/core/Archive/Single.php index 4035e2804bca6849309a82285c76b6e775c88de5..79003c3b62aa4989ee4b9dc70fd7c0e3b6320d5b 100644 --- a/core/Archive/Single.php +++ b/core/Archive/Single.php @@ -303,7 +303,7 @@ class Piwik_Archive_Single extends Piwik_Archive public function freeBlob( $name ) { $this->blobCached[$name] = null; -// $this->blobCached = array(); + unset($this->blobCached[$name]); } /** @@ -452,7 +452,7 @@ class Piwik_Archive_Single extends Piwik_Archive $this->preFetchBlob($name); $dataTableToLoad = $this->getDataTable($name, $idSubTable); $this->loadSubDataTables($name, $dataTableToLoad, $addMetadataSubtableId = true); + $this->freeBlob($name); return $dataTableToLoad; } } -?> diff --git a/core/ArchiveProcessing.php b/core/ArchiveProcessing.php index a728c980036d4c9fbb1cff29f482a4963847f601..7bad89b1f2a85feda642a4d06b9a8bfee6775f3e 100644 --- a/core/ArchiveProcessing.php +++ b/core/ArchiveProcessing.php @@ -174,13 +174,10 @@ abstract class Piwik_ArchiveProcessing protected $debugAlwaysArchive = false; /** - * Builds the archive processing object, - * Reads some configuration value from the config file - * + * Constructor */ public function __construct() { - $this->debugAlwaysArchive = Zend_Registry::get('config')->Debug->always_archive_data; } /** @@ -480,6 +477,7 @@ abstract class Piwik_ArchiveProcessing } $record = new Piwik_ArchiveProcessing_Record_Blob($name, $value); $this->insertRecord($record); + unset($record); return true; } @@ -491,7 +489,7 @@ abstract class Piwik_ArchiveProcessing protected function insertRecord($record) { // table to use to save the data - if(Piwik::isNumeric($record->value)) + if(is_numeric($record->value)) { $table = $this->tableArchiveNumeric; } diff --git a/core/ArchiveProcessing/Day.php b/core/ArchiveProcessing/Day.php index 77558a3f3486746740fed1687b9aa09f15fa064c..66782c98384f31b275cb104a0b7de96dd96ad5cb 100644 --- a/core/ArchiveProcessing/Day.php +++ b/core/ArchiveProcessing/Day.php @@ -36,6 +36,7 @@ class Piwik_ArchiveProcessing_Day extends Piwik_ArchiveProcessing { parent::__construct(); $this->db = Zend_Registry::get('db'); + $this->debugAlwaysArchive = Zend_Registry::get('config')->Debug->always_archive_data_day; } /** diff --git a/core/ArchiveProcessing/Period.php b/core/ArchiveProcessing/Period.php index 3b13a975516932ab4bde9ecbe5fff3d48b157570..2a5fae2e935b87d972a490475d9fb762eeb5cead 100644 --- a/core/ArchiveProcessing/Period.php +++ b/core/ArchiveProcessing/Period.php @@ -21,6 +21,12 @@ */ class Piwik_ArchiveProcessing_Period extends Piwik_ArchiveProcessing { + public function __construct() + { + parent::__construct(); + $this->debugAlwaysArchive = Zend_Registry::get('config')->Debug->always_archive_data_period; + } + /** * Sums all values for the given field names $aNames over the period * See @archiveNumericValuesGeneral for more information @@ -160,11 +166,14 @@ class Piwik_ArchiveProcessing_Period extends Piwik_ArchiveProcessing $nameToCount[$recordName]['recursive'] = $table->getRowsCountRecursive(); $blob = $table->getSerialized( $maximumRowsInDataTableLevelZero, $maximumRowsInSubDataTable, $columnToSortByBeforeTruncation ); + destroy($table); $this->insertBlobRecord($recordName, $blob); } + Piwik_DataTable_Manager::getInstance()->deleteAll(); + return $nameToCount; } - + /** * This method selects all DataTables that have the name $name over the period. * It calls the appropriate methods that sum all these tables together. diff --git a/core/ArchiveProcessing/Record.php b/core/ArchiveProcessing/Record.php index cce1b9a0fc6f9024bc6dd432a5eb53c62e203aee..c34c37552ec29acd8e5834fd45f5331de63a6ea4 100644 --- a/core/ArchiveProcessing/Record.php +++ b/core/ArchiveProcessing/Record.php @@ -34,9 +34,6 @@ abstract class Piwik_ArchiveProcessing_Record $this->value = $value; } - public function __destruct() - { - } } diff --git a/core/DataTable.php b/core/DataTable.php index 132a940d6468900eee1eb21cd05ad6a392ce7d0d..82dc72b74a1c484975152041c57625806c5b5168 100644 --- a/core/DataTable.php +++ b/core/DataTable.php @@ -167,7 +167,17 @@ class Piwik_DataTable * * @var bool */ - protected $indexNotUpToDate = false; + protected $indexNotUpToDate = true; + + /** + * This flag sets the index to be rebuild whenever a new row is added, + * as opposed to re-building the full index when getRowFromLabel is called. + * This is to optimize and not rebuild the full Index in the case where we + * add row, getRowFromLabel, addRow, getRowFromLabel thousands of times. + * + * @var bool + */ + protected $rebuildIndexContinuously = false; /** * Column name of last time the table was sorted @@ -221,6 +231,22 @@ class Piwik_DataTable $this->currentId = Piwik_DataTable_Manager::getInstance()->addTable($this); } + /** + * At destruction we free all memory + */ + public function __destruct() + { + // destruct can be called several times + if(isset($this->rows)) + { + foreach($this->getRows() as $row) { + destroy($row); + } + unset($this->rows); + Piwik_DataTable_Manager::getInstance()->setTableDeleted($this->getId()); + } + } + /** * Sort the dataTable rows using the php callback function * @@ -351,7 +377,7 @@ class Piwik_DataTable { if( $labelToLookFor === self::LABEL_SUMMARY_ROW ) { - $this->addSummaryRow($row ); + $this->addSummaryRow( $row ); } else { @@ -382,6 +408,7 @@ class Piwik_DataTable */ public function getRowFromLabel( $label ) { + $this->rebuildIndexContinuously = true; if($this->indexNotUpToDate) { $this->rebuildIndex(); @@ -411,7 +438,6 @@ class Piwik_DataTable foreach($this->rows as $id => $row) { $label = $row->getColumn('label'); - if($label !== false) { $this->rowsIndexByLabel[$label] = $id; @@ -441,14 +467,23 @@ class Piwik_DataTable } /** - * Shortcut function used for performance reasons + * Add a row to the table and rebuild the index if necessary * * @param Piwik_DataTable_Row $row to add at the end of the array */ public function addRow( Piwik_DataTable_Row $row ) { - $this->rows[] = $row; - $this->indexNotUpToDate = true; + $this->rows[] = $row; + if(!$this->indexNotUpToDate + && $this->rebuildIndexContinuously) + { + $label = $row->getColumn('label'); + if($label !== false) + { + $this->rowsIndexByLabel[$label] = count($this->rows)-1; + } + $this->indexNotUpToDate = false; + } } /** @@ -1037,13 +1072,5 @@ class Piwik_DataTable } } - /** - * At destruction we try to free memory - * But php doesn't give us much control on this - */ - public function __destruct() - { - unset($this->rows); - } - } + diff --git a/core/DataTable/Filter/Sort.php b/core/DataTable/Filter/Sort.php index 5e4e324c7e5a4929204328870f4989d52c643f0e..222a2ca5d854fdbd8ea08da38ae2c4b763431962 100644 --- a/core/DataTable/Filter/Sort.php +++ b/core/DataTable/Filter/Sort.php @@ -148,7 +148,7 @@ class Piwik_DataTable_Filter_Sort extends Piwik_DataTable_Filter $this->columnToSort = $this->selectColumnToSort($row); $value = $row->getColumn($this->columnToSort); - if( Piwik::isNumeric($value)) + if( is_numeric($value)) { $methodToUse = "sort"; } diff --git a/core/DataTable/Manager.php b/core/DataTable/Manager.php index 50ee38e486381167564163b7fe34a94ab43e9a27..ea34b4e5d29e1de4e828e50ed73b096cf77c46af 100644 --- a/core/DataTable/Manager.php +++ b/core/DataTable/Manager.php @@ -85,12 +85,17 @@ class Piwik_DataTable_Manager */ public function deleteAll() { + foreach($this->tables as $id => $table) + { + destroy($table); + } $this->tables = array(); $this->lastTableId = 0; } /** - * Deletes the datatable given its id + * Deletes (unsets) the datatable given its id and removes it from the manager + * Subsequent get for this table will fail * * @param int $id */ @@ -98,10 +103,21 @@ class Piwik_DataTable_Manager { if(isset($this->tables[$id])) { - $this->tables[$id] = null; + destroy($this->tables[$id]); + $this->setTableDeleted($id); } } + /** + * Remove the table from the manager (table has already been unset) + * @param $id + * @return void + */ + public function setTableDeleted($id) + { + $this->tables[$id] = null; + } + /** * Debug only. Dumps all tables currently registered in the Manager * diff --git a/core/DataTable/Row.php b/core/DataTable/Row.php index 20d46c9a50dcb2d325f27490fcf6bbc9647560b0..2a26327b38fad92222cc3f3da3e19ae5c2f779ae 100644 --- a/core/DataTable/Row.php +++ b/core/DataTable/Row.php @@ -80,7 +80,7 @@ class Piwik_DataTable_Row && $row[self::DATATABLE_ASSOCIATED] instanceof Piwik_DataTable) { $this->c[self::DATATABLE_ASSOCIATED] = $row[self::DATATABLE_ASSOCIATED]->getId(); - } + } } /** @@ -273,16 +273,7 @@ class Piwik_DataTable_Row */ public function setColumn($name, $value) { - if(isset($this->c[self::COLUMNS][$name]) - || $name != 'label') - { - $this->c[self::COLUMNS][$name] = $value; - } - // we make sure when adding the label it goes first in the table - else - { - $this->c[self::COLUMNS] = array($name => $value) + $this->c[self::COLUMNS]; - } + $this->c[self::COLUMNS][$name] = $value; } /** @@ -318,6 +309,14 @@ class Piwik_DataTable_Row $this->c[self::METADATA][$name] = $value; } + //TODO this should not be hardcoded here + protected $columnsExcludedFromSum = array( + 'label' => true, + 'nb_uniq_visitors' => true, + 'entry_nb_uniq_visitors' => true, + 'exit_nb_uniq_visitors' => true, + ); + /** * Sums the given $row columns values to the existing row' columns values. * It will sum only the int or float values of $row. @@ -331,13 +330,7 @@ class Piwik_DataTable_Row { foreach($rowToSum->getColumns() as $columnToSumName => $columnToSumValue) { - //TODO this should not be hardcoded here. - if($columnToSumName != 'label' - && $columnToSumName != 'nb_uniq_visitors' - && $columnToSumName != 'entry_nb_uniq_visitors' - && $columnToSumName != 'exit_nb_uniq_visitors' - - ) + if(!isset($this->columnsExcludedFromSum[$columnToSumName])) { $thisColumnValue = $this->getColumn($columnToSumName); $newValue = $this->sumRowArray($thisColumnValue, $columnToSumValue); @@ -348,36 +341,33 @@ class Piwik_DataTable_Row protected function sumRowArray( $thisColumnValue, $columnToSumValue ) { - $newValue = 0; - if(Piwik::isNumeric($columnToSumValue)) + if(is_numeric($columnToSumValue)) { if($thisColumnValue === false) { $thisColumnValue = 0; } - $newValue = $thisColumnValue + $columnToSumValue; + return $thisColumnValue + $columnToSumValue; } - elseif(is_array($columnToSumValue)) + + if(is_array($columnToSumValue)) { - $newValue = array(); if($thisColumnValue == false) { - $newValue = $columnToSumValue; + return $columnToSumValue; } - else + $newValue = $thisColumnValue; + foreach($columnToSumValue as $arrayIndex => $arrayValue) { - $newValue = $thisColumnValue; - foreach($columnToSumValue as $arrayIndex => $arrayValue) + if(!isset($newValue[$arrayIndex])) { - if(!isset($newValue[$arrayIndex])) - { - $newValue[$arrayIndex] = false; - } - $newValue[$arrayIndex] = $this->sumRowArray($newValue[$arrayIndex], $arrayValue); + $newValue[$arrayIndex] = false; } + $newValue[$arrayIndex] = $this->sumRowArray($newValue[$arrayIndex], $arrayValue); } + return $newValue; } - return $newValue; + return 0; } /** diff --git a/core/FrontController.php b/core/FrontController.php index aa2fc38a5969e1bde288f8a9d180a61ab77c8e6e..7e804f09384a4613a82ef42dcb933febc532ad65 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -298,3 +298,10 @@ class Exception_PluginDeactivated extends Exception parent::__construct("The plugin '$module' is not activated. You can activate the plugin on the 'Plugins admin' page."); } } + +function destroy(&$var) +{ + if (is_object($var)) $var->__destruct(); + unset($var); + $var = null; +} diff --git a/core/Log.php b/core/Log.php index 23cb476cbfd8771cd4038c8aae0b61c5cc0eaea2..25166a32587d2ac43844014a2639247920677f81 100644 --- a/core/Log.php +++ b/core/Log.php @@ -93,7 +93,7 @@ abstract class Piwik_Log extends Zend_Log if (empty($this->_writers)) { throw new Zend_Log_Exception('No writers were added'); } - + $event['timestamp'] = date('c'); // pack into event required by filters and writers @@ -115,12 +115,10 @@ abstract class Piwik_Log extends Zend_Log } /** - * - * * @package Piwik_Log */ class Piwik_Log_Formatter_FileFormatter implements Zend_Log_Formatter_Interface -{ +{ /** * Formats data into a single line to be written by the writer. * @@ -141,6 +139,12 @@ class Piwik_Log_Formatter_FileFormatter implements Zend_Log_Formatter_Interface class Piwik_Log_Formatter_ScreenFormatter implements Zend_Log_Formatter_Interface { + function formatEvent($event) + { + // no injection in error messages, backtrace when displayed on screen + return array_map('htmlspecialchars', $event); + } + function format($string) { $string = self::getFormattedString($string); diff --git a/core/Log/Error.php b/core/Log/Error.php index c2ae08f9fd24e6796c0d656060e95799eef312f0..c5db22cbbcb972857b177c846e443f11b9a9004e 100644 --- a/core/Log/Error.php +++ b/core/Log/Error.php @@ -73,6 +73,8 @@ class Piwik_Log_Formatter_Error_ScreenFormatter extends Piwik_Log_Formatter_Scre */ public function format($event) { + $event = parent::formatEvent($event); + $errno = $event['errno'] ; $errstr = $event['message'] ; $errfile = $event['errfile'] ; diff --git a/core/Log/Exception.php b/core/Log/Exception.php index 5845bae4f0059e80d0bc3f086c860cf4b5adf9eb..4e678cc2115ee33eb40d1f0fcfaef6c7877ea2d5 100644 --- a/core/Log/Exception.php +++ b/core/Log/Exception.php @@ -73,6 +73,7 @@ class Piwik_Log_Formatter_Exception_ScreenFormatter extends Piwik_Log_Formatter_ */ public function format($event) { + $event = parent::formatEvent($event); $errno = $event['errno'] ; $errstr = $event['message'] ; $errfile = $event['errfile'] ; diff --git a/core/Log/Message.php b/core/Log/Message.php index 37e44a1a248272b552016ec18f8dad6e604422f6..648d1dc57c1405952f0285b4932100a8961cf298 100644 --- a/core/Log/Message.php +++ b/core/Log/Message.php @@ -38,7 +38,6 @@ class Piwik_Log_Message extends Piwik_Log { $event = array(); $event['message'] = $message; - parent::log($event); } } diff --git a/core/Piwik.php b/core/Piwik.php index e987523f9e03d45385ed2d695b87f6b2b0102fec..bc49c0051e49e9c2e0031c186a6f09717992b69d 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -334,6 +334,13 @@ class Piwik { echo Zend_Registry::get('timer'); } + + static public function printMemoryLeak($prefix = '', $suffix = '<br>') + { + echo $prefix; + echo Zend_Registry::get('timer')->getMemoryLeak(); + echo $suffix; + } static public function printMemoryUsage( $prefixString = null ) { @@ -384,11 +391,6 @@ class Piwik return in_array(substr(php_sapi_name(), 0, 3), array('cgi', 'cli')); } - static public function isNumeric($value) - { - return is_numeric($value); - } - static public function getCurrency() { static $symbol = null; diff --git a/core/PluginsManager.php b/core/PluginsManager.php index ffdb24e7846194e29e0cbc36114808b00e08c49e..35c934fad03a4a5f886b472df0e06c66dc8a37ea 100644 --- a/core/PluginsManager.php +++ b/core/PluginsManager.php @@ -495,7 +495,8 @@ class Piwik_Plugin_Exception extends Exception */ function Piwik_PostEvent( $eventName, &$object = null, $info = array() ) { - Piwik_PluginsManager::getInstance()->dispatcher->post( $object, $eventName, $info, true, false ); + $notification = new Piwik_Event_Notification($object, $eventName, $info); + Piwik_PluginsManager::getInstance()->dispatcher->postNotification( $notification, true, false ); } /** @@ -505,3 +506,20 @@ function Piwik_AddAction( $hookName, $function ) { Piwik_PluginsManager::getInstance()->dispatcher->addObserver( $function, $hookName ); } + +class Piwik_Event_Notification extends Event_Notification +{ + static $showProfiler = false; + function increaseNotificationCount($className, $method) { + parent::increaseNotificationCount(); + if(self::$showProfiler) + { + echo "after $className -> $method <br>"; + echo "-"; Piwik::printTimer(); + echo "<br>"; + echo "-"; Piwik::printMemoryLeak(); + echo "<br>"; + } + } +} + diff --git a/core/Tracker.php b/core/Tracker.php index 2dfaa9ef3ce9e176747e74061ef43deb5fcba94f..97cd1519e3f7be64ca84a01dc670fcb57ee9ce86 100644 --- a/core/Tracker.php +++ b/core/Tracker.php @@ -119,7 +119,7 @@ class Piwik_Tracker } printDebug("End of the page."); - if($GLOBALS['DEBUGPIWIK'] === true) + if($GLOBALS['PIWIK_TRACKER_DEBUG'] === true) { Piwik::printSqlProfilingReportTracker(self::$db); } @@ -203,7 +203,7 @@ class Piwik_Tracker protected function outputTransparentGif() { - if( !isset($GLOBALS['DEBUGPIWIK']) || !$GLOBALS['DEBUGPIWIK'] ) + if( !isset($GLOBALS['PIWIK_TRACKER_DEBUG']) || !$GLOBALS['PIWIK_TRACKER_DEBUG'] ) { $trans_gif_64 = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="; header("Content-type: image/gif"); @@ -310,7 +310,7 @@ class Piwik_Tracker function printDebug( $info = '' ) { - if(isset($GLOBALS['DEBUGPIWIK']) && $GLOBALS['DEBUGPIWIK']) + if(isset($GLOBALS['PIWIK_TRACKER_DEBUG']) && $GLOBALS['PIWIK_TRACKER_DEBUG']) { if(is_array($info)) { diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php index bb34e5843cd62f465626caf1d9da35574f11ca9c..0a54946d8490f4892e98fcd5554fd2b832dab2fd 100644 --- a/core/Tracker/Visit.php +++ b/core/Tracker/Visit.php @@ -101,7 +101,7 @@ class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface } $actionId = $action->getIdAction(); - if($GLOBALS['DEBUGPIWIK']) + if($GLOBALS['PIWIK_TRACKER_DEBUG']) { switch($action->getActionType()) { case Piwik_Tracker_Action::TYPE_ACTION: diff --git a/index.php b/index.php index 4925251aa475b7366b2566e0c824d6b353571487..16a492aa969aa82daedad516ca99871bc8a24f7d 100755 --- a/index.php +++ b/index.php @@ -35,7 +35,6 @@ if(!defined('PIWIK_ENABLE_ERROR_HANDLER') || PIWIK_ENABLE_ERROR_HANDLER) set_error_handler('Piwik_ErrorHandler'); set_exception_handler('Piwik_ExceptionHandler'); } - if(strlen(session_id()) === 0) { session_start(); diff --git a/libs/Event/Dispatcher.php b/libs/Event/Dispatcher.php index fe6430587548e35705dc0747185d9fe39ef7d451..6e6a72eb2173b6b7bb300d1bc2f673b26f2aaa90 100755 --- a/libs/Event/Dispatcher.php +++ b/libs/Event/Dispatcher.php @@ -278,7 +278,9 @@ class Event_Dispatcher if (empty($rObserver['class']) || strcasecmp($rObserver['class'], $objClass) == 0) { call_user_func_array($rObserver['callback'], array(&$notification)); - $notification->increaseNotificationCount(); + //-- Piwik Hack --// + $notification->increaseNotificationCount(get_class($rObserver['callback'][0]), $rObserver['callback'][1]); + //-- End Piwik Hack --// } } } @@ -475,4 +477,3 @@ class Event_Dispatcher } } -?> diff --git a/libs/Event/Notification.php b/libs/Event/Notification.php index 58d08fa4cf762423cb43fa382d9e76226dc45329..1ce2ccde8dc91e3d74dd224b98e72379e21b857b 100755 --- a/libs/Event/Notification.php +++ b/libs/Event/Notification.php @@ -191,4 +191,3 @@ class Event_Notification return ($this->_notificationState === EVENT_NOTIFICATION_STATE_CANCELLED); } } -?> diff --git a/misc/generateVisits.php b/misc/generateVisits.php index 7e87c1257e680a9b01ca60e5c42499fe7e097d35..0258fa6c5df2434ff9101c0a64d47c8731253b4c 100644 --- a/misc/generateVisits.php +++ b/misc/generateVisits.php @@ -3,10 +3,10 @@ * The script can be used to generate huge number of visits and actions * for a given number of days. */ -$minVisitors = 200; -$maxVisitors = 200; -$nbActions = 5; -$daysToCompute = 2; +$minVisitors = 20000; +$maxVisitors = 20000; +$nbActions = 10; +$daysToCompute = 5; //----------------------------------------------------------------------------- error_reporting(E_ALL|E_NOTICE); @@ -19,7 +19,7 @@ set_include_path(PIWIK_INCLUDE_PATH . PATH_SEPARATOR . PIWIK_INCLUDE_PATH . '/core' . PATH_SEPARATOR . get_include_path() ); -$GLOBALS['DEBUGPIWIK'] = false; +$GLOBALS['PIWIK_TRACKER_DEBUG'] = false; ob_start(); // first check that user has privileges to create some random data in the DB -> he must be super user diff --git a/piwik.php b/piwik.php index d882b8ab28dab65f5ae1753de839a860843a0ead..92c571d958bafd263e7a6e994eab15c99f1c71ff 100644 --- a/piwik.php +++ b/piwik.php @@ -7,7 +7,7 @@ * @version $Id$ */ -$GLOBALS['DEBUGPIWIK'] = false; +$GLOBALS['PIWIK_TRACKER_DEBUG'] = false; if(defined('PIWIK_ENABLE_TRACKING') && !PIWIK_ENABLE_TRACKING) { return; @@ -36,7 +36,7 @@ require_once "Tracker/GoalManager.php"; ob_start(); -if($GLOBALS['DEBUGPIWIK'] === true) +if($GLOBALS['PIWIK_TRACKER_DEBUG'] === true) { date_default_timezone_set(date_default_timezone_get()); require_once "core/ErrorHandler.php"; diff --git a/plugins/Actions/Actions.php b/plugins/Actions/Actions.php index d212d703abca113a12e738e9c932ae36476a7fbf..dd9e449c126f9cf7a8964640102a14b73948e46b 100644 --- a/plugins/Actions/Actions.php +++ b/plugins/Actions/Actions.php @@ -87,6 +87,7 @@ class Piwik_Actions extends Piwik_Plugin */ public function archiveDay( $notification ) { + //TODO Actions should use integer based keys like other archive in piwik $archiveProcessing = $notification->getNotificationObject(); require_once "Tracker/Action.php"; @@ -178,7 +179,6 @@ class Piwik_Actions extends Piwik_Plugin "; $query = $archiveProcessing->db->query($query, array( $archiveProcessing->strDateStart, $archiveProcessing->idsite )); $modified = $this->updateActionsTableWithRowQuery($query); - $this->archiveDayRecordInDatabase($archiveProcessing); } @@ -187,35 +187,34 @@ class Piwik_Actions extends Piwik_Plugin $dataTable = Piwik_ArchiveProcessing_Day::generateDataTable($this->actionsTablesByType[Piwik_Tracker_Action::TYPE_ACTION]); $s = $dataTable->getSerialized( $this->maximumRowsInDataTableLevelZero, $this->maximumRowsInSubDataTable, $this->columnToSortByBeforeTruncation ); $archiveProcessing->insertBlobRecord('Actions_actions', $s); + destroy($dataTable); $dataTable = Piwik_ArchiveProcessing_Day::generateDataTable($this->actionsTablesByType[Piwik_Tracker_Action::TYPE_DOWNLOAD]); $s = $dataTable->getSerialized($this->maximumRowsInDataTableLevelZero, $this->maximumRowsInSubDataTable, $this->columnToSortByBeforeTruncation ); $archiveProcessing->insertBlobRecord('Actions_downloads', $s); - + destroy($dataTable); + $dataTable = Piwik_ArchiveProcessing_Day::generateDataTable($this->actionsTablesByType[Piwik_Tracker_Action::TYPE_OUTLINK]); $s = $dataTable->getSerialized( $this->maximumRowsInDataTableLevelZero, $this->maximumRowsInSubDataTable, $this->columnToSortByBeforeTruncation ); $archiveProcessing->insertBlobRecord('Actions_outlink', $s); - + destroy($dataTable); + unset($this->actionsTablesByType); } - static public function getHostAndPageNameFromUrl($url) - { - $matches = $split_arr = array(); - if(preg_match("#://[^/]+(/)#",$url, $matches, PREG_OFFSET_CAPTURE)) - { - $host = substr($url, 0, $matches[1][1]); - return array($host, substr($url,strlen($host))); - } - return array($url, "/"); - } - static public function getActionExplodedNames($name, $type) { if($type == Piwik_Tracker_Action::TYPE_DOWNLOAD || $type == Piwik_Tracker_Action::TYPE_OUTLINK) { - return self::getHostAndPageNameFromUrl($name); + $matches = $split_arr = array(); + //TODO optimize with substring count rather than preg_match + if(preg_match("#://[^/]+(/)#", $name, $matches, PREG_OFFSET_CAPTURE)) + { + $host = substr($name, 0, $matches[1][1]); + return array($host, substr($name, strlen($host))); + } + return array($name, "/"); } if(empty(self::$actionCategoryDelimiter)) { diff --git a/plugins/Provider/Provider.php b/plugins/Provider/Provider.php index e9f555f9c110fde5af8da4c928f54da307a64bad..556dbfce99e89e54f55eb483f132bfdf05e0fab7 100644 --- a/plugins/Provider/Provider.php +++ b/plugins/Provider/Provider.php @@ -98,6 +98,7 @@ class Piwik_Provider extends Piwik_Plugin $interestByProvider = $archiveProcessing->getArrayInterestForLabel($labelSQL); $tableProvider = $archiveProcessing->getDataTableFromArray($interestByProvider); $archiveProcessing->insertBlobRecord($recordName, $tableProvider->getSerialized()); + destroy($tableProvider); } /** diff --git a/plugins/Referers/Referers.php b/plugins/Referers/Referers.php index c1ed78bb0bcb7c96cf36b2d113b4727064cd5900..b027bdbaffd597b74d93c3b0965b9a7f76ae37d8 100644 --- a/plugins/Referers/Referers.php +++ b/plugins/Referers/Referers.php @@ -128,11 +128,25 @@ class Piwik_Referers extends Piwik_Plugin * @var Piwik_ArchiveProcessing_Day */ $this->archiveProcessing = $notification->getNotificationObject(); - $this->archiveDayAggregateVisits($this->archiveProcessing); $this->archiveDayAggregateGoals($this->archiveProcessing); Piwik_PostEvent('Referers.archiveDay', $this); $this->archiveDayRecordInDatabase($this->archiveProcessing); + $this->cleanup(); + } + + protected function cleanup() + { + destroy($this->interestBySearchEngine); + destroy($this->interestByKeyword); + destroy($this->interestBySearchEngineAndKeyword); + destroy($this->interestByKeywordAndSearchEngine); + destroy($this->interestByWebsite); + destroy($this->interestByWebsiteAndUrl); + destroy($this->interestByCampaignAndKeyword); + destroy($this->interestByCampaign); + destroy($this->interestByType); + destroy($this->distinctUrls); } protected function archiveDayAggregateVisits($archiveProcessing) @@ -165,7 +179,6 @@ class Piwik_Referers extends Piwik_Plugin $this->interestByCampaign = $this->interestByType = $this->distinctUrls = array(); - while($row = $query->fetch() ) { if(empty($row['referer_type'])) @@ -296,8 +309,9 @@ class Piwik_Referers extends Piwik_Plugin $archiveProcessing->insertNumericRecord($name, $value); } - $data = $archiveProcessing->getDataTableSerialized($this->interestByType); - $archiveProcessing->insertBlobRecord('Referers_type', $data); + $dataTable = $archiveProcessing->getDataTableSerialized($this->interestByType); + $archiveProcessing->insertBlobRecord('Referers_type', $dataTable); + destroy($dataTable); $blobRecords = array( 'Referers_keywordBySearchEngine' => $archiveProcessing->getDataTableWithSubtablesFromArraysIndexedByLabel($this->interestBySearchEngineAndKeyword, $this->interestBySearchEngine), @@ -305,11 +319,11 @@ class Piwik_Referers extends Piwik_Plugin 'Referers_keywordByCampaign' => $archiveProcessing->getDataTableWithSubtablesFromArraysIndexedByLabel($this->interestByCampaignAndKeyword, $this->interestByCampaign), 'Referers_urlByWebsite' => $archiveProcessing->getDataTableWithSubtablesFromArraysIndexedByLabel($this->interestByWebsiteAndUrl, $this->interestByWebsite), ); - foreach($blobRecords as $recordName => $table ) { - $dataToRecord = $table->getSerialized($this->maximumRowsInDataTableLevelZero, $this->maximumRowsInSubDataTable, $this->columnToSortByBeforeTruncation); - $archiveProcessing->insertBlobRecord($recordName, $dataToRecord); + $blob = $table->getSerialized($this->maximumRowsInDataTableLevelZero, $this->maximumRowsInSubDataTable, $this->columnToSortByBeforeTruncation); + $archiveProcessing->insertBlobRecord($recordName, $blob); + destroy($table); } } } diff --git a/plugins/UserCountry/UserCountry.php b/plugins/UserCountry/UserCountry.php index d408e08962f969b84dec359cf3ec9b1e3da411c8..7f39f2a147f26541df44aad1d5e82669fffbca71 100644 --- a/plugins/UserCountry/UserCountry.php +++ b/plugins/UserCountry/UserCountry.php @@ -99,9 +99,11 @@ class Piwik_UserCountry extends Piwik_Plugin $tableCountry = $archiveProcessing->getDataTableFromArray($this->interestByCountry); $archiveProcessing->insertBlobRecord('UserCountry_country', $tableCountry->getSerialized()); $archiveProcessing->insertNumericRecord('UserCountry_distinctCountries', $tableCountry->getRowsCount()); + destroy($tableCountry); $tableContinent = $archiveProcessing->getDataTableFromArray($this->interestByContinent); $archiveProcessing->insertBlobRecord('UserCountry_continent', $tableContinent->getSerialized()); + destroy($tableContinent); } } diff --git a/plugins/UserSettings/UserSettings.php b/plugins/UserSettings/UserSettings.php index 2218494d3c8232118d00bc25d7b306d7f3818dad..4043c08c272f4a793af3d87d7ec593dfd20f51be 100644 --- a/plugins/UserSettings/UserSettings.php +++ b/plugins/UserSettings/UserSettings.php @@ -81,12 +81,14 @@ class Piwik_UserSettings extends Piwik_Plugin $interestByConfiguration = $archiveProcessing->getArrayInterestForLabel($labelSQL); $tableConfiguration = $archiveProcessing->getDataTableFromArray($interestByConfiguration); $archiveProcessing->insertBlobRecord($recordName, $tableConfiguration->getSerialized()); + destroy($tableConfiguration); $recordName = 'UserSettings_os'; $labelSQL = "config_os"; $interestByOs = $archiveProcessing->getArrayInterestForLabel($labelSQL); $tableOs = $archiveProcessing->getDataTableFromArray($interestByOs); $archiveProcessing->insertBlobRecord($recordName, $tableOs->getSerialized()); + destroy($tableOs); $recordName = 'UserSettings_browser'; $labelSQL = "CONCAT(config_browser_name, ';', config_browser_version)"; @@ -97,6 +99,8 @@ class Piwik_UserSettings extends Piwik_Plugin $recordName = 'UserSettings_browserType'; $tableBrowserType = $this->getTableBrowserByType($tableBrowser); $archiveProcessing->insertBlobRecord($recordName, $tableBrowserType->getSerialized()); + destroy($tableBrowser); + destroy($tableBrowserType); $recordName = 'UserSettings_resolution'; $labelSQL = "config_resolution"; @@ -108,10 +112,13 @@ class Piwik_UserSettings extends Piwik_Plugin $recordName = 'UserSettings_wideScreen'; $tableWideScreen = $this->getTableWideScreen($tableResolution); $archiveProcessing->insertBlobRecord($recordName, $tableWideScreen->getSerialized()); + destroy($tableResolution); + destroy($tableWideScreen); $recordName = 'UserSettings_plugin'; $tablePlugin = $this->getDataTablePlugin(); $archiveProcessing->insertBlobRecord($recordName, $tablePlugin->getSerialized()); + destroy($tablePlugin); } function archivePeriod( $notification ) diff --git a/plugins/VisitTime/VisitTime.php b/plugins/VisitTime/VisitTime.php index 88947ee100a93148d27971928ee6d23a0a2fb10f..531c30301483e591e36e0475617a72ffbe87d4fd 100644 --- a/plugins/VisitTime/VisitTime.php +++ b/plugins/VisitTime/VisitTime.php @@ -91,10 +91,12 @@ class Piwik_VisitTime extends Piwik_Plugin $tableLocalTime = $archiveProcessing->getDataTableFromArray($this->interestByLocalTime); $this->makeSureAllHoursAreSet($tableLocalTime, $archiveProcessing); $archiveProcessing->insertBlobRecord('VisitTime_localTime', $tableLocalTime->getSerialized()); - + destroy($tableLocalTime); + $tableServerTime = $archiveProcessing->getDataTableFromArray($this->interestByServerTime); $this->makeSureAllHoursAreSet($tableServerTime, $archiveProcessing); $archiveProcessing->insertBlobRecord('VisitTime_serverTime', $tableServerTime->getSerialized()); + destroy($tableServerTime); } private function makeSureAllHoursAreSet($table, $archiveProcessing) diff --git a/tests/core/Piwik.test.php b/tests/core/Piwik.test.php index e28e3f429d8bb98b84a3f81b8768b378adb59b81..bd3431111aafb0bb6e530fed2d83150664d97ba3 100644 --- a/tests/core/Piwik.test.php +++ b/tests/core/Piwik.test.php @@ -19,7 +19,7 @@ class Test_Piwik extends UnitTestCase ); foreach($valid as $toTest) { - $this->assertTrue(Piwik::isNumeric($toTest), $toTest." not valid but should!"); + $this->assertTrue(is_numeric($toTest), $toTest." not valid but should!"); } } @@ -30,7 +30,7 @@ class Test_Piwik extends UnitTestCase ); foreach($notvalid as $toTest) { - $this->assertFalse(Piwik::isNumeric($toTest), $toTest." valid but shouldn't!"); + $this->assertFalse(is_numeric($toTest), $toTest." valid but shouldn't!"); } } diff --git a/tests/core/ReleaseCheckList.test.php b/tests/core/ReleaseCheckList.test.php index 0f8e89eca02f619ab30810afae917a9c8cd9fa2f..ecbcb957be6988697c4b0f026c88c45b5236942b 100644 --- a/tests/core/ReleaseCheckList.test.php +++ b/tests/core/ReleaseCheckList.test.php @@ -68,10 +68,10 @@ class Test_Piwik_ReleaseCheckList extends UnitTestCase function test_piwikTrackerDebugIsOff() { - $this->assertTrue(!isset($GLOBALS['DEBUGPIWIK'])); + $this->assertTrue(!isset($GLOBALS['PIWIK_TRACKER_DEBUG'])); define('PIWIK_ENABLE_TRACKING', false); include PIWIK_PATH_TEST_TO_ROOT . "/piwik.php"; - $this->assertTrue($GLOBALS['DEBUGPIWIK'] === false); + $this->assertTrue($GLOBALS['PIWIK_TRACKER_DEBUG'] === false); } }