Skip to content

Commit 9eff6c2

Browse files
committed
Fixed several bugs in data replication.
1 parent 70e890e commit 9eff6c2

File tree

8 files changed

+57
-29
lines changed

8 files changed

+57
-29
lines changed

install/sql/ispconfig3.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ CREATE TABLE `server` (
598598
`db_server` tinyint(4) NOT NULL default '0',
599599
`vserver_server` tinyint(4) NOT NULL default '0',
600600
`config` text NOT NULL,
601-
`updated` tinyint(4) NOT NULL default '0',
601+
`updated` bigint(20) unsigned NOT NULL default '0',
602602
`active` tinyint(4) NOT NULL default '1',
603603
PRIMARY KEY (`server_id`)
604604
) ENGINE=MyISAM AUTO_INCREMENT=1 ;
@@ -1004,6 +1004,7 @@ INSERT INTO `sys_group` (`groupid`, `name`, `description`, `client_id`) VALUES (
10041004
CREATE TABLE `sys_log` (
10051005
`syslog_id` int(10) unsigned NOT NULL auto_increment,
10061006
`server_id` int(10) unsigned NOT NULL default '0',
1007+
`datalog_id` bigint(20) unsigned NOT NULL default '0',
10071008
`loglevel` tinyint(4) NOT NULL default '0',
10081009
`tstamp` int(10) unsigned NOT NULL,
10091010
`message` text,

install/update.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,15 @@
134134

135135
//* Update $conf array with values from the server.ini that shall be preserved
136136
$tmp = $inst->db->queryOneRecord("SELECT * FROM ".$conf["mysql"]["database"].".server WHERE server_id = ".$conf['server_id']);
137+
$ini_array = ini_to_array(stripslashes($tmp['config']));
137138

138139
$conf['services']['mail'] = ($tmp['mail_server'] == 1)?true:false;
139140
$conf['services']['web'] = ($tmp['web_server'] == 1)?true:false;
140141
$conf['services']['dns'] = ($tmp['dns_server'] == 1)?true:false;
141142
$conf['services']['file'] = ($tmp['file_server'] == 1)?true:false;
142143
$conf['services']['db'] = ($tmp['db_server'] == 1)?true:false;
143144
$conf['services']['vserver'] = ($tmp['vserver_server'] == 1)?true:false;
145+
$conf['postfix']['vmail_mailbox_base'] = $ini_array['mail']['homedir_path'];
144146

145147
//** Delete the old database
146148
if( !$inst->db->query('DROP DATABASE IF EXISTS '.$conf['mysql']['database']) ) {

interface/lib/app.inc.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,11 @@ public function lng($text)
145145
//* loading global and module Wordbook
146146
// TODO: this need to be made clearer somehow - pedro
147147
@include_once(ISPC_ROOT_PATH.'/lib/lang/'.$_SESSION['s']['language'].'.lng');
148-
$lng_file = ISPC_ROOT_PATH.'/web/'.$_SESSION['s']['module']['name'].'/lib/lang/'.$_SESSION['s']['language'].'.lng';
149-
if(!file_exists($lng_file)) $lng_file = ISPC_ROOT_PATH.'/web/'.$_SESSION['s']['module']['name'].'/lib/lang/en.lng';
150-
include_once($lng_file);
148+
if(isset($_SESSION['s']['module']['name']) && isset($_SESSION['s']['language'])) {
149+
$lng_file = ISPC_ROOT_PATH.'/web/'.$_SESSION['s']['module']['name'].'/lib/lang/'.$_SESSION['s']['language'].'.lng';
150+
if(!file_exists($lng_file)) $lng_file = ISPC_ROOT_PATH.'/web/'.$_SESSION['s']['module']['name'].'/lib/lang/en.lng';
151+
@include_once($lng_file);
152+
}
151153
$this->_wb = $wb;
152154
$this->_language_inc = 1;
153155
}

server/lib/app.inc.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,27 @@ function log($msg, $priority = 0) {
125125
}
126126
echo date("d.m.Y-H:i")." - ".$priority_txt." - ". $msg."\n";
127127
fclose($fp);
128-
128+
129129
// Log to database
130-
if(isset($this->db)) {
130+
if(isset($this->dbmaster)) {
131131
$server_id = $conf['server_id'];
132132
$loglevel = $priority;
133133
$tstamp = time();
134-
$message = $this->db->quote($msg);
135-
$sql = "INSERT INTO sys_log (server_id,loglevel,tstamp,message) VALUES ('$server_id','$loglevel','$tstamp','$message')";
136-
$this->db->query($sql);
134+
$message = $this->dbmaster->quote($msg);
135+
$datalog_id = (isset($this->modules->current_datalog_id) && $this->modules->current_datalog_id > 0)?$this->modules->current_datalog_id:0;
136+
if($datalog_id > 0) {
137+
$tmp_rec = $this->dbmaster->queryOneRecord("SELECT count(syslog_id) as number FROM sys_log WHERE datalog_id = $datalog_id AND loglevel = ".LOGLEVEL_ERROR);
138+
//* Do not insert duplicate errors into the web log.
139+
if($tmp_rec['number'] == 0) {
140+
$sql = "INSERT INTO sys_log (server_id,datalog_id,loglevel,tstamp,message) VALUES ('$server_id',$datalog_id,'$loglevel','$tstamp','$message')";
141+
$this->dbmaster->query($sql);
142+
}
143+
} else {
144+
$sql = "INSERT INTO sys_log (server_id,datalog_id,loglevel,tstamp,message) VALUES ('$server_id',0,'$loglevel','$tstamp','$message')";
145+
$this->dbmaster->query($sql);
146+
}
147+
148+
137149
}
138150

139151
//} else {

server/lib/classes/modules.inc.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
class modules {
3232

3333
var $notification_hooks = array();
34+
var $current_datalog_id = 0;
35+
var $debug = false;
3436

3537
/*
3638
This function is called to load the modules from the mods-enabled or the mods-core folder
@@ -48,7 +50,7 @@ function loadModules($type) {
4850
if($file != '.' && $file != '..' && substr($file,-8,8) == '.inc.php') {
4951
$module_name = substr($file,0,-8);
5052
include_once($modules_dir.$file);
51-
$app->log("Loading Module: $module_name",LOGLEVEL_DEBUG);
53+
if($this->debug) $app->log("Loading Module: $module_name",LOGLEVEL_DEBUG);
5254
$app->loaded_modules[$module_name] = new $module_name;
5355
$app->loaded_modules[$module_name]->onLoad();
5456
}
@@ -68,7 +70,7 @@ function loadModules($type) {
6870
function registerTableHook($table_name,$module_name,$function_name) {
6971
global $app;
7072
$this->notification_hooks[$table_name][] = array('module' => $module_name, 'function' => $function_name);
71-
$app->log("Registered TableHook '$table_name' in module '$module_name' for processing function '$function_name'",LOGLEVEL_DEBUG);
73+
if($this->debug) $app->log("Registered TableHook '$table_name' in module '$module_name' for processing function '$function_name'",LOGLEVEL_DEBUG);
7274
}
7375

7476
/*
@@ -83,13 +85,15 @@ function processDatalog() {
8385
// TODO: process only new entries.
8486
//* If its a multiserver setup
8587
if($app->db->dbHost != $app->dbmaster->dbHost) {
86-
$sql = "SELECT * FROM sys_datalog WHERE server_id = ".$conf["server_id"]." ORDER BY datalog_id";
88+
$sql = "SELECT * FROM sys_datalog WHERE datalog_id > ".$conf['last_datalog_id']." AND (server_id = ".$conf["server_id"]." OR server_id = 0) ORDER BY datalog_id";
8789
$records = $app->dbmaster->queryAllRecords($sql);
8890
foreach($records as $d) {
8991

9092
$data = unserialize(stripslashes($d["data"]));
9193
$replication_error = false;
9294

95+
$this->current_datalog_id = $d["datalog_id"];
96+
9397
if($d["action"] == 'i') {
9498
$idx = explode(":",$d["dbidx"]);
9599
$tmp_sql1 = '';
@@ -144,25 +148,25 @@ function processDatalog() {
144148
$this->raiseTableHook($d["dbtable"],$d["action"],$data);
145149
//$app->dbmaster->query("DELETE FROM sys_datalog WHERE datalog_id = ".$d["datalog_id"]);
146150
//$app->log("Deleting sys_datalog ID ".$d["datalog_id"],LOGLEVEL_DEBUG);
147-
$app->db->query("UPDATE sys_datalog SET status = 'ok' WHERE datalog_id = ".$d["datalog_id"]);
148-
$app->log("Changing datalog status to -ok- for sys_datalog ID ".$rec["datalog_id"],LOGLEVEL_DEBUG);
151+
$app->dbmaster->query("UPDATE server SET updated = ".$d["datalog_id"]." WHERE server_id = ".$conf["server_id"]);
152+
$app->log("Processed datalog_id ".$d["datalog_id"],LOGLEVEL_DEBUG);
149153
} else {
150154
$app->log("Error in Repliction, changes were not processed.",LOGLEVEL_ERROR);
151-
$app->db->query("UPDATE sys_datalog SET status = 'error' WHERE datalog_id = ".$d["datalog_id"]);
152155
}
153156
}
154157

155158
//* if we have a single server setup
156159
} else {
157-
$sql = "SELECT * FROM sys_datalog WHERE server_id = ".$conf["server_id"]." ORDER BY datalog_id";
160+
$sql = "SELECT * FROM sys_datalog WHERE datalog_id > ".$conf['last_datalog_id']." AND (server_id = ".$conf["server_id"]." OR server_id = 0) ORDER BY datalog_id";
158161
$records = $app->db->queryAllRecords($sql);
159-
foreach($records as $rec) {
160-
$data = unserialize(stripslashes($rec["data"]));
161-
$this->raiseTableHook($rec["dbtable"],$rec["action"],$data);
162+
foreach($records as $d) {
163+
$data = unserialize(stripslashes($d["data"]));
164+
$this->current_datalog_id = $d["datalog_id"];
165+
$this->raiseTableHook($d["dbtable"],$d["action"],$data);
162166
//$app->db->query("DELETE FROM sys_datalog WHERE datalog_id = ".$rec["datalog_id"]);
163167
//$app->log("Deleting sys_datalog ID ".$rec["datalog_id"],LOGLEVEL_DEBUG);
164-
$app->db->query("UPDATE sys_datalog SET status = 'ok' WHERE datalog_id = ".$rec["datalog_id"]);
165-
$app->log("Changing datalog status to -ok- for sys_datalog ID ".$rec["datalog_id"],LOGLEVEL_DEBUG);
168+
$app->db->query("UPDATE server SET updated = ".$d["datalog_id"]." WHERE server_id = ".$conf["server_id"]);
169+
$app->log("Processed datalog_id ".$d["datalog_id"],LOGLEVEL_DEBUG);
166170
}
167171
}
168172

@@ -177,14 +181,14 @@ function raiseTableHook($table_name,$action,$data) {
177181

178182
// Get the hooks for this table
179183
$hooks = $this->notification_hooks[$table_name];
180-
$app->log("Raised TableHook for table: '$table_name'",LOGLEVEL_DEBUG);
184+
if($this->debug) $app->log("Raised TableHook for table: '$table_name'",LOGLEVEL_DEBUG);
181185

182186
if(is_array($hooks)) {
183187
foreach($hooks as $hook) {
184188
$module_name = $hook["module"];
185189
$function_name = $hook["function"];
186190
// Claa the processing function of the module
187-
$app->log("Call function '$function_name' in module '$module_name' raised by TableHook '$table_name'.",LOGLEVEL_DEBUG);
191+
if($this->debug) $app->log("Call function '$function_name' in module '$module_name' raised by TableHook '$table_name'.",LOGLEVEL_DEBUG);
188192
call_user_method($function_name,$app->loaded_modules[$module_name],$table_name,$action,$data);
189193
unset($module_name);
190194
unset($function_name);

server/lib/classes/plugins.inc.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class plugins {
3232

3333
var $available_events = array();
3434
var $subscribed_events = array();
35+
var $debug = false;
3536

3637
/*
3738
This function is called to load the plugins from the plugins-enabled or the plugins-core folder
@@ -61,7 +62,7 @@ function loadPlugins($type) {
6162
//** load the plugins
6263
foreach($tmp_plugins as $plugin_name => $file) {
6364
include_once($plugins_dir.$file);
64-
$app->log("Loading Plugin: $plugin_name",LOGLEVEL_DEBUG);
65+
if($this->debug) $app->log("Loading Plugin: $plugin_name",LOGLEVEL_DEBUG);
6566
$app->loaded_plugins[$plugin_name] = new $plugin_name;
6667
$app->loaded_plugins[$plugin_name]->onLoad();
6768
}
@@ -82,7 +83,7 @@ function announceEvents($module_name,$events) {
8283
global $app;
8384
foreach($events as $event_name) {
8485
$this->available_events[$event_name] = $module_name;
85-
$app->log("Announced event: $event_name",LOGLEVEL_DEBUG);
86+
if($this->debug) $app->log("Announced event: $event_name",LOGLEVEL_DEBUG);
8687
}
8788
}
8889

@@ -97,7 +98,7 @@ function registerEvent($event_name,$plugin_name,$function_name) {
9798
$app->log("Unable to register the function '$function_name' in the plugin '$plugin_name' for event '$event_name'",LOGLEVEL_DEBUG);
9899
} else {
99100
$this->subscribed_events[$event_name][] = array('plugin' => $plugin_name, 'function' => $function_name);
100-
$app->log("Registered the function '$function_name' in the plugin '$plugin_name' for event '$event_name'.",LOGLEVEL_DEBUG);
101+
if($this->debug) $app->log("Registered the function '$function_name' in the plugin '$plugin_name' for event '$event_name'.",LOGLEVEL_DEBUG);
101102
}
102103
}
103104

@@ -107,7 +108,7 @@ function raiseEvent($event_name,$data) {
107108

108109
// Get the subscriptions for this event
109110
$events = $this->subscribed_events[$event_name];
110-
$app->log("Raised event: '$event_name'",LOGLEVEL_DEBUG);
111+
if($this->debug) $app->log("Raised event: '$event_name'",LOGLEVEL_DEBUG);
111112

112113
if(is_array($events)) {
113114
foreach($events as $event) {

server/lib/classes/services.inc.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class services {
3232

3333
var $registered_services = array();
3434
var $delayed_restarts = array();
35+
var $debug = false;
3536

3637
// This function adds a request for restarting
3738
// a service at the end of the configuration run.
@@ -64,7 +65,7 @@ function restartService($service_name,$action = 'restart') {
6465
function registerService($service_name,$module_name, $function_name) {
6566
global $app;
6667
$this->registered_services[$service_name] = array('module' => $module_name, 'function' => $function_name);
67-
$app->log("Registered Service '$service_name' in module '$module_name' for processing function '$function_name'",LOGLEVEL_DEBUG);
68+
if($this->debug) $app->log("Registered Service '$service_name' in module '$module_name' for processing function '$function_name'",LOGLEVEL_DEBUG);
6869
}
6970

7071
// This function is called at the end of the server script to restart services.

server/server.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,13 @@
6666
$app->log("Set Lock: ".$conf["temppath"].$conf["fs_div"].".ispconfig_lock", LOGLEVEL_DEBUG);
6767
*/
6868

69+
// get the dalaog_id of the last performed record
70+
$tmp_rec = $app->dbmaster->queryOneRecord("SELECT updated FROM server WHERE server_id = ".$conf["server_id"]);
71+
$conf['last_datalog_id'] = (int)$tmp_rec['updated'];
72+
unset($tmp_rec);
73+
6974
// Check if there is anything to update
70-
$tmp_rec = $app->dbmaster->queryOneRecord("SELECT count(server_id) as number from sys_datalog WHERE server_id = ".$conf["server_id"]." AND status = 'pending'");
75+
$tmp_rec = $app->dbmaster->queryOneRecord("SELECT count(server_id) as number from sys_datalog WHERE datalog_id > ".$conf['last_datalog_id']." AND (server_id = ".$conf["server_id"]." OR server_id = 0)");
7176
$tmp_num_records = $tmp_rec["number"];
7277
unset($tmp_rec);
7378

0 commit comments

Comments
 (0)