From d3335217d2b8925c9243496a0ed8122329fc0f2d Mon Sep 17 00:00:00 2001
From: Florian Bogner <f.bogner@pcsg.de>
Date: Fri, 11 Nov 2016 10:54:16 +0100
Subject: [PATCH] fix: Minor bugfixes and improvements for the cronservice
 client.

---
 ajax/cronservice/getStatus.php |  1 +
 bin/CronServiceWindow.js       |  7 ++++---
 locale.xml                     |  7 +++++--
 src/QUI/Cron/CronService.php   | 20 ++++++++++++--------
 4 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/ajax/cronservice/getStatus.php b/ajax/cronservice/getStatus.php
index 93cc62a..8c5d208 100644
--- a/ajax/cronservice/getStatus.php
+++ b/ajax/cronservice/getStatus.php
@@ -9,6 +9,7 @@ QUI::$Ajax->registerFunction(
     'package_quiqqer_cron_ajax_cronservice_getStatus',
     function () {
         $CronService = new \QUI\Cron\CronService();
+
         return $CronService->getStatus();
     },
     array(),
diff --git a/bin/CronServiceWindow.js b/bin/CronServiceWindow.js
index e12e93b..0386447 100644
--- a/bin/CronServiceWindow.js
+++ b/bin/CronServiceWindow.js
@@ -69,17 +69,16 @@ define('package/quiqqer/cron/bin/CronServiceWindow', [
             this.Loader.show();
 
             QUIAjax.get('package_quiqqer_cron_ajax_cronservice_getStatus', function (result) {
-                console.log(result);
                 var status = result;
 
                 var statusText = QUILocale.get(lg, 'cron.window.cronservice.status.text.unregistered');
-
                 if (status['status'] == 1) {
                     statusText = QUILocale.get(lg, 'cron.window.cronservice.status.text.registered');
                 }
                 if (status['status'] == 2) {
                     statusText = QUILocale.get(lg, 'cron.window.cronservice.status.text.inactive');
                 }
+                console.log(status);
 
                 Content.set('html', Mustache.render(template, {
                     cron_window_cronservice_content_title                           : QUILocale.get(lg, 'cron.window.cronservice.content.title'),
@@ -94,7 +93,7 @@ define('package/quiqqer/cron/bin/CronServiceWindow', [
                     cron_window_cronservice_content_register_lbl_stats_lastExecution: QUILocale.get(lg, 'cron.window.cronservice.content.register.lbl.stats.lastExecution'),
                     statusText                                                      : statusText,
                     status                                                          : status['status'],
-                    statusErrors                                                    : status['errors'],
+                    statusErrors                                                    : status['current_failures'], //== 0 ? "0": status['errors'].toString(),
                     statusLastExecution                                             : status['last_execution'],
                     registered                                                      : (status['status'] != 0),
                     active                                                          : (status['status'] == 1),
@@ -175,6 +174,8 @@ define('package/quiqqer/cron/bin/CronServiceWindow', [
                             self.register(Email.value).then(function () {
                                 self.refresh();
                                 Sheet.destroy();
+                            }).catch(function () {
+                                self.Loader.hide();
                             });
                         });
                     },
diff --git a/locale.xml b/locale.xml
index db7cdf1..a972e89 100644
--- a/locale.xml
+++ b/locale.xml
@@ -64,13 +64,16 @@
         </locale>
         <locale name="exception.registration.empty.email">
             <de><![CDATA[Es muss eine Email angegeben sein.]]></de>
-            <en><![CDATA[A email must be given.]]></en>
+            <en><![CDATA[An email must be given.]]></en>
         </locale>
         <locale name="exception.registration.empty.packageDir">
             <de><![CDATA[Konnte den "package" Pfad nicht auslesen!]]></de>
             <en><![CDATA[Could not parse the "package" folder path.]]></en>
         </locale>
-
+        <locale name="cron.window.cronservice.status.text.last_execution.never">
+            <de><![CDATA[Nie]]></de>
+            <en><![CDATA[Never]]></en>
+        </locale>
     </groups>
     <groups name="quiqqer/cron" datatype="js">
         <locale name="cron.id">
diff --git a/src/QUI/Cron/CronService.php b/src/QUI/Cron/CronService.php
index a67aed0..aeab499 100644
--- a/src/QUI/Cron/CronService.php
+++ b/src/QUI/Cron/CronService.php
@@ -8,7 +8,8 @@ use QUI\System\Log;
 class CronService
 {
 
-    const CRONSERVICE_URL = "https://cron.quiqqer.com";
+    const CRONSERVICE_URL = "http://server.local"; // TODO DEBUG REMOVE
+    //const CRONSERVICE_URL = "https://cron.quiqqer.com";
 
     private $domain;
     private $https;
@@ -56,7 +57,9 @@ class CronService
      *       'status'           => 0,  (0=unregistered; 1=active; 2=inactive)
      *       'current_failures' => int,
      *       'total_failures'   => int,
-     *       'last_execution'   => string (mysql dateformat)
+     *       'last_execution'   => string (mysql dateformat | Localized 'never')
+     * )
+     *
      * @return mixed
      */
     public function getStatus()
@@ -65,6 +68,13 @@ class CronService
             'domain' => $this->domain
         ));
 
+        if (empty($status['last_execution'])) {
+            $status['last_execution'] = QUI::getLocale()->get(
+                'quiqqer/cron',
+                'cron.window.cronservice.status.text.last_execution.never'
+            );
+        }
+
         return $status;
     }
 
@@ -171,8 +181,6 @@ class CronService
             $url .= '&' . $param . '=' . urlencode($value);
         }
 
-        Log::addDebug("Ajax Request : " . $url);
-
         $curl = curl_init();
         curl_setopt_array($curl, array(
             CURLOPT_RETURNTRANSFER => 1,
@@ -182,8 +190,6 @@ class CronService
 
         $response = curl_exec($curl);
 
-        Log::addDebug($response);
-
         curl_close($curl);
 
         // Process raw ajax response
@@ -195,8 +201,6 @@ class CronService
             throw new QUI\Exception($response[$function]['Exception']['message']);
         }
 
-        Log::writeRecursive($response);
-
         return $response[$function]['result'];
     }
 
-- 
GitLab