From 6bed3370614019fde588d1cdcc76bf414ad8786b Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Thu, 1 Sep 2022 11:11:13 -0600 Subject: [PATCH] Chunk the work into batches of a 1000 numbers at a time. This is useful for customers with over 1000 destination numbers. Will work from command line with any number of destination numbers. --- app/destinations/app_defaults.php | 32 ++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/app/destinations/app_defaults.php b/app/destinations/app_defaults.php index c0d11ca399..f48e1d8757 100644 --- a/app/destinations/app_defaults.php +++ b/app/destinations/app_defaults.php @@ -58,7 +58,11 @@ if ($domains_processed == 1) { $database = new database; $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) { //prepare the actions array if (isset($row['destination_app']) && $row['destination_data'] != '') { @@ -76,7 +80,33 @@ if ($domains_processed == 1) { $array['destinations'][$z]['destination_actions'] = json_encode($actions); $z++; } - + + //process a chunk of the array + if ($row_id === 1000) { + //save to the data + if (is_array($array)) { + //add temporary permissions + $p = new permissions; + $p->add('destination_edit', 'temp'); + + //create the database object and save the data + $database = new database; + $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 + $row_id++; + //unset actions unset($actions); }