Skip to content

Commit d053cb0

Browse files
committed
Fixed moving of site when the client is changed.
1 parent e107101 commit d053cb0

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

interface/web/sites/web_domain_edit.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,15 +330,15 @@ function onAfterUpdate() {
330330
$client_id = intval($client["client_id"]);
331331
}
332332

333-
/*
334-
// Set the values for document_root, system_user and system_group
335-
$system_user = 'web'.$this->id;
336-
$system_group = 'client'.$client_id;
337-
$document_root = str_replace("[client_id]",$client_id,$document_root);
333+
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"]) && $this->dataRecord["client_group_id"] != $this->oldDataRecord["client_group_id"]) {
334+
// Set the values for document_root, system_user and system_group
335+
$system_user = 'web'.$this->id;
336+
$system_group = 'client'.$client_id;
337+
$document_root = str_replace("[client_id]",$client_id,$document_root);
338338

339-
$sql = "UPDATE web_domain SET system_user = '$system_user', system_group = '$system_group', document_root = '$document_root' WHERE domain_id = ".$this->id;
340-
$app->db->query($sql);
341-
*/
339+
$sql = "UPDATE web_domain SET system_user = '$system_user', system_group = '$system_group', document_root = '$document_root' WHERE domain_id = ".$this->id;
340+
$app->db->query($sql);
341+
}
342342

343343
}
344344

server/plugins-available/apache2_plugin.inc.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)