Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add event that allows plugins to disable archiving for certain periods/sites if they want. #15457

Merged
merged 2 commits into from
Jan 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions core/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,10 +649,11 @@ private function cacheArchiveIdsAfterLaunching($archiveGroups, $plugins)
foreach ($this->params->getIdSites() as $idSite) {
$site = new Site($idSite);

if ($period->getLabel() === 'day'
if ($period->getLabel() === 'day'
&& !$this->params->getSegment()->isEmpty()
&& Common::getRequestVar('skipArchiveSegmentToday', 0, 'int')
&& $period->getDateStart()->toString() == Date::factory('now', $site->getTimezone())->toString()) {
&& $period->getDateStart()->toString() == Date::factory('now', $site->getTimezone())->toString()
) {

Log::debug("Skipping archive %s for %s as segment today is disabled", $period->getLabel(), $period->getPrettyString());
continue;
Expand Down
20 changes: 16 additions & 4 deletions core/ArchiveProcessor/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,21 @@ public static function isArchivingDisabledFor(array $idSites, Segment $segment,
return !$isArchivingEnabled;
}

public static function isRequestAuthorizedToArchive()
public static function isRequestAuthorizedToArchive(Parameters $params = null)
{
return Rules::isBrowserTriggerEnabled() || SettingsServer::isArchivePhpTriggered();
$isRequestAuthorizedToArchive = Rules::isBrowserTriggerEnabled() || SettingsServer::isArchivePhpTriggered();

if (!empty($params)) {
/**
* @ignore
*
* @params bool &$isRequestAuthorizedToArchive
* @params Parameters $params
*/
Piwik::postEvent('Archiving.isRequestAuthorizedToArchive', [&$isRequestAuthorizedToArchive, $params]);
}

return $isRequestAuthorizedToArchive;
}

public static function isBrowserTriggerEnabled()
Expand Down Expand Up @@ -293,11 +305,11 @@ public static function isSegmentPreProcessed(array $idSites, Segment $segment)
*
* @return string[]
*/
public static function getSelectableDoneFlagValues($includeInvalidated = true)
public static function getSelectableDoneFlagValues($includeInvalidated = true, Parameters $params = null)
{
$possibleValues = array(ArchiveWriter::DONE_OK, ArchiveWriter::DONE_OK_TEMPORARY);

if (!Rules::isRequestAuthorizedToArchive()
if (!Rules::isRequestAuthorizedToArchive($params)
&& $includeInvalidated
) {
//If request is not authorized to archive then fetch also invalidated archives
Expand Down
2 changes: 1 addition & 1 deletion core/DataAccess/ArchiveSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function getArchiveIdAndVisits(ArchiveProcessor\Parameters $params
$plugins = array("VisitsSummary", $requestedPlugin);

$doneFlags = Rules::getDoneFlags($plugins, $segment);
$doneFlagValues = Rules::getSelectableDoneFlagValues($includeInvalidated);
$doneFlagValues = Rules::getSelectableDoneFlagValues($includeInvalidated, $params);

$results = self::getModel()->getArchiveIdAndVisits($numericTable, $idSite, $period, $dateStartIso, $dateEndIso, $minDatetimeIsoArchiveProcessedUTC, $doneFlags, $doneFlagValues);

Expand Down