From ada4903715e0f6a7e15ae3736fb87822d5367f7d Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Sun, 13 Jul 2025 10:28:01 -0600 Subject: [PATCH] synch the actions with destination_app and destination_data --- app/destinations/app_defaults.php | 94 +++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 4 deletions(-) diff --git a/app/destinations/app_defaults.php b/app/destinations/app_defaults.php index 411bbd5760..02f255d69f 100644 --- a/app/destinations/app_defaults.php +++ b/app/destinations/app_defaults.php @@ -50,7 +50,7 @@ if ($domains_processed == 1) { } unset($extensions, $row, $array); - //use destinations actions to + //update destinations actions $sql = "select * from v_destinations "; $sql .= "where destination_actions is null "; $destinations = $database->select($sql, null, 'all'); @@ -85,19 +85,105 @@ if ($domains_processed == 1) { //add temporary permissions $p = permissions::new(); $p->add('destination_edit', 'temp'); - + //create the database object and save the data $database->app_name = 'destinations'; $database->app_uuid = '5ec89622-b19c-3559-64f0-afde802ab139'; $database->save($array, false); unset($array); - + //remove the temporary permissions $p->delete('destination_edit', 'temp'); } //set the row id back to 0 - $row_id = 0; + $row_id = 0; + } + + //increment the number + $row_id++; + + //unset actions + unset($actions); + } + + if (!empty($array)) { + //add temporary permissions + $p = permissions::new(); + $p->add('destination_edit', 'temp'); + + //create the database object and save the data + $database->app_name = 'destinations'; + $database->app_uuid = '5ec89622-b19c-3559-64f0-afde802ab139'; + $database->save($array, false); + unset($array); + + //remove the temporary permissions + $p->delete('destination_edit', 'temp'); + } + } + unset($sql, $num_rows); + + //synchronize the destination actions with destination_app and destination_data + $sql = "select * from v_destinations "; + $sql .= "where destination_actions is not null "; + $destinations = $database->select($sql, null, 'all'); + if (is_array($destinations)) { + //pre-set the numbers + $row_id = 0; + $z=0; + + //loop through the array + foreach ($destinations as $row) { + $i = 0; + foreach (json_decode($row['destination_actions'], true) as $action) { + //build the array of destinations + if ($i == 0 ) { + $destination_action = $action['destination_app'] . ' ' . $action['destination_data']; + if ($destination_action !== $row['destination_app'] . ' ' . $row['destination_data']) { + $array['destinations'][$z]['destination_uuid'] = $row['destination_uuid']; + $array['destinations'][$z]['destination_number'] = $row['destination_number']; + $array['destinations'][$z]['destination_app'] = $action['destination_app']; + $array['destinations'][$z]['destination_data'] = $action['destination_data']; + $z++; + } + } + if ($i == 1) { + $destination_action = $action['destination_app'] . ' ' . $action['destination_data']; + if ($destination_action !== $row['destination_alternate_app'] . ' ' . $row['destination_alternate_data']) { + $array['destinations'][$z]['destination_uuid'] = $row['destination_uuid']; + $array['destinations'][$z]['destination_number'] = $row['destination_number']; + $array['destinations'][$z]['destination_alternate_app'] = $action['destination_app']; + $array['destinations'][$z]['destination_alternate_data'] = $action['destination_data']; + $z++; + } + } + + //increment the id + $i++; + } + + //process a chunk of the array + if ($row_id === 1000) { + //save to the data + if (!empty($array)) { + + //add temporary permissions + $p = permissions::new(); + $p->add('destination_edit', 'temp'); + + //create the database object and save the data + $database->app_name = 'destinations'; + $database->app_uuid = '5ec89622-b19c-3559-64f0-afde802ab139'; + //$database->save($array, false); + unset($array); + + //remove the temporary permissions + $p->delete('destination_edit', 'temp'); + } + + //set the row id back to 0 + $row_id = 0; } //increment the number