From e20184d893fd10a80f420c8a832dcb8191d5ba02 Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Wed, 8 Feb 2017 13:29:48 -0700 Subject: [PATCH] Update app_defaults.php --- app/recordings/app_defaults.php | 140 ++++++++++++++++---------------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/app/recordings/app_defaults.php b/app/recordings/app_defaults.php index 4341ceee6e..ab440e6889 100644 --- a/app/recordings/app_defaults.php +++ b/app/recordings/app_defaults.php @@ -24,79 +24,79 @@ Mark J Crane */ -if ($domains_processed == 1) { +//if the recordings directory doesn't exist then create it + if (is_array($_SESSION['switch']['recordings']) && strlen($_SESSION['switch']['recordings']['dir']."/".$domain_name) > 0) { + if (!is_readable($_SESSION['switch']['recordings']['dir']."/".$domain_name)) { event_socket_mkdir($_SESSION['switch']['recordings']['dir']."/".$domain_name,02770,true); } + } - //if the recordings directory doesn't exist then create it - if (is_array($_SESSION['switch']['recordings']) && strlen($_SESSION['switch']['recordings']['dir']."/".$domain_name) > 0) { - if (!is_readable($_SESSION['switch']['recordings']['dir']."/".$domain_name)) { event_socket_mkdir($_SESSION['switch']['recordings']['dir']."/".$domain_name,02770,true); } - } +//process one time + if ($domains_processed == 1) { - //if base64, populate from existing recording files, then remove - 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)) { - 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'].'/'.$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)); - //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 + //if base64, populate from existing recording files, then remove + 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)) { + 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'].'/'.$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)); + //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 (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) { + 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'].'/'.$domain_name; + //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); - } - //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) { - 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'].'/'.$domain_name; - //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); - } - -} + unset($sql, $prep_statement, $result, $row); + } + } ?>