Deleting wav file if mp3 conversion succeded see BT#6613

1.9.x
Julio Montoya 11 years ago
parent 51a76eefdd
commit e344aae3f3
  1. 47
      main/inc/lib/document.lib.php
  2. 11
      main/inc/lib/fileUpload.lib.php
  3. 12
      main/inc/lib/nanogong/upload_nanogong_file.php
  4. 5
      main/inc/lib/wami-recorder/record_document.php

@ -1241,7 +1241,6 @@ class DocumentManager
} }
} }
} }
// Checking inconsistency // Checking inconsistency
//error_log('Doc status: (1 del db :'.($file_deleted_from_db?'yes':'no').') - (2 del disk: '.($file_deleted_from_disk?'yes':'no').') - (3 ren disk: '.($file_renamed_from_disk?'yes':'no').')'); //error_log('Doc status: (1 del db :'.($file_deleted_from_db?'yes':'no').') - (2 del disk: '.($file_deleted_from_disk?'yes':'no').') - (3 ren disk: '.($file_renamed_from_disk?'yes':'no').')');
if ($file_deleted_from_db && $file_deleted_from_disk || if ($file_deleted_from_db && $file_deleted_from_disk ||
@ -1363,6 +1362,7 @@ class DocumentManager
$id = intval($id); $id = intval($id);
$sql = "SELECT * FROM $TABLE_DOCUMENT $sql = "SELECT * FROM $TABLE_DOCUMENT
WHERE c_id = $course_id AND session_id = $session_id AND id = $id"; WHERE c_id = $course_id AND session_id = $session_id AND id = $id";
$result = Database::query($sql); $result = Database::query($sql);
if ($result && Database::num_rows($result) == 1) { if ($result && Database::num_rows($result) == 1) {
$row = Database::fetch_array($result, 'ASSOC'); $row = Database::fetch_array($result, 'ASSOC');
@ -4203,11 +4203,12 @@ class DocumentManager
/** /**
* @param string $filePath * @param string $filePath
* @param string $path * @param string $path
* @param $courseInfo * @param array $courseInfo
* @param int $sessionId
* @param string $whatIfFileExists overwrite|rename * @param string $whatIfFileExists overwrite|rename
* @param null $userId * @param int $userId
* @param null $groupId * @param int $groupId
* @param null $toUserId * @param int $toUserId
* @param string $comment * @param string $comment
* @return bool|path * @return bool|path
*/ */
@ -4215,6 +4216,7 @@ class DocumentManager
$filePath, $filePath,
$path, $path,
$courseInfo, $courseInfo,
$sessionId,
$userId, $userId,
$whatIfFileExists = 'overwrite', $whatIfFileExists = 'overwrite',
$groupId = null, $groupId = null,
@ -4249,11 +4251,16 @@ class DocumentManager
$whatIfFileExists, $whatIfFileExists,
false, false,
false, false,
$comment $comment,
$sessionId
); );
if ($filePath) { if ($filePath) {
return DocumentManager::get_document_id($courseInfo, $filePath); return DocumentManager::get_document_id(
$courseInfo,
$filePath,
$sessionId
);
} }
return false; return false;
} }
@ -4292,16 +4299,21 @@ class DocumentManager
} }
/** /**
* @param string $documentData * @param string $documentData wav document information
* @param array $courseInfo * @param array $courseInfo
* @param int $sessionId
* @param int $userId user that adds the document
* @param string $whatIfFileExists * @param string $whatIfFileExists
* @param bool $deleteWavFile
* @return bool|path * @return bool|path
*/ */
public static function addAndConvertWavToMp3( public static function addAndConvertWavToMp3(
$documentData, $documentData,
$courseInfo, $courseInfo,
$sessionId,
$userId, $userId,
$whatIfFileExists = 'overwrite' $whatIfFileExists = 'overwrite',
$deleteWavFile = false
) { ) {
if (empty($documentData)) { if (empty($documentData)) {
return false; return false;
@ -4311,12 +4323,14 @@ class DocumentManager
file_exists($documentData['absolute_path']) file_exists($documentData['absolute_path'])
) { ) {
$mp3FilePath = self::convertWavToMp3($documentData['absolute_path']); $mp3FilePath = self::convertWavToMp3($documentData['absolute_path']);
if (!empty($mp3FilePath)) {
if (!empty($mp3FilePath) && file_exists($mp3FilePath)) {
$documentId = self::addFileToDocumentTool( $documentId = self::addFileToDocumentTool(
$mp3FilePath, $mp3FilePath,
dirname($documentData['path']), dirname($documentData['path']),
$courseInfo, $courseInfo,
$sessionId,
$userId, $userId,
$whatIfFileExists, $whatIfFileExists,
null, null,
@ -4325,6 +4339,19 @@ class DocumentManager
); );
if (!empty($documentId)) { if (!empty($documentId)) {
if ($deleteWavFile) {
$coursePath = $courseInfo['directory'].'/document';
$documentPath = api_get_path(SYS_COURSE_PATH).$coursePath;
self::delete_document(
$courseInfo,
null,
$documentPath,
$sessionId,
$documentData['id']
);
}
return $documentId; return $documentId;
} }
} }

@ -195,17 +195,22 @@ function handle_uploaded_document(
$what_if_file_exists = '', $what_if_file_exists = '',
$output = true, $output = true,
$onlyUploadFile = false, $onlyUploadFile = false,
$comment = null $comment = null,
$sessionId = null
) { ) {
if (!$user_id) { if (!$user_id) {
return false; return false;
} }
// Strip slashes
$uploaded_file['name'] = stripslashes($uploaded_file['name']); $uploaded_file['name'] = stripslashes($uploaded_file['name']);
// Add extension to files without one (if possible) // Add extension to files without one (if possible)
$uploaded_file['name'] = add_ext_on_mime($uploaded_file['name'], $uploaded_file['type']); $uploaded_file['name'] = add_ext_on_mime($uploaded_file['name'], $uploaded_file['type']);
$current_session_id = api_get_session_id();
if (empty($sessionId)) {
$current_session_id = api_get_session_id();
} else {
$current_session_id = intval($sessionId);
}
// Just in case process_uploaded_file is not called // Just in case process_uploaded_file is not called
$max_filled_space = DocumentManager::get_course_quota(); $max_filled_space = DocumentManager::get_course_quota();

@ -37,7 +37,15 @@ $documentData = DocumentManager::upload_document($_FILES, $_GET['path'], null, n
if (!empty($documentData)) { if (!empty($documentData)) {
$newDocId = $documentData['id']; $newDocId = $documentData['id'];
$newMp3DocumentId = DocumentManager::addAndConvertWavToMp3($documentData, $courseInfo, api_get_user_id()); $newMp3DocumentId = DocumentManager::addAndConvertWavToMp3(
$documentData,
$courseInfo,
api_get_session_id(),
api_get_user_id(),
'overwrite',
true
);
if ($newMp3DocumentId) { if ($newMp3DocumentId) {
$newDocId = $newMp3DocumentId; $newDocId = $newMp3DocumentId;
} }
@ -53,4 +61,4 @@ if (!empty($documentData)) {
$lpItem->add_audio_from_documents($newDocId); $lpItem->add_audio_from_documents($newDocId);
} }
} }
} }

@ -106,7 +106,10 @@ if (!empty($documentData)) {
$newMp3DocumentId = DocumentManager::addAndConvertWavToMp3( $newMp3DocumentId = DocumentManager::addAndConvertWavToMp3(
$documentData, $documentData,
$courseInfo, $courseInfo,
api_get_user_id() api_get_session_id(),
api_get_user_id(),
'overwrite',
true
); );
if ($newMp3DocumentId) { if ($newMp3DocumentId) {

Loading…
Cancel
Save