summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/common/sync_log.lua
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:05:14 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:05:14 +0100
commiteaad37485fe59d0306c37cc038dda6d210052910 (patch)
tree072c4b0e33d442528555b82c415f5e7a1712b2b0 /misc/freeswitch/scripts/common/sync_log.lua
parent3e706c2025ecc5523e81ad649639ef2ff75e7bac (diff)
parentb80bd744ad873f6fc43018bc4bfb90677de167bd (diff)
Merge branch 'develop'
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