From 49a1b33df4074b6be58d2e23759801f2eaefbd16 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Mon, 16 May 2022 15:54:04 +0200 Subject: [PATCH 1/2] check extension dependency on shell commands --- CHANGELOG | 1 + inc/inc.ClassExtensionMgr.php | 8 ++++++++ inc/inc.Utils.php | 31 +++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 5f7f5d223..ab08c277e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ - add hook additionalDocumentContentInfo - add restapi function 'statstotal' - custom attributes of type 'date' regard the date format +- check extension dependency on shell commands -------------------------------------------------------------------------------- Changes in version 5.1.25 diff --git a/inc/inc.ClassExtensionMgr.php b/inc/inc.ClassExtensionMgr.php index b70f0fe3b..07e7d51d3 100644 --- a/inc/inc.ClassExtensionMgr.php +++ b/inc/inc.ClassExtensionMgr.php @@ -441,6 +441,14 @@ class SeedDMS_Extension_Mgr { } } break; + case 'cmd': + if(is_array($dval) && $dval) { + foreach($dval as $d) { + if(!commandExists($d)) + $this->errmsgs[] = sprintf("Missing command '%s'", $d); + } + } + break; default: $tmp = explode('-', $dval, 2); if(isset($this->extconf[$dkey]['version'])) { diff --git a/inc/inc.Utils.php b/inc/inc.Utils.php index 3192b6fbd..6628a5df2 100644 --- a/inc/inc.Utils.php +++ b/inc/inc.Utils.php @@ -696,6 +696,37 @@ function addDirSep($str) { /* {{{ */ return trim($str); } /* }}} */ +/** + * Determines if a command exists on the current environment + * + * @param string $command The command to check + * @return bool True if the command has been found ; otherwise, false. + */ +function commandExists ($command) { + $whereIsCommand = (PHP_OS == 'WINNT') ? 'where' : 'command -v'; + + $process = proc_open( + "$whereIsCommand $command", + array( + 0 => array("pipe", "r"), //STDIN + 1 => array("pipe", "w"), //STDOUT + 2 => array("pipe", "w"), //STDERR + ), + $pipes + ); + if ($process !== false) { + $stdout = stream_get_contents($pipes[1]); + $stderr = stream_get_contents($pipes[2]); + fclose($pipes[1]); + fclose($pipes[2]); + proc_close($process); + + return $stdout != ''; + } + + return false; +} + /** * Send a file from disk to the browser * From c9d6d840d9696874a9d2f0ff78414261bcb0ab95 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Tue, 17 May 2022 07:51:17 +0200 Subject: [PATCH 2/2] use preview converters or conversion mgr --- out/out.MyDocuments.php | 2 ++ views/bootstrap/class.MyDocuments.php | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/out/out.MyDocuments.php b/out/out.MyDocuments.php index 311488d1d..e64a5b9ed 100644 --- a/out/out.MyDocuments.php +++ b/out/out.MyDocuments.php @@ -55,7 +55,9 @@ if($view) { $view->setParam('showinprocess', $showInProcess); $view->setParam('workflowmode', $settings->_workflowMode); $view->setParam('cachedir', $settings->_cacheDir); + $view->setParam('conversionmgr', $conversionmgr); $view->setParam('previewWidthList', $settings->_previewWidthList); + $view->setParam('previewConverters', isset($settings->_converters['preview']) ? $settings->_converters['preview'] : array()); $view->setParam('timeout', $settings->_cmdTimeout); $view->setParam('accessobject', $accessop); $view->setParam('xsendfile', $settings->_enableXsendfile); diff --git a/views/bootstrap/class.MyDocuments.php b/views/bootstrap/class.MyDocuments.php index dd3136c03..4e000f217 100644 --- a/views/bootstrap/class.MyDocuments.php +++ b/views/bootstrap/class.MyDocuments.php @@ -53,13 +53,19 @@ class SeedDMS_View_MyDocuments extends SeedDMS_Theme_Style { $orderby = $this->params['orderby']; $showInProcess = $this->params['showinprocess']; $cachedir = $this->params['cachedir']; + $conversionmgr = $this->params['conversionmgr']; $workflowmode = $this->params['workflowmode']; $previewwidth = $this->params['previewWidthList']; + $previewconverters = $this->params['previewConverters']; $timeout = $this->params['timeout']; $xsendfile = $this->params['xsendfile']; $db = $dms->getDB(); $previewer = new SeedDMS_Preview_Previewer($cachedir, $previewwidth, $timeout, $xsendfile); + if($conversionmgr) + $previewer->setConversionMgr($conversionmgr); + else + $previewer->setConverters($previewconverters); $this->htmlStartPage(getMLText("my_documents")); $this->globalNavigation(); @@ -951,7 +957,6 @@ class SeedDMS_View_MyDocuments extends SeedDMS_Theme_Style { print "".getMLText("action")."\n"; print "\n\n\n"; - $previewer = new SeedDMS_Preview_Previewer($cachedir, $previewwidth, $timeout, $xsendfile); foreach ($resArr as $res) { $document = $dms->getDocument($res["documentID"]); $document->verifyLastestContentExpriry();