From b80bd744ad873f6fc43018bc4bfb90677de167bd Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 17 Dec 2012 12:01:45 +0100 Subject: Start of GS5. --- misc/freeswitch/scripts/common/sync_log.lua | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 misc/freeswitch/scripts/common/sync_log.lua (limited to 'misc/freeswitch/scripts/common/sync_log.lua') 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 -- cgit v1.2.3