diff options
author | mattpiwik <matthieu.aubry@gmail.com> | 2007-08-17 01:45:46 +0400 |
---|---|---|
committer | mattpiwik <matthieu.aubry@gmail.com> | 2007-08-17 01:45:46 +0400 |
commit | def7586305ef208ec0456e5840cb239a25ff9124 (patch) | |
tree | 7e79d27330b83a9b3f4442b5f794ea326b788fbd /modules | |
parent | 9f3b6ceb18b3e1ec4cdcbb01d8642fb5aaba1635 (diff) |
Ooch what a productive day!!!
feeling good darling :-)
plugged all the basic features from phpmyvisites for daily archives
but with a nice architecture, modularity, plugins are configurable in the config file (waiting for a nice GUI of course)
handles empty days, multiple sites, fixed small bugs here and there
git-svn-id: http://dev.piwik.org/svn/trunk@42 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'modules')
-rw-r--r-- | modules/Archive.php | 41 | ||||
-rw-r--r-- | modules/ArchiveProcessing.php | 44 | ||||
-rw-r--r-- | modules/ArchiveProcessing/Day.php | 374 | ||||
-rw-r--r-- | modules/ArchiveProcessing/Record.php | 4 | ||||
-rw-r--r-- | modules/Common.php | 2 | ||||
-rw-r--r-- | modules/DataTable.php | 7 | ||||
-rw-r--r-- | modules/DataTable/Renderer.php | 1 | ||||
-rw-r--r-- | modules/LogStats.php | 2 | ||||
-rw-r--r-- | modules/LogStats/Generator.php | 12 | ||||
-rw-r--r-- | modules/LogStats/Plugins.php | 47 | ||||
-rw-r--r-- | modules/LogStats/Visit.php | 15 | ||||
-rwxr-xr-x | modules/Piwik.php | 47 | ||||
-rw-r--r-- | modules/PluginsManager.php | 23 |
13 files changed, 169 insertions, 450 deletions
diff --git a/modules/Archive.php b/modules/Archive.php index bf254cc271..5b6f5693ec 100644 --- a/modules/Archive.php +++ b/modules/Archive.php @@ -51,6 +51,8 @@ class Piwik_Archive protected $period = null; protected $id = null; + protected $isThereSomeVisits = false; + protected $alreadyChecked = false; // to be used only once public function setPeriod( Piwik_Period $period ) @@ -63,17 +65,44 @@ class Piwik_Archive $this->site = $site; } + + function prepareArchive() + { + if(!$this->alreadyChecked) + { + // we make sure the archive is available for the given date + $periodLabel = $this->period->getLabel(); + $archiveProcessing = Piwik_ArchiveProcessing::factory($periodLabel); + $archiveProcessing->setSite($this->site); + $archiveProcessing->setPeriod($this->period); + $IdArchive = $archiveProcessing->loadArchive(); + + $isThereSomeVisits = Zend_Registry::get('db')->fetchOne( + 'SELECT value + FROM '.$archiveProcessing->getTableArchiveNumericName(). + ' WHERE name = ? AND idarchive = ?', array('nb_visits',$IdArchive)); + + if($isThereSomeVisits!==false) + { + $this->isThereSomeVisits = true; + } + $this->alreadyChecked = true; + } + } // returns a field of the archive function get( $name ) { + $this->prepareArchive(); Piwik::log("-- get '$name'"); - // we make sure the archive is available for the given date - $periodLabel = $this->period->getLabel(); - $archiveProcessing = Piwik_ArchiveProcessing::factory($periodLabel); - $archiveProcessing->setSite($this->site); - $archiveProcessing->setPeriod($this->period); - $IdArchive = $archiveProcessing->loadArchive(); + + if(!$this->isThereSomeVisits) + { + return false; + } + return 1; + // select the data requested + } // fetches many fields at once for performance diff --git a/modules/ArchiveProcessing.php b/modules/ArchiveProcessing.php index 69973551ea..b7ac4ef3d2 100644 --- a/modules/ArchiveProcessing.php +++ b/modules/ArchiveProcessing.php @@ -33,7 +33,7 @@ abstract class Piwik_ArchiveProcessing protected $maxTimestampArchive; // Attributes that can be used by plugins - public $idsite; + public $idsite = null; public $period = null; public $site = null; @@ -70,6 +70,10 @@ abstract class Piwik_ArchiveProcessing } } + public function getTableArchiveNumericName() + { + return $this->tableArchiveNumeric; + } // to be used only once public function setPeriod( Piwik_Period $period ) { @@ -88,9 +92,11 @@ abstract class Piwik_ArchiveProcessing if(!$idArchive) { $this->idArchivesSubperiods = $this->loadSubperiodsArchive(); + $this->initCompute(); $this->compute(); $this->postCompute(); + Piwik::log("New archive computed, id = {$this->idArchives}"); } else @@ -120,22 +126,18 @@ abstract class Piwik_ArchiveProcessing $this->logActionTable = Piwik::prefixTable('log_action'); } - protected function loadNextIdarchives() - { - $db = Zend_Registry::get('db'); - $id = $db->fetchOne("SELECT max(idarchive) FROM ".$this->tableArchiveNumeric); - if(empty($id)) - { - $id = 1; - } - $this->idArchives = $id; - - } protected function postCompute() { // echo "<br>".Piwik_Archive_ProcessingRecord_Manager::getInstance()->toString(); + // delete the first done = ERROR + Zend_Registry::get('db')->query(" + DELETE FROM ".$this->tableArchiveNumeric." + WHERE idarchive = ? AND name = 'done'", + array($this->idArchives) + ); + $finalRecord = new Piwik_Archive_Processing_Record_Numeric('done', Piwik_ArchiveProcessing::DONE_OK); // save in the database the records @@ -145,13 +147,25 @@ abstract class Piwik_ArchiveProcessing { $this->insertRecord( $record); } - // save the final record 'done' + + // we delete all tables from the table register + Piwik_Archive_Processing_Record_Manager::getInstance()->deleteAll(); } - protected function insertRecord($record) + + protected function loadNextIdarchives() { $db = Zend_Registry::get('db'); + $id = $db->fetchOne("SELECT max(idarchive) FROM ".$this->tableArchiveNumeric); + if(empty($id)) + { + $id = 0; + } + $this->idArchives = $id + 1; + } + protected function insertRecord($record) + { // table to use to save the data if(is_numeric($record->value)) { @@ -164,7 +178,7 @@ abstract class Piwik_ArchiveProcessing $query = "INSERT INTO ".$table." (idarchive, idsite, date1, date2, period, ts_archived, name, value) VALUES (?,?,?,?,?,?,?,?)"; - $db->query($query, array( $this->idArchives, + Zend_Registry::get('db')->query($query, array( $this->idArchives, $this->idsite, $this->strDateStart, $this->strDateEnd, diff --git a/modules/ArchiveProcessing/Day.php b/modules/ArchiveProcessing/Day.php index 9431d161e0..78d1a08242 100644 --- a/modules/ArchiveProcessing/Day.php +++ b/modules/ArchiveProcessing/Day.php @@ -1,17 +1,11 @@ <?php class Piwik_ArchiveProcessing_Day extends Piwik_ArchiveProcessing { - static protected $actionCategoryDelimiter = null; function __construct() { - $this->setCategoryDelimiter( Zend_Registry::get('config')->General->action_category_delimiter); $this->db = Zend_Registry::get('db'); } - public function setCategoryDelimiter($delimiter) - { - self::$actionCategoryDelimiter = $delimiter; - } /** * Reads the log and compute the essential reports. @@ -27,8 +21,7 @@ class Piwik_ArchiveProcessing_Day extends Piwik_ArchiveProcessing * */ protected function compute() - { - + { $query = "SELECT count(distinct visitor_idcookie) as nb_uniq_visitors, count(*) as nb_visits, sum(visit_total_actions) as nb_actions, @@ -44,7 +37,7 @@ class Piwik_ArchiveProcessing_Day extends Piwik_ArchiveProcessing if($row === false) { - throw new Exception("TODO to implement when no visit"); + return; } foreach($row as $name => $value) @@ -52,49 +45,29 @@ class Piwik_ArchiveProcessing_Day extends Piwik_ArchiveProcessing $record = new Piwik_Archive_Processing_Record_Numeric($name, $value); } Piwik::log($row); -/* - $query = "SELECT count(distinct l.idaction) as nb_uniq_actions - FROM ".$this->logTable." as v - LEFT JOIN ".$this->logActionTable." as l USING (idvisit) - WHERE v.visit_server_date = ? - AND v.idsite = ? - LIMIT 1"; - $row = $this->db->fetchRow($query, array( $this->strDateStart, $this->idsite ) ); - $record = new Piwik_Archive_Processing_Numeric_Record('nb_uniq_actions', $row['nb_uniq_actions']); - */ - $query = "SELECT count(distinct visitor_idcookie) as nb_uniq_visitors_returning, - count(*) as nb_visits_returning, - sum(visit_total_actions) as nb_actions_returning, - max(visit_total_actions) as max_actions_returning, - sum(visit_total_time) as sum_visit_length_returning, - sum(case visit_total_actions when 1 then 1 else 0 end) as bounce_count_returning - FROM ".$this->logTable." - WHERE visit_server_date = ? - AND idsite = ? - AND visitor_returning = 1 - GROUP BY visitor_returning"; - $row = $this->db->fetchRow($query, array( $this->strDateStart, $this->idsite ) ); + + Piwik_PostEvent('ArchiveProcessing_Day.compute', $this); + } + + public function getSimpleDataTableFromSelect($select, $labelCount) + { + $query = "SELECT $select + FROM ".$this->logTable." + WHERE visit_server_date = ? + AND idsite = ?"; + $data = $this->db->fetchRow($query, array( $this->strDateStart, $this->idsite )); - foreach($row as $name => $value) + foreach($data as $label => &$count) { - $record = new Piwik_Archive_Processing_Record_Numeric($name, $value); + $count = array($labelCount => $count); } - - - /** - * referers - */ -// $this->computeReferer(); - - /** - * actions - */ -// $this->computeActions(); - - Piwik_PostEvent('ArchiveProcessing_Day.compute', $this); + $table = new Piwik_DataTable; + $table->loadFromArrayLabelIsKey($data); + return $table; } + public function getDataTableInterestForLabel( $label ) { $query = "SELECT $label as label, @@ -132,160 +105,6 @@ class Piwik_ArchiveProcessing_Day extends Piwik_ArchiveProcessing return $table; } - static public function getActionCategoryFromName($name) - { - // case the name is an URL we dont clean the name the same way - if(Piwik_Common::isUrl($name)) - { - $split = array($name); - } - else - { - $split = explode(self::$actionCategoryDelimiter, $name); - } - return $split; - } - - /** - * Compute all the actions along with their hierarchies. - * - * For each action we process the "interest statistics" : - * visits, unique visitors, bouce count, sum visit length. - * - * - */ - protected function computeActions() - { - $this->actionsTablesByType = array(); - $timer = new Piwik_Timer; - - /* - * Actions global information - */ - $query = "SELECT name, - type, - count(distinct idvisit) as nb_visits, - count(*) as nb_hits - FROM (".$this->logTable." - LEFT JOIN ".$this->logVisitActionTable." USING (idvisit)) - LEFT JOIN ".$this->logActionTable." USING (idaction) - WHERE visit_server_date = ? - AND idsite = ? - GROUP BY idaction - "; - $query = $this->db->query($query, array( $this->strDateStart, $this->idsite )); - - $modified = $this->updateActionsTableWithRowQuery($query); - - Piwik::log("$modified rows for all actions"); - - - /* - * Entry actions - */ - $query = "SELECT name, - type, - count(distinct visitor_idcookie) as entry_nb_unique_visitor, - count(*) as entry_nb_visits, - sum(visit_total_actions) as entry_nb_actions, - sum(visit_total_time) as entry_sum_visit_length, - sum(case visit_total_actions when 1 then 1 else 0 end) as entry_bounce_count - - FROM ".$this->logTable." - LEFT JOIN ".$this->logActionTable." ON (visit_entry_idaction = idaction) - WHERE visit_server_date = ? - AND idsite = ? - GROUP BY visit_entry_idaction - "; - $query = $this->db->query($query, array( $this->strDateStart, $this->idsite )); - - $modified = $this->updateActionsTableWithRowQuery($query); - - Piwik::log("$modified rows for entry actions"); - - - /* - * Exit actions - */ - $query = "SELECT name, - type, - count(distinct visitor_idcookie) as exit_nb_unique_visitor, - count(*) as exit_nb_visits, - sum(case visit_total_actions when 1 then 1 else 0 end) as exit_bounce_count - - FROM ".$this->logTable." - LEFT JOIN ".$this->logActionTable." ON (visit_exit_idaction = idaction) - WHERE visit_server_date = ? - AND idsite = ? - GROUP BY visit_exit_idaction - "; - $query = $this->db->query($query, array( $this->strDateStart, $this->idsite )); - - $modified = $this->updateActionsTableWithRowQuery($query); - - Piwik::log("$modified rows for exit actions"); - - - require_once "LogStats/Action.php"; - $data = $this->generateDataTable($this->actionsTablesByType[Piwik_LogStats_Action::TYPE_ACTION]); - $s = $data->getSerialized(); - - $record = new Piwik_Archive_Processing_Record_Blob_Array('actions', $s); - -// var_export($s); - print(" serialized has ".count($s)." elements"); - -// var_export($this->actionsTablesByType); - } - - protected function updateActionsTableWithRowQuery($query) - { - $rowsProcessed = 0; - - while( $row = $query->fetch() ) - { - // split the actions by category - $aActions = $this->getActionCategoryFromName($row['name']); - - $currentTable =& $this->actionsTablesByType[$row['type']]; - - // go at the level of this subcategory - foreach($aActions as $actionCategory) - { - $currentTable =& $currentTable[$actionCategory]; - } - - // add the row to the matching sub category subtable - if(!($currentTable instanceof Piwik_DataTable_Row)) - { - $currentTable = new Piwik_DataTable_Row( - array( Piwik_DataTable_Row::COLUMNS => - array( 'label' => (string)$actionCategory, - ) - ) - ); - } - foreach($row as $name => $value) - { - // we don't add this information as it not pertinent - // name is already set as the label // and it has been cleaned from the categories and extracted from the initial string - // type is used to partition the different actions type in different table. Adding the info to the row would be a duplicate. - if($name != 'name' && $name != 'type') - { - $currentTable->addColumn($name, $value); - } - } - - // simple count - $rowsProcessed++; - } - - // just to make sure php copies the last $currentTable in the $parentTable array - $currentTable =& $this->actionsTablesByType; - - return $rowsProcessed; - } - static public function generateDataTable( $table ) { $dataTableToReturn = new Piwik_DataTable; @@ -314,159 +133,16 @@ class Piwik_ArchiveProcessing_Day extends Piwik_ArchiveProcessing return $dataTableToReturn; } - protected function computeReferer() + public function getDataTableSerialized( $arrayLevel0 ) { - $query = "SELECT referer_type, - referer_name, - referer_keyword, - referer_url, - count(distinct visitor_idcookie) as nb_uniq_visitors, - count(*) as nb_visits, - sum(visit_total_actions) as nb_actions, - max(visit_total_actions) as max_actions, - sum(visit_total_time) as sum_visit_length, - sum(case visit_total_actions when 1 then 1 else 0 end) as bounce_count - FROM ".$this->logTable." - WHERE visit_server_date = ? - AND idsite = ? - GROUP BY referer_type, referer_name, referer_keyword"; - $query = $this->db->query($query, array( $this->strDateStart, $this->idsite )); - - $timer = new Piwik_Timer; - while($rowBefore = $query->fetch() ) - { - $row = array( - Piwik_Archive::INDEX_NB_UNIQ_VISITORS => $rowBefore['nb_uniq_visitors'], - Piwik_Archive::INDEX_NB_VISITS => $rowBefore['nb_visits'], - Piwik_Archive::INDEX_NB_ACTIONS => $rowBefore['nb_actions'], - Piwik_Archive::INDEX_MAX_ACTIONS => $rowBefore['max_actions'], - Piwik_Archive::INDEX_SUM_VISIT_LENGTH => $rowBefore['sum_visit_length'], - Piwik_Archive::INDEX_BOUNCE_COUNT => $rowBefore['bounce_count'], - 'referer_type' => $rowBefore['referer_type'], - 'referer_name' => $rowBefore['referer_name'], - 'referer_keyword' => $rowBefore['referer_keyword'], - 'referer_url' => $rowBefore['referer_url'], - ); - - switch($row['referer_type']) - { - case Piwik_Common::REFERER_TYPE_SEARCH_ENGINE: - - if(!isset($interestBySearchEngine[$row['referer_name']])) $interestBySearchEngine[$row['referer_name']]= $this->getNewInterestRow(); - if(!isset($interestByKeyword[$row['referer_keyword']])) $interestByKeyword[$row['referer_keyword']]= $this->getNewInterestRow(); - if(!isset($keywordBySearchEngine[$row['referer_name']][$row['referer_keyword']])) $keywordBySearchEngine[$row['referer_name']][$row['referer_keyword']]= $this->getNewInterestRow(); - if(!isset($searchEngineByKeyword[$row['referer_keyword']][$row['referer_name']])) $searchEngineByKeyword[$row['referer_keyword']][$row['referer_name']]= $this->getNewInterestRow(); - - $this->updateInterestStats( $row, $interestBySearchEngine[$row['referer_name']]); - $this->updateInterestStats( $row, $interestByKeyword[$row['referer_keyword']]); - $this->updateInterestStats( $row, $keywordBySearchEngine[$row['referer_name']][$row['referer_keyword']]); - $this->updateInterestStats( $row, $searchEngineByKeyword[$row['referer_keyword']][$row['referer_name']]); - break; - - case Piwik_Common::REFERER_TYPE_WEBSITE: - case Piwik_Common::REFERER_TYPE_PARTNER: - - // for a website we remove the HOST from the url, to save some bytes in the DB - // for partners URLs we keep the full URL as the partner's name can be an alias and - // so is not necessarily the hostname of the URL... - if($row['referer_type']==Piwik_Common::REFERER_TYPE_WEBSITE - && !empty($row['referer_url'])) - { - $row['referer_url'] = Piwik_Common::getPathAndQueryFromUrl($row['referer_url']); - } - - if(!isset($interestByWebsite[$row['referer_type']][$row['referer_name']])) $interestByWebsite[$row['referer_type']][$row['referer_name']]= $this->getNewInterestRow(); - $this->updateInterestStats( $row, $interestByWebsite[$row['referer_type']][$row['referer_name']]); - - if(!isset($urlByWebsite[$row['referer_type']][$row['referer_name']][$row['referer_url']])) $urlByWebsite[$row['referer_type']][$row['referer_name']][$row['referer_url']]= $this->getNewInterestRow(); - $this->updateInterestStats( $row, $urlByWebsite[$row['referer_type']][$row['referer_name']][$row['referer_url']]); - - break; - - case Piwik_Common::REFERER_TYPE_NEWSLETTER: - if(!isset($interestByNewsletter[$row['referer_name']])) $interestByNewsletter[$row['referer_name']]= $this->getNewInterestRow(); - $this->updateInterestStats( $row, $interestByNewsletter[$row['referer_name']]); - - break; - - case Piwik_Common::REFERER_TYPE_CAMPAIGN: - if(!empty($row['referer_keyword'])) - { - if(!isset($keywordByCampaign[$row['referer_name']][$row['referer_keyword']])) $keywordByCampaign[$row['referer_name']][$row['referer_keyword']]= $this->getNewInterestRow(); - $this->updateInterestStats( $row, $keywordByCampaign[$row['referer_name']][$row['referer_keyword']]); - } - if(!isset($interestByCampaign[$row['referer_name']])) $interestByCampaign[$row['referer_name']]= $this->getNewInterestRow(); - $this->updateInterestStats( $row, $interestByCampaign[$row['referer_name']]); - break; - } - - if(!isset($interestByType[$row['referer_type']] )) $interestByType[$row['referer_type']] = $this->getNewInterestRow(); - $this->updateInterestStats($row, $interestByType[$row['referer_type']]); - } - echo "after loop = ". $timer; - -// Piwik::log("By search engine:"); -// Piwik::log($interestBySearchEngine); -// Piwik::log("By keyword:"); -// Piwik::log($interestByKeyword); -// Piwik::log("Kwd by search engine:"); -// Piwik::log($keywordBySearchEngine); -// Piwik::log("Search engine by keyword:"); -// Piwik::log($searchEngineByKeyword); -// - -// Piwik::log("By campaign:"); -// Piwik::log($interestByCampaign); -// Piwik::log("Kwd by campaign:"); -// Piwik::log($keywordByCampaign); - - -// Piwik::log("By referer type:"); -// Piwik::log($interestByType); - -// Piwik::log("By website:"); -// Piwik::log($interestByWebsite[Piwik_Common::REFERER_TYPE_WEBSITE]); -// Piwik::log("Urls by website:"); -// Piwik::log($urlByWebsite[Piwik_Common::REFERER_TYPE_WEBSITE]); -// Piwik::log("By partner website:"); -// Piwik::log($interestByWebsite[Piwik_Common::REFERER_TYPE_PARTNER]); -// Piwik::log("Urls by partner website:"); -// Piwik::log($urlByWebsite[Piwik_Common::REFERER_TYPE_PARTNER]); - - - $data = $this->getDataTableSerialized($interestByType); - $record = new Piwik_Archive_Processing_Record_Blob_Array('referer_type', $data); - - $data = $this->getDataTablesSerialized($keywordBySearchEngine, $interestBySearchEngine); - $record = new Piwik_Archive_Processing_Record_Blob_Array('referer_keyword_by_searchengine', $data); - - var_export($data); - - $data = $this->getDataTablesSerialized($searchEngineByKeyword, $interestByKeyword); - $record = new Piwik_Archive_Processing_Record_Blob_Array('referer_searchengine_by_keyword', $data); - - $data = $this->getDataTablesSerialized($keywordByCampaign, $interestByCampaign); - $record = new Piwik_Archive_Processing_Record_Blob_Array('referer_keyword_by_campaign', $data); - - $data = $this->getDataTablesSerialized($urlByWebsite[Piwik_Common::REFERER_TYPE_WEBSITE], $interestByWebsite[Piwik_Common::REFERER_TYPE_WEBSITE]); - $record = new Piwik_Archive_Processing_Record_Blob_Array('referer_url_by_website', $data); - - $data = $this->getDataTablesSerialized($urlByWebsite[Piwik_Common::REFERER_TYPE_PARTNER], $interestByWebsite[Piwik_Common::REFERER_TYPE_PARTNER]); - $record = new Piwik_Archive_Processing_Record_Blob_Array('referer_url_by_partner', $data); - - echo "after serialization = ". $timer; - } - - protected function getDataTableSerialized( $arrayLevel0 ) - { - $table->loadFromArrayLabelIsKey($arrayLevel0); $table = new Piwik_DataTable; + $table->loadFromArrayLabelIsKey($arrayLevel0); $toReturn = $table->getSerialized(); return $toReturn; } - protected function getDataTablesSerialized( $arrayLevel0, $subArrayLevel1ByKey) + public function getDataTablesSerialized( $arrayLevel0, $subArrayLevel1ByKey) { $tablesByLabel = array(); @@ -479,13 +155,13 @@ class Piwik_ArchiveProcessing_Day extends Piwik_ArchiveProcessing $parentTableLevel0 = new Piwik_DataTable; $parentTableLevel0->loadFromArrayLabelIsKey($subArrayLevel1ByKey, $tablesByLabel); -// $render = new Piwik_DataTable_Renderer_Console( $parentTableLevel0 ); +// echo $parentTableLevel0; $toReturn = $parentTableLevel0->getSerialized(); return $toReturn; } - protected function getNewInterestRow() + public function getNewInterestRow() { return array( Piwik_Archive::INDEX_NB_UNIQ_VISITORS => 0, Piwik_Archive::INDEX_NB_VISITS => 0, @@ -496,7 +172,7 @@ class Piwik_ArchiveProcessing_Day extends Piwik_ArchiveProcessing ); } - protected function updateInterestStats( $newRowToAdd, &$oldRowToUpdate) + public function updateInterestStats( $newRowToAdd, &$oldRowToUpdate) { $oldRowToUpdate[Piwik_Archive::INDEX_NB_UNIQ_VISITORS] += $newRowToAdd[Piwik_Archive::INDEX_NB_UNIQ_VISITORS]; $oldRowToUpdate[Piwik_Archive::INDEX_NB_VISITS] += $newRowToAdd[Piwik_Archive::INDEX_NB_VISITS]; diff --git a/modules/ArchiveProcessing/Record.php b/modules/ArchiveProcessing/Record.php index acde20f9cc..bfb82a6367 100644 --- a/modules/ArchiveProcessing/Record.php +++ b/modules/ArchiveProcessing/Record.php @@ -48,6 +48,10 @@ class Piwik_Archive_Processing_Record_Manager { return $this->records; } + public function deleteAll() + { + unset($this->records); + } } abstract class Piwik_Archive_Processing_Record diff --git a/modules/Common.php b/modules/Common.php index c052af653f..6abece1f09 100644 --- a/modules/Common.php +++ b/modules/Common.php @@ -361,7 +361,7 @@ class Piwik_Common /** - * Returns the best possible IP + * Returns the best possible IP in the format A.B.C.D * * @return string ip */ diff --git a/modules/DataTable.php b/modules/DataTable.php index dba6a5874e..e2c1032ea1 100644 --- a/modules/DataTable.php +++ b/modules/DataTable.php @@ -127,7 +127,8 @@ class Piwik_DataTable_Manager function addTable( $table ) { $this->tables[] = $table; - return count($this->tables); + $this->count++; + return $this->count; } function getTable( $idTable ) @@ -445,7 +446,7 @@ class Piwik_DataTable_Row_ActionTableSummary extends Piwik_DataTable_Row foreach($columns as $name => $value) { if($name != 'label' - && ( is_int($value) || is_float($value) ) + && ( Piwik::isNumeric($value) ) ) { if(!isset($currentColumns[$name])) @@ -605,7 +606,7 @@ class Piwik_DataTable_Row { foreach($rowToSum->getColumns() as $name => $value) { - if(is_int($value) || is_float($value)) + if(Piwik::isNumeric($value)) { $current = $this->getColumn($name); if($current==false) diff --git a/modules/DataTable/Renderer.php b/modules/DataTable/Renderer.php index 74b95c443a..06aca5d62f 100644 --- a/modules/DataTable/Renderer.php +++ b/modules/DataTable/Renderer.php @@ -47,6 +47,7 @@ class Piwik_DataTable_Renderer_Console extends Piwik_DataTable_Renderer $columns=array(); foreach($row->getColumns() as $column => $value) { + if(is_string($value)) $value = "'$value'"; $columns[] = "'$column' => $value"; } $columns = implode(", ", $columns); diff --git a/modules/LogStats.php b/modules/LogStats.php index 3b15aa0412..ef10f58285 100644 --- a/modules/LogStats.php +++ b/modules/LogStats.php @@ -76,6 +76,8 @@ class Piwik_LogStats private function initProcess() { + Piwik_PluginsManager::getInstance()->setPluginsToLoad( Piwik_LogStats_Config::getInstance()->Plugins_LogStats['enabled'] ); + $saveStats = Piwik_LogStats_Config::getInstance()->LogStats['record_statistics']; if($saveStats == 0) diff --git a/modules/LogStats/Generator.php b/modules/LogStats/Generator.php index 3f03205021..c540ac530a 100644 --- a/modules/LogStats/Generator.php +++ b/modules/LogStats/Generator.php @@ -277,7 +277,7 @@ class Piwik_LogStats_Generator { if(rand(0,2)==1) { - $this->setCurrentRequest( 'action_name' , $this->getRandomString(8,4)); + $this->setCurrentRequest( 'action_name' , $this->getRandomString(3,3)); } } } @@ -292,10 +292,10 @@ class Piwik_LogStats_Generator { $url = $host; - $deep = mt_rand(0,5); + $deep = mt_rand(0,2); for($i=0;$i<$deep;$i++) { - $name = $this->getRandomString(5,3,'ALNUM'); + $name = $this->getRandomString(1,2,'alnum'); $url .= '/'.$name; } @@ -308,8 +308,7 @@ class Piwik_LogStats_Generator $len = mt_rand($minLength, $maxLength); // Register the lower case alphabet array - $alpha = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); + $alpha = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm'); // Register the upper case alphabet array $ALPHA = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', @@ -343,6 +342,9 @@ class Piwik_LogStats_Generator case 'ALPHA' : $keyVals = array_merge($alpha, $ALPHA); break; + case 'alnum' : + $keyVals = array_merge($alpha, $num); + break; case 'ALNUM' : $keyVals = array_merge($alpha, $ALPHA, $num); break; diff --git a/modules/LogStats/Plugins.php b/modules/LogStats/Plugins.php deleted file mode 100644 index 70ce3d3bf7..0000000000 --- a/modules/LogStats/Plugins.php +++ /dev/null @@ -1,47 +0,0 @@ -<?php - -class Piwik_Plugin_LogStats_Provider extends Piwik_Plugin -{ - public function __construct() - { - } - - public function getInformation() - { - $info = array( - 'name' => 'LogProvider', - 'description' => 'Log in the DB the hostname looked up from the IP', - 'author' => 'Piwik', - 'homepage' => 'http://piwik.org/plugins/LogProvider', - 'version' => '0.1', - ); - - return $info; - } - - function install() - { - // add column hostname / hostname ext in the visit table - } - - function uninstall() - { - // add column hostname / hostname ext in the visit table - } - - function getListHooksRegistered() - { - $hooks = array( - 'LogsStats.NewVisitor' => 'detectHostname' - ); - return $hooks; - } - - function detectHostname( $notification ) - { - $object = $notification->getNotificationObject(); - printDebug(); - } -} - -?> diff --git a/modules/LogStats/Visit.php b/modules/LogStats/Visit.php index 7cc3c676fe..04d0c38c5d 100644 --- a/modules/LogStats/Visit.php +++ b/modules/LogStats/Visit.php @@ -33,9 +33,7 @@ class Piwik_LogStats_Visit { return date("Y-m-d H:i:s",$timestamp); } - - - + // test if the visitor is excluded because of // - IP // - cookie @@ -121,8 +119,8 @@ class Piwik_LogStats_Visit printDebug("The visitor is known because he has the piwik cookie (idcookie = {$this->visitorInfo['visitor_idcookie']}, idvisit = {$this->visitorInfo['idvisit']}, last action = ".date("r", $this->visitorInfo['visit_last_action_time']).") "); } - } - + } + /* * If the visitor doesn't have the piwik cookie, we look for a visitor that has exactly the same configuration * and that visited the website today. @@ -131,7 +129,7 @@ class Piwik_LogStats_Visit { $userInfo = $this->getUserSettingsInformation(); $md5Config = $userInfo['config_md5config']; - + $visitRow = $this->db->fetch( " SELECT visitor_idcookie, UNIX_TIMESTAMP(visit_last_action_time) as visit_last_action_time, @@ -282,7 +280,9 @@ class Piwik_LogStats_Visit $this->recognizeTheVisitor(); - if($this->isVisitorKnown() + //TODO delete + if(false + &&$this->isVisitorKnown() && $this->isLastActionInTheSameVisit()) { $this->handleKnownVisit(); @@ -473,6 +473,7 @@ class Piwik_LogStats_Visit 'location_continent' => $continent, ); + Piwik_PostEvent('LogStats.newVisitorInformation', &$informationToSave); $fields = implode(", ", array_keys($informationToSave)); $values = substr(str_repeat( "?,",count($informationToSave)),0,-1); diff --git a/modules/Piwik.php b/modules/Piwik.php index f6fa760764..831b280a45 100755 --- a/modules/Piwik.php +++ b/modules/Piwik.php @@ -22,7 +22,24 @@ class Piwik Zend_Registry::get('logger_message')->log($message); Zend_Registry::get('logger_message')->log( "<br>" . PHP_EOL); } - + //TODO TEST secureDiv + static public function secureDiv( $i1, $i2 ) + { + if ( is_numeric($i1) && is_numeric($i2) && floatval($i2) != 0) + { + return $i1 / $i2; + } + return 0; + } + static public function printMemoryUsage() + { + $usage = round(memory_get_usage() / 1024 / 1024, 2); + Piwik::log("Memory usage = $usage Mb"); + } + static public function isNumeric($value) + { + return !is_array($value) && ereg('^([0-9.]*)$', $value); + } static public function loadPlugins() { Piwik_PluginsManager::getInstance()->setPluginsToLoad( Zend_Registry::get('config')->Plugins->enabled ); @@ -195,29 +212,27 @@ class Piwik ", 'archive_numeric' => "CREATE TABLE {$prefixTables}archive_numeric ( - - idarchive INTEGER UNSIGNED NOT NULL, - idsite INTEGER UNSIGNED NULL, - date1 DATE NULL, - date2 DATE NULL, - period TINYINT UNSIGNED NULL, - ts_archived DATETIME NULL, - name VARCHAR(255) NULL, - value FLOAT NULL, - INDEX i1(idarchive, name) -); + idarchive INTEGER UNSIGNED NOT NULL, + name VARCHAR(255) NOT NULL, + idsite INTEGER UNSIGNED NULL, + date1 DATE NULL, + date2 DATE NULL, + period TINYINT UNSIGNED NULL, + ts_archived TIME NULL, + value FLOAT NULL, + PRIMARY KEY(idarchive, name) + ) ", 'archive_blob' => "CREATE TABLE {$prefixTables}archive_blob ( - - idarchive INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, + idarchive INTEGER UNSIGNED NOT NULL, + name VARCHAR(255) NOT NULL, idsite INTEGER UNSIGNED NULL, date1 DATE NULL, date2 DATE NULL, period TINYINT UNSIGNED NULL, ts_archived DATETIME NULL, - name VARCHAR(255) NULL, value BLOB NULL, - INDEX i1(idarchive, name) + PRIMARY KEY(idarchive, name) ) ", ); diff --git a/modules/PluginsManager.php b/modules/PluginsManager.php index 4141f4d206..94a8b36faf 100644 --- a/modules/PluginsManager.php +++ b/modules/PluginsManager.php @@ -24,12 +24,14 @@ * */ require_once "Plugin.php"; +require_once "Event/Dispatcher.php"; class Piwik_PluginsManager { public $dispatcher; private $pluginsPath; protected $pluginsToLoad = array(); + protected $installPlugins = false; static private $instance = null; @@ -57,6 +59,15 @@ class Piwik_PluginsManager $this->loadPlugins(); } + + public function setInstallPlugins() + { + $this->installPlugins = true; + } + public function doInstallPlugins() + { + return $this->installPlugins; + } /** * Load the plugins classes installed. * Register the observers for every plugin. @@ -95,6 +106,16 @@ class Piwik_PluginsManager } $newPlugin = new $pluginClassName; + + if($this->doInstallPlugins()) + { + try{ + $newPlugin->install(); + } catch(Exception $e) { + //TODO Better plugin management.... + } + } + $this->addPluginObservers( $newPlugin ); } } @@ -108,7 +129,7 @@ class Piwik_PluginsManager foreach($hooks as $hookName => $methodToCall) { - $this->dispatcher->addObserver( array( $plugin, $methodToCall) ); + $this->dispatcher->addObserver( array( $plugin, $methodToCall), $hookName ); } } |