瀏覽代碼

fix null be_user bug

Olivier Massot 4 年之前
父節點
當前提交
df9dc90c29
共有 2 個文件被更改,包括 38 次插入1 次删除
  1. 6 1
      ot_core/Classes/Page/OtPageRepository.php
  2. 32 0
      ot_core/Classes/Utility/FileUtility.php

+ 6 - 1
ot_core/Classes/Page/OtPageRepository.php

@@ -222,7 +222,12 @@ class OtPageRepository
     {
         // Check if the current be-user has a db_mountpoint, and only has one.
         // If so, this will be considered as the selected site (since its the only one available)
-        $mountpoints = $GLOBALS['BE_USER']->returnWebmounts();
+        $be_user = $GLOBALS['BE_USER'];
+        if ($be_user == null) {
+            return [];
+        }
+
+        $mountpoints = $be_user->returnWebmounts();
         $mountpoints = array_filter($mountpoints, function($m) { return $m != 0; });
 
         return $mountpoints;

+ 32 - 0
ot_core/Classes/Utility/FileUtility.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace Opentalent\OtCore\Utility;
+
+class FileUtility
+{
+    /**
+     * If $recursive is true, recursively delete a directory and all its content.
+     * Else, does a simple rmdir($dir)
+     *
+     * @param $dir
+     */
+    public static function rmdir($dir, $recursive=false) {
+        if (!$recursive) {
+            rmdir($dir);
+        } else {
+            if (is_dir($dir)) {
+                $objects = scandir($dir);
+                foreach ($objects as $object) {
+                    if ($object != "." && $object != "..") {
+                        if (is_dir($dir. DIRECTORY_SEPARATOR .$object) && !is_link($dir."/".$object))
+                            self::rmdir($dir. DIRECTORY_SEPARATOR. $object, true);
+                        else
+                            unlink($dir. DIRECTORY_SEPARATOR. $object);
+                    }
+                }
+                rmdir($dir);
+            }
+        }
+    }
+
+}