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,48 +328,66 @@ class SeedDMS_Extension_Mgr {
return $ret; return $ret;
} /* }}} */ } /* }}} */
public function checkExtensionByDir($dir, $options = array()) { /* {{{ */
$this->errmsgs = array();
if(!file_exists($dir)) {
if(!file_exists($this->extdir.'/'.$dir))
return false;
else
$dir = $this->extdir.'/'.$dir;
}
if(!file_exists($dir."/conf.php")) {
$this->errmsgs[] = "Missing extension configuration";
return false;
}
include($dir."/conf.php");
if(!isset($EXT_CONF)) {
$this->errmsgs[] = "Missing \$EXT_CONF in configuration";
return false;
}
$extname = key($EXT_CONF);
if(!$extname || !preg_match('/[a-zA-Z_]*/', $extname)) {
$this->errmsgs[] = "Extension has invalid or no name";
return false;
}
$extconf = $EXT_CONF[$extname];
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($this->errmsgs)
return false;
return self::checkExtensionByName($extname, $extconf, $options);
}
/** /**
* Check content of extension directory or configuration of extension * Check content of extension directory or configuration of extension
* *
* @param string|array $dir full path to extension directory or extension name * @param string|array $dir full path to extension directory or extension name
* or an array containing the configuration. * or an array containing the configuration.
* @param boolean $noconstraints set to true if constraints to local seeddms * @param array $options array with options elements 'noconstraints' and 'nofiles'.
* installation shall not be checked. * 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 checkExtension($dir, $options=array()) { /* {{{ */ public function checkExtensionByName($extname, $extconf, $options=array()) { /* {{{ */
$this->errmsgs = array(); if(isset($this->configcache[$extname])) {
return $this->configcache[$extname];
if(is_string($dir)) {
if(!file_exists($dir)) {
if(!file_exists($this->extdir.'/'.$dir))
return false;
else
$dir = $this->extdir.'/'.$dir;
}
if(!file_exists($dir."/conf.php")) {
$this->errmsgs[] = "Missing extension configuration";
return false;
}
include($dir."/conf.php");
if(!isset($EXT_CONF)) {
$this->errmsgs[] = "Missing \$EXT_CONF in configuration";
return false;
}
$extname = key($EXT_CONF);
if(!$extname || !preg_match('/[a-zA-Z_]*/', $extname)) {
$this->errmsgs[] = "Extension has invalid or no name";
return false;
}
$extconf = $EXT_CONF[$extname];
} elseif(is_array($dir)) {
$extconf = $dir;
/* If just the configuration is passed, then there is no way to check
* for existence of files.
*/
$options['nofiles'] = true;
} }
$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 */
@ -41,30 +42,30 @@ foreach($extMgr->getExtensionConfiguration() as $extname=>$extconf) {
} }
*/ */
if(!$disabled) { if(!$disabled) {
if(isset($extconf['class']) && isset($extconf['class']['file']) && isset($extconf['class']['name'])) { if(isset($extconf['class']) && isset($extconf['class']['file']) && isset($extconf['class']['name'])) {
$classfile = $settings->_rootDir."/ext/".$extname."/".$extconf['class']['file']; $classfile = $settings->_rootDir."/ext/".$extname."/".$extconf['class']['file'];
if(file_exists($classfile)) { if(file_exists($classfile)) {
include($classfile); include($classfile);
$obj = new $extconf['class']['name']($settings, null, $logger); $obj = new $extconf['class']['name']($settings, null, $logger);
if(method_exists($obj, 'init')) if(method_exists($obj, 'init'))
$obj->init(); $obj->init();
}
} }
} if(isset($extconf['language']['file'])) {
if(isset($extconf['language']['file'])) { $langfile = $settings->_rootDir."/ext/".$extname."/".$extconf['language']['file'];
$langfile = $settings->_rootDir."/ext/".$extname."/".$extconf['language']['file']; if(file_exists($langfile)) {
if(file_exists($langfile)) { unset($__lang);
unset($__lang); include($langfile);
include($langfile); if(isset($__lang) && $__lang) {
if(isset($__lang) && $__lang) { foreach($__lang as $lang=>&$data) {
foreach($__lang as $lang=>&$data) { if(isset($GLOBALS['LANG'][$lang]))
if(isset($GLOBALS['LANG'][$lang])) $GLOBALS['LANG'][$lang] = array_merge($GLOBALS['LANG'][$lang], $data);
$GLOBALS['LANG'][$lang] = array_merge($GLOBALS['LANG'][$lang], $data); else
else $GLOBALS['LANG'][$lang] = $data;
$GLOBALS['LANG'][$lang] = $data; }
} }
} }
} }
} }
}
} }
} }