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.
This commit is contained in:
FusionPBX
2022-09-01 11:11:13 -06:00
committed by GitHub
parent 52b06b5afc
commit 6bed337061

View File

@@ -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);
}