From 970ddbf110afe0fc1f3a13c272bbfd8df47379f7 Mon Sep 17 00:00:00 2001
From: mattab <matthieu.aubry@gmail.com>
Date: Sun, 12 Jul 2015 19:25:04 +0200
Subject: [PATCH] When script is called from misc/cron/archive.php, still
 return correct Piwik URL

---
 core/SettingsPiwik.php                  | 3 +++
 tests/PHPUnit/System/ArchiveWebTest.php | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/core/SettingsPiwik.php b/core/SettingsPiwik.php
index af1ea26173..a1082eb4a0 100644
--- a/core/SettingsPiwik.php
+++ b/core/SettingsPiwik.php
@@ -179,6 +179,9 @@ class SettingsPiwik
 
         $currentUrl = Common::sanitizeInputValue(Url::getCurrentUrlWithoutFileName());
 
+        // when script is called from /misc/cron/archive.php, Piwik URL is /index.php
+        $currentUrl = str_replace("/misc/cron/", "", $currentUrl);
+
         if (empty($url)
             // if URL changes, always update the cache
             || $currentUrl != $url
diff --git a/tests/PHPUnit/System/ArchiveWebTest.php b/tests/PHPUnit/System/ArchiveWebTest.php
index 527f5c6477..745b12e0ec 100644
--- a/tests/PHPUnit/System/ArchiveWebTest.php
+++ b/tests/PHPUnit/System/ArchiveWebTest.php
@@ -74,7 +74,7 @@ class ArchiveWebTest extends SystemTestCase
         $this->assertNotContains('WARNING', $output);
 
         // Check there are enough lines in output
-        $minimumLinesInOutput = 60;
+        $minimumLinesInOutput = 30;
         $linesInOutput = count( explode(PHP_EOL, $output) );
         $this->assertGreaterThan($minimumLinesInOutput, $linesInOutput);
     }
-- 
GitLab