exists() || ! $userLib->user_has_perm_on_object($user, $file->fileId, 'file', 'tiki_p_download_files')) { return null; } if (! self::canConvertToPDF($file->filetype)) { $error = 'File type not supported.'; $message = sprintf("Failed to convert document %s (id: %s) to pdf. Error: %s", $file->filename, $fileId, $error); $logsLib = \TikiLib::lib('logs'); $logsLib->add_log('File', $message); return null; } $sourceFile = $file->getWrapper()->getReadableFile(); $targetFile = implode(DIRECTORY_SEPARATOR, ['temp', 'cache', $tikidomain, 'target_' . $fileId . '.pdf']); try { $convertFail = false; $unoconv = new UnoconvLib(); $unoconv->convertFile($sourceFile, $targetFile); } catch (\Exception $e) { $convertFail = true; $message = sprintf("Failed to convert document %s (id: %s) to pdf. Error: %s", $file->filename, $fileId, $e->getMessage()); $logsLib = \TikiLib::lib('logs'); $previous = $e->getPrevious(); while ($previous) { $logsLib->add_log('Unoconv', $previous->getMessage()); $previous = $previous->getPrevious(); } $logsLib->add_log('Unoconv', $message); } if ((empty($targetFile) && file_exists($targetFile)) || $convertFail) { $message = tr('Failed to convert document %0 to pdf.', $file->filename); $userlib = \TikiLib::lib('user'); if ($userlib->user_has_permission($user, 'tiki_p_view_actionlog')) { $message .= ' ' . tr('Please check Action Log for more information.'); } else { $message .= ' ' . tr('Please contact the administrator.'); } $access = \TikiLib::lib('access'); $access->display_error('', $message); } return $targetFile; } }