mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-11 06:28:40 +00:00
Improve module list results and improve types
This commit is contained in:
parent
4c178b17a5
commit
c681d9697f
|
|
@ -58,7 +58,7 @@ final class ModuleManager
|
||||||
* @var array
|
* @var array
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private $installed = null;
|
private $installed = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All active modules (on all pages not just the ones that are running now).
|
* All active modules (on all pages not just the ones that are running now).
|
||||||
|
|
@ -66,7 +66,7 @@ final class ModuleManager
|
||||||
* @var array
|
* @var array
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private $active = null;
|
private $active = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Module path.
|
* Module path.
|
||||||
|
|
@ -82,7 +82,7 @@ final class ModuleManager
|
||||||
* @var array
|
* @var array
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private $all = null;
|
private $all = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To load based on request uri.
|
* To load based on request uri.
|
||||||
|
|
@ -195,18 +195,32 @@ final class ModuleManager
|
||||||
*/
|
*/
|
||||||
public function getActiveModules(bool $useCache = true) : array
|
public function getActiveModules(bool $useCache = true) : array
|
||||||
{
|
{
|
||||||
if ($this->active === null || !$useCache) {
|
if (empty($this->active) || !$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');
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
$this->active = $sth->fetchAll(\PDO::FETCH_COLUMN);
|
$active = $sth->fetchAll(\PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
|
foreach ($active as $module) {
|
||||||
|
$path = $this->modulePath . '/' . $module . '/info.json';
|
||||||
|
|
||||||
|
if (!\file_exists($path)) {
|
||||||
|
continue;
|
||||||
|
// throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
$json = \json_decode(file_get_contents($path), true);
|
||||||
|
$this->active[$json['name']['internal']] = $json;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new InvalidDatabaseTypeException($this->app->dbPool->get('select')->getType());
|
throw new InvalidDatabaseTypeException($this->app->dbPool->get('select')->getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $this->active;
|
return $this->active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -233,7 +247,7 @@ final class ModuleManager
|
||||||
*/
|
*/
|
||||||
public function getAllModules() : array
|
public function getAllModules() : array
|
||||||
{
|
{
|
||||||
if ($this->all === null) {
|
if (empty($this->all)) {
|
||||||
chdir($this->modulePath);
|
chdir($this->modulePath);
|
||||||
$files = glob('*', GLOB_ONLYDIR);
|
$files = glob('*', GLOB_ONLYDIR);
|
||||||
$c = count($files);
|
$c = count($files);
|
||||||
|
|
@ -277,12 +291,25 @@ final class ModuleManager
|
||||||
*/
|
*/
|
||||||
public function getInstalledModules(bool $useCache = true) : array
|
public function getInstalledModules(bool $useCache = true) : array
|
||||||
{
|
{
|
||||||
if ($this->installed === null || !$useCache) {
|
if (empty($this->installed) || !$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_path` FROM `' . $this->app->dbPool->get('select')->prefix . 'module`');
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
$this->installed = $sth->fetchAll(\PDO::FETCH_GROUP);
|
$installed = $sth->fetchAll(\PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
|
foreach ($installed as $module) {
|
||||||
|
$path = $this->modulePath . '/' . $module . '/info.json';
|
||||||
|
|
||||||
|
if (!\file_exists($path)) {
|
||||||
|
continue;
|
||||||
|
// throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
$json = \json_decode(file_get_contents($path), true);
|
||||||
|
$this->installed[$json['name']['internal']] = $json;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new InvalidDatabaseTypeException($this->app->dbPool->get('select')->getType());
|
throw new InvalidDatabaseTypeException($this->app->dbPool->get('select')->getType());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user