summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/common/sync_log.lua
diff options
context:
space:
mode:
Diffstat (limited to 'misc/freeswitch/scripts/common/sync_log.lua')
-rw-r--r--misc/freeswitch/scripts/common/sync_log.lua39
1 files changed, 39 insertions, 0 deletions
diff --git a/misc/freeswitch/scripts/common/sync_log.lua b/misc/freeswitch/scripts/common/sync_log.lua
new file mode 100644
index 0000000..05b0dcf
--- /dev/null
+++ b/misc/freeswitch/scripts/common/sync_log.lua
@@ -0,0 +1,39 @@
+-- Gemeinschaft 5 module: sync log class
+-- (c) AMOOMA GmbH 2012
+--
+
+module(...,package.seeall)
+
+SyncLog = {}
+
+-- create sync log object
+function SyncLog.new(self, arg)
+ arg = arg or {}
+ object = arg.object or {}
+ setmetatable(object, self);
+ self.__index = self;
+ self.log = arg.log;
+ self.database = arg.database;
+ self.homebase_ip_address = arg.homebase_ip_address;
+ return object;
+end
+
+-- create new entry
+function SyncLog.insert(self, entry_name, entry_record, action, history_entries)
+ local content = {}
+ for key, value in pairs(entry_record) do
+ require 'common.str'
+ table.insert(content, '"'.. key ..'":' .. common.str.to_json(value));
+ end
+
+ local history = '';
+ if action == 'update' then
+ history = 'Changed: ["' .. table.concat(history_entries, '","') .. '"]';
+ end
+
+ local sql_query = 'INSERT INTO `gs_cluster_sync_log_entries` (`waiting_to_be_synced`,`created_at`,`updated_at`,`class_name`,`action`,`content`,`history`,`homebase_ip_address`) \
+ VALUES \
+ (TRUE, NOW(), NOW(), \'' .. entry_name .. '\', \'' .. action .. '\', \'{' .. table.concat(content, ',') .. '}\', \'' .. history .. '\', \'' .. self.homebase_ip_address .. '\')';
+
+ return self.database:query(sql_query);
+end