extension mgr can now cache check result

This commit is contained in:
Uwe Steinmann 2021-11-04 17:06:47 +01:00
parent de003de613
commit b6ed28b4ec
3 changed files with 88 additions and 71 deletions

View File

@ -51,6 +51,12 @@ class SeedDMS_Extension_Mgr {
*/ */
protected $cachedir; protected $cachedir;
/**
* @var array $configcache cached result of checkExtensionByName()
* @access protected
*/
protected $configcache;
/** /**
* @var string[] $errmsg list of error message from last operation * @var string[] $errmsg list of error message from last operation
* @access protected * @access protected
@ -104,6 +110,7 @@ class SeedDMS_Extension_Mgr {
* is given * is given
*/ */
public function __construct($extdir = '', $cachedir = '', $reposurl = '', $proxyurl='', $proxyuser='', $proxypass='') { /* {{{ */ public function __construct($extdir = '', $cachedir = '', $reposurl = '', $proxyurl='', $proxyuser='', $proxypass='') { /* {{{ */
$this->configcache = [];
$this->cachedir = $cachedir; $this->cachedir = $cachedir;
$this->extdir = $extdir; $this->extdir = $extdir;
$this->reposurl = $reposurl; $this->reposurl = $reposurl;
@ -321,18 +328,9 @@ class SeedDMS_Extension_Mgr {
return $ret; return $ret;
} /* }}} */ } /* }}} */
/** public function checkExtensionByDir($dir, $options = array()) { /* {{{ */
* Check content of extension directory or configuration of extension
*
* @param string|array $dir full path to extension directory or extension name
* or an array containing the configuration.
* @param boolean $noconstraints set to true if constraints to local seeddms
* installation shall not be checked.
*/
public function checkExtension($dir, $options=array()) { /* {{{ */
$this->errmsgs = array(); $this->errmsgs = array();
if(is_string($dir)) {
if(!file_exists($dir)) { if(!file_exists($dir)) {
if(!file_exists($this->extdir.'/'.$dir)) if(!file_exists($this->extdir.'/'.$dir))
return false; return false;
@ -355,13 +353,40 @@ class SeedDMS_Extension_Mgr {
} }
$extconf = $EXT_CONF[$extname]; $extconf = $EXT_CONF[$extname];
} elseif(is_array($dir)) {
$extconf = $dir; if(!empty($extconf['language']['file']) && !file_exists($dir."/".$extconf['language']['file'])) {
/* If just the configuration is passed, then there is no way to check $this->errmsgs[] = "Missing language file";
* for existence of files.
*/
$options['nofiles'] = true;
} }
if(!empty($extconf['class']['file']) && !file_exists($dir."/".$extconf['class']['file'])) {
$this->errmsgs[] = "Missing class file";
}
if(!empty($extconf['icon']) && !file_exists($dir."/".$extconf['icon'])) {
$this->errmsgs[] = "Missing icon file";
}
if($this->errmsgs)
return false;
return self::checkExtensionByName($extname, $extconf, $options);
}
/**
* Check content of extension directory or configuration of extension
*
* @param string|array $dir full path to extension directory or extension name
* or an array containing the configuration.
* @param array $options array with options elements 'noconstraints' and 'nofiles'.
* Set 'noconstraints' to true if
* constraints to local seeddms installation shall not be checked. Set 'nofiles'
* to true to turn off checking of files
* @return boolean true if check was successful, otherwise false
*/
public function checkExtensionByName($extname, $extconf, $options=array()) { /* {{{ */
if(isset($this->configcache[$extname])) {
return $this->configcache[$extname];
}
$this->errmsgs = array();
if(!isset($extconf['constraints']['depends']['seeddms'])) { if(!isset($extconf['constraints']['depends']['seeddms'])) {
$this->errmsgs[] = "Missing dependency on SeedDMS"; $this->errmsgs[] = "Missing dependency on SeedDMS";
@ -378,17 +403,6 @@ class SeedDMS_Extension_Mgr {
if(!isset($extconf['author'])) { if(!isset($extconf['author'])) {
$this->errmsgs[] = "Missing author"; $this->errmsgs[] = "Missing author";
} }
if(!isset($options['nofiles']) || $options['nofiles'] == false) {
if(!empty($extconf['language']['file']) && !file_exists($dir."/".$extconf['language']['file'])) {
$this->errmsgs[] = "Missing language file";
}
if(!empty($extconf['class']['file']) && !file_exists($dir."/".$extconf['class']['file'])) {
$this->errmsgs[] = "Missing class file";
}
if(!empty($extconf['icon']) && !file_exists($dir."/".$extconf['icon'])) {
$this->errmsgs[] = "Missing icon file";
}
}
if(!isset($options['noconstraints']) || $options['noconstraints'] == false) { if(!isset($options['noconstraints']) || $options['noconstraints'] == false) {
if(isset($extconf['constraints']['depends'])) { if(isset($extconf['constraints']['depends'])) {
@ -442,9 +456,11 @@ class SeedDMS_Extension_Mgr {
} }
if($this->errmsgs) if($this->errmsgs)
return false; $this->configcache[$extname] = false;
else
$this->configcache[$extname] = true;
return true; return $this->configcache[$extname];
} /* }}} */ } /* }}} */
static protected function rrmdir($dir) { /* {{{ */ static protected function rrmdir($dir) { /* {{{ */
@ -494,7 +510,7 @@ class SeedDMS_Extension_Mgr {
// exec($cmd); // exec($cmd);
/* Check if extension is complete and fullfills the constraints */ /* Check if extension is complete and fullfills the constraints */
if(!self::checkExtension($newdir)) { if(!self::checkExtensionByDir($newdir)) {
self::rrmdir($newdir); self::rrmdir($newdir);
return false; return false;
} }

View File

@ -56,7 +56,7 @@ class UI extends UI_Default {
$decorators = array(); $decorators = array();
foreach($extMgr->getExtensionConfiguration() as $extname=>$extconf) { foreach($extMgr->getExtensionConfiguration() as $extname=>$extconf) {
if(!$settings->extensionIsDisabled($extname)) { if(!$settings->extensionIsDisabled($extname)) {
if($extMgr->checkExtension($extconf)) { if($extMgr->checkExtensionByName($extname, $extconf)) {
if(isset($extconf['decorators'][$class])) { if(isset($extconf['decorators'][$class])) {
$filename = $settings->_rootDir.'ext/'.$extname.'/decorators/'.$theme."/".$extconf['decorators'][$class]['file']; $filename = $settings->_rootDir.'ext/'.$extname.'/decorators/'.$theme."/".$extconf['decorators'][$class]['file'];
if(file_exists($filename)) { if(file_exists($filename)) {
@ -73,7 +73,7 @@ class UI extends UI_Default {
$httpbasedir = ''; $httpbasedir = '';
foreach($extMgr->getExtensionConfiguration() as $extname=>$extconf) { foreach($extMgr->getExtensionConfiguration() as $extname=>$extconf) {
if(!$settings->extensionIsDisabled($extname)) { if(!$settings->extensionIsDisabled($extname)) {
if($extMgr->checkExtension($extconf)) { if($extMgr->checkExtensionByName($extname, $extconf)) {
/* Setting the 'views' element in the configuration can be used to /* Setting the 'views' element in the configuration can be used to
* replace an existing view in views/bootstrap/, e.g. class.ViewFolder.php * replace an existing view in views/bootstrap/, e.g. class.ViewFolder.php
* without providing an out/out.ViewFolder.php. In that case $httpbasedir * without providing an out/out.ViewFolder.php. In that case $httpbasedir

View File

@ -25,9 +25,10 @@ $version = new SeedDMS_Version;
foreach($extMgr->getExtensionConfiguration() as $extname=>$extconf) { foreach($extMgr->getExtensionConfiguration() as $extname=>$extconf) {
if(!$settings->extensionIsDisabled($extname)) { if(!$settings->extensionIsDisabled($extname)) {
$disabled = true; $disabled = true;
if($extMgr->checkExtension($extconf)) { if($extMgr->checkExtensionByName($extname, $extconf)) {
$disabled = false; $disabled = false;
} else { } else {
$settings->disableExtension($extname);
// echo $extMgr->getErrorMsg(); // echo $extMgr->getErrorMsg();
} }
/* check for requirements */ /* check for requirements */