mirror of
https://git.code.sf.net/p/seeddms/code
synced 2024-11-26 15:32:13 +00:00
extension mgr can now cache check result
This commit is contained in:
parent
de003de613
commit
b6ed28b4ec
|
@ -51,6 +51,12 @@ class SeedDMS_Extension_Mgr {
|
|||
*/
|
||||
protected $cachedir;
|
||||
|
||||
/**
|
||||
* @var array $configcache cached result of checkExtensionByName()
|
||||
* @access protected
|
||||
*/
|
||||
protected $configcache;
|
||||
|
||||
/**
|
||||
* @var string[] $errmsg list of error message from last operation
|
||||
* @access protected
|
||||
|
@ -104,6 +110,7 @@ class SeedDMS_Extension_Mgr {
|
|||
* is given
|
||||
*/
|
||||
public function __construct($extdir = '', $cachedir = '', $reposurl = '', $proxyurl='', $proxyuser='', $proxypass='') { /* {{{ */
|
||||
$this->configcache = [];
|
||||
$this->cachedir = $cachedir;
|
||||
$this->extdir = $extdir;
|
||||
$this->reposurl = $reposurl;
|
||||
|
@ -321,48 +328,66 @@ class SeedDMS_Extension_Mgr {
|
|||
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
|
||||
*
|
||||
* @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.
|
||||
* @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 checkExtension($dir, $options=array()) { /* {{{ */
|
||||
$this->errmsgs = array();
|
||||
|
||||
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;
|
||||
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'])) {
|
||||
$this->errmsgs[] = "Missing dependency on SeedDMS";
|
||||
}
|
||||
|
@ -378,17 +403,6 @@ class SeedDMS_Extension_Mgr {
|
|||
if(!isset($extconf['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($extconf['constraints']['depends'])) {
|
||||
|
@ -442,9 +456,11 @@ class SeedDMS_Extension_Mgr {
|
|||
}
|
||||
|
||||
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) { /* {{{ */
|
||||
|
@ -494,7 +510,7 @@ class SeedDMS_Extension_Mgr {
|
|||
// exec($cmd);
|
||||
|
||||
/* Check if extension is complete and fullfills the constraints */
|
||||
if(!self::checkExtension($newdir)) {
|
||||
if(!self::checkExtensionByDir($newdir)) {
|
||||
self::rrmdir($newdir);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ class UI extends UI_Default {
|
|||
$decorators = array();
|
||||
foreach($extMgr->getExtensionConfiguration() as $extname=>$extconf) {
|
||||
if(!$settings->extensionIsDisabled($extname)) {
|
||||
if($extMgr->checkExtension($extconf)) {
|
||||
if($extMgr->checkExtensionByName($extname, $extconf)) {
|
||||
if(isset($extconf['decorators'][$class])) {
|
||||
$filename = $settings->_rootDir.'ext/'.$extname.'/decorators/'.$theme."/".$extconf['decorators'][$class]['file'];
|
||||
if(file_exists($filename)) {
|
||||
|
@ -73,7 +73,7 @@ class UI extends UI_Default {
|
|||
$httpbasedir = '';
|
||||
foreach($extMgr->getExtensionConfiguration() as $extname=>$extconf) {
|
||||
if(!$settings->extensionIsDisabled($extname)) {
|
||||
if($extMgr->checkExtension($extconf)) {
|
||||
if($extMgr->checkExtensionByName($extname, $extconf)) {
|
||||
/* Setting the 'views' element in the configuration can be used to
|
||||
* replace an existing view in views/bootstrap/, e.g. class.ViewFolder.php
|
||||
* without providing an out/out.ViewFolder.php. In that case $httpbasedir
|
||||
|
|
|
@ -25,9 +25,10 @@ $version = new SeedDMS_Version;
|
|||
foreach($extMgr->getExtensionConfiguration() as $extname=>$extconf) {
|
||||
if(!$settings->extensionIsDisabled($extname)) {
|
||||
$disabled = true;
|
||||
if($extMgr->checkExtension($extconf)) {
|
||||
if($extMgr->checkExtensionByName($extname, $extconf)) {
|
||||
$disabled = false;
|
||||
} else {
|
||||
$settings->disableExtension($extname);
|
||||
// echo $extMgr->getErrorMsg();
|
||||
}
|
||||
/* check for requirements */
|
||||
|
@ -41,30 +42,30 @@ foreach($extMgr->getExtensionConfiguration() as $extname=>$extconf) {
|
|||
}
|
||||
*/
|
||||
if(!$disabled) {
|
||||
if(isset($extconf['class']) && isset($extconf['class']['file']) && isset($extconf['class']['name'])) {
|
||||
$classfile = $settings->_rootDir."/ext/".$extname."/".$extconf['class']['file'];
|
||||
if(file_exists($classfile)) {
|
||||
include($classfile);
|
||||
$obj = new $extconf['class']['name']($settings, null, $logger);
|
||||
if(method_exists($obj, 'init'))
|
||||
$obj->init();
|
||||
if(isset($extconf['class']) && isset($extconf['class']['file']) && isset($extconf['class']['name'])) {
|
||||
$classfile = $settings->_rootDir."/ext/".$extname."/".$extconf['class']['file'];
|
||||
if(file_exists($classfile)) {
|
||||
include($classfile);
|
||||
$obj = new $extconf['class']['name']($settings, null, $logger);
|
||||
if(method_exists($obj, 'init'))
|
||||
$obj->init();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isset($extconf['language']['file'])) {
|
||||
$langfile = $settings->_rootDir."/ext/".$extname."/".$extconf['language']['file'];
|
||||
if(file_exists($langfile)) {
|
||||
unset($__lang);
|
||||
include($langfile);
|
||||
if(isset($__lang) && $__lang) {
|
||||
foreach($__lang as $lang=>&$data) {
|
||||
if(isset($GLOBALS['LANG'][$lang]))
|
||||
$GLOBALS['LANG'][$lang] = array_merge($GLOBALS['LANG'][$lang], $data);
|
||||
else
|
||||
$GLOBALS['LANG'][$lang] = $data;
|
||||
if(isset($extconf['language']['file'])) {
|
||||
$langfile = $settings->_rootDir."/ext/".$extname."/".$extconf['language']['file'];
|
||||
if(file_exists($langfile)) {
|
||||
unset($__lang);
|
||||
include($langfile);
|
||||
if(isset($__lang) && $__lang) {
|
||||
foreach($__lang as $lang=>&$data) {
|
||||
if(isset($GLOBALS['LANG'][$lang]))
|
||||
$GLOBALS['LANG'][$lang] = array_merge($GLOBALS['LANG'][$lang], $data);
|
||||
else
|
||||
$GLOBALS['LANG'][$lang] = $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user