@@ -233,6 +233,44 @@ function update($event_name,$data) {
233233 return 0 ;
234234 }
235235
236+ if ($ this ->action == 'update ' && $ data ["new " ]["document_root " ] != $ data ["old " ]["document_root " ]) {
237+
238+ // Get the old client ID
239+ $ old_client = $ app ->dbmaster ->queryOneRecord ("SELECT client_id FROM sys_group WHERE sys_group.groupid = " .intval ($ data ["old " ]["sys_groupid " ]));
240+ $ old_client_id = intval ($ old_client ["client_id " ]);
241+ unset($ old_client );
242+
243+ // Remove the old symlinks
244+ $ tmp_symlinks_array = explode (': ' ,$ web_config ["website_symlinks " ]);
245+ if (is_array ($ tmp_symlinks_array )) {
246+ foreach ($ tmp_symlinks_array as $ tmp_symlink ) {
247+ $ tmp_symlink = str_replace ("[client_id] " ,$ old_client_id ,$ tmp_symlink );
248+ $ tmp_symlink = str_replace ("[website_domain] " ,$ data ["old " ]["domain " ],$ tmp_symlink );
249+ // Remove trailing slash
250+ if (substr ($ tmp_symlink , -1 , 1 ) == '/ ' ) $ tmp_symlink = substr ($ tmp_symlink , 0 , -1 );
251+ // create the symlinks, if not exist
252+ if (!is_link ($ tmp_symlink )) {
253+ exec ("rm -f " .escapeshellcmd ($ tmp_symlink ));
254+ $ app ->log ("Removed Symlink: rm -f " .$ tmp_symlink ,LOGLEVEL_DEBUG );
255+ }
256+ }
257+ }
258+
259+ $ tmp_docroot = explode ('/ ' ,$ data ["new " ]["document_root " ]);
260+ unset($ tmp_docroot [count ($ tmp_docroot )-1 ]);
261+ $ new_dir = implode ('/ ' ,$ tmp_docroot );
262+
263+ $ tmp_docroot = explode ('/ ' ,$ data ["old " ]["document_root " ]);
264+ unset($ tmp_docroot [count ($ tmp_docroot )-1 ]);
265+ $ old_dir = implode ('/ ' ,$ tmp_docroot );
266+
267+ exec ('rm -rf ' .$ data ["new " ]["document_root " ]);
268+ if (!is_dir ($ new_dir )) exec ('mkdir -p ' .$ new_dir );
269+ exec ('mv ' .$ data ["old " ]["document_root " ].' ' .$ new_dir );
270+ $ app ->log ("Moving site to new document root: " .'mv ' .$ data ["old " ]["document_root " ].' ' .$ new_dir ,LOGLEVEL_DEBUG );
271+
272+ }
273+
236274 //print_r($data);
237275
238276 // Check if the directories are there and create them if nescessary.
0 commit comments