mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-08 21:28:40 +00:00
Remove todos and make use of query builder
This commit is contained in:
parent
7a5f75eedc
commit
39635c1115
|
|
@ -82,7 +82,6 @@ abstract class SettingsAbstract implements OptionsInterface
|
||||||
* @return mixed Option value
|
* @return mixed Option value
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @todo: don't db request if exists. check exists()
|
|
||||||
*/
|
*/
|
||||||
public function get($columns)
|
public function get($columns)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,6 @@ interface SessionInterface
|
||||||
/**
|
/**
|
||||||
* Save session.
|
* Save session.
|
||||||
*
|
*
|
||||||
* @todo : implement save type (session, cache, database)
|
|
||||||
*
|
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -251,8 +251,6 @@ final class Localization
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
* @todo : maybe make parameter int
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function setTimezone(string $timezone) : void
|
public function setTimezone(string $timezone) : void
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ use phpOMS\Message\Http\Request;
|
||||||
use phpOMS\Message\RequestAbstract;
|
use phpOMS\Message\RequestAbstract;
|
||||||
use phpOMS\System\File\PathException;
|
use phpOMS\System\File\PathException;
|
||||||
use phpOMS\Module\Exception\InvalidModuleException;
|
use phpOMS\Module\Exception\InvalidModuleException;
|
||||||
|
use phpOMs\DataStorage\Database\Query\Builder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modules class.
|
* Modules class.
|
||||||
|
|
@ -141,44 +142,19 @@ final class ModuleManager
|
||||||
public function getUriLoad(RequestAbstract $request) : array
|
public function getUriLoad(RequestAbstract $request) : array
|
||||||
{
|
{
|
||||||
if ($this->uriLoad === null) {
|
if ($this->uriLoad === null) {
|
||||||
switch ($this->app->dbPool->get('select')->getType()) {
|
$uriHash = $request->getHash();
|
||||||
case DatabaseType::MYSQL:
|
$uriPdo = '';
|
||||||
$uriHash = $request->getHash();
|
|
||||||
$uriPdo = '';
|
|
||||||
|
|
||||||
$i = 1;
|
$query = new Builder($this->app->dbPool->get('select'));
|
||||||
$c = \count($uriHash);
|
$query->prefix($this->app->dbPool->get('select')->prefix);
|
||||||
|
$sth = $query->select('module_load.module_load_type', 'module_load.*')
|
||||||
|
->from('module_load')
|
||||||
|
->innerJoin('module')->on('module_load.module_load_from', '=', 'module.module_id')->orOn('module_load.module_load_for', '=', 'module.module_id')
|
||||||
|
->whereIn('module_load.module_load_pid', $uriHash)
|
||||||
|
->andWhere('module.module_active', '=', 1)
|
||||||
|
->execute();
|
||||||
|
|
||||||
for ($k = 0; $k < $c; ++$k) {
|
$this->uriLoad = $sth->fetchAll(\PDO::FETCH_GROUP);
|
||||||
$uriPdo .= ':pid' . $i . ',';
|
|
||||||
++$i;
|
|
||||||
}
|
|
||||||
|
|
||||||
$uriPdo = \rtrim($uriPdo, ',');
|
|
||||||
|
|
||||||
/* TODO: make join in order to see if they are active */
|
|
||||||
$sth = $this->app->dbPool->get('select')->con->prepare(
|
|
||||||
'SELECT
|
|
||||||
`' . $this->app->dbPool->get('select')->prefix . 'module_load`.`module_load_type`, `' . $this->app->dbPool->get('select')->prefix . 'module_load`.*
|
|
||||||
FROM
|
|
||||||
`' . $this->app->dbPool->get('select')->prefix . 'module_load`
|
|
||||||
WHERE
|
|
||||||
`module_load_pid` IN(' . $uriPdo . ')'
|
|
||||||
);
|
|
||||||
|
|
||||||
$i = 1;
|
|
||||||
foreach ($uriHash as $hash) {
|
|
||||||
$sth->bindValue(':pid' . $i, $hash, \PDO::PARAM_STR);
|
|
||||||
++$i;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sth->execute();
|
|
||||||
|
|
||||||
$this->uriLoad = $sth->fetchAll(\PDO::FETCH_GROUP);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new InvalidDatabaseTypeException($this->app->dbPool->get('select')->getType());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->uriLoad;
|
return $this->uriLoad;
|
||||||
|
|
@ -196,32 +172,30 @@ final class ModuleManager
|
||||||
public function getActiveModules(bool $useCache = true) : array
|
public function getActiveModules(bool $useCache = true) : array
|
||||||
{
|
{
|
||||||
if (empty($this->active) || !$useCache) {
|
if (empty($this->active) || !$useCache) {
|
||||||
switch ($this->app->dbPool->get('select')->getType()) {
|
$query = new Builder($this->app->dbPool->get('select'));
|
||||||
case DatabaseType::MYSQL:
|
$query->prefix($this->app->dbPool->get('select')->prefix);
|
||||||
$sth = $this->app->dbPool->get('select')->con->prepare('SELECT `module_path` FROM `' . $this->app->dbPool->get('select')->prefix . 'module` WHERE `module_active` = 1');
|
$sth = $query->select('module.module_path')
|
||||||
$sth->execute();
|
->from('module')
|
||||||
$active = $sth->fetchAll(\PDO::FETCH_COLUMN);
|
->where('module.module_active', '=', 1)
|
||||||
|
->execute();
|
||||||
|
|
||||||
foreach ($active as $module) {
|
$active = $sth->fetchAll(\PDO::FETCH_COLUMN);
|
||||||
$path = $this->modulePath . '/' . $module . '/info.json';
|
|
||||||
|
|
||||||
if (!\file_exists($path)) {
|
foreach ($active as $module) {
|
||||||
continue;
|
$path = $this->modulePath . '/' . $module . '/info.json';
|
||||||
// throw new PathException($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
$content = \file_get_contents($path);
|
if (!\file_exists($path)) {
|
||||||
$json = \json_decode($content === false ? '[]' : $content, true);
|
continue;
|
||||||
$this->active[$json['name']['internal']] = $json === false ? [] : $json;
|
// throw new PathException($path);
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
default:
|
$content = \file_get_contents($path);
|
||||||
throw new InvalidDatabaseTypeException($this->app->dbPool->get('select')->getType());
|
$json = \json_decode($content === false ? '[]' : $content, true);
|
||||||
|
$this->active[$json['name']['internal']] = $json === false ? [] : $json;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $this->active;
|
return $this->active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -294,28 +268,25 @@ final class ModuleManager
|
||||||
public function getInstalledModules(bool $useCache = true) : array
|
public function getInstalledModules(bool $useCache = true) : array
|
||||||
{
|
{
|
||||||
if (empty($this->installed) || !$useCache) {
|
if (empty($this->installed) || !$useCache) {
|
||||||
switch ($this->app->dbPool->get('select')->getType()) {
|
$query = new Builder($this->app->dbPool->get('select'));
|
||||||
case DatabaseType::MYSQL:
|
$query->prefix($this->app->dbPool->get('select')->prefix);
|
||||||
$sth = $this->app->dbPool->get('select')->con->prepare('SELECT `module_path` FROM `' . $this->app->dbPool->get('select')->prefix . 'module`');
|
$sth = $query->select('module.module_path')
|
||||||
$sth->execute();
|
->from('module')
|
||||||
$installed = $sth->fetchAll(\PDO::FETCH_COLUMN);
|
->execute();
|
||||||
|
|
||||||
foreach ($installed as $module) {
|
$installed = $sth->fetchAll(\PDO::FETCH_COLUMN);
|
||||||
$path = $this->modulePath . '/' . $module . '/info.json';
|
|
||||||
|
|
||||||
if (!\file_exists($path)) {
|
foreach ($installed as $module) {
|
||||||
continue;
|
$path = $this->modulePath . '/' . $module . '/info.json';
|
||||||
// throw new PathException($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
$content = \file_get_contents($path);
|
if (!\file_exists($path)) {
|
||||||
$json = \json_decode($content === false ? '[]' : $content, true);
|
continue;
|
||||||
$this->installed[$json['name']['internal']] = $json === false ? [] : $json;
|
// throw new PathException($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
$content = \file_get_contents($path);
|
||||||
default:
|
$json = \json_decode($content === false ? '[]' : $content, true);
|
||||||
throw new InvalidDatabaseTypeException($this->app->dbPool->get('select')->getType());
|
$this->installed[$json['name']['internal']] = $json === false ? [] : $json;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user