From c02b31f93b148970d501f742c1b24707c572f3ee Mon Sep 17 00:00:00 2001
From: "florian.azizian" <florian.azizian@maarch.org>
Date: Sun, 7 Jul 2019 22:07:02 +0100
Subject: [PATCH] FIX #9305 improve minor update process

---
 install/class/Class_Install.php     | 14 +++++++-------
 install/scripts/backupVersion.php   | 10 ++++++++--
 install/view/update_backup_view.php | 21 ++++++++-------------
 3 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/install/class/Class_Install.php b/install/class/Class_Install.php
index fbd885e3ff1..ab95fca638b 100755
--- a/install/class/Class_Install.php
+++ b/install/class/Class_Install.php
@@ -1320,7 +1320,7 @@ class Install extends functions
         $db->query($query, array($sec->getPasswordHash($newPass)));
     }
 
-    public function copy_dir($dir2copy, $dir_paste, $excludeExt = false, $excludeSymlink = false)
+    public function copy_dir($dir2copy, $dir_paste, $excludeExt = false, $excludeSymlink = false, $excludeDirectories = [])
     {
         // On vérifie si $dir2copy est un dossier
         if (is_dir($dir2copy)) {
@@ -1336,11 +1336,11 @@ class Install extends functions
                     }
                     // S'il s'agit d'un dossier, on relance la fonction recursive
                     if ($excludeSymlink) {
-                        if (is_dir($dir2copy.$file) && $file != '..' && $file != '.' && !is_link($dir2copy.$file)) {
-                            if (!$this->copy_dir($dir2copy.$file.'/', $dir_paste.$file.'/', $excludeExt, $excludeSymlink)) {
+                        if (is_dir($dir2copy.$file) && $file != '..' && $file != '.' && !is_link($dir2copy.$file) && !in_array($file, $excludeDirectories)) {
+                            if (!$this->copy_dir($dir2copy.$file.'/', $dir_paste.$file.'/', $excludeExt, $excludeSymlink, $excludeDirectories)) {
                                 return false;
                             }
-                        } elseif ($file != '..' && $file != '.' && !is_link($dir2copy.$file)) {
+                        } elseif ($file != '..' && $file != '.' && !is_link($dir2copy.$file) && !in_array($file, $excludeDirectories)) {
                             if (is_array($excludeExt) && count($excludeExt)>0) {
                                 $copyIt = true;
                                 foreach ($excludeExt as $key => $value) {
@@ -1356,11 +1356,11 @@ class Install extends functions
                             }
                         }
                     } else {
-                        if (is_dir($dir2copy.$file) && $file != '..' && $file != '.') {
-                            if (!$this->copy_dir($dir2copy.$file.'/', $dir_paste.$file.'/', $excludeExt, $excludeSymlink)) {
+                        if (is_dir($dir2copy.$file) && $file != '..' && $file != '.' && !in_array($file, $excludeDirectories)) {
+                            if (!$this->copy_dir($dir2copy.$file.'/', $dir_paste.$file.'/', $excludeExt, $excludeSymlink, $excludeDirectories)) {
                                 return false;
                             }
-                        } elseif ($file != '..' && $file != '.') {
+                        } elseif ($file != '..' && $file != '.' && !in_array($file, $excludeDirectories)) {
                             if (is_array($excludeExt) && count($excludeExt) > 0) {
                                 $copyIt = true;
                                 foreach ($excludeExt as $key => $value) {
diff --git a/install/scripts/backupVersion.php b/install/scripts/backupVersion.php
index 8013d02de7a..beefe73e525 100755
--- a/install/scripts/backupVersion.php
+++ b/install/scripts/backupVersion.php
@@ -50,7 +50,7 @@ if (!$Class_Install->createPath($path)) {
     exit;
 }
 
-if (!$Class_Install->copy_dir($_SESSION['config']['corepath'] , $path . DIRECTORY_SEPARATOR, false, true)) {
+if (!$Class_Install->copy_dir($_SESSION['config']['corepath'], $path . DIRECTORY_SEPARATOR, false, true, ['logs', 'log', 'tmp'])) {
     $return['status'] = 0;
     $return['text'] = _CAN_NOT_COPY_TO . ' : ' . $path . '<br>' . _CHECK_RIGHT_SOURCE_FOLDER;
 
@@ -59,5 +59,11 @@ if (!$Class_Install->copy_dir($_SESSION['config']['corepath'] , $path . DIRECTOR
     echo $jsonReturn;
     exit;
 }
-echo '{"status":1}';
+
+$return['status'] = 1;
+$return['text'] = '';
+
+$jsonReturn = json_encode($return);
+
+echo $jsonReturn;
 exit;
diff --git a/install/view/update_backup_view.php b/install/view/update_backup_view.php
index 1131ad485f6..0f31b6a92e7 100755
--- a/install/view/update_backup_view.php
+++ b/install/view/update_backup_view.php
@@ -24,8 +24,7 @@ if ($_SESSION['user']['UserId'] <> 'superadmin') {
 <script>
     function launchProcess(
         myVar
-    )
-    {
+    ) {
         $(document).ready(function() {
             var oneIsEmpty = false;
             if (myVar.length < 1) {
@@ -41,7 +40,7 @@ if ($_SESSION['user']['UserId'] <> 'superadmin') {
 
             ajax(
                 'backupVersion',
-                'myVar|'+myVar,
+                'myVar|' + myVar,
                 'ajaxReturn',
                 'false'
             );
@@ -71,7 +70,7 @@ if ($_SESSION['user']['UserId'] <> 'superadmin') {
                                 :
                             </td>
                             <td>
-                                <input type="text" id="actualPath" size="60" disabled name="actualPath" value="<?php echo $_SESSION['config']['corepath'];?>"/>
+                                <input type="text" id="actualPath" size="60" disabled name="actualPath" value="<?php echo $_SESSION['config']['corepath'];?>" />
                             </td>
                         </tr>
                         <tr>
@@ -82,7 +81,7 @@ if ($_SESSION['user']['UserId'] <> 'superadmin') {
                                 :
                             </td>
                             <td>
-                                <input type="text" id="path" size="60" name="backupPath" value=""/>
+                                <input type="text" id="path" size="60" name="backupPath" value="" />
                             </td>
                         </tr>
                         <tr>
@@ -94,11 +93,7 @@ if ($_SESSION['user']['UserId'] <> 'superadmin') {
                             <td></td>
                             <td></td>
                             <td>
-                                <input
-                                  type="button"
-                                  name="Submit" id="ajaxReturn_button"  value="<?php echo _BACKUP_ACTUAL_VERSION;?>"
-                                  onClick="$(this).css('display', 'none');launchProcess($('#path').val());"
-                                />
+                                <input type="button" name="Submit" id="ajaxReturn_button" value="<?php echo _BACKUP_ACTUAL_VERSION;?>" onClick="$(this).css('display', 'none');launchProcess($('#path').val());" />
                             </td>
                         </tr>
                     </table>
@@ -106,7 +101,7 @@ if ($_SESSION['user']['UserId'] <> 'superadmin') {
                 <br />
                 <div id="ajaxReturn_ko"></div>
                 <div align="center">
-                    <img src="img/wait.gif" width="100" class="wait" style="display: none; background-color: rgba(0, 0, 0, 0.2);"/>
+                    <img src="img/wait.gif" width="100" class="wait" style="display: none; background-color: rgba(0, 0, 0, 0.2);" />
                 </div>
             </p>
         </div>
@@ -123,7 +118,7 @@ if ($_SESSION['user']['UserId'] <> 'superadmin') {
                     </a>
                 </div>
                 <div style="float: right;" class="nextButton" id="next">
-                    <a href="#" onClick="goTo('index.php?step=update_download');" class="ajaxReturn" id="ajaxReturn_ok" style="display: none;">
+                    <a href="#" onClick="goTo('index.php?step=update_download');" id="ajaxReturn" style="display: none;">
                         <?php echo _NEXT_INSTALL;?>
                     </a>
                 </div>
@@ -132,4 +127,4 @@ if ($_SESSION['user']['UserId'] <> 'superadmin') {
             <br />
         </p>
     </div>
-</div>
+</div>
\ No newline at end of file
-- 
GitLab