From 4933d1a0b6ba7fc81ae725546606e053f3cc90f5 Mon Sep 17 00:00:00 2001 From: christianbeeznest <84335353+christianbeeznest@users.noreply.github.com> Date: Thu, 4 May 2023 02:30:40 -0500 Subject: [PATCH] Exercise: Improve export results to pdfs in zip - refs BT#20691 Author: @christianbeeznest --- main/inc/lib/exercise.lib.php | 21 ++++++++++++++++++++- main/inc/lib/pdf.lib.php | 24 ++++++++++++++++-------- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 7aaaee482e..6ca9295a5a 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -7169,9 +7169,16 @@ EOT; curl_setopt($ch, CURLOPT_FAILONERROR, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch, CURLOPT_HEADER, true); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $result = curl_exec($ch); + if (false === $result) { + error_log('saveFileExerciseResultPdf error: '.curl_error($ch)); + } + curl_close($ch); } @@ -7188,6 +7195,7 @@ EOT; '' ); + $exportOk = false; if (!empty($exeResults)) { $exportName = 'S'.$sessionId.'-C'.$courseId.'-T'.$exerciseId; $baseDir = api_get_path(SYS_ARCHIVE_PATH); @@ -7209,7 +7217,8 @@ EOT; // 3. If export folder is not empty will be zipped. $isFolderPathEmpty = (file_exists($exportFolderPath) && 2 == count(scandir($exportFolderPath))); - if (!$isFolderPathEmpty) { + if (is_dir($exportFolderPath) && !$isFolderPathEmpty) { + $exportOk = true; $exportFilePath = $baseDir.$exportName.'.zip'; $zip = new \PclZip($exportFilePath); $zip->create($exportFolderPath, PCLZIP_OPT_REMOVE_PATH, $exportFolderPath); @@ -7220,6 +7229,16 @@ EOT; } } + if (!$exportOk) { + Display::addFlash( + Display::return_message( + get_lang('ExportExerciseNoResult'), + 'warning', + false + ) + ); + } + return false; } } diff --git a/main/inc/lib/pdf.lib.php b/main/inc/lib/pdf.lib.php index 5e964bf97e..274cda3ce3 100755 --- a/main/inc/lib/pdf.lib.php +++ b/main/inc/lib/pdf.lib.php @@ -560,15 +560,23 @@ class PDF if ($saveInFile) { $fileToSave = !empty($fileToSave) ? $fileToSave : api_get_path(SYS_ARCHIVE_PATH).uniqid(); - @$this->pdf->Output( - $fileToSave, - $outputMode - ); // F to save the pdf in a file + try { + @$this->pdf->Output( + $fileToSave, + $outputMode + ); // F to save the pdf in a file + } catch (MpdfException $e) { + error_log($e); + } } else { - @$this->pdf->Output( - $output_file, - $outputMode - ); // F to save the pdf in a file + try { + @$this->pdf->Output( + $output_file, + $outputMode + ); // F to save the pdf in a file + } catch (MpdfException $e) { + error_log($e); + } } if ($outputMode != 'F') {