check extension dependency on shell commands

This commit is contained in:
Uwe Steinmann 2022-05-16 15:54:04 +02:00
parent 395e60ca71
commit 49a1b33df4
3 changed files with 40 additions and 0 deletions

View File

@ -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

View File

@ -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'])) {

View File

@ -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
*