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:
Diffstat (limited to 'core/ArchiveProcessor/Rules.php')
-rw-r--r--core/ArchiveProcessor/Rules.php207
1 files changed, 102 insertions, 105 deletions
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