From 7bf06fd06279e8cc0df7cfd2efa5319d58c9bce2 Mon Sep 17 00:00:00 2001 From: Guillaume Heurtier <guillaume.heurtier@maarch.org> Date: Thu, 9 Jul 2020 13:53:20 +0200 Subject: [PATCH] FEAT #14242 TIME 1:00 check maarchUrl before converting with onlyoffice + convert with unoconv if conversion failed --- .../controllers/OnlyOfficeController.php | 15 ++++++++++++++- .../controllers/ConvertPdfController.php | 17 ++++++++--------- src/app/convert/scripts/ConvertPdfScript.php | 10 +++++----- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/app/contentManagement/controllers/OnlyOfficeController.php b/src/app/contentManagement/controllers/OnlyOfficeController.php index dfb318c7c23..23f1e7bea0d 100644 --- a/src/app/contentManagement/controllers/OnlyOfficeController.php +++ b/src/app/contentManagement/controllers/OnlyOfficeController.php @@ -318,7 +318,20 @@ class OnlyOfficeController return false; } - return $isAvailable; + if (!$isAvailable) { + return false; + } + + $file = CoreConfigModel::getJsonLoaded(['path' => 'apps/maarch_entreprise/xml/config.json']); + if (empty($file['config']['maarchUrl'])) { + return false; + } + + if (strpos($file['config']['maarchUrl'], 'localhost') !== false || strpos($file['config']['maarchUrl'], '127.0.0.1') !== false ) { + return false; + } + + return true; } public static function convert(array $args) diff --git a/src/app/convert/controllers/ConvertPdfController.php b/src/app/convert/controllers/ConvertPdfController.php index a06ab809115..663ebf862c3 100755 --- a/src/app/convert/controllers/ConvertPdfController.php +++ b/src/app/convert/controllers/ConvertPdfController.php @@ -41,18 +41,17 @@ class ConvertPdfController exec('export DISPLAY=:0 && '.$command.' 2>&1', $output, $return); } else { if (OnlyOfficeController::canConvert()) { - $output = []; - $return = 0; $converted = OnlyOfficeController::convert(['fullFilename' => $aArgs['fullFilename']]); - if (!empty($converted['errors'])) { - $output = [$converted['errors']]; + if (empty($converted['errors'])) { + return ['output' => [], 'return' => 0]; } - } else { - ConvertPdfController::addBom($aArgs['fullFilename']); - $command = "timeout 30 unoconv -f pdf " . escapeshellarg($aArgs['fullFilename']); - - exec('export HOME=' . $tmpPath . ' && ' . $command . ' 2>&1', $output, $return); } + + ConvertPdfController::addBom($aArgs['fullFilename']); + $command = "timeout 30 unoconv -f pdf " . escapeshellarg($aArgs['fullFilename']); + + exec('export HOME=' . $tmpPath . ' && ' . $command . ' 2>&1', $output, $return); + } return ['output' => $output, 'return' => $return]; diff --git a/src/app/convert/scripts/ConvertPdfScript.php b/src/app/convert/scripts/ConvertPdfScript.php index d811342acd4..f30921d6d67 100644 --- a/src/app/convert/scripts/ConvertPdfScript.php +++ b/src/app/convert/scripts/ConvertPdfScript.php @@ -101,13 +101,13 @@ class ConvertPdfScript if (strtolower($docInfo['extension']) != 'pdf') { $fullFilename = "{$tmpPath}{$fileNameOnTmp}.{$docInfo['extension']}"; + $converted = false; + $output = []; if (OnlyOfficeController::canConvert()) { - $output = []; $converted = OnlyOfficeController::convert(['fullFilename' => $fullFilename]); - if (!empty($converted['errors'])) { - $output = [$converted['errors']]; - } - } else { + $converted = empty($converted['errors']); + } + if (!$converted){ ConvertPdfController::addBom($fullFilename); $command = "timeout 30 unoconv -f pdf " . escapeshellarg($fullFilename); exec('export HOME=' . $tmpPath . ' && '.$command, $output, $return); -- GitLab