From 6ab57de0ce2a426fa598d395a8d50cf664886e7b Mon Sep 17 00:00:00 2001
From: Thomas Steur <thomas.steur@gmail.com>
Date: Sun, 30 Aug 2015 11:10:55 +0000
Subject: [PATCH] Fix custom date ranges are still being archived when
 --force-periods=day

---
 core/CronArchive.php                          | 17 ++++++++++-------
 plugins/CoreConsole/Commands/CoreArchiver.php |  2 +-
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/core/CronArchive.php b/core/CronArchive.php
index ba0b163220..6828519ad1 100644
--- a/core/CronArchive.php
+++ b/core/CronArchive.php
@@ -612,13 +612,16 @@ class CronArchive
             $success = $periodArchiveWasSuccessful && $success;
         }
 
-        // period=range
-        $customDateRangesToPreProcessForSite = $this->getCustomDateRangeToPreProcess($idSite);
-        foreach ($customDateRangesToPreProcessForSite as $dateRange) {
-            $archiveSegments = false; // do not pre-process segments for period=range #7611
-            $periodArchiveWasSuccessful = $this->archiveReportsFor($idSite, 'range', $dateRange, $archiveSegments);
-            $success = $periodArchiveWasSuccessful && $success;
+        if ($this->shouldProcessPeriod('range')) {
+            // period=range
+            $customDateRangesToPreProcessForSite = $this->getCustomDateRangeToPreProcess($idSite);
+            foreach ($customDateRangesToPreProcessForSite as $dateRange) {
+                $archiveSegments = false; // do not pre-process segments for period=range #7611
+                $periodArchiveWasSuccessful = $this->archiveReportsFor($idSite, 'range', $dateRange, $archiveSegments);
+                $success = $periodArchiveWasSuccessful && $success;
+            }
         }
+
         return $success;
     }
 
@@ -1285,7 +1288,7 @@ class CronArchive
      */
     private function getDefaultPeriodsToProcess()
     {
-        return array('day', 'week', 'month', 'year');
+        return array('day', 'week', 'month', 'year', 'range');
     }
 
     /**
diff --git a/plugins/CoreConsole/Commands/CoreArchiver.php b/plugins/CoreConsole/Commands/CoreArchiver.php
index 40fc7d4c71..7f1eb6107d 100644
--- a/plugins/CoreConsole/Commands/CoreArchiver.php
+++ b/plugins/CoreConsole/Commands/CoreArchiver.php
@@ -100,7 +100,7 @@ class CoreArchiver extends ConsoleCommand
         $command->addOption('force-idsites', null, InputOption::VALUE_OPTIONAL,
             'If specified, archiving will be processed only for these Sites Ids (comma separated)');
         $command->addOption('force-periods', null, InputOption::VALUE_OPTIONAL,
-            "If specified, archiving will be processed only for these Periods (comma separated eg. day,week,month)");
+            "If specified, archiving will be processed only for these Periods (comma separated eg. day,week,month,year,range)");
         $command->addOption('force-date-last-n', null, InputOption::VALUE_REQUIRED,
             "This script calls the API with period=lastN. You can force the N in lastN by specifying this value.");
         $command->addOption('force-date-range', null, InputOption::VALUE_OPTIONAL,
-- 
GitLab