Explorar el Código

fix the regen sites config command

Olivier Massot hace 4 años
padre
commit
1be0f2a6c5
Se han modificado 2 ficheros con 18 adiciones y 1 borrados
  1. 1 0
      docker/.gitignore
  2. 17 1
      ot_admin/Classes/Controller/SiteController.php

+ 1 - 0
docker/.gitignore

@@ -0,0 +1 @@
+/.idea/

+ 17 - 1
ot_admin/Classes/Controller/SiteController.php

@@ -1781,10 +1781,11 @@ class SiteController extends ActionController
             if (!$commitSuccess) {
                 throw new \RuntimeException('Something went wrong while committing the result');
             }
+            $this->rrmdir($backupConfigDir);
         }
         catch (\Throwable $e) {
             // rollback
-            rmdir($configRootDir);
+            $this->rrmdir($configRootDir);
             rename($backupConfigDir, $configRootDir);
             $this->connectionPool->getConnectionByName('Default')->rollback();
             throw $e;
@@ -2186,6 +2187,21 @@ class SiteController extends ActionController
         return $identifier;
     }
 
+    /**
+     * Recursively remove the target directory (! no rollback available)
+     */
+    private function rrmdir(string $dir) {
+        if (!is_dir($dir) || is_link($dir)) return unlink($dir);
+        foreach (scandir($dir) as $file) {
+            if ($file == '.' || $file == '..') continue;
+            if (!$this->rrmdir($dir . DIRECTORY_SEPARATOR . $file)) {
+                chmod($dir . DIRECTORY_SEPARATOR . $file, 0777);
+                if (!$this->rrmdir($dir . DIRECTORY_SEPARATOR . $file)) return false;
+            };
+        }
+        return rmdir($dir);
+    }
+
     /**
      * Create the BE user for the website, then return its uid
      * The user shall be already created in the Opentalent DB