Skip to content

Commit

Permalink
- new feature: you can now disable the automatic archiving triggering…
Browse files Browse the repository at this point in the history
… from the piwik UI. Useful when launching the archiving from the cron overnight.
  • Loading branch information
matt committed May 11, 2008
1 parent 98cf83c commit ef3ab14
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 73 deletions.
37 changes: 10 additions & 27 deletions config/global.ini.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
; Possible values: yesterday, today, or any YYYY-MM-DD
default_day = yesterday

; When loading the piwik interface in the browser (as opposed to from the PHP-CLI client)
; should we launch the archiving process if the archives have not yet been processed?
; You want to set it to false when triggering the archiving through a crontab,
; so that your users do not trigger archiving in their browser when this is not expected
enable_browser_archiving_triggering = true

; character used to automatically create categories in the "Action" "Downloads" reports
; for example a URL like "example.com/blog/development/first-post" will create
; the page first-post in the subcategory development which belongs to the blog category
Expand Down Expand Up @@ -134,61 +140,38 @@

[log]

;possible values for log: screen, database, file
; normal messages
logger_message[] = screen
;logger_message[] = database
;logger_message[] = file

; all calls to the API (method name, parameters, execution time, caller IP, etc.)
;logger_api_call[] = screen
;logger_api_call[] = database
;logger_api_call[] = file

; error intercepted
logger_error[] = screen
;logger_error[] = database
;logger_error[] = file

; exception raised
logger_exception[] = screen
;logger_exception[] = database
;logger_exception[] = file

; query profiling information (SQL, avg execution time, etc.)
logger_query_profile[] = screen
;logger_query_profile[] = database
;logger_query_profile[] = file
; all calls to the API (method name, parameters, execution time, caller IP, etc.)
;logger_api_call[] = file

[log_tests]
logger_message[] = screen
logger_api_call[] = screen
logger_error[] = screen
logger_exception[] = screen
logger_query_profile[] = screen


[path]
log = tmp/logs/


[smarty]
; the list of directories in which to look for templates
template_dir[] = plugins
template_dir[] = themes/default
template_dir[] = themes

; smarty provided plugins
plugins_dir[] = libs/Smarty/plugins
; smarty plugins provided by piwik
plugins_dir[] = modules/SmartyPlugins

; where to store the compiled smarty templates
compile_dir = tmp/templates_c

cache_dir = tmp/cache

; error reporting inside Smarty
error_reporting = E_ALL|E_NOTICE

; should be set to false in a piwik release
; allow smarty debugging using {debug}
debugging = true
17 changes: 9 additions & 8 deletions modules/Archive/Single.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public function getPrettyDate()
*/
public function getIdArchive()
{
if(is_null($this->idArchive))
{
throw new Exception("idArchive is null");
}
return $this->idArchive;
}

Expand Down Expand Up @@ -131,21 +135,20 @@ public function prepareArchive()
{
if(!$this->alreadyChecked)
{
$this->isThereSomeVisits = false;
$this->alreadyChecked = true;

// if the END of the period is BEFORE the website creation date
// we already know there are no stats for this period
// we add one day to make sure we don't miss the day of the website creation
if( $this->period->getDateEnd()->addDay(2)->isEarlier( $this->site->getCreationDate() ) )
{
$this->isThereSomeVisits = false;
$this->alreadyChecked = true;
return;
}

// if the starting date is in the future we know there is no visit
if( $this->period->getDateStart()->subDay(1)->isLater( Piwik_Date::today() ) )
{
$this->isThereSomeVisits = false;
$this->alreadyChecked = true;
return;
}

Expand All @@ -155,12 +158,12 @@ public function prepareArchive()
$archiveProcessing->setSite($this->site);
$archiveProcessing->setPeriod($this->period);

$IdArchive = $archiveProcessing->loadArchive();
$idArchive = $archiveProcessing->loadArchive();
$this->isThereSomeVisits = $archiveProcessing->isThereSomeVisits;

$this->archiveProcessing = $archiveProcessing;

$this->idArchive = $IdArchive;
$this->idArchive = $idArchive;
$this->alreadyChecked = true;
}
}
Expand Down Expand Up @@ -316,8 +319,6 @@ public function freeBlob( $name )
*/
public function preFetchBlob( $name )
{
// Piwik::log("-- prefetch blob ".$name."_*");

if(!$this->isThereSomeVisits)
{
return false;
Expand Down
109 changes: 71 additions & 38 deletions modules/ArchiveProcessing.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,15 @@ public function loadArchive()
{
$this->loadArchiveProperties();
$this->idArchive = $this->isArchived();

if($this->idArchive === false
|| $this->debugAlwaysArchive)

if($this->isArchivingDisabled())
{
$this->archivesSubperiods = $this->loadSubperiodsArchive();
$this->initCompute();
$this->compute();
$this->postCompute();
// we execute again the isArchived that does some initialization work
$this->idArchive = $this->isArchived();
$this->isThereSomeVisits = false;
}
elseif($this->idArchive === false
|| $this->debugAlwaysArchive)
{
$this->launchArchiving();
}
else
{
Expand All @@ -294,6 +293,20 @@ public function loadArchive()
return $this->idArchive;
}

/**
* @see loadArchive()
*
*/
protected function launchArchiving()
{
$this->archivesSubperiods = $this->loadSubperiodsArchive();
$this->initCompute();
$this->compute();
$this->postCompute();
// we execute again the isArchived that does some initialization work
$this->idArchive = $this->isArchived();
}

/**
* This methods reads the subperiods if necessary,
* and computes the archive of the current period.
Expand Down Expand Up @@ -525,46 +538,66 @@ protected function isArchived()

$results = Zend_Registry::get('db')->fetchAll($sqlQuery, $bindSQL );
// the archive exists in the table
if(!empty($results))
if(empty($results))
{
// echo $this->strDateStart . " " . $this->strDateEnd;
// var_dump($results);

$idarchive = false;
// let's look for the more recent idarchive
foreach($results as $result)
return false;
}

$idarchive = false;
// let's look for the more recent idarchive
foreach($results as $result)
{
if($result['name'] == 'done')
{
if($result['name'] == 'done')
{
$idarchive = $result['idarchive'];
$this->timestampDateStart = $result['timestamp'];
break;
}
$idarchive = $result['idarchive'];
$this->timestampDateStart = $result['timestamp'];
break;
}

if($idarchive === false)
}

if($idarchive === false)
{
throw new Exception("Error during the archiving process: ". var_export($results,true));
}

// let's look for the nb_visits result for this more recent archive
foreach($results as $result)
{
if($result['name'] == 'nb_visits'
&& $result['idarchive'] == $idarchive)
{
throw new Exception("Error during the archiving process: ". var_export($results,true));
$this->isThereSomeVisits = ($result['value'] != 0);
break;
}
}
return $idarchive;
}

/**
* Returns true if, for various reasons, archiving is disabled.
*
* @return bool
*/
protected function isArchivingDisabled()
{
static $archivingIsDisabled = null;

if(is_null($archivingIsDisabled))
{
$archivingIsDisabled = false;

// let's look for the nb_visits result for this more recent archive
foreach($results as $result)
$enableBrowserArchivingTriggering = (bool)Zend_Registry::get('config')->General->enable_browser_archiving_triggering;
if($enableBrowserArchivingTriggering == false)
{
if($result['name'] == 'nb_visits'
&& $result['idarchive'] == $idarchive)
$sapi_type = php_sapi_name();
if( !in_array(substr($sapi_type, 0, 3), array('cgi', 'cli')))
{
$this->isThereSomeVisits = ($result['value'] != 0);
break;
$archivingIsDisabled = true;
}
}
return $idarchive;
}
else
{
// echo "no archive for ".$this->strDateStart . " " . $this->strDateEnd; exit;
return false;
}

return $archivingIsDisabled;
}

}

0 comments on commit ef3ab14

Please sign in to comment.