From 96b8339d21eab4bc275d365b9ba51c24108feda7 Mon Sep 17 00:00:00 2001
From: Regis Houssin <regis.houssin@capnetworks.com>
Date: Fri, 26 May 2017 17:38:57 +0200
Subject: [PATCH] Fix: [Restler] Delete the cache file otherwise it does not
 update

---
 htdocs/api/admin/index.php | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/htdocs/api/admin/index.php b/htdocs/api/admin/index.php
index 8142b564c1e..8ea22cee1d3 100644
--- a/htdocs/api/admin/index.php
+++ b/htdocs/api/admin/index.php
@@ -43,12 +43,29 @@ if ($action == 'setproductionmode')
 
 	if (dolibarr_set_const($db, 'API_PRODUCTION_MODE', $status, 'chaine', 0, '', $conf->entity) > 0)
 	{
-	    $result = dol_mkdir($conf->api->dir_temp);
-	    if ($result < 0)
-	    {
-	        setEventMessages($langs->trans("ErrorFaildToCreateDir", $conf->api->dir_temp), null, 'errors');
-	    }
-	    else
+		$error=0;
+
+		if ($status == 1)
+		{
+			$result = dol_mkdir($conf->api->dir_temp);
+			if ($result < 0)
+			{
+				setEventMessages($langs->trans("ErrorFailedToCreateDir", $conf->api->dir_temp), null, 'errors');
+				$error++;
+			}
+		}
+		else
+		{
+			// Delete the cache file otherwise it does not update
+			$result = dol_delete_file($conf->api->dir_temp.'/routes.php');
+			if ($result < 0)
+			{
+				setEventMessages($langs->trans("ErrorFailedToDeleteFile", $conf->api->dir_temp.'/routes.php'), null, 'errors');
+				$error++;
+			}
+		}
+
+	    if (!$error)
 	    {
     		header("Location: ".$_SERVER["PHP_SELF"]);
 	   	    exit;
-- 
GitLab