mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 00:53:50 +00:00
Recordings: app_defaults to move recordings from file system to base64 in db (and vice versa).
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Portions created by the Initial Developer are Copyright (C) 2008-2012
|
||||
Portions created by the Initial Developer are Copyright (C) 2008-2015
|
||||
the Initial Developer. All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
@@ -29,4 +29,74 @@
|
||||
if (!is_readable($_SESSION['switch']['recordings']['dir'])) { mkdir($_SESSION['switch']['recordings']['dir'],0777,true); }
|
||||
}
|
||||
|
||||
if ($domains_processed == 1) {
|
||||
|
||||
//if base64, populate from existing recording files, then remove
|
||||
if ($_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 (count($result) > 0) {
|
||||
foreach ($result as &$row) {
|
||||
$recording_uuid = $row['recording_uuid'];
|
||||
$recording_domain_uuid = $row['domain_uuid'];
|
||||
$recording_filename = $row['recording_filename'];
|
||||
//set recording directory
|
||||
$recording_directory = $_SESSION['switch']['recordings']['dir'];
|
||||
//encode recording file (if exists)
|
||||
if (file_exists($recording_directory.'/'.$recording_filename)) {
|
||||
$recording_base64 = base64_encode(file_get_contents($recording_directory.'/'.$recording_filename));
|
||||
//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);
|
||||
//remove local recording file
|
||||
@unlink($recording_directory.'/'.$recording_filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($sql, $prep_statement, $result, $row);
|
||||
}
|
||||
//if not base64, decode to local files, remove base64 data from db
|
||||
else if ($_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) {
|
||||
foreach ($result as &$row) {
|
||||
$recording_uuid = $row['recording_uuid'];
|
||||
$recording_domain_uuid = $row['domain_uuid'];
|
||||
$recording_filename = $row['recording_filename'];
|
||||
$recording_base64 = $row['recording_base64'];
|
||||
//set recording directory
|
||||
$recording_directory = $_SESSION['switch']['recordings']['dir'];
|
||||
//remove local file, if any
|
||||
if (file_exists($recording_directory.'/'.$recording_filename)) {
|
||||
@unlink($recording_directory.'/'.$recording_filename);
|
||||
}
|
||||
//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);
|
||||
}
|
||||
}
|
||||
unset($sql, $prep_statement, $result, $row);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user