* Move model function checkDepends and compare4Limit to extensionZen function getDependsByDB and compareForLimit.
This commit is contained in:
@@ -186,7 +186,7 @@ class extension extends control
|
||||
}
|
||||
|
||||
/* 相关依赖插件检查。 */
|
||||
$dependsExts = $this->extension->checkDepends($extension);
|
||||
$dependsExts = $this->extensionZen->getDependsByDB($extension);
|
||||
if($dependsExts)
|
||||
{
|
||||
$this->view->error = sprintf($this->lang->extension->errorUninstallDepends, join(' ', $dependsExts));
|
||||
|
||||
@@ -659,55 +659,16 @@ class extensionModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* Check depends extension.
|
||||
* 获取可能依赖此插件的其他插件。
|
||||
* Get other extensions that may depend on this extension.
|
||||
*
|
||||
* @param string $extension
|
||||
* @param string $extension
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function checkDepends($extension)
|
||||
public function getDependsExtension(string $extension): array
|
||||
{
|
||||
$result = array();
|
||||
$extensionInfo = $this->dao->select('*')->from(TABLE_EXTENSION)->where('code')->eq($extension)->fetch();
|
||||
$dependsExts = $this->dao->select('*')->from(TABLE_EXTENSION)->where('depends')->like("%$extension%")->andWhere('status')->ne('available')->fetchAll();
|
||||
if($dependsExts)
|
||||
{
|
||||
foreach($dependsExts as $dependsExt)
|
||||
{
|
||||
$depends = json_decode($dependsExt->depends, true);
|
||||
if($this->compare4Limit($extensionInfo->version, $depends[$extension])) $result[] = $dependsExt->name;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare for limit data.
|
||||
*
|
||||
* @param string $version
|
||||
* @param array $limit
|
||||
* @param string $type
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function compare4Limit($version, $limit, $type = 'between')
|
||||
{
|
||||
$result = false;
|
||||
if(empty($limit)) return true;
|
||||
|
||||
if($limit == 'all')
|
||||
{
|
||||
$result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!empty($limit['min']) and $version >= $limit['min']) $result = true;
|
||||
if(!empty($limit['max']) and $version <= $limit['max']) $result = true;
|
||||
if(!empty($limit['max']) and $version > $limit['max'] and $result) $result = false;
|
||||
}
|
||||
|
||||
if($type != 'between') return !$result;
|
||||
return $result;
|
||||
return $this->dao->select('*')->from(TABLE_EXTENSION)->where('depends')->like("%$extension%")->andWhere('status')->ne('available')->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -139,7 +139,7 @@ class extensionZen extends extension
|
||||
{
|
||||
if(isset($installedExts[$code]))
|
||||
{
|
||||
if($this->extension->compare4Limit($installedExts[$code]->version, $limit)) $conflictsExt .= $installedExts[$code]->name . " ";
|
||||
if($this->compareForLimit($installedExts[$code]->version, $limit)) $conflictsExt .= $installedExts[$code]->name . " ";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ class extensionZen extends extension
|
||||
$noDepends = false;
|
||||
if(isset($installedExts[$code]))
|
||||
{
|
||||
if($this->extension->compare4Limit($installedExts[$code]->version, $limit, 'noBetween')) $noDepends = true;
|
||||
if($this->compareForLimit($installedExts[$code]->version, $limit, 'noBetween')) $noDepends = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -524,4 +524,57 @@ class extensionZen extends extension
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据数据库数据获取依赖当前插件的其他插件。
|
||||
* Get depends extension by database.
|
||||
*
|
||||
* @param string $extension
|
||||
* @access protected
|
||||
* @return array
|
||||
*/
|
||||
protected function getDependsByDB(string $extension): array
|
||||
{
|
||||
$extensionInfo = $this->extension->getInfoFromDB($extension);
|
||||
$dependsList = $this->extension->getDependsExtension($extension);
|
||||
|
||||
$result = array();
|
||||
if($dependsList)
|
||||
{
|
||||
foreach($dependsList as $dependsExtension)
|
||||
{
|
||||
$depends = json_decode($dependsExtension->depends, true);
|
||||
if(empty($depends[$extension])) continue;
|
||||
|
||||
if($this->compareForLimit($extensionInfo->version, $depends[$extension])) $result[] = $dependsExtension->name;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare for limit data.
|
||||
*
|
||||
* @param string $version
|
||||
* @param array|string $limit
|
||||
* @param string $type
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
private function compareForLimit(string $version, array|string $limit, string $type = 'between'): bool
|
||||
{
|
||||
$result = false;
|
||||
if(empty($limit)) return true;
|
||||
if($limit == 'all') return true;
|
||||
|
||||
if(!empty($limit['min']) && $version >= $limit['min']) $result = true;
|
||||
if(!empty($limit['max']) && $version <= $limit['max']) $result = true;
|
||||
if(!empty($limit['max']) && $version > $limit['max'] && $result) $result = false;
|
||||
|
||||
/* 如果取的不是被包含则返回取反的布尔值。 */
|
||||
if($type != 'between') return !$result;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user