@@ -216,14 +216,41 @@ function update($event_name,$data) {
216216 if (!is_dir ($ data ["new " ]["document_root " ]."/ssl " )) exec ("mkdir -p " .$ data ["new " ]["document_root " ]."/ssl " );
217217 if (!is_dir ($ data ["new " ]["document_root " ]."/cgi-bin " )) exec ("mkdir -p " .$ data ["new " ]["document_root " ]."/cgi-bin " );
218218
219+ // Remove the symlink for the site, if site is renamed
220+ if ($ this ->action == 'update ' && $ data ["old " ]["domain " ] != '' && $ data ["new " ]["domain " ] != $ data ["old " ]["domain " ]) {
221+ if (is_dir ('/var/log/ispconfig/httpd/ ' .$ data ["old " ]["domain " ])) exec ('rm -rf /var/log/ispconfig/httpd/ ' .$ data ["old " ]["domain " ]);
222+ if (is_link ($ data ["new " ]["document_root " ]."/log " )) exec ("rm -f " .$ data ["new " ]["document_root " ]."/log " );
223+ }
224+
219225 // Create the symlink for the logfiles
220226 if (!is_dir ('/var/log/ispconfig/httpd/ ' .$ data ["new " ]["domain " ])) exec ('mkdir -p /var/log/ispconfig/httpd/ ' .$ data ["new " ]["domain " ]);
221227 if (!is_link ($ data ["new " ]["document_root " ]."/log " )) exec ("ln -s /var/log/ispconfig/httpd/ " .$ data ["new " ]["domain " ]." " .$ data ["new " ]["document_root " ]."/log " );
222228
223- // Create the symlinks for the sites
229+
230+ // Get the client ID
224231 $ client = $ app ->db ->queryOneRecord ("SELECT client_id FROM sys_group WHERE sys_group.groupid = " .intval ($ data ["new " ]["sys_groupid " ]));
225232 $ client_id = intval ($ client ["client_id " ]);
226233 unset($ client );
234+
235+ // Remove old symlinks, if site is renamed
236+ if ($ this ->action == 'update ' && $ data ["old " ]["domain " ] != '' && $ data ["new " ]["domain " ] != $ data ["old " ]["domain " ]) {
237+ $ tmp_symlinks_array = explode (': ' ,$ web_config ["website_symlinks " ]);
238+ if (is_array ($ tmp_symlinks_array )) {
239+ foreach ($ tmp_symlinks_array as $ tmp_symlink ) {
240+ $ tmp_symlink = str_replace ("[client_id] " ,$ client_id ,$ tmp_symlink );
241+ $ tmp_symlink = str_replace ("[website_domain] " ,$ data ["new " ]["domain " ],$ tmp_symlink );
242+ // Remove trailing slash
243+ if (substr ($ tmp_symlink , -1 , 1 ) == '/ ' ) $ tmp_symlink = substr ($ tmp_symlink , 0 , -1 );
244+ // create the symlinks, if not exist
245+ if (!is_link ($ tmp_symlink )) {
246+ exec ("rm -f " .escapeshellcmd ($ tmp_symlink ));
247+ $ app ->log ("Removed Symlink: rm -f " .$ tmp_symlink ,LOGLEVEL_DEBUG );
248+ }
249+ }
250+ }
251+ }
252+
253+ // Create the symlinks for the sites
227254 $ tmp_symlinks_array = explode (': ' ,$ web_config ["website_symlinks " ]);
228255 if (is_array ($ tmp_symlinks_array )) {
229256 foreach ($ tmp_symlinks_array as $ tmp_symlink ) {
@@ -239,6 +266,7 @@ function update($event_name,$data) {
239266 }
240267 }
241268
269+
242270 if ($ this ->action == 'insert ' ) {
243271 // Copy the error pages
244272 $ error_page_path = escapeshellcmd ($ data ["new " ]["document_root " ])."/web/error/ " ;
0 commit comments