From 049580fd3012e7ca61dd6f0499d7baa636926e86 Mon Sep 17 00:00:00 2001 From: koldoa Date: Tue, 1 Sep 2015 18:33:26 +0200 Subject: [PATCH 1/3] Random strategy for ring groups --- app/ring_groups/app_languages.php | 11 ++++++++ app/ring_groups/ring_group_edit.php | 1 + .../install/scripts/app/ring_groups/index.lua | 27 ++++++++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/app/ring_groups/app_languages.php b/app/ring_groups/app_languages.php index 41e87e22f2..4ce8421826 100644 --- a/app/ring_groups/app_languages.php +++ b/app/ring_groups/app_languages.php @@ -88,6 +88,17 @@ $text['option-rollover']['uk'] = ""; $text['option-rollover']['de-at'] = "Überrollen"; $text['option-rollover']['he'] = ""; +$text['option-random']['en-us'] = "Random"; +$text['option-random']['es-cl'] = "Aleatorio"; +$text['option-random']['pt-pt'] = ""; +$text['option-random']['fr-fr'] = ""; +$text['option-random']['pt-br'] = ""; +$text['option-random']['pl'] = ""; +$text['option-random']['sv-se'] = ""; +$text['option-random']['uk'] = ""; +$text['option-random']['de-at'] = ""; +$text['option-random']['he'] = ""; + $text['option-ptring']['en-us'] = "pt-ring"; $text['option-ptring']['es-cl'] = "pt-ring"; $text['option-ptring']['fr-fr'] = "Portugal"; diff --git a/app/ring_groups/ring_group_edit.php b/app/ring_groups/ring_group_edit.php index 9d7083e70e..929f7086d6 100644 --- a/app/ring_groups/ring_group_edit.php +++ b/app/ring_groups/ring_group_edit.php @@ -499,6 +499,7 @@ else { echo " \n"; echo " \n"; echo " \n"; + echo " \n"; echo " \n"; echo "
\n"; echo $text['description-strategy']."\n"; diff --git a/resources/install/scripts/app/ring_groups/index.lua b/resources/install/scripts/app/ring_groups/index.lua index 336f5ace28..b122bc371a 100644 --- a/resources/install/scripts/app/ring_groups/index.lua +++ b/resources/install/scripts/app/ring_groups/index.lua @@ -160,6 +160,28 @@ --forward the ring group session:execute("transfer", ring_group_forward_destination.." XML "..context); else + --get the strategy of the ring group, if random, we use random() to order the destinations + sql = [[ + SELECT + r.ring_group_strategy + FROM + v_ring_groups as r, v_ring_group_destinations as d + WHERE + d.ring_group_uuid = r.ring_group_uuid + AND d.ring_group_uuid = ']]..ring_group_uuid..[[' + AND r.domain_uuid = ']]..domain_uuid..[[' + AND r.ring_group_enabled = 'true' + ]]; + + --freeswitch.consoleLog("notice", "SQL:" .. sql .. "\n"); + assert(dbh:query(sql, function(row) + if (row.ring_group_strategy == "random") then + sql_order = 'random()' + else + sql_order='d.destination_delay, d.destination_number asc' + end + end)); + --get the ring group destinations sql = [[ SELECT @@ -174,7 +196,7 @@ AND r.domain_uuid = ']]..domain_uuid..[[' AND r.ring_group_enabled = 'true' ORDER BY - d.destination_delay, d.destination_number asc + ]]..sql_order..[[ ]]; --freeswitch.consoleLog("notice", "SQL:" .. sql .. "\n"); destinations = {}; @@ -293,6 +315,9 @@ if (ring_group_strategy == "sequence") then delimiter = "|"; end + if (ring_group_strategy == "random") then + delimiter = "|"; + end if (ring_group_strategy == "simultaneous") then delimiter = ","; end From 28e967f01c2d9879b0f87b05569d74dfcca89c8f Mon Sep 17 00:00:00 2001 From: koldoa Date: Wed, 2 Sep 2015 14:24:47 +0200 Subject: [PATCH 2/3] Translation typo --- app/devices/app_languages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/devices/app_languages.php b/app/devices/app_languages.php index 75ecf92aa3..577792fd96 100644 --- a/app/devices/app_languages.php +++ b/app/devices/app_languages.php @@ -1690,7 +1690,7 @@ $text['label-blf']['ar-eg'] = ""; $text['label-blf']['he'] = ""; $text['label-callers']['en-us'] = "Callers"; -$text['label-callers']['es-cl'] = "Llaamadas"; +$text['label-callers']['es-cl'] = "Llamadas"; $text['label-callers']['pt-pt'] = ""; $text['label-callers']['fr-fr'] = ""; $text['label-callers']['pt-br'] = ""; From b2cbcdfc97c01723f717a0d4892dfb34370bbaa7 Mon Sep 17 00:00:00 2001 From: koldoa Date: Thu, 3 Sep 2015 11:53:28 +0200 Subject: [PATCH 3/3] Detection of SQL backend for random functions --- .../install/scripts/app/ring_groups/index.lua | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/resources/install/scripts/app/ring_groups/index.lua b/resources/install/scripts/app/ring_groups/index.lua index b122bc371a..dee8542206 100644 --- a/resources/install/scripts/app/ring_groups/index.lua +++ b/resources/install/scripts/app/ring_groups/index.lua @@ -160,6 +160,16 @@ --forward the ring group session:execute("transfer", ring_group_forward_destination.." XML "..context); else + --first we check what version of SQL are we using + sql = "SELECT version() as version"; + assert(dbh:query(sql, function(row) + if (string.find(row.version, "PostgreSQL")) then + sql_verion = 'postgresql' + else + sql_verion = 'mysql' + end + end)); + --get the strategy of the ring group, if random, we use random() to order the destinations sql = [[ SELECT @@ -172,16 +182,21 @@ AND r.domain_uuid = ']]..domain_uuid..[[' AND r.ring_group_enabled = 'true' ]]; - - --freeswitch.consoleLog("notice", "SQL:" .. sql .. "\n"); + + assert(dbh:query(sql, function(row) if (row.ring_group_strategy == "random") then - sql_order = 'random()' + if (sql_verion == "postgresql") then + sql_order = 'random()' + end + if (sql_verion == "mysql") then + sql_order = 'rand()' + end else sql_order='d.destination_delay, d.destination_number asc' end end)); - + --get the ring group destinations sql = [[ SELECT @@ -196,7 +211,7 @@ AND r.domain_uuid = ']]..domain_uuid..[[' AND r.ring_group_enabled = 'true' ORDER BY - ]]..sql_order..[[ + ]]..sql_order..[[ ]]; --freeswitch.consoleLog("notice", "SQL:" .. sql .. "\n"); destinations = {};