Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/API/ResponseBuilder.php3
-rw-r--r--core/Archive.php45
-rw-r--r--core/ArchiveProcessor.php255
-rw-r--r--core/ArchiveProcessor/Period.php7
-rw-r--r--core/ArchiveProcessor/Rules.php207
-rw-r--r--core/DataAccess/ArchiveSelector.php267
-rw-r--r--core/Option.php14
-rw-r--r--core/Piwik.php2
-rw-r--r--core/TablePartitioning.php2
-rw-r--r--core/UpdateCheck.php2
-rw-r--r--core/Updater.php2
-rw-r--r--tests/PHPUnit/Core/ArchiveProcessingTest.php8
-rw-r--r--tests/PHPUnit/MockPiwikOption.php2
13 files changed, 286 insertions, 530 deletions
diff --git a/core/API/ResponseBuilder.php b/core/API/ResponseBuilder.php
index be5639d1c8..f74365df99 100644
--- a/core/API/ResponseBuilder.php
+++ b/core/API/ResponseBuilder.php
@@ -15,6 +15,8 @@
*/
class Piwik_API_ResponseBuilder
{
+ const DISPLAY_BACKTRACE_DEBUG = false;
+
private $request = null;
private $outputFormat = null;
@@ -133,7 +135,6 @@ class Piwik_API_ResponseBuilder
return $renderer->renderException();
}
- const DISPLAY_BACKTRACE_DEBUG = false;
/**
* @param Exception $e
diff --git a/core/Archive.php b/core/Archive.php
index 4f4717f091..a7b98cb22a 100644
--- a/core/Archive.php
+++ b/core/Archive.php
@@ -103,6 +103,8 @@ class Piwik_Archive
const INDEX_GOAL_ECOMMERCE_ITEMS = 8;
const REQUEST_ALL_WEBSITES_FLAG = 'all';
+ const ARCHIVE_ALL_PLUGINS_FLAG = 'all';
+ const ID_SUBTABLE_LOAD_ALL_SUBTABLES = 'all';
public static function getVisitsMetricNames()
{
@@ -213,7 +215,7 @@ class Piwik_Archive
const LABEL_ECOMMERCE_CART = 'ecommerceAbandonedCart';
const LABEL_ECOMMERCE_ORDER = 'ecommerceOrder';
-
+
/**
* List of archive IDs for the site, periods and segment we are querying with.
* Archive IDs are indexed by done flag and period, ie:
@@ -257,14 +259,6 @@ class Piwik_Archive
* @var bool
*/
private $forceIndexedByDate;
-
- /**
- * Cache of Piwik_ArchiveProcessor instances used when launching the archiving
- * process.
- *
- * @var array
- */
- private $processingCache = array();
/**
* @var Piwik_Archive_Parameters
@@ -284,16 +278,15 @@ class Piwik_Archive
$this->forceIndexedByDate = $forceIndexedByDate;
}
-
/**
* Builds an Archive object using query parameter values.
*
- * @param int|string $idSite Integer, or comma separated list of integer site IDs.
+ * @param $idSites
* @param string $period 'day', 'week', 'month', 'year' or 'range'
* @param Piwik_Date|string $strDate 'YYYY-MM-DD', magic keywords (ie, 'today'; @see Piwik_Date::factory())
* or date range (ie, 'YYYY-MM-DD,YYYY-MM-DD').
- * @param false|string $segment Segment definition - defaults to false for backward compatibility.
- * @param false|string $_restrictSitesToLogin Used only when running as a scheduled task.
+ * @param bool|string $segment Segment definition - defaults to false for backward compatibility.
+ * @param bool|string $_restrictSitesToLogin Used only when running as a scheduled task.
* @return Piwik_Archive
*/
public static function build($idSites, $period, $strDate, $segment = false, $_restrictSitesToLogin = false)
@@ -359,15 +352,16 @@ class Piwik_Archive
return $result;
}
-
+
/**
* Returns the value of the elements in $names from the current archive.
- *
+ *
* The value to be returned is a blob value and is stored in the archive_blob_* tables.
- *
+ *
* It can return anything from strings, to serialized PHP arrays or PHP objects, etc.
*
* @param string|array $names One or more archive names, eg, 'Referers_keywordBySearchEngine'.
+ * @param null $idSubtable
* @return string|array|false False if no value with the given name, numeric if only one site
* and date and we're not forcing an index, and array if multiple
* sites/dates are queried.
@@ -419,14 +413,14 @@ class Piwik_Archive
* Piwik_DataTable_Manager::getTable() function.
*
* @param string $name The name of the record to get.
- * @param int|string|null $idSubtable The subtable ID (if any) or 'all' if requesting every datatable.
+ * @param int|string|null $idSubtable The subtable ID (if any) or self::ID_SUBTABLE_LOAD_ALL_SUBTABLES if requesting every datatable.
* @param bool $addMetadataSubtableId Whether to add the DB subtable ID as metadata to each datatable,
* or not.
* @return Piwik_DataTable
*/
public function getDataTableExpanded($name, $idSubtable = null, $addMetadataSubtableId = true)
{
- $data = $this->get($name, 'blob', 'all');
+ $data = $this->get($name, 'blob', self::ID_SUBTABLE_LOAD_ALL_SUBTABLES);
return $data->getExpandedDataTable($this->getResultIndices(), $idSubtable, $addMetadataSubtableId);
}
@@ -502,7 +496,7 @@ class Piwik_Archive
// apply idSubtable
if ($idSubtable !== null
- && $idSubtable != 'all'
+ && $idSubtable != self::ID_SUBTABLE_LOAD_ALL_SUBTABLES
) {
foreach ($archiveNames as &$name) {
$name .= "_$idSubtable";
@@ -516,8 +510,9 @@ class Piwik_Archive
if (empty($archiveIds)) {
return $result;
}
-
- $archiveData = Piwik_DataAccess_ArchiveSelector::getArchiveData($archiveIds, $archiveNames, $archiveDataType, $idSubtable);
+
+ $loadAllSubtables = $idSubtable == self::ID_SUBTABLE_LOAD_ALL_SUBTABLES;
+ $archiveData = Piwik_DataAccess_ArchiveSelector::getArchiveData($archiveIds, $archiveNames, $archiveDataType, $loadAllSubtables);
foreach ($archiveData as $row) {
// values are grouped by idsite (site ID), date1-date2 (date range), then name (field name)
$idSite = $row['idsite'];
@@ -643,7 +638,7 @@ class Piwik_Archive
// process for each plugin as well
foreach ($archiveGroups as $plugin) {
- if ($plugin == 'all') {
+ if ($plugin == self::ARCHIVE_ALL_PLUGINS_FLAG) {
$plugin = reset($plugins);
}
@@ -672,7 +667,9 @@ class Piwik_Archive
{
$idarchivesByReport = Piwik_DataAccess_ArchiveSelector::getArchiveIds(
$this->params->getIdSites(), $this->params->getPeriods(), $this->params->getSegment(), $plugins);
-
+
+// FIXMEA: this should throw in tests! throw new Exception("this is tested");
+
// initialize archive ID cache for each report
foreach ($plugins as $plugin) {
$doneFlag = $this->getDoneStringForPlugin($plugin);
@@ -789,7 +786,7 @@ class Piwik_Archive
private function getArchiveGroupOfPlugin($plugin)
{
if ($this->getPeriodLabel() != 'range') {
- return 'all';;
+ return self::ARCHIVE_ALL_PLUGINS_FLAG;
}
return $plugin;
diff --git a/core/ArchiveProcessor.php b/core/ArchiveProcessor.php
index c475177ee1..0949408219 100644
--- a/core/ArchiveProcessor.php
+++ b/core/ArchiveProcessor.php
@@ -48,6 +48,11 @@ abstract class Piwik_ArchiveProcessor
protected $idArchive;
/**
+ * @var Piwik_DataAccess_ArchiveWriter
+ */
+ protected $archiveWriter;
+
+ /**
* Object used to generate (depending on the $dateStart) the name of the DB table to use to store numeric values
*
* @var Piwik_TablePartitioning
@@ -116,6 +121,11 @@ abstract class Piwik_ArchiveProcessor
}
return $this->logAggregator;
}
+ public function getIdArchive()
+ {
+ return $this->idArchive;
+ }
+
public function preProcessArchive($requestedPlugin, $enforceProcessCoreMetricsOnly = false)
{
@@ -161,7 +171,8 @@ abstract class Piwik_ArchiveProcessor
* Returns the idArchive if the archive is available in the database for the requested plugin.
* Returns false if the archive needs to be processed.
*
- * @return int|false
+ * @param $requestedPlugin
+ * @return int or false
*/
protected function loadExistingArchiveIdFromDb($requestedPlugin)
{
@@ -169,9 +180,8 @@ abstract class Piwik_ArchiveProcessor
$site = $this->getSite();
$period = $this->getPeriod();
$segment = $this->getSegment();
- $numericTableName = $this->getTableArchiveNumericName();
- $idAndVisits = Piwik_DataAccess_ArchiveSelector::getArchiveIdAndVisits($numericTableName, $site, $period, $segment, $minDatetimeArchiveProcessedUTC, $requestedPlugin);
+ $idAndVisits = Piwik_DataAccess_ArchiveSelector::getArchiveIdAndVisits($site, $period, $segment, $minDatetimeArchiveProcessedUTC, $requestedPlugin);
if (!$idAndVisits) {
return false;
}
@@ -180,18 +190,6 @@ abstract class Piwik_ArchiveProcessor
return $idArchive;
}
- protected static function determineIfArchivePermanent(Piwik_Date $dateEnd)
- {
- $now = time();
- $endTimestampUTC = strtotime($dateEnd->getDateEndUTC());
- if ($endTimestampUTC <= $now) {
- // - if the period we are looking for is finished, we look for a ts_archived that
- // is greater than the last day of the archive
- return $endTimestampUTC;
- }
- return false;
- }
-
/**
* Returns the minimum archive processed datetime to look at
*
@@ -201,12 +199,11 @@ abstract class Piwik_ArchiveProcessor
*/
public function getMinTimeArchivedProcessed()
{
-
$endDateTimestamp = self::determineIfArchivePermanent($this->getDateEnd());
$isArchiveTemporary = ($endDateTimestamp === false);
$this->temporaryArchive = $isArchiveTemporary;
- if($endDateTimestamp) {
+ if ($endDateTimestamp) {
// Permanent archive
return $endDateTimestamp;
}
@@ -214,6 +211,26 @@ abstract class Piwik_ArchiveProcessor
return Piwik_ArchiveProcessor_Rules::getMinTimeProcessedForTemporaryArchive($this->getDateStart(), $this->getPeriod(), $this->getSegment(), $this->getSite());
}
+ protected static function determineIfArchivePermanent(Piwik_Date $dateEnd)
+ {
+ $now = time();
+ $endTimestampUTC = strtotime($dateEnd->getDateEndUTC());
+ if ($endTimestampUTC <= $now) {
+ // - if the period we are looking for is finished, we look for a ts_archived that
+ // is greater than the last day of the archive
+ return $endTimestampUTC;
+ }
+ return false;
+ }
+
+ /**
+ * @return Piwik_Date
+ */
+ public function getDateEnd()
+ {
+ return $this->getPeriod()->getDateEnd()->setTimezone($this->getSite()->getTimezone());
+ }
+
/**
* @return Piwik_Date
*/
@@ -223,11 +240,11 @@ abstract class Piwik_ArchiveProcessor
}
/**
- * @return Piwik_Date
+ * @return Piwik_Period
*/
- public function getDateEnd()
+ public function getPeriod()
{
- return $this->getPeriod()->getDateEnd()->setTimezone($this->getSite()->getTimezone());
+ return $this->period;
}
/**
@@ -279,15 +296,12 @@ abstract class Piwik_ArchiveProcessor
*/
protected function computeNewArchive($requestedPlugin, $enforceProcessCoreMetricsOnly)
{
- Piwik_DataAccess_ArchiveSelector::getArchiveProcessorLock($this->getSite()->getId(), $this->getPeriod(), $this->getSegment());
+ $archiveWriter = new Piwik_DataAccess_ArchiveWriter($this->getSite()->getId(), $this->getSegment(), $this->getPeriod(), $requestedPlugin, $this->isArchiveTemporary());
+ $archiveWriter->initNewArchive();
- $this->idArchive = Piwik_DataAccess_ArchiveSelector::allocateNewArchiveId($this->getTableArchiveNumericName(), $this->getSite()->getId());
-
- $doneFlag = Piwik_ArchiveProcessor_Rules::getDoneStringFlagFor($this->getSegment(), $this->getPeriod()->getLabel(), $requestedPlugin);
- $this->insertNumericRecord($doneFlag, Piwik_ArchiveProcessor::DONE_ERROR);
+ $this->archiveWriter = $archiveWriter;
$visitsNotKnownYet = $this->getNumberOfVisits() === false;
-
if ($visitsNotKnownYet
|| $this->doesRequestedPluginIncludeVisitsSummary($requestedPlugin)
|| $enforceProcessCoreMetricsOnly
@@ -300,8 +314,7 @@ abstract class Piwik_ArchiveProcessor
$this->setNumberOfVisits($metrics['nb_visits'], $metrics['nb_visits_converted']);
}
}
-
- $this->logStatus($requestedPlugin);
+ $this->logStatusDebug($requestedPlugin);
if ($this->getNumberOfVisits() > 0
&& !$enforceProcessCoreMetricsOnly
@@ -309,17 +322,8 @@ abstract class Piwik_ArchiveProcessor
$this->compute();
}
- Piwik_DataAccess_ArchiveSelector::deletePreviousArchiveStatus($this->getTableArchiveNumericName(), $doneFlag, $this->getIdArchive());
-
- $flag = Piwik_ArchiveProcessor::DONE_OK;
- if ($this->isArchiveTemporary()) {
- $flag = Piwik_ArchiveProcessor::DONE_OK_TEMPORARY;
- }
- $this->insertNumericRecord($doneFlag, $flag);
-
- Piwik_DataAccess_ArchiveSelector::releaseArchiveProcessorLock($this->getSite()->getId(), $this->getPeriod(), $this->getSegment());
-
- return $this->idArchive;
+ $archiveWriter->finalizeArchive();
+ return $archiveWriter->getIdArchive();
}
abstract protected function aggregateCoreVisitsMetrics();
@@ -327,7 +331,7 @@ abstract class Piwik_ArchiveProcessor
/**
* @param $requestedPlugin
*/
- protected function logStatus($requestedPlugin)
+ protected function logStatusDebug($requestedPlugin)
{
$temporary = 'definitive archive';
if ($this->isArchiveTemporary()) {
@@ -346,6 +350,9 @@ abstract class Piwik_ArchiveProcessor
public function isArchiveTemporary()
{
+ if (is_null($this->temporaryArchive)) {
+ throw new Exception("getMinTimeArchivedProcessed() should be called prior to isArchiveTemporary()");
+ }
return $this->temporaryArchive;
}
@@ -355,6 +362,16 @@ abstract class Piwik_ArchiveProcessor
*/
abstract protected function compute();
+ /**
+ * @param string $name
+ * @param int|float $value
+ */
+ public function insertNumericRecord($name, $value)
+ {
+ $value = round($value, 2);
+ return $this->archiveWriter->insertRecord($name, $value);
+ }
+
public function getNumberOfVisitsConverted()
{
return $this->convertedVisitsMetricCached;
@@ -369,16 +386,6 @@ abstract class Piwik_ArchiveProcessor
/**
* @param string $name
- * @param int|float $value
- */
- public function insertNumericRecord($name, $value)
- {
- $value = round($value, 2);
- return $this->insertRecord($name, $value);
- }
-
- /**
- * @param string $name
* @param string|array $values
* @return bool|array
*/
@@ -399,12 +406,11 @@ abstract class Piwik_ArchiveProcessor
$value = $this->compress($value);
$clean[] = array($newName, $value);
}
- return $this->insertBulkRecords($clean);
+ return $this->archiveWriter->insertBulkRecords($clean);
}
$values = $this->compress($values);
-
- $this->insertRecord($name, $values);
+ $this->archiveWriter->insertRecord($name, $values);
return array($name => $values);
}
@@ -416,141 +422,13 @@ abstract class Piwik_ArchiveProcessor
return $data;
}
- protected function insertBulkRecords($records)
- {
- // Using standard plain INSERT if there is only one record to insert
- if ($DEBUG_DO_NOT_USE_BULK_INSERT = false
- || count($records) == 1
- ) {
- foreach ($records as $record) {
- $this->insertRecord($record[0], $record[1]);
- }
- return;
- }
- $bindSql = $this->getInsertRecordBind();
- $values = array();
-
- $valueSeen = false;
- foreach ($records as $record) {
- // don't record zero
- if (empty($record[1])) continue;
-
- $bind = $bindSql;
- $bind[] = $record[0]; // name
- $bind[] = $record[1]; // value
- $values[] = $bind;
-
- $valueSeen = $record[1];
- }
- if (empty($values)) return;
-
- $tableName = $this->getTableNameToInsert($valueSeen);
-
- Piwik::tableInsertBatch($tableName, $this->getInsertFields(), $values);
- return true;
- }
-
- /**
- * Inserts a record in the right table (either NUMERIC or BLOB)
- *
- * @param string $name
- * @param mixed $value
- *
- * @return void
- */
- protected function insertRecord($name, $value)
- {
- if ($this->isRecordZero($name, $value)) {
- return;
- }
-
- $tableName = $this->getTableNameToInsert($value);
-
- // duplicate idarchives are Ignored, see http://dev.piwik.org/trac/ticket/987
-
- $query = "INSERT IGNORE INTO " . $tableName . "
- (" . implode(", ", $this->getInsertFields()) . ")
- VALUES (?,?,?,?,?,?,?,?)";
- $bindSql = $this->getInsertRecordBind();
- $bindSql[] = $name;
- $bindSql[] = $value;
- Piwik_Query($query, $bindSql);
- return true;
- }
-
- /**
- * @param $name
- * @param $value
- * @return bool
- */
- protected function isRecordZero($name, $value)
- {
- return ($value === '0' || $value === false || $value === 0 || $value === 0.0);
- }
-
- protected function getTableNameToInsert($value)
- {
- if (is_numeric($value)) {
- $tableName = $this->getTableArchiveNumericName();
- return $tableName;
- }
- $tableName = $this->getTableArchiveBlobName();
- return $tableName;
- }
-
- /**
- * Returns the name of the numeric table where the archive numeric values are stored
- *
- * @return string
- */
- public function getTableArchiveNumericName()
- {
- if (empty($this->tableArchiveNumeric)) {
- $this->tableArchiveNumeric = new Piwik_TablePartitioning_Monthly('archive_numeric');
- $this->tableArchiveNumeric->setTimestamp($this->getPeriod()->getDateStart()->getTimestamp());
- }
- return $this->tableArchiveNumeric->getTableName();
- }
-
- public function getPeriod()
- {
- return $this->period;
- }
-
/**
- * Returns the name of the blob table where the archive blob values are stored
- *
- * @return string
+ * @return Piwik_Segment
*/
- public function getTableArchiveBlobName()
- {
- if (empty($this->tableArchiveBlob)) {
- $this->tableArchiveBlob = new Piwik_TablePartitioning_Monthly('archive_blob');
- $this->tableArchiveBlob->setTimestamp($this->getPeriod()->getDateStart()->getTimestamp());
- }
- return $this->tableArchiveBlob->getTableName();
- }
-
- protected function getInsertFields()
- {
- return array('idarchive', 'idsite', 'date1', 'date2', 'period', 'ts_archived', 'name', 'value');
- }
-
- protected function getInsertRecordBind()
- {
- return array($this->getIdArchive(),
- $this->getSite()->getId(),
- $this->getPeriod()->getDateStart()->toString('Y-m-d'),
- $this->getPeriod()->getDateEnd()->toString('Y-m-d'),
- $this->getPeriod()->getId(),
- date("Y-m-d H:i:s"));
- }
-
- public function getIdArchive()
+ public function getSegment()
{
- return $this->idArchive;
+ return $this->segment;
}
-
/**
* @return Piwik_Site
*/
@@ -559,6 +437,7 @@ abstract class Piwik_ArchiveProcessor
return $this->site;
}
+
/**
* Whether the specified plugin's reports should be archived
* @param string $pluginName
@@ -580,14 +459,6 @@ abstract class Piwik_ArchiveProcessor
return false;
}
- /**
- * @return Piwik_Segment
- */
- public function getSegment()
- {
- return $this->segment;
- }
-
protected function getRequestedPlugin()
{
return $this->requestedPlugin;
diff --git a/core/ArchiveProcessor/Period.php b/core/ArchiveProcessor/Period.php
index ae00e00632..8d7add191f 100644
--- a/core/ArchiveProcessor/Period.php
+++ b/core/ArchiveProcessor/Period.php
@@ -130,8 +130,6 @@ class Piwik_ArchiveProcessor_Period extends Piwik_ArchiveProcessor
protected function compute()
{
Piwik_PostEvent('ArchiveProcessing_Period.compute', $this);
-
- Piwik_ArchiveProcessor_Rules::doPurgeOutdatedArchives($this->getTableArchiveNumericName());
}
protected function aggregateCoreVisitsMetrics()
@@ -181,15 +179,14 @@ class Piwik_ArchiveProcessor_Period extends Piwik_ArchiveProcessor
if (array_key_exists('nb_uniq_visitors', $results)) {
if (Piwik::isUniqueVisitorsEnabled($this->getPeriod()->getLabel())) {
- $value = (float)$this->computeNbUniqVisitors();
- $this->insertRecord('nb_uniq_visitors', $value);
+ $results['nb_uniq_visitors'] = (float)$this->computeNbUniqVisitors();
} else {
unset($results['nb_uniq_visitors']);
}
}
foreach ($results as $name => $value) {
- $this->insertRecord($name, $value);
+ $this->archiveWriter->insertRecord($name, $value);
}
// if asked for only one field to sum
diff --git a/core/ArchiveProcessor/Rules.php b/core/ArchiveProcessor/Rules.php
index 942f21420e..9d17c0e5bf 100644
--- a/core/ArchiveProcessor/Rules.php
+++ b/core/ArchiveProcessor/Rules.php
@@ -5,55 +5,37 @@
class Piwik_ArchiveProcessor_Rules
{
-
const OPTION_TODAY_ARCHIVE_TTL = 'todayArchiveTimeToLive';
- const OPTION_BROWSER_TRIGGER_ARCHIVING = 'enableBrowserTriggerArchiving';
- static public function isBrowserTriggerEnabled()
- {
- $browserArchivingEnabled = Piwik_GetOption(self::OPTION_BROWSER_TRIGGER_ARCHIVING);
- if ($browserArchivingEnabled !== false) {
- return (bool)$browserArchivingEnabled;
- }
- return (bool)Piwik_Config::getInstance()->General['enable_browser_archiving_triggering'];
- }
-
- public static function getTodayArchiveTimeToLive()
- {
- $timeToLive = Piwik_GetOption(self::OPTION_TODAY_ARCHIVE_TTL);
- if ($timeToLive !== false) {
- return $timeToLive;
- }
- return Piwik_Config::getInstance()->General['time_before_today_archive_considered_outdated'];
- }
+ const OPTION_BROWSER_TRIGGER_ARCHIVING = 'enableBrowserTriggerArchiving';
- public static function setBrowserTriggerArchiving($enabled)
- {
- if (!is_bool($enabled)) {
- throw new Exception('Browser trigger archiving must be set to true or false.');
- }
- Piwik_SetOption(self::OPTION_BROWSER_TRIGGER_ARCHIVING, (int)$enabled, $autoload = true);
- Piwik_Tracker_Cache::clearCacheGeneral();
- }
+ const FLAG_TABLE_PURGED = 'lastPurge_';
- // Old Archives purge can be disabled (used in tests only)
+ /** Old Archives purge can be disabled (used in tests only) */
static public $purgeDisabledByTests = true;
- // Flag that will forcefully disable the archiving process (used in tests only)
+ /** Flag that will forcefully disable the archiving process (used in tests only) */
public static $archivingDisabledByTests = false;
- const FLAG_TABLE_PURGED = 'lastPurge_';
-
- protected static function isRequestAuthorizedToArchive()
+ /**
+ * Returns the name of the archive field used to tell the status of an archive, (ie,
+ * whether the archive was created successfully or not).
+ *
+ * @param Piwik_Segment $segment
+ * @param string $periodLabel
+ * @param string $plugin
+ * @return string
+ */
+ // FIXMEA: this is called all over the place, not right
+ public static function getDoneStringFlagFor($segment, $periodLabel, $plugin)
{
- return !self::$archivingDisabledByTests &&
- (Piwik_ArchiveProcessor_Rules::isBrowserTriggerEnabled()
- || Piwik_Common::isPhpCliMode()
- || (Piwik::isUserIsSuperUser()
- && Piwik_Common::isArchivePhpTriggered()));
+ if (!self::shouldProcessReportsAllPlugins($segment, $periodLabel)) {
+ return self::getDoneFlagArchiveContainsOnePlugin($segment, $plugin);
+ }
+ return self::getDoneFlagArchiveContainsAllPlugins($segment);
}
- static public function shouldProcessReportsAllPlugins(Piwik_Segment $segment, $periodLabel)
+ public static function shouldProcessReportsAllPlugins(Piwik_Segment $segment, $periodLabel)
{
if ($segment->isEmpty() && $periodLabel != 'range') {
return true;
@@ -71,58 +53,16 @@ class Piwik_ArchiveProcessor_Rules
return false;
}
- public static function isArchivingDisabledFor(Piwik_Segment $segment, $periodLabel)
- {
- if ($periodLabel == 'range') {
- return false;
- }
- $processOneReportOnly = !self::shouldProcessReportsAllPlugins($segment, $periodLabel);
- $isArchivingDisabled = !self::isRequestAuthorizedToArchive();
-
- if ($processOneReportOnly) {
- // When there is a segment, archiving is not necessary allowed
- // If browser archiving is allowed, then archiving is enabled
- // if browser archiving is not allowed, then archiving is disabled
- if (!$segment->isEmpty()
- && $isArchivingDisabled
- && Piwik_Config::getInstance()->General['browser_archiving_disabled_enforce']
- ) {
- Piwik::log("Archiving is disabled because of config setting browser_archiving_disabled_enforce=1");
- return true;
- }
- return false;
- }
- return $isArchivingDisabled;
- }
-
- /**
- * Returns the name of the archive field used to tell the status of an archive, (ie,
- * whether the archive was created successfully or not).
- *
- * @param Piwik_Segment $segment
- * @param string $periodLabel
- * @param string $plugin
- * @return string
- */
- // FIXMEA: this is called all over the place, not right
- public static function getDoneStringFlagFor($segment, $periodLabel, $plugin)
+ private static function getDoneFlagArchiveContainsOnePlugin(Piwik_Segment $segment, $plugin)
{
- if (!self::shouldProcessReportsAllPlugins($segment, $periodLabel)) {
- return self::getDoneFlagArchiveContainsOnePlugin($segment, $plugin);
- }
- return self::getDoneFlagArchiveContainsAllPlugins($segment);
+ return 'done' . $segment->getHash() . '.' . $plugin;
}
- private static function getDoneFlagArchiveContainsAllPlugins($segment)
+ private static function getDoneFlagArchiveContainsAllPlugins(Piwik_Segment $segment)
{
return 'done' . $segment->getHash();
}
- private static function getDoneFlagArchiveContainsOnePlugin($segment, $plugin)
- {
- return 'done' . $segment->getHash() . '.' . $plugin;
- }
-
/**
* @param array $plugins
* @param $segment
@@ -144,13 +84,12 @@ class Piwik_ArchiveProcessor_Rules
* Given a monthly archive table, will delete all reports that are now outdated,
* or reports that ended with an error
*/
- static public function doPurgeOutdatedArchives($numericTable)
+ public static function doPurgeOutdatedArchives(Piwik_Date $date)
{
if (self::$purgeDisabledByTests) {
- return;
+ return false;
}
- $blobTable = str_replace("numeric", "blob", $numericTable);
- $key = self::FLAG_TABLE_PURGED . $blobTable;
+ $key = self::FLAG_TABLE_PURGED . "blob_" . $date->toString('Y_m');
$timestamp = Piwik_GetOption($key);
// we shall purge temporary archives after their timeout is finished, plus an extra 6 hours
@@ -169,32 +108,23 @@ class Piwik_ArchiveProcessor_Rules
) {
Piwik_SetOption($key, time());
- // If Browser Archiving is enabled, it is likely there are many more temporary archives
- // We delete more often which is safe, since reports are re-processed on demand
if (self::isBrowserTriggerEnabled()) {
+ // If Browser Archiving is enabled, it is likely there are many more temporary archives
+ // We delete more often which is safe, since reports are re-processed on demand
$purgeArchivesOlderThan = Piwik_Date::factory(time() - 2 * $temporaryArchivingTimeout)->getDateTime();
- } // If archive.php via Cron is building the reports, we should keep all temporary reports from today
- else {
+ } else {
+ // If archive.php via Cron is building the reports, we should keep all temporary reports from today
$purgeArchivesOlderThan = Piwik_Date::factory('today')->getDateTime();
}
- Piwik_DataAccess_ArchiveSelector::purgeOutdatedArchives($numericTable, $blobTable, $purgeArchivesOlderThan);
- // these tables will be OPTIMIZEd daily in a scheduled task, to claim lost space
- } else {
- Piwik::log("Purging temporary archives: skipped.");
+ return $purgeArchivesOlderThan;
}
- }
- public static function setTodayArchiveTimeToLive($timeToLiveSeconds)
- {
- $timeToLiveSeconds = (int)$timeToLiveSeconds;
- if ($timeToLiveSeconds <= 0) {
- throw new Exception(Piwik_TranslateException('General_ExceptionInvalidArchiveTimeToLive'));
- }
- Piwik_SetOption(self::OPTION_TODAY_ARCHIVE_TTL, $timeToLiveSeconds, $autoload = true);
+ Piwik::log("Purging temporary archives: skipped.");
+ return false;
}
- static public function getMinTimeProcessedForTemporaryArchive(Piwik_Date $dateStart, Piwik_Period $period, Piwik_Segment $segment,
- Piwik_Site $site)
+
+ public static function getMinTimeProcessedForTemporaryArchive(Piwik_Date $dateStart, Piwik_Period $period, Piwik_Segment $segment, Piwik_Site $site)
{
$now = time();
$minimumArchiveTime = $now - Piwik_ArchiveProcessor_Rules::getTodayArchiveTimeToLive();
@@ -215,4 +145,71 @@ class Piwik_ArchiveProcessor_Rules
return $minimumArchiveTime;
}
+ public static function setTodayArchiveTimeToLive($timeToLiveSeconds)
+ {
+ $timeToLiveSeconds = (int)$timeToLiveSeconds;
+ if ($timeToLiveSeconds <= 0) {
+ throw new Exception(Piwik_TranslateException('General_ExceptionInvalidArchiveTimeToLive'));
+ }
+ Piwik_SetOption(self::OPTION_TODAY_ARCHIVE_TTL, $timeToLiveSeconds, $autoLoad = true);
+ }
+ public static function getTodayArchiveTimeToLive()
+ {
+ $timeToLive = Piwik_GetOption(self::OPTION_TODAY_ARCHIVE_TTL);
+ if ($timeToLive !== false) {
+ return $timeToLive;
+ }
+ return Piwik_Config::getInstance()->General['time_before_today_archive_considered_outdated'];
+ }
+
+ public static function isArchivingDisabledFor(Piwik_Segment $segment, $periodLabel)
+ {
+ if ($periodLabel == 'range') {
+ return false;
+ }
+ $processOneReportOnly = !self::shouldProcessReportsAllPlugins($segment, $periodLabel);
+ $isArchivingDisabled = !self::isRequestAuthorizedToArchive();
+
+ if ($processOneReportOnly) {
+ // When there is a segment, archiving is not necessary allowed
+ // If browser archiving is allowed, then archiving is enabled
+ // if browser archiving is not allowed, then archiving is disabled
+ if (!$segment->isEmpty()
+ && $isArchivingDisabled
+ && Piwik_Config::getInstance()->General['browser_archiving_disabled_enforce']
+ ) {
+ Piwik::log("Archiving is disabled because of config setting browser_archiving_disabled_enforce=1");
+ return true;
+ }
+ return false;
+ }
+ return $isArchivingDisabled;
+ }
+
+ protected static function isRequestAuthorizedToArchive()
+ {
+ return !self::$archivingDisabledByTests &&
+ (Piwik_ArchiveProcessor_Rules::isBrowserTriggerEnabled()
+ || Piwik_Common::isPhpCliMode()
+ || (Piwik::isUserIsSuperUser()
+ && Piwik_Common::isArchivePhpTriggered()));
+ }
+
+ public static function isBrowserTriggerEnabled()
+ {
+ $browserArchivingEnabled = Piwik_GetOption(self::OPTION_BROWSER_TRIGGER_ARCHIVING);
+ if ($browserArchivingEnabled !== false) {
+ return (bool)$browserArchivingEnabled;
+ }
+ return (bool)Piwik_Config::getInstance()->General['enable_browser_archiving_triggering'];
+ }
+
+ public static function setBrowserTriggerArchiving($enabled)
+ {
+ if (!is_bool($enabled)) {
+ throw new Exception('Browser trigger archiving must be set to true or false.');
+ }
+ Piwik_SetOption(self::OPTION_BROWSER_TRIGGER_ARCHIVING, (int)$enabled, $autoLoad = true);
+ Piwik_Tracker_Cache::clearCacheGeneral();
+ }
} \ No newline at end of file
diff --git a/core/DataAccess/ArchiveSelector.php b/core/DataAccess/ArchiveSelector.php
index 98937fe9f8..6d09634604 100644
--- a/core/DataAccess/ArchiveSelector.php
+++ b/core/DataAccess/ArchiveSelector.php
@@ -28,105 +28,7 @@ class Piwik_DataAccess_ArchiveSelector
const NB_VISITS_RECORD_LOOKED_UP = "nb_visits";
const NB_VISITS_CONVERTED_RECORD_LOOKED_UP = "nb_visits_converted";
- public static function deletePreviousArchiveStatus($numericTable, $done, $idArchive)
- {
- Piwik_Query("DELETE FROM " . $numericTable . "
- WHERE idarchive = ? AND (name = '" . $done . "' OR name LIKE '" . self::PREFIX_SQL_LOCK . "%')",
- array($idArchive)
- );
- }
-
- /**
- * Generate advisory lock name
- *
- * @param int $idsite
- * @param Piwik_Period $period
- * @param Piwik_Segment $segment
- * @return string
- */
- static protected function getArchiveProcessorLockName($idsite, $period, Piwik_Segment $segment)
- {
- $config = Piwik_Config::getInstance();
-
- $lockName = 'piwik.'
- . $config->database['dbname'] . '.'
- . $config->database['tables_prefix'] . '/'
- . $idsite . '/'
- . (!$segment->isEmpty() ? $segment->getHash() . '/' : '')
- . $period->getId() . '/'
- . $period->getDateStart()->toString('Y-m-d') . ','
- . $period->getDateEnd()->toString('Y-m-d');
- return $lockName . '/' . md5($lockName . Piwik_Common::getSalt());
- }
-
- /**
- * Get an advisory lock
- *
- * @param int $idsite
- * @param Piwik_Period $period
- * @param Piwik_Segment $segment
- * @return bool True if lock acquired; false otherwise
- */
- static public function getArchiveProcessorLock($idsite, $period, $segment)
- {
-
- $lockName = self::getArchiveProcessorLockName($idsite, $period, $segment);
- $result = Piwik_GetDbLock($lockName, $maxRetries = 30);
- if(!$result) {
- Piwik::log('SELECT GET_LOCK(?, 1) FAILED to acquire lock. Proceeding anyway...');
- }
- }
-
- /**
- * Release an advisory lock
- *
- * @param int $idsite
- * @param Piwik_Period $period
- * @param Piwik_Segment $segment
- * @return bool True if lock released; false otherwise
- */
- static public function releaseArchiveProcessorLock($idsite, $period, $segment)
- {
- $lockName = self::getArchiveProcessorLockName($idsite, $period, $segment);
- return Piwik_ReleaseDbLock($lockName);
- }
-
/**
- * A row is created to lock an idarchive for the current archive being processed
- * @var string
- */
- const PREFIX_SQL_LOCK = "locked_";
-
-
- public static function allocateNewArchiveId($table, $idSite)
- {
- $dbLockName = "allocateNewArchiveId.$table";
-
- $db = Zend_Registry::get('db');
- $locked = self::PREFIX_SQL_LOCK . Piwik_Common::generateUniqId();
- $date = date("Y-m-d H:i:s");
-
- if (Piwik_GetDbLock($dbLockName, $maxRetries = 30) === false) {
- throw new Exception("allocateNewArchiveId: Cannot get named lock for table $table.");
- }
- $db->exec("INSERT INTO $table "
- . " SELECT ifnull(max(idarchive),0)+1,
- '" . $locked . "',
- " . (int)$idSite . ",
- '" . $date . "',
- '" . $date . "',
- 0,
- '" . $date . "',
- 0 "
- . " FROM $table as tb1");
- Piwik_ReleaseDbLock($dbLockName);
- $id = $db->fetchOne("SELECT idarchive FROM $table WHERE name = ? LIMIT 1", $locked);
- return $id;
- }
-
-
- /**
- * @param $numericTableName
* @param $site
* @param $period
* @param $segment
@@ -134,10 +36,11 @@ class Piwik_DataAccess_ArchiveSelector
* @param $requestedPlugin
* @return array|bool
*/
- static public function getArchiveIdAndVisits($numericTableName, Piwik_Site $site, Piwik_Period $period, Piwik_Segment $segment, $minDatetimeArchiveProcessedUTC, $requestedPlugin)
+ static public function getArchiveIdAndVisits(Piwik_Site $site, Piwik_Period $period, Piwik_Segment $segment, $minDatetimeArchiveProcessedUTC, $requestedPlugin)
{
+ $dateStart = $period->getDateStart();
$bindSQL = array($site->getId(),
- $period->getDateStart()->toString('Y-m-d'),
+ $dateStart->toString('Y-m-d'),
$period->getDateEnd()->toString('Y-m-d'),
$period->getId(),
);
@@ -152,8 +55,9 @@ class Piwik_DataAccess_ArchiveSelector
$pluginOrVisitsSummary = array_unique($pluginOrVisitsSummary);
$sqlWhereArchiveName = self::getNameCondition($pluginOrVisitsSummary, $segment);
+
$sqlQuery = " SELECT idarchive, value, name, date1 as startDate
- FROM " . $numericTableName . "``
+ FROM " . Piwik_DataAccess_ArchiveTableCreator::getNumericTable($dateStart) . "``
WHERE idsite = ?
AND date1 = ?
AND date2 = ?
@@ -243,15 +147,19 @@ class Piwik_DataAccess_ArchiveSelector
AND ". self::getNameCondition($plugins, $segment) ."
AND idsite IN (".implode(',', $siteIds).")
GROUP BY idsite, date1, date2";
-
+
+ $monthToPeriods = array();
+ foreach ($periods as $period) {
+ /** @var Piwik_Period $period */
+ $table = Piwik_DataAccess_ArchiveTableCreator::getNumericTable($period->getDateStart());
+ $monthToPeriods[$table][] = $period;
+ }
+
// for every month within the archive query, select from numeric table
$result = array();
- foreach (self::getPeriodsByTableMonth($periods) as $tableMonth => $periods) {
+ foreach ($monthToPeriods as $table => $periods) {
$firstPeriod = reset($periods);
- $table = Piwik_Common::prefixTable("archive_numeric_$tableMonth");
- Piwik_TablePartitioning_Monthly::createArchiveTablesIfAbsent($firstPeriod->getDateStart());
-
// if looking for a range archive. NOTE: we assume there's only one period if its a range.
$bind = array($firstPeriod->getId());
if ($firstPeriod instanceof Piwik_Period_Range) {
@@ -287,37 +195,35 @@ class Piwik_DataAccess_ArchiveSelector
* Queries and returns archive data using a set of archive IDs.
*
* @param array $archiveIds The IDs of the archives to get data from.
- * @param array $archiveNames The names of the data to retrieve (ie, nb_visits,
+ * @param array $recordNames The names of the data to retrieve (ie, nb_visits,
* nb_actions, etc.)
* @param string $archiveDataType The archive data type (either, 'blob' or 'numeric').
- * @param string|null $idSubtable The subtable to retrieve ('all' for all subtables).
+ * @param bool $loadAllSubtables Whether to pre-load all subtables
*/
- static public function getArchiveData($archiveIds, $archiveNames, $archiveDataType, $idSubtable)
+ static public function getArchiveData($archiveIds, $recordNames, $archiveDataType, $loadAllSubtables)
{
- $archiveTableType = 'archive_'.$archiveDataType;
-
// create the SQL to select archive data
- $inNames = Piwik_Common::getSqlStringFieldsArray($archiveNames);
- if ($idSubtable == 'all') {
- $name = reset($archiveNames);
+ $inNames = Piwik_Common::getSqlStringFieldsArray($recordNames);
+ if ($loadAllSubtables) {
+ $name = reset($recordNames);
// select blobs w/ name like "$name_[0-9]+" w/o using RLIKE
$nameEnd = strlen($name) + 2;
- $getValuesSql = "SELECT value, name, idsite, date1, date2, ts_archived
- FROM %s
- WHERE idarchive IN (%s)
- AND (name = ? OR
- (name LIKE ? AND SUBSTRING(name, $nameEnd, 1) >= '0'
- AND SUBSTRING(name, $nameEnd, 1) <= '9') )";
+ $whereNameIs = "(name = ?
+ OR (name LIKE ?
+ AND SUBSTRING(name, $nameEnd, 1) >= '0'
+ AND SUBSTRING(name, $nameEnd, 1) <= '9') )";
$bind = array($name, $name.'%');
} else {
- $getValuesSql = "SELECT name, value, idsite, date1, date2, ts_archived
- FROM %s
- WHERE idarchive IN (%s)
- AND name IN ($inNames)";
- $bind = array_values($archiveNames);
+ $whereNameIs = "name IN ($inNames)";
+ $bind = array_values($recordNames);
}
-
+
+ $getValuesSql = "SELECT value, name, idsite, date1, date2, ts_archived
+ FROM %s
+ WHERE idarchive IN (%s)
+ AND " . $whereNameIs;
+
// get data from every table we're querying
$rows = array();
foreach ($archiveIds as $period => $ids) {
@@ -325,12 +231,12 @@ class Piwik_DataAccess_ArchiveSelector
throw new Exception("Unexpected: id archive not found for period '$period' '");
}
// $period = "2009-01-04,2009-01-04",
- $date = substr($period, 0, 10);
- $tableMonth = str_replace('-', '_', substr($date, 0, 7) );
-
- Piwik_TablePartitioning_Monthly::createArchiveTablesIfAbsent(Piwik_Date::factory($date));
-
- $table = Piwik_Common::prefixTable($archiveTableType."_".$tableMonth);
+ $date = Piwik_Date::factory( substr($period, 0, 10) );
+ if($archiveDataType == 'numeric') {
+ $table = Piwik_DataAccess_ArchiveTableCreator::getNumericTable($date);
+ } else {
+ $table = Piwik_DataAccess_ArchiveTableCreator::getBlobTable($date);
+ }
$sql = sprintf($getValuesSql, $table, implode(',', $ids));
foreach (Piwik_FetchAll($sql, $bind) as $row) {
$rows[] = $row;
@@ -339,12 +245,12 @@ class Piwik_DataAccess_ArchiveSelector
return $rows;
}
-
+
/**
* Returns the SQL condition used to find successfully completed archives that
* this instance is querying for.
*
- * @param array $plugins @see getArchiveData
+ * @param array $plugins
* @param Piwik_Segment $segment
* @return string
*/
@@ -362,74 +268,65 @@ class Piwik_DataAccess_ArchiveSelector
" value = '".Piwik_ArchiveProcessor::DONE_OK_TEMPORARY."')";
}
- /**
- * Returns the periods of the archives this instance is querying for grouped by
- * by year & month.
- *
- * @return array The result will be an array of Piwik_Period instances, where each
- * instance is associated w/ a string describing the year and month,
- * eg, 2012_01. The format is the same format used in archive database
- * table names.
+
+ static public function purgeOutdatedArchives(Piwik_Date $dateStart, $purgeArchivesOlderThan)
+ {
+ $numericTable = Piwik_DataAccess_ArchiveTableCreator::getNumericTable($dateStart);
+ $blobTable = Piwik_DataAccess_ArchiveTableCreator::getBlobTable($dateStart);
+ $idArchivesToDelete = self::getTemporaryArchiveIdsOlderThan($numericTable, $purgeArchivesOlderThan);
+ if(!empty($idArchivesToDelete)) {
+ self::deleteArchiveIds($numericTable, $blobTable, $idArchivesToDelete);
+ }
+ Piwik::log("Purging temporary archives: done [ purged archives older than $purgeArchivesOlderThan from $blobTable and $numericTable ] [Deleted IDs: " . implode(',', $idArchivesToDelete) . "]");
+ self::deleteArchivesWithPeriodRange($numericTable, $blobTable);
+ }
+
+ /*
+ * Deleting "Custom Date Range" reports after 1 day, since they can be re-processed and would take up un-necessary space
*/
- static private function getPeriodsByTableMonth($periods)
+ protected static function deleteArchivesWithPeriodRange($numericTable, $blobTable)
{
- $result = array();
- foreach ($periods as $period) {
- $tableMonth = $period->getDateStart()->toString('Y_m');
- $result[$tableMonth][] = $period;
+ $query = "DELETE FROM %s WHERE period = ? AND ts_archived < ?";
+
+ $yesterday = Piwik_Date::factory('yesterday')->getDateTime();
+ Piwik::log("Purging Custom Range archives: done [ purged archives older than $yesterday from $blobTable and $numericTable ]");
+ $bind = array(Piwik::$idPeriods['range'], $yesterday);
+ Piwik_Query(sprintf($query, $numericTable), $bind);
+ try {
+ Piwik_Query(sprintf($query, $blobTable), $bind);
+ } catch (Exception $e) {
+ // Individual blob tables could be missing
}
- return $result;
}
+ protected static function deleteArchiveIds($numericTable, $blobTable, $idArchivesToDelete)
+ {
+ $query = "DELETE FROM %s WHERE idarchive IN (" . implode(',', $idArchivesToDelete) . ")";
- static public function purgeOutdatedArchives($numericTable, $blobTable, $purgeArchivesOlderThan)
+ Piwik_Query(sprintf($query, $numericTable));
+ try {
+ Piwik_Query(sprintf($query, $blobTable));
+ } catch (Exception $e) {
+ // Individual blob tables could be missing
+ }
+ }
+
+ protected static function getTemporaryArchiveIdsOlderThan($numericTable, $purgeArchivesOlderThan)
{
- $result = Piwik_FetchAll("
- SELECT idarchive
+ $query = "SELECT idarchive
FROM $numericTable
WHERE name LIKE 'done%'
AND (( value = " . Piwik_ArchiveProcessor::DONE_OK_TEMPORARY . "
AND ts_archived < ?)
- OR value = " . Piwik_ArchiveProcessor::DONE_ERROR . ")",
- array($purgeArchivesOlderThan)
- );
+ OR value = " . Piwik_ArchiveProcessor::DONE_ERROR . ")";
+ $result = Piwik_FetchAll($query,array($purgeArchivesOlderThan));
$idArchivesToDelete = array();
if (!empty($result)) {
foreach ($result as $row) {
$idArchivesToDelete[] = $row['idarchive'];
}
- $query = "DELETE
- FROM %s
- WHERE idarchive IN (" . implode(',', $idArchivesToDelete) . ")
- ";
-
- Piwik_Query(sprintf($query, $numericTable));
-
- // Individual blob tables could be missing
- try {
- Piwik_Query(sprintf($query, $blobTable));
- } catch (Exception $e) {
- }
- }
- Piwik::log("Purging temporary archives: done [ purged archives older than $purgeArchivesOlderThan from $blobTable and $numericTable ] [Deleted IDs: " . implode(',', $idArchivesToDelete) . "]");
-
- // Deleting "Custom Date Range" reports after 1 day, since they can be re-processed
- // and would take up unecessary space
- $yesterday = Piwik_Date::factory('yesterday')->getDateTime();
- $query = "DELETE
- FROM %s
- WHERE period = ?
- AND ts_archived < ?";
- $bind = array(Piwik::$idPeriods['range'], $yesterday);
- Piwik::log("Purging Custom Range archives: done [ purged archives older than $yesterday from $blobTable and $numericTable ]");
-
- Piwik_Query(sprintf($query, $numericTable), $bind);
-
- // Individual blob tables could be missing
- try {
- Piwik_Query(sprintf($query, $blobTable), $bind);
- } catch (Exception $e) {
}
+ return $idArchivesToDelete;
}
}
diff --git a/core/Option.php b/core/Option.php
index 4275b8afa1..ab3a1c672f 100644
--- a/core/Option.php
+++ b/core/Option.php
@@ -82,15 +82,15 @@ class Piwik_Option
*
* @param string $name
* @param string $value
- * @param int $autoload if set to 1, this option value will be automatically loaded; should be set to 1 for options that will always be used in the Piwik request.
+ * @param int $autoLoad if set to 1, this option value will be automatically loaded; should be set to 1 for options that will always be used in the Piwik request.
*/
- public function set($name, $value, $autoload = 0)
+ public function set($name, $value, $autoLoad = 0)
{
- $autoload = (int)$autoload;
+ $autoLoad = (int)$autoLoad;
Piwik_Query('INSERT INTO `' . Piwik_Common::prefixTable('option') . '` (option_name, option_value, autoload) ' .
' VALUES (?, ?, ?) ' .
' ON DUPLICATE KEY UPDATE option_value = ?',
- array($name, $value, $autoload, $value));
+ array($name, $value, $autoLoad, $value));
$this->all[$name] = $value;
}
@@ -187,9 +187,9 @@ function Piwik_GetOption($name)
*
* @param string $name
* @param string $value
- * @param int $autoload if set to 1, this option value will be automatically loaded; should be set to 1 for options that will always be used in the Piwik request.
+ * @param int $autoLoad if set to 1, this option value will be automatically loaded; should be set to 1 for options that will always be used in the Piwik request.
*/
-function Piwik_SetOption($name, $value, $autoload = 0)
+function Piwik_SetOption($name, $value, $autoLoad = 0)
{
- Piwik_Option::getInstance()->set($name, $value, $autoload);
+ Piwik_Option::getInstance()->set($name, $value, $autoLoad);
}
diff --git a/core/Piwik.php b/core/Piwik.php
index 15fbcee79a..937c8b4ed8 100644
--- a/core/Piwik.php
+++ b/core/Piwik.php
@@ -174,7 +174,7 @@ class Piwik
|| $currentUrl != $url
) {
if (strlen($currentUrl) >= strlen('http://a/')) {
- Piwik_SetOption($key, $currentUrl, $autoload = true);
+ Piwik_SetOption($key, $currentUrl, $autoLoad = true);
}
$url = $currentUrl;
}
diff --git a/core/TablePartitioning.php b/core/TablePartitioning.php
index 7dee00bf9c..330c9f168a 100644
--- a/core/TablePartitioning.php
+++ b/core/TablePartitioning.php
@@ -114,7 +114,7 @@ class Piwik_TablePartitioning_Monthly extends Piwik_TablePartitioning
*
* @param Piwik_Date
*/
- public static function createArchiveTablesIfAbsent($dateInMonth)
+ public static function createArchiveTablesIfAbsent(Piwik_Date $dateInMonth)
{
$timestamp = $dateInMonth->getTimestamp();
diff --git a/core/UpdateCheck.php b/core/UpdateCheck.php
index e79d5df431..84e4e11df4 100644
--- a/core/UpdateCheck.php
+++ b/core/UpdateCheck.php
@@ -40,7 +40,7 @@ class Piwik_UpdateCheck
|| time() - $interval > $lastTimeChecked
) {
// set the time checked first, so that parallel Piwik requests don't all trigger the http requests
- Piwik_SetOption(self::LAST_TIME_CHECKED, time(), $autoload = 1);
+ Piwik_SetOption(self::LAST_TIME_CHECKED, time(), $autoLoad = 1);
$parameters = array(
'piwik_version' => Piwik_Version::VERSION,
'php_version' => PHP_VERSION,
diff --git a/core/Updater.php b/core/Updater.php
index 1b91f70349..4b86b7d9ed 100644
--- a/core/Updater.php
+++ b/core/Updater.php
@@ -56,7 +56,7 @@ class Piwik_Updater
public function recordComponentSuccessfullyUpdated($name, $version)
{
try {
- Piwik_SetOption($this->getNameInOptionTable($name), $version, $autoload = 1);
+ Piwik_SetOption($this->getNameInOptionTable($name), $version, $autoLoad = 1);
} catch (Exception $e) {
// case when the option table is not yet created (before 0.2.10)
}
diff --git a/tests/PHPUnit/Core/ArchiveProcessingTest.php b/tests/PHPUnit/Core/ArchiveProcessingTest.php
index cca5b50acd..646ae795cc 100644
--- a/tests/PHPUnit/Core/ArchiveProcessingTest.php
+++ b/tests/PHPUnit/Core/ArchiveProcessingTest.php
@@ -361,9 +361,7 @@ class ArchiveProcessingTest extends DatabaseTestCase
{
$siteTimezone = 'America/Toronto';
$dateLabel = '2011-03-31';
- $archiveProcessor = $this->_createArchiveProcessor('day', $dateLabel, $siteTimezone);
-
- $table = $archiveProcessor->getTableArchiveBlobName();
+ $table = Piwik_DataAccess_ArchiveTableCreator::getBlobTable(Piwik_Date::factory($dateLabel));
$data = $this->_getBlobDataInsert();
try {
@@ -396,9 +394,7 @@ class ArchiveProcessingTest extends DatabaseTestCase
{
$siteTimezone = 'America/Toronto';
$dateLabel = '2011-03-31';
- $archiveProcessor = $this->_createArchiveProcessor('day', $dateLabel, $siteTimezone);
-
- $table = $archiveProcessor->getTableArchiveBlobName();
+ $table = Piwik_DataAccess_ArchiveTableCreator::getBlobTable(Piwik_Date::factory($dateLabel));
$data = $this->_getBlobDataInsert();
Piwik::tableInsertBatchIterate($table, array('idarchive', 'name', 'idsite', 'date1', 'date2', 'period', 'ts_archived', 'value'), $data);
diff --git a/tests/PHPUnit/MockPiwikOption.php b/tests/PHPUnit/MockPiwikOption.php
index 455638032c..58bfda20c1 100644
--- a/tests/PHPUnit/MockPiwikOption.php
+++ b/tests/PHPUnit/MockPiwikOption.php
@@ -19,7 +19,7 @@ class MockPiwikOption extends Piwik_Option
return $this->forcedOptionValue;
}
- public function set($name, $value, $autoload = 0)
+ public function set($name, $value, $autoLoad = 0)
{
$this->forcedOptionValue = $value;
}