From d03eea08a1b1cc2a0583004d1478d112f8dadc9b Mon Sep 17 00:00:00 2001
From: lvessiller <lvessiller@open-dsi.fr>
Date: Wed, 3 Feb 2021 15:20:32 +0100
Subject: [PATCH] FIX Pastell config flow is NULL

---
 lib/Controller/PageController.php | 10 ++++++++++
 lib/Settings/AdminSettings.php    | 10 ++++++++++
 2 files changed, 20 insertions(+)

diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index 3d3f0ae..1b104ee 100644
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -1001,6 +1001,16 @@ class PageController extends Controller {
         if (empty($this->_dematpayslipConfigList['payslip_dir']) || empty($this->_dematpayslipConfigList['user_id'])) {
             $this->_msgList['error'][] = $this->l->t('Veuillez vérifier la configuration de cette application.');
         }
+
+        $pastellUse = OC::$server->getConfig()->getAppValue($this->appName, 'pastell_use', '');
+        if (!empty($pastellUse)) {
+            // check Pastell API config
+            $pastellConfigFlow1Id = OC::$server->getConfig()->getAppValue($this->appName, 'pastell_config_f1_id', '');
+            $pastellConfigFlow2Id = OC::$server->getConfig()->getAppValue($this->appName, 'pastell_config_f2_id', '');
+            if (!($pastellConfigFlow1Id > 0) || !($pastellConfigFlow2Id > 0)) {
+                $this->_msgList['error'][] = $this->l->t('Veuillez vérifier la configuration de cette application.');
+            }
+        }
     }
 
     /**
diff --git a/lib/Settings/AdminSettings.php b/lib/Settings/AdminSettings.php
index f93e255..22a6774 100644
--- a/lib/Settings/AdminSettings.php
+++ b/lib/Settings/AdminSettings.php
@@ -276,6 +276,16 @@ class AdminSettings implements ISettings {
             }
 
             if (count($this->_msgList['error']) <= 0) {
+                $pastellConfigF1Id = $this->config->getAppValue($this->appName, 'pastell_config_f1_id');
+                // FIX -- Pastell config flow is NULL
+                if (empty($pastellConfigF1Id)) {
+                    $this->config->deleteAppValue($this->appName,'pastell_config_f1_id');
+                }
+                $pastellConfigF2Id = $this->config->getAppValue($this->appName, 'pastell_config_f2_id');
+                // FIX -- Pastell config flow is NULL
+                if (empty($pastellConfigF2Id)) {
+                    $this->config->deleteAppValue($this->appName,'pastell_config_f2_id');
+                }
                 $this->config->setAppValue($this->appName, 'pastell_config_f1_id', $pastellConfigFlow1Id);
                 $this->config->setAppValue($this->appName, 'pastell_config_f2_id', $pastellConfigFlow2Id);
             }
-- 
GitLab