Remove todos and make use of query builder

This commit is contained in:
Dennis Eichhorn 2018-09-08 18:22:34 +02:00
parent 7a5f75eedc
commit 39635c1115
4 changed files with 47 additions and 81 deletions

View File

@ -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)
{ {

View File

@ -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

View File

@ -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

View File

@ -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,31 +172,29 @@ 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';
foreach ($active as $module) {
$path = $this->modulePath . '/' . $module . '/info.json';
if (!\file_exists($path)) { if (!\file_exists($path)) {
continue; continue;
// throw new PathException($path); // throw new PathException($path);
} }
$content = \file_get_contents($path); $content = \file_get_contents($path);
$json = \json_decode($content === false ? '[]' : $content, true); $json = \json_decode($content === false ? '[]' : $content, true);
$this->active[$json['name']['internal']] = $json === false ? [] : $json; $this->active[$json['name']['internal']] = $json === false ? [] : $json;
}
break;
default:
throw new InvalidDatabaseTypeException($this->app->dbPool->get('select')->getType());
} }
}
}
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)) {
continue;
// throw new PathException($path);
}
$content = \file_get_contents($path);
$json = \json_decode($content === false ? '[]' : $content, true);
$this->installed[$json['name']['internal']] = $json === false ? [] : $json;
}
break; foreach ($installed as $module) {
default: $path = $this->modulePath . '/' . $module . '/info.json';
throw new InvalidDatabaseTypeException($this->app->dbPool->get('select')->getType());
if (!\file_exists($path)) {
continue;
// throw new PathException($path);
}
$content = \file_get_contents($path);
$json = \json_decode($content === false ? '[]' : $content, true);
$this->installed[$json['name']['internal']] = $json === false ? [] : $json;
} }
} }