]> source.dussan.org Git - nextcloud-server.git/commitdiff
make it possible to prepopulate a new user gome with a skeleton
authorFrank Karlitschek <frank@owncloud.org>
Thu, 3 Oct 2013 21:22:11 +0000 (23:22 +0200)
committerFrank Karlitschek <frank@owncloud.org>
Thu, 3 Oct 2013 21:22:11 +0000 (23:22 +0200)
core/skeleton/.gitignore [new file with mode: 0644]
lib/private/util.php

diff --git a/core/skeleton/.gitignore b/core/skeleton/.gitignore
new file mode 100644 (file)
index 0000000..5e7d273
--- /dev/null
@@ -0,0 +1,4 @@
+# Ignore everything in this directory
+*
+# Except this file
+!.gitignore
index 1cbb19eaec44ae70f4ef8a3506db79b20bc1d217..004e82d7d2691eeae95fbdcd71538a13b9bb204d 100755 (executable)
@@ -68,6 +68,7 @@ class OC_Util {
                        $userDirectory = $userRoot . '/files';
                        if( !is_dir( $userDirectory )) {
                                mkdir( $userDirectory, 0755, true );
+                               OC_Util::copySkeleton($userDirectory);
                        }
                        //jail the user into his "home" directory
                        \OC\Files\Filesystem::init($user, $userDir);
@@ -92,6 +93,37 @@ class OC_Util {
                }
        }
 
+       /**
+        * @brief copies the user skeleton files into the fresh userr home files
+        * @param string $userDirectory
+        * @return void
+        */
+       public static function copySkeleton($userDirectory) {
+               error_log('skeleton init '.$userDirectory);
+               OC_Util::copyr(\OC::$SERVERROOT.'/core/skeleton' , $userDirectory);
+       }
+
+       /**
+        * @brief copies a directory recursively
+        * @param string $source
+        * @param string $target
+        * @return void
+        */
+       function copyr($source,$target) {
+               $dir = opendir($source);
+               @mkdir($target);
+               while(false !== ( $file = readdir($dir)) ) {
+                       if (( $file != '.' ) && ( $file != '..' )) {
+                               if ( is_dir($source . '/' . $file) ) {
+                                       OC_Util::copyr($source . '/' . $file , $target . '/' . $file);
+                               } else {
+                                       copy($source . '/' . $file,$target . '/' . $file);
+                               }
+                       }
+               }
+               closedir($dir);
+       }
+
        /**
         * @return void
         */