TWLIO MEDIA AWS S3
This commit is contained in:
parent
eb673710bb
commit
850d09db8f
@ -9698,7 +9698,12 @@ public function getCompaniesListsFromGeneralFormRawJSON_post()
|
||||
$random_string = $this->post('random_string');
|
||||
$this->load->library('twlio');
|
||||
$result_data = array();
|
||||
$query = "SELECT * FROM ".VIDEO_ROOM_INFO." where fk_pd_id = $pd_id and is_call_ended = 1 and composition_id is not null";
|
||||
$pd_master_details = $this->PD_Model->getPDMasterDetails($pd_id,$random_string);
|
||||
|
||||
$bucket_name = LENDER_BUCKET_NAME_PREFIX.$pd_master_details[0]['fk_lender_id'];
|
||||
|
||||
|
||||
$query = "SELECT * FROM ".VIDEO_ROOM_INFO." where fk_pd_id = $pd_id";// and is_call_ended = 1 and composition_id is not null";
|
||||
$video_info = $this->db->query($query);
|
||||
if($video_info->num_rows())
|
||||
{
|
||||
@ -9707,10 +9712,11 @@ public function getCompaniesListsFromGeneralFormRawJSON_post()
|
||||
foreach ($video_info as $key => $value)
|
||||
{
|
||||
$video_name = $value['composition_id'].'.mp4';
|
||||
if($value['twilo_status'] == 'completed')
|
||||
if($value['s3_copied'])
|
||||
{
|
||||
$singed_uri = $this->twlio->compositionVideoFile($value['composition_id']);
|
||||
$result_data[] = array('video_name' => $video_name, 'url' => $singed_uri,'status' => $value['twilo_status']);
|
||||
$final_key = 'pd'.$pd_master_details[0]['pd_id'].'/video/'.$value['composition_id'].'.mp4';
|
||||
$singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$final_key,'+7 dys');
|
||||
$result_data[] = array('video_name' => $video_name,'url' => $singed_uri,'status' => $value['twilo_status']);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -9733,27 +9739,9 @@ public function getCompaniesListsFromGeneralFormRawJSON_post()
|
||||
{
|
||||
$pd_id = $this->post('pd_id');
|
||||
$random_string = $this->post('random_string');
|
||||
$this->load->library('twlio');
|
||||
$result_data = 0;
|
||||
$query = "SELECT * FROM ".VIDEO_ROOM_INFO." where fk_pd_id = $pd_id and twilo_status = 'enqueued' and composition_id is not null;";
|
||||
$video_info = $this->db->query($query);
|
||||
if($video_info->num_rows())
|
||||
{
|
||||
$video_info = $video_info->result_array();
|
||||
//print_r($video_info);die();
|
||||
foreach ($video_info as $key => $value)
|
||||
{
|
||||
$res = $this->twlio->getCompositionStatus($value['composition_id']);
|
||||
//echo $res['status'];
|
||||
if(count($res) && $res['status'] == 'completed')
|
||||
{
|
||||
$id = $this->PD_Model->updateRecords(array('twilo_status' => 'completed'),VIDEO_ROOM_INFO,array('video_room_info_id' => $value['video_room_info_id']));
|
||||
if($id){ $result_data++ ;}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
$room_id = $this->post('room_id');
|
||||
|
||||
$result_data = $this->getTwiloVideoStatus($pd_id,$random_string,$room_id);
|
||||
|
||||
$data['dataStatus'] = true;
|
||||
$data['status'] = REST_Controller::HTTP_OK;
|
||||
@ -9763,10 +9751,90 @@ public function getCompaniesListsFromGeneralFormRawJSON_post()
|
||||
|
||||
}
|
||||
|
||||
// funtion getTwiloVideoStatus_post()
|
||||
// {
|
||||
|
||||
// }
|
||||
function getTwiloVideoStatus($pd_id,$random_string,$room_id = '')
|
||||
{
|
||||
$this->load->library('twlio');
|
||||
$result_data = 0;
|
||||
// $query = "SELECT * FROM ".VIDEO_ROOM_INFO." where fk_pd_id = $pd_id and twilo_status = 'enqueued' and composition_id is not null;";
|
||||
$pd_master_details = $this->PD_Model->getPDMasterDetails($pd_id,$random_string);
|
||||
$query = "SELECT * FROM ".VIDEO_ROOM_INFO." where fk_pd_id = $pd_id";// and twilo_status = 'enqueued' and composition_id is not null;";
|
||||
if($room_id)
|
||||
{
|
||||
$query .=" and room_id = '$room_id'";
|
||||
}
|
||||
$video_info = $this->db->query($query);
|
||||
if($video_info->num_rows())
|
||||
{
|
||||
$video_info = $video_info->result_array();
|
||||
//print_r($video_info);die();
|
||||
foreach ($video_info as $key => $value)
|
||||
{
|
||||
|
||||
if($value['composition_id'])
|
||||
{
|
||||
$res = $this->twlio->getCompositionStatus($value['composition_id']);
|
||||
//echo $res['status'];
|
||||
if(count($res) && $res['status'] == 'completed')
|
||||
{
|
||||
|
||||
$is_copied = $this->copyMediaFromTwiloToS3($pd_master_details,$value);// copy media from twlio s3 to our s3
|
||||
$fields_to_update = array('twilo_status' => 'completed');
|
||||
if($is_copied) { $fields_to_update['s3_copied'] = 1; }
|
||||
$id = $this->PD_Model->updateRecords($fields_to_update,VIDEO_ROOM_INFO,array('video_room_info_id' => $value['video_room_info_id']));
|
||||
|
||||
if($id){ if($room_id) {$result_data = $is_copied;}else{$result_data++ ;}}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$composition_result_data = $this->twlio->startComposistion($value['room_id']);
|
||||
// $composition_result_data = $this->twlio->startComposistion('RM23b8d502434e46e696d1fbd5d64c59c8');
|
||||
// print_r($composition_result_data);
|
||||
$composition_result_data_json = json_encode($composition_result_data);
|
||||
// print_r($composition_result_data_json);
|
||||
$records['res_json'] = $composition_result_data_json;
|
||||
$records['twilo_status'] = $composition_result_data['status'];
|
||||
$records['composition_id'] = $composition_result_data['compositionId'];
|
||||
$records['is_call_ended'] = 1;
|
||||
$id = $this->PD_Model->updateRecords($records,VIDEO_ROOM_INFO,array('room_id' => $records['room_id'],'fk_pd_id' => $records['fk_pd_id']));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return $result_data;
|
||||
}
|
||||
|
||||
function copyMediaFromTwiloToS3($pd_master_details,$value)// copy media from twlio s3 to our s3
|
||||
{
|
||||
EXTERNAL_DIR_CHECK::checkExternalDirectory($pd_master_details[0]['pd_id']);
|
||||
//get media uri from twlio
|
||||
$singed_uri = $this->twlio->compositionVideoFile($value['composition_id']);
|
||||
//echo $singed_uri;
|
||||
$internal_server_tmp_location = XLPATH.'/pd_reports/'.$pd_master_details[0]['pd_id'].'/videos';
|
||||
$internal_server_tmp_location_filename = ($internal_server_tmp_location.'/'.$value['composition_id'].'.mp4');
|
||||
//echo $internal_server_tmp_location;
|
||||
if(!file_exists($internal_server_tmp_location)){ mkdir($internal_server_tmp_location); };
|
||||
$is_writed = file_put_contents($internal_server_tmp_location_filename,file_get_contents($singed_uri));
|
||||
//upload it to aws s3
|
||||
$bucket_name = LENDER_BUCKET_NAME_PREFIX.$pd_master_details[0]['fk_lender_id'];
|
||||
$final_key = 'pd'.$pd_master_details[0]['pd_id'].'/video/'.$value['composition_id'].'.mp4';
|
||||
|
||||
$bucket_data = array('bucket_name'=>$bucket_name,'key'=>$final_key,'sourcefile'=>($internal_server_tmp_location_filename));
|
||||
$s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data);
|
||||
if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200)
|
||||
{
|
||||
log_message('ERROR','###TWLIO TO S3 STARTED'.$value['composition_id']);
|
||||
|
||||
unlink($internal_server_tmp_location_filename);
|
||||
return $temp_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$final_key,'+7 dys');
|
||||
//unlink($folder_to_check.'/'.$final_video_name.'.mp4');
|
||||
}
|
||||
return null;
|
||||
|
||||
|
||||
}
|
||||
|
||||
function mergeVideo($pd_id,$pd_master_details,$final_video_name,$video_key)
|
||||
{
|
||||
|
||||
@ -26,8 +26,10 @@ class User_Management_Controller extends REST_Controller {
|
||||
{
|
||||
//echo "function";
|
||||
$entityid = null;
|
||||
$user_type = null;
|
||||
if($this->get('eid')){$entityid = $this->get('eid');}
|
||||
$result = $this->User_Management_Model->listAllUsers($entityid);
|
||||
if($this->get('user_type')){$entityid = $this->get('user_type');}
|
||||
$result = $this->User_Management_Model->listAllUsers($entityid,$user_type);
|
||||
//echo "result";
|
||||
if($result['data_status'])
|
||||
{
|
||||
@ -106,10 +108,10 @@ class User_Management_Controller extends REST_Controller {
|
||||
|
||||
|
||||
}
|
||||
if(($records['fk_entity_id'] == 35 && ENVIRONMENT == 'testing') || ($records['fk_entity_id'] == 7 && ENVIRONMENT == 'prodcution'))
|
||||
{
|
||||
$records['user_type'] = 'SMC';
|
||||
}
|
||||
// if(($records['fk_entity_id'] == 35 && ENVIRONMENT == 'testing') || ($records['fk_entity_id'] == 7 && ENVIRONMENT == 'prodcution'))
|
||||
// {
|
||||
// $records['user_type'] = 'SMC';
|
||||
// }
|
||||
|
||||
$user_id = $this->User_Management_Model->saveRecords($records,USERPROFILE);//insert user records and get userid
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ class User_Management_Model extends SPARQ_Model {
|
||||
}
|
||||
|
||||
|
||||
public function listAllUsers($entityid)
|
||||
public function listAllUsers($entityid,$user_type)
|
||||
{
|
||||
|
||||
$result_data = array();
|
||||
@ -32,6 +32,12 @@ class User_Management_Model extends SPARQ_Model {
|
||||
{
|
||||
$this->db->where('USERPROFILE.fk_entity_id',$entityid);
|
||||
}
|
||||
|
||||
if($user_type == 'SMC')
|
||||
{
|
||||
$current_smc_lender_id = ENVIRONMENT == 'production' ? 7 : 35; //pk id of SMC in live and demo
|
||||
$this->db->where('USERPROFILE.fk_entity_id',$current_smc_lender_id);
|
||||
}
|
||||
|
||||
|
||||
$result = $this->db->get()->result_array();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user