mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2026-01-06 11:43:50 +00:00
Recordings: Database class integration.
This commit is contained in:
@@ -36,11 +36,12 @@
|
||||
if (is_array($_SESSION['recordings']['storage_type']) && $_SESSION['recordings']['storage_type']['text'] == 'base64') {
|
||||
//get recordings without base64 in db
|
||||
$sql = "select recording_uuid, domain_uuid, recording_filename ";
|
||||
$sql .= "from v_recordings where recording_base64 is null or recording_base64 = '' ";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
if (is_array($result)) {
|
||||
$sql .= "from v_recordings ";
|
||||
$sql .= "where recording_base64 is null ";
|
||||
$sql .= "or recording_base64 = '' ";
|
||||
$database = new database;
|
||||
$result = $database->select($sql, null, 'all');
|
||||
if (is_array($result) && @sizeof($result) != 0) {
|
||||
foreach ($result as &$row) {
|
||||
$recording_uuid = $row['recording_uuid'];
|
||||
$recording_domain_uuid = $row['domain_uuid'];
|
||||
@@ -49,30 +50,38 @@
|
||||
$recording_directory = $_SESSION['switch']['recordings']['dir'].'/'.$domain_name;
|
||||
//encode recording file (if exists)
|
||||
if (file_exists($recording_directory.'/'.$recording_filename)) {
|
||||
$recording_base64 = base64_encode(file_get_contents($recording_directory.'/'.$recording_filename));
|
||||
//build array
|
||||
$recording_base64 = base64_encode(file_get_contents($recording_directory.'/'.$recording_filename));
|
||||
$array['recordings'][0]['recording_uuid'] = $recording_uuid;
|
||||
$array['recordings'][0]['domain_uuid'] = $recording_domain_uuid;
|
||||
$array['recordings'][0]['recording_base64'] = $recording_base64;
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('recording_edit', 'temp');
|
||||
//update recording record with base64
|
||||
$sql = "update v_recordings set ";
|
||||
$sql .= "recording_base64 = '".$recording_base64."' ";
|
||||
$sql .= "where domain_uuid = '".$recording_domain_uuid."' ";
|
||||
$sql .= "and recording_uuid = '".$recording_uuid."' ";
|
||||
$db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
$database = new database;
|
||||
$database->app_name = 'recordings';
|
||||
$database->app_uuid = '83913217-c7a2-9e90-925d-a866eb40b60e';
|
||||
$database->save($array);
|
||||
unset($array);
|
||||
//revoke temporary permissions
|
||||
$p->delete('recording_edit', 'temp');
|
||||
//remove local recording file
|
||||
@unlink($recording_directory.'/'.$recording_filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($sql, $prep_statement, $result, $row);
|
||||
unset($sql, $result, $row);
|
||||
}
|
||||
//if not base64, decode to local files, remove base64 data from db
|
||||
else if (is_array($_SESSION['recordings']['storage_type']) && $_SESSION['recordings']['storage_type']['text'] != 'base64') {
|
||||
//get recordings with base64 in db
|
||||
$sql = "select recording_uuid, domain_uuid, recording_filename, recording_base64 ";
|
||||
$sql .= "from v_recordings where recording_base64 is not null ";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
if (count($result) > 0) {
|
||||
$sql .= "from v_recordings ";
|
||||
$sql .= "where recording_base64 is not null ";
|
||||
$database = new database;
|
||||
$result = $database->select($sql, null, 'all');
|
||||
if (is_array($result) && @sizeof($result) != 0) {
|
||||
foreach ($result as &$row) {
|
||||
$recording_uuid = $row['recording_uuid'];
|
||||
$recording_domain_uuid = $row['domain_uuid'];
|
||||
@@ -87,15 +96,24 @@
|
||||
//decode base64, save to local file
|
||||
$recording_decoded = base64_decode($recording_base64);
|
||||
file_put_contents($recording_directory.'/'.$recording_filename, $recording_decoded);
|
||||
$sql = "update v_recordings ";
|
||||
$sql .= "set recording_base64 = null ";
|
||||
$sql .= "where domain_uuid = '".$recording_domain_uuid."' ";
|
||||
$sql .= "and recording_uuid = '".$recording_uuid."' ";
|
||||
$db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
//build array
|
||||
$array['recordings'][0]['recording_uuid'] = $recording_uuid;
|
||||
$array['recordings'][0]['domain_uuid'] = $recording_domain_uuid;
|
||||
$array['recordings'][0]['recording_base64'] = null;
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('recording_edit', 'temp');
|
||||
//update recording record
|
||||
$database = new database;
|
||||
$database->app_name = 'recordings';
|
||||
$database->app_uuid = '83913217-c7a2-9e90-925d-a866eb40b60e';
|
||||
$database->save($array);
|
||||
unset($array);
|
||||
//revoke temporary permissions
|
||||
$p->delete('recording_edit', 'temp');
|
||||
}
|
||||
}
|
||||
unset($sql, $prep_statement, $result, $row);
|
||||
unset($sql, $result, $row);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user