From cbc8714a9e281721e1e4ceddd7b9826339a1520a Mon Sep 17 00:00:00 2001
From: diosmosis <benaka@piwik.pro>
Date: Wed, 15 Oct 2014 18:48:09 -0700
Subject: [PATCH] Moving CronArchive token auth check to archive script since
 it is only for when the archive.php script is invoked from a web request.

---
 core/CronArchive.php  | 20 --------------------
 misc/cron/archive.php | 11 +++++++++++
 2 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/core/CronArchive.php b/core/CronArchive.php
index 47fbd7d3df..8549cbb8ea 100644
--- a/core/CronArchive.php
+++ b/core/CronArchive.php
@@ -853,26 +853,6 @@ class CronArchive
         }
     }
 
-    /**
-     * Script does run on http:// ONLY if the SU token is specified
-     */
-    private function initCheckCli()
-    {
-        if (Common::isPhpCliMode()) {
-            return;
-        }
-
-        $token_auth = Common::getRequestVar('token_auth', '', 'string');
-        if ($token_auth !== $this->token_auth
-            || strlen($token_auth) != 32
-        ) {
-            die('<b>You must specify the Super User token_auth as a parameter to this script, eg. <code>?token_auth=XYZ</code> if you wish to run this script through the browser. </b><br>
-                However it is recommended to run it <a href="http://piwik.org/docs/setup-auto-archiving/">via cron in the command line</a>, since it can take a long time to run.<br/>
-                In a shell, execute for example the following to trigger archiving on the local Piwik server:<br/>
-                <code>$ /path/to/php /path/to/piwik/console core:archive --url=http://your-website.org/path/to/piwik/</code>');
-        }
-    }
-
     /**
      * Init Piwik, connect DB, create log & config objects, etc.
      */
diff --git a/misc/cron/archive.php b/misc/cron/archive.php
index 015a827986..bf8ed3317b 100644
--- a/misc/cron/archive.php
+++ b/misc/cron/archive.php
@@ -56,6 +56,17 @@ if (isset($_SERVER['argv']) && Piwik\Console::isSupported()) {
 
     $console->run();
 } else { // if running via web request, use CronArchive directly
+    $token_auth = Piwik\Common::getRequestVar('token_auth', '', 'string');
+
+    if ($token_auth !== $this->token_auth
+        || strlen($token_auth) != 32
+    ) {
+        die('<b>You must specify the Super User token_auth as a parameter to this script, eg. <code>?token_auth=XYZ</code> if you wish to run this script through the browser. </b><br>
+                However it is recommended to run it <a href="http://piwik.org/docs/setup-auto-archiving/">via cron in the command line</a>, since it can take a long time to run.<br/>
+                In a shell, execute for example the following to trigger archiving on the local Piwik server:<br/>
+                <code>$ /path/to/php /path/to/piwik/console core:archive --url=http://your-website.org/path/to/piwik/</code>');
+    }
+
     $archiver = new Piwik\CronArchive();
     $archiver->main();
 }
\ No newline at end of file
-- 
GitLab