set repository url in ext manager, force download of repos content

This commit is contained in:
Uwe Steinmann 2018-03-14 13:11:35 +01:00
parent b1a9ade799
commit 4ac7fe0c07
3 changed files with 56 additions and 12 deletions

View File

@ -32,6 +32,12 @@ class SeedDMS_Extension_Mgr {
*/ */
protected $extdir; protected $extdir;
/**
* @var string $reposurl url for fetching list of extensions in repository
* @access protected
*/
protected $reposurl;
/** /**
* @var array[] $extconf configuration of all extensions * @var array[] $extconf configuration of all extensions
* @access protected * @access protected
@ -91,9 +97,10 @@ class SeedDMS_Extension_Mgr {
* configuration file if it does not exist and the extension dir * configuration file if it does not exist and the extension dir
* is given * is given
*/ */
public function __construct($extdir = '', $cachedir = '') { /* {{{ */ public function __construct($extdir = '', $cachedir = '', $reposurl = '') { /* {{{ */
$this->cachedir = $cachedir; $this->cachedir = $cachedir;
$this->extdir = $extdir; $this->extdir = $extdir;
$this->reposurl = $reposurl;
$this->extconf = array(); $this->extconf = array();
if($extdir) { if($extdir) {
if(!file_exists($this->getExtensionsConfFile())) { if(!file_exists($this->getExtensionsConfFile())) {
@ -262,6 +269,15 @@ class SeedDMS_Extension_Mgr {
if(self::cmpVersion($tmp[0], phpversion()) > 0 || ($tmp[1] && self::cmpVersion($tmp[1], phpversion()) < 0)) if(self::cmpVersion($tmp[0], phpversion()) > 0 || ($tmp[1] && self::cmpVersion($tmp[1], phpversion()) < 0))
$this->errmsgs[] = sprintf("Incorrect PHP version (needs version %s)", $extconf['constraints']['depends']['php']); $this->errmsgs[] = sprintf("Incorrect PHP version (needs version %s)", $extconf['constraints']['depends']['php']);
break; break;
case 'phpext':
if(is_array($dval) && $dval) {
$extlist = get_loaded_extensions();
foreach($dval as $d) {
if(!in_array($d, $extlist))
$this->errmsgs[] = sprintf("Missing php extension '%s'", $d);
}
}
break;
default: default:
$tmp = explode('-', $dval, 2); $tmp = explode('-', $dval, 2);
if(isset($GLOBALS['EXT_CONF'][$dkey]['version'])) { if(isset($GLOBALS['EXT_CONF'][$dkey]['version'])) {
@ -343,12 +359,29 @@ class SeedDMS_Extension_Mgr {
* *
* @param boolean $force force download even if file already exists * @param boolean $force force download even if file already exists
*/ */
public function importExtensionList($url, $force=false) { /* {{{ */ public function getExtensionList() { /* {{{ */
if(!file_exists($this->cachedir."/repository.json") || $force) { if(file_exists($this->cachedir."/repository.json")) {
$file = file_get_contents($url."/repository.json"); return file($this->cachedir."/repository.json");
file_put_contents($this->cachedir."/repository.json", $file); } else {
return array();
}
} /* }}} */
/**
* Import list of extension from repository
*
* @param boolean $force force download even if file already exists
*/
public function updateExtensionList($force=false) { /* {{{ */
if($this->reposurl) {
if(!file_exists($this->cachedir."/repository.json") || $force) {
$file = file_get_contents($this->reposurl."/repository.json");
file_put_contents($this->cachedir."/repository.json", $file);
}
return true;
} else {
return false;
} }
return file($this->cachedir."/repository.json");
} /* }}} */ } /* }}} */
/** /**

View File

@ -32,15 +32,26 @@ if (!$user->isAdmin()) {
UI::exitError(getMLText("admin_tools"),getMLText("access_denied")); UI::exitError(getMLText("admin_tools"),getMLText("access_denied"));
} }
$reposurl = 'http://seeddms.steinmann.cx/repository';
$v = new SeedDMS_Version; $v = new SeedDMS_Version;
$extmgr = new SeedDMS_Extension_Mgr($settings->_rootDir."/ext", $settings->_cacheDir); $extmgr = new SeedDMS_Extension_Mgr($settings->_rootDir."/ext", $settings->_cacheDir, $reposurl);
$currenttab = 'installed'; if(isset($_GET['currenttab']))
$currenttab = $_GET['currenttab'];
else
$currenttab = 'installed';
if(isset($_GET['forceupdate']) && $_GET['forceupdate']==1)
$extmgr->updateExtensionList(true);
else
$extmgr->updateExtensionList();
if($view) { if($view) {
$view->setParam('httproot', $settings->_httpRoot); $view->setParam('httproot', $settings->_httpRoot);
$view->setParam('version', $v); $view->setParam('version', $v);
$view->setParam('extmgr', $extmgr); $view->setParam('extmgr', $extmgr);
$view->setParam('currenttab', $currenttab); $view->setParam('currenttab', $currenttab);
$view->setParam('reposurl', $reposurl);
$view($_GET); $view($_GET);
exit; exit;
} }

View File

@ -70,9 +70,8 @@ class SeedDMS_View_ExtensionMgr extends SeedDMS_Bootstrap_Style {
$version = $this->params['version']; $version = $this->params['version'];
$extmgr = $this->params['extmgr']; $extmgr = $this->params['extmgr'];
$currenttab = $this->params['currenttab']; $currenttab = $this->params['currenttab'];
$reposurl = $this->params['reposurl'];
$reposurl = 'http://seeddms.steinmann.cx/repository';
$this->htmlStartPage(getMLText("admin_tools")); $this->htmlStartPage(getMLText("admin_tools"));
$this->globalNavigation(); $this->globalNavigation();
$this->contentStart(); $this->contentStart();
@ -177,7 +176,7 @@ class SeedDMS_View_ExtensionMgr extends SeedDMS_Bootstrap_Style {
print "<th>".getMLText('author')."</th>\n"; print "<th>".getMLText('author')."</th>\n";
print "<th></th>\n"; print "<th></th>\n";
print "</tr></thead><tbody>\n"; print "</tr></thead><tbody>\n";
$list = $extmgr->importExtensionList($reposurl); $list = $extmgr->getExtensionList();
foreach($list as $e) { foreach($list as $e) {
if($e[0] != '#') { if($e[0] != '#') {
$re = json_decode($e, true); $re = json_decode($e, true);
@ -210,6 +209,7 @@ class SeedDMS_View_ExtensionMgr extends SeedDMS_Bootstrap_Style {
} }
echo "</tbody></table>\n"; echo "</tbody></table>\n";
?> ?>
<div><a href="?forceupdate=1&currenttab=repository" class="btn btn-delete"><?= getMLText('force_update')?></a></div>
</div> </div>
</div> </div>
</div> </div>