@@ -226,6 +226,9 @@ function update($event_name, $data) {
226226 $ homedir_old = $ data ['old ' ]['dir ' ].'/home/ ' .$ data ['old ' ]['username ' ];
227227 }
228228
229+ $ app ->log ("Homedir New: " .$ homedir , LOGLEVEL_DEBUG );
230+ $ app ->log ("Homedir Old: " .$ homedir_old , LOGLEVEL_DEBUG );
231+
229232 // Check if the user that we want to update exists, if not, we insert it
230233 if ($ app ->system ->is_user ($ data ['old ' ]['username ' ])) {
231234 //* Remove webfolder protection
@@ -246,16 +249,27 @@ function update($event_name, $data) {
246249 $app->log("Executed command: $command ",LOGLEVEL_DEBUG);
247250 */
248251 //$groupinfo = $app->system->posix_getgrnam($data['new']['pgroup']);
249- if ($ homedir != $ homedir_old && ! is_dir ( $ homedir ) ){
252+ if ($ homedir != $ homedir_old ){
250253 $ app ->system ->web_folder_protection ($ web ['document_root ' ], false );
251- if (!is_dir ($ data ['new ' ]['dir ' ].'/home ' )){
254+ // Rename dir, in case the new directory exists already.
255+ if (is_dir ($ homedir )) {
256+ $ app ->log ("New Homedir exists, renaming it to " .$ homedir .'_bak ' , LOGLEVEL_DEBUG );
257+ $ app ->system ->rename (escapeshellcmd ($ homedir ),escapeshellcmd ($ homedir .'_bak ' ));
258+ }
259+ /*if(!is_dir($data['new']['dir'].'/home')){
252260 $app->file->mkdirs(escapeshellcmd($data['new']['dir'].'/home'), '0750');
253261 $app->system->chown(escapeshellcmd($data['new']['dir'].'/home'),escapeshellcmd($data['new']['puser']));
254262 $app->system->chgrp(escapeshellcmd($data['new']['dir'].'/home'),escapeshellcmd($data['new']['pgroup']));
255263 }
256264 $app->file->mkdirs(escapeshellcmd($homedir), '0755');
257265 $app->system->chown(escapeshellcmd($homedir),'root');
258- $ app ->system ->chgrp (escapeshellcmd ($ homedir ),'root ' );
266+ $app->system->chgrp(escapeshellcmd($homedir),'root');*/
267+
268+ // Move old directory to new path
269+ $ app ->system ->rename (escapeshellcmd ($ homedir_old ),escapeshellcmd ($ homedir ));
270+ $ app ->file ->mkdirs (escapeshellcmd ($ homedir ), '0750 ' );
271+ $ app ->system ->chown (escapeshellcmd ($ homedir ),escapeshellcmd ($ data ['new ' ]['puser ' ]));
272+ $ app ->system ->chgrp (escapeshellcmd ($ homedir ),escapeshellcmd ($ data ['new ' ]['pgroup ' ]));
259273 $ app ->system ->web_folder_protection ($ web ['document_root ' ], true );
260274 } else {
261275 if (!is_dir ($ homedir )){
0 commit comments