2017-12-03 00:50:34 +01:00
< ? php
/*
FusionPBX
Version : MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 ( the " License " ); you may not use this file except in compliance with
the License . You may obtain a copy of the License at
http :// www . mozilla . org / MPL /
Software distributed under the License is distributed on an " AS IS " basis ,
WITHOUT WARRANTY OF ANY KIND , either express or implied . See the License
for the specific language governing rights and limitations under the
License .
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane < markjcrane @ fusionpbx . com >
2022-07-16 06:38:21 +02:00
Portions created by the Initial Developer are Copyright ( C ) 2017 - 2022
2017-12-03 00:50:34 +01:00
the Initial Developer . All Rights Reserved .
Contributor ( s ) :
Mark J Crane < markjcrane @ fusionpbx . com >
*/
2022-07-16 06:38:21 +02:00
if ( $domains_processed == 1 ) {
//update the v_destinations set destination_app and destination_data
2017-12-03 00:50:34 +01:00
$sql = " select dialplan_uuid, dialplan_detail_type as destination_app, dialplan_detail_data as destination_data \n " ;
$sql .= " from v_dialplan_details \n " ;
$sql .= " where dialplan_uuid in (select dialplan_uuid from v_destinations where destination_type = 'inbound' and destination_app is null and destination_data is null) \n " ;
$sql .= " and dialplan_detail_tag = 'action' \n " ;
$sql .= " and (dialplan_detail_type = 'transfer' or dialplan_detail_type = 'bridge') \n " ;
$sql .= " order by dialplan_detail_order; \n " ;
2019-07-29 21:18:48 +02:00
$extensions = $database -> select ( $sql , null , 'all' );
unset ( $sql );
2023-05-17 18:07:49 +02:00
if ( ! empty ( $extensions )) {
2017-12-03 00:50:34 +01:00
foreach ( $extensions as $row ) {
2019-07-29 21:18:48 +02:00
$sql = " update v_destinations " ;
2020-10-02 03:12:30 +02:00
$sql .= " set destination_app = :destination_app, destination_data = :destination_data " ;
2019-07-29 21:18:48 +02:00
$sql .= " where dialplan_uuid = :dialplan_uuid " ;
$parameters [ 'destination_app' ] = $row [ 'destination_app' ];
$parameters [ 'destination_data' ] = $row [ 'destination_data' ];
$parameters [ 'dialplan_uuid' ] = $row [ 'dialplan_uuid' ];
$database -> execute ( $sql , $parameters );
unset ( $sql , $parameters );
2017-12-03 00:50:34 +01:00
}
}
2022-07-16 06:38:21 +02:00
unset ( $extensions , $row , $array );
//use destinations actions to
$sql = " select * from v_destinations " ;
$sql .= " where destination_actions is null " ;
$destinations = $database -> select ( $sql , null , 'all' );
if ( is_array ( $destinations )) {
2022-09-01 19:11:13 +02:00
//pre-set the numbers
$row_id = 0 ;
2022-07-16 06:38:21 +02:00
$z = 0 ;
2022-09-01 19:11:13 +02:00
//loop through the array
2022-07-16 06:38:21 +02:00
foreach ( $destinations as $row ) {
//prepare the actions array
2023-05-17 18:07:49 +02:00
if ( isset ( $row [ 'destination_app' ]) && ! empty ( $row [ 'destination_data' ])) {
2022-07-16 06:38:21 +02:00
$actions [ 0 ][ 'destination_app' ] = $row [ 'destination_app' ];
$actions [ 0 ][ 'destination_data' ] = $row [ 'destination_data' ];
}
2023-05-17 18:07:49 +02:00
if ( isset ( $row [ 'destination_alternate_data' ]) && ! empty ( $row [ 'destination_alternate_data' ])) {
2022-08-23 01:30:31 +02:00
$actions [ 1 ][ 'destination_app' ] = $row [ 'destination_alternate_app' ];
$actions [ 1 ][ 'destination_data' ] = $row [ 'destination_alternate_data' ];
2022-07-16 06:38:21 +02:00
}
//build the array of destinations
2023-05-17 18:07:49 +02:00
if ( ! empty ( $actions )) {
2022-07-16 06:38:21 +02:00
$array [ 'destinations' ][ $z ][ 'destination_uuid' ] = $row [ 'destination_uuid' ];
$array [ 'destinations' ][ $z ][ 'destination_actions' ] = json_encode ( $actions );
$z ++ ;
}
2022-09-01 19:11:13 +02:00
//process a chunk of the array
if ( $row_id === 1000 ) {
//save to the data
2023-05-17 18:07:49 +02:00
if ( ! empty ( $array )) {
2022-09-01 19:11:13 +02:00
//add temporary permissions
2024-11-29 21:57:01 +01:00
$p = permissions :: new ();
2022-09-01 19:11:13 +02:00
$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
$row_id ++ ;
2022-08-23 01:54:29 +02:00
//unset actions
unset ( $actions );
2022-07-16 06:38:21 +02:00
}
2023-05-17 18:07:49 +02:00
if ( ! empty ( $array )) {
2022-07-16 06:38:21 +02:00
//add temporary permissions
2024-11-29 21:57:01 +01:00
$p = permissions :: new ();
2022-07-16 06:38:21 +02:00
$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 );
}
2017-12-03 00:50:34 +01:00
?>