Batch download of audio for 1000+ CDRs
Example is for download all audio from CDRs where caller number starts with 0012345 and call started in time range 2019-01-01 00:00:00 - 2019-02-01 00:00:00) (beware that script not tests errors in paths credentials etc - jsut outputs which file is currently processed and total of observed CDRs to process)
<?php $guiDir="/var/www/html"; $batchDir="/backup/batch"; $user="myGuiUser"; $pass="myGuiPass"; exec('echo \'{"task": "getVoipCalls", "user": "'.$user.'", "password": "'.$pass.'", "params": {"startTime": "2019-01-01 00:00:00", "startTimeTo": "2019-02-01 00:00:00","caller": "0012345%", "onlyConnected": "1"}}\' | php '.$guiDir.'/php/api.php',$ret,$rv); if (!$rv) { $tmpres=(json_decode($ret[0])); foreach($tmpres->cdr as $record) { $results[]=$record->cdrId; } $items=count($results); foreach ($results as $n => $result) { echo ("processing CDRid $result ".($n+1)."/$items\n"); exec ('echo \'{"task": "getVoiceRecording", "user": "'.$user.'", "password": "'.$pass.'", "params": {"cdrId": "'.$result.'"}}\' | php '.$guiDir.'/php/api.php > '.$batchDir.'/'.$result.'.wav',$ret2,$rv2); } } ?>