mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-12 14:58:42 +00:00
Optimize module tests
This commit is contained in:
parent
041d604f2b
commit
3993033465
|
|
@ -34,6 +34,7 @@ class Auth
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ class CacheFactory
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -183,14 +183,16 @@ class ModuleManager
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all installed modules that are active (not just on this uri).
|
* Get all installed modules that are active (not just on this uri).
|
||||||
|
*
|
||||||
|
* @param bool $useCache Use Cache or load new
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function getActiveModules() : array
|
public function getActiveModules(bool $useCache = true) : array
|
||||||
{
|
{
|
||||||
if ($this->active === null) {
|
if ($this->active === null || !$useCache) {
|
||||||
switch ($this->app->dbPool->get('select')->getType()) {
|
switch ($this->app->dbPool->get('select')->getType()) {
|
||||||
case DatabaseType::MYSQL:
|
case DatabaseType::MYSQL:
|
||||||
$sth = $this->app->dbPool->get('select')->con->prepare('SELECT `module_path` FROM `' . $this->app->dbPool->get('select')->prefix . 'module` WHERE `module_active` = 1');
|
$sth = $this->app->dbPool->get('select')->con->prepare('SELECT `module_path` FROM `' . $this->app->dbPool->get('select')->prefix . 'module` WHERE `module_active` = 1');
|
||||||
|
|
@ -203,6 +205,11 @@ class ModuleManager
|
||||||
return $this->active;
|
return $this->active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isActive(string $module) : bool
|
||||||
|
{
|
||||||
|
return in_array($module, $this->getActiveModules(false));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all modules in the module directory.
|
* Get all modules in the module directory.
|
||||||
*
|
*
|
||||||
|
|
@ -245,51 +252,18 @@ class ModuleManager
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Deactivate module.
|
|
||||||
*
|
|
||||||
* @param string $module Module name
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function deactivate(string $module) : bool
|
|
||||||
{
|
|
||||||
$installed = $this->getInstalledModules();
|
|
||||||
|
|
||||||
if (isset($installed[$module])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$info = $this->loadInfo($module);
|
|
||||||
|
|
||||||
$this->deactivateModule($info);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (PathException $e) {
|
|
||||||
// todo: handle module doesn't exist or files are missing
|
|
||||||
//echo $e->getMessage();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
//echo $e->getMessage();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all installed modules.
|
* Get all installed modules.
|
||||||
|
*
|
||||||
|
* @param bool $useCache Use Cache
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function getInstalledModules() : array
|
public function getInstalledModules(bool $useCache = true) : array
|
||||||
{
|
{
|
||||||
if ($this->installed === null) {
|
if ($this->installed === null || !$useCache) {
|
||||||
switch ($this->app->dbPool->get('select')->getType()) {
|
switch ($this->app->dbPool->get('select')->getType()) {
|
||||||
case DatabaseType::MYSQL:
|
case DatabaseType::MYSQL:
|
||||||
$sth = $this->app->dbPool->get('select')->con->prepare('SELECT `module_id`,`module_theme`,`module_version` FROM `' . $this->app->dbPool->get('select')->prefix . 'module`');
|
$sth = $this->app->dbPool->get('select')->con->prepare('SELECT `module_id`,`module_theme`,`module_version` FROM `' . $this->app->dbPool->get('select')->prefix . 'module`');
|
||||||
|
|
@ -325,6 +299,41 @@ class ModuleManager
|
||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deactivate module.
|
||||||
|
*
|
||||||
|
* @param string $module Module name
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function deactivate(string $module) : bool
|
||||||
|
{
|
||||||
|
$installed = $this->getInstalledModules(false);
|
||||||
|
|
||||||
|
if (!isset($installed[$module])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$info = $this->loadInfo($module);
|
||||||
|
|
||||||
|
$this->deactivateModule($info);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (PathException $e) {
|
||||||
|
// todo: handle module doesn't exist or files are missing
|
||||||
|
//echo $e->getMessage();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
//echo $e->getMessage();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deactivate module.
|
* Deactivate module.
|
||||||
*
|
*
|
||||||
|
|
@ -359,9 +368,9 @@ class ModuleManager
|
||||||
*/
|
*/
|
||||||
public function activate(string $module) : bool
|
public function activate(string $module) : bool
|
||||||
{
|
{
|
||||||
$installed = $this->getInstalledModules();
|
$installed = $this->getInstalledModules(false);
|
||||||
|
|
||||||
if (isset($installed[$module])) {
|
if (!isset($installed[$module])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -441,7 +450,7 @@ class ModuleManager
|
||||||
*/
|
*/
|
||||||
public function install(string $module) : bool
|
public function install(string $module) : bool
|
||||||
{
|
{
|
||||||
$installed = $this->getInstalledModules();
|
$installed = $this->getInstalledModules(false);
|
||||||
|
|
||||||
if (isset($installed[$module])) {
|
if (isset($installed[$module])) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user