diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index 9558325df3..cec3ec0d12 100755 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -1241,7 +1241,6 @@ class DocumentManager } } } - // 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').')'); if ($file_deleted_from_db && $file_deleted_from_disk || @@ -1363,6 +1362,7 @@ class DocumentManager $id = intval($id); $sql = "SELECT * FROM $TABLE_DOCUMENT WHERE c_id = $course_id AND session_id = $session_id AND id = $id"; + $result = Database::query($sql); if ($result && Database::num_rows($result) == 1) { $row = Database::fetch_array($result, 'ASSOC'); @@ -4203,11 +4203,12 @@ class DocumentManager /** * @param string $filePath * @param string $path - * @param $courseInfo + * @param array $courseInfo + * @param int $sessionId * @param string $whatIfFileExists overwrite|rename - * @param null $userId - * @param null $groupId - * @param null $toUserId + * @param int $userId + * @param int $groupId + * @param int $toUserId * @param string $comment * @return bool|path */ @@ -4215,6 +4216,7 @@ class DocumentManager $filePath, $path, $courseInfo, + $sessionId, $userId, $whatIfFileExists = 'overwrite', $groupId = null, @@ -4249,11 +4251,16 @@ class DocumentManager $whatIfFileExists, false, false, - $comment + $comment, + $sessionId ); if ($filePath) { - return DocumentManager::get_document_id($courseInfo, $filePath); + return DocumentManager::get_document_id( + $courseInfo, + $filePath, + $sessionId + ); } return false; } @@ -4292,16 +4299,21 @@ class DocumentManager } /** - * @param string $documentData + * @param string $documentData wav document information * @param array $courseInfo + * @param int $sessionId + * @param int $userId user that adds the document * @param string $whatIfFileExists + * @param bool $deleteWavFile * @return bool|path */ public static function addAndConvertWavToMp3( $documentData, $courseInfo, + $sessionId, $userId, - $whatIfFileExists = 'overwrite' + $whatIfFileExists = 'overwrite', + $deleteWavFile = false ) { if (empty($documentData)) { return false; @@ -4311,12 +4323,14 @@ class DocumentManager file_exists($documentData['absolute_path']) ) { $mp3FilePath = self::convertWavToMp3($documentData['absolute_path']); - if (!empty($mp3FilePath)) { + + if (!empty($mp3FilePath) && file_exists($mp3FilePath)) { $documentId = self::addFileToDocumentTool( $mp3FilePath, dirname($documentData['path']), $courseInfo, + $sessionId, $userId, $whatIfFileExists, null, @@ -4325,6 +4339,19 @@ class DocumentManager ); 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; } } diff --git a/main/inc/lib/fileUpload.lib.php b/main/inc/lib/fileUpload.lib.php index 7066fe38e3..630f92ae84 100755 --- a/main/inc/lib/fileUpload.lib.php +++ b/main/inc/lib/fileUpload.lib.php @@ -195,17 +195,22 @@ function handle_uploaded_document( $what_if_file_exists = '', $output = true, $onlyUploadFile = false, - $comment = null + $comment = null, + $sessionId = null ) { if (!$user_id) { return false; } - // Strip slashes $uploaded_file['name'] = stripslashes($uploaded_file['name']); // Add extension to files without one (if possible) $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 $max_filled_space = DocumentManager::get_course_quota(); diff --git a/main/inc/lib/nanogong/upload_nanogong_file.php b/main/inc/lib/nanogong/upload_nanogong_file.php index 22c410ebb0..e7c75788f2 100755 --- a/main/inc/lib/nanogong/upload_nanogong_file.php +++ b/main/inc/lib/nanogong/upload_nanogong_file.php @@ -37,7 +37,15 @@ $documentData = DocumentManager::upload_document($_FILES, $_GET['path'], null, n if (!empty($documentData)) { $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) { $newDocId = $newMp3DocumentId; } @@ -53,4 +61,4 @@ if (!empty($documentData)) { $lpItem->add_audio_from_documents($newDocId); } } -} \ No newline at end of file +} diff --git a/main/inc/lib/wami-recorder/record_document.php b/main/inc/lib/wami-recorder/record_document.php index 69fb55e730..f009343ebf 100755 --- a/main/inc/lib/wami-recorder/record_document.php +++ b/main/inc/lib/wami-recorder/record_document.php @@ -106,7 +106,10 @@ if (!empty($documentData)) { $newMp3DocumentId = DocumentManager::addAndConvertWavToMp3( $documentData, $courseInfo, - api_get_user_id() + api_get_session_id(), + api_get_user_id(), + 'overwrite', + true ); if ($newMp3DocumentId) {