From cf0ba4d06c6c8d643fbbcd7cca7bbc7d0419cd9f Mon Sep 17 00:00:00 2001
From: diosmosis <benaka@piwik.pro>
Date: Mon, 17 Nov 2014 22:57:58 -0800
Subject: [PATCH] Fix cron archiving if no visits on some days.

---
 core/CronArchive.php | 4 +++-
 plugins/API/API.php  | 4 ++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/core/CronArchive.php b/core/CronArchive.php
index 89848e4c3c..eff5e0277d 100644
--- a/core/CronArchive.php
+++ b/core/CronArchive.php
@@ -857,6 +857,8 @@ class CronArchive
 
         $config->log = $log;
 
+        Log::unsetInstance();
+
         // Make sure we log at least INFO (if logger is set to DEBUG then keep it)
         $logLevel = Log::getInstance()->getLogLevel();
         if ($logLevel < Log::INFO) {
@@ -1211,7 +1213,7 @@ class CronArchive
 
         $today = end($stats);
 
-        if (empty($today)) {
+        if (empty($today['nb_visits'])) {
             return 0;
         }
 
diff --git a/plugins/API/API.php b/plugins/API/API.php
index e40aaec20e..e7470b2ab0 100644
--- a/plugins/API/API.php
+++ b/plugins/API/API.php
@@ -441,6 +441,10 @@ class API extends \Piwik\Plugin\API
         }
 
         $firstRow1 = $table1->getFirstRow();
+        if (empty($firstRow1)) {
+            $firstRow1 = $table1->addRow(new Row());
+        }
+
         $firstRow2 = $table2->getFirstRow();
         if ($firstRow2 instanceof Row) {
             foreach ($firstRow2->getColumns() as $metric => $value) {
-- 
GitLab