From 643a9371525b0438b2a8973a9579b487a1e32160 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sat, 18 Jul 2020 02:16:18 +0000 Subject: [PATCH] [DATABASE][WRAPPER] Update DATABASE wrapper so entity names are provided without the namespace --- src/Controller/AdminConfigController.php | 4 +++- src/Core/DB/DB.php | 6 ++++++ src/Core/DB/DefaultSettings.php | 4 ++-- src/Util/Common.php | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Controller/AdminConfigController.php b/src/Controller/AdminConfigController.php index e1c59d0459..6d107e69a6 100644 --- a/src/Controller/AdminConfigController.php +++ b/src/Controller/AdminConfigController.php @@ -1,6 +1,7 @@ . + // }}} /** @@ -65,7 +67,7 @@ class AdminConfigController extends Controller $value = $data[_m('Value')]; $default = $defaults[$section][$setting]; if (gettype($default) === gettype($value)) { - $conf = DB::find('\App\Entity\Config', ['section' => $section, 'setting' => $setting]); + $conf = DB::find('config', ['section' => $section, 'setting' => $setting]); $old_value = $conf->getValue(); $conf->setValue(serialize($value)); DB::flush(); diff --git a/src/Core/DB/DB.php b/src/Core/DB/DB.php index 54cbc82962..44129371cd 100644 --- a/src/Core/DB/DB.php +++ b/src/Core/DB/DB.php @@ -42,6 +42,12 @@ abstract class DB public static function __callStatic(string $name, array $args) { + foreach (['find', 'getReference', 'getPartialReference', 'getRepository'] as $m) { + if ($name == $m) { + $args[0] = '\App\Entity\\' . ucfirst($args[0]); + } + } + return self::$em->{$name}(...$args); } } diff --git a/src/Core/DB/DefaultSettings.php b/src/Core/DB/DefaultSettings.php index e6c6c77daa..6e1d03053b 100644 --- a/src/Core/DB/DefaultSettings.php +++ b/src/Core/DB/DefaultSettings.php @@ -41,7 +41,7 @@ abstract class DefaultSettings public static array $defaults; public static function setDefaults() { - $conf = DB::find('\App\Entity\Config', ['section' => 'site', 'setting' => 'defaults_modified']); + $conf = DB::find('config', ['section' => 'site', 'setting' => 'defaults_modified']); if ($conf != null && filemtime(__FILE__) < $conf->getValue()) { // Don't bother modifying the table if this file is older return; @@ -269,7 +269,7 @@ abstract class DefaultSettings // doesn't implement it. The difference between this and the // normal version is that that one does 221 queries in 30 to // 50ms, while this does 2 in 10 to 15 ms. - if (DB::getRepository('\App\Entity\Config')->count([]) == 0) { + if (DB::getRepository('config')->count([]) == 0) { $sql = 'insert into config (section, setting, value) values'; foreach (self::$defaults as $section => $def) { foreach ($def as $setting => $value) { diff --git a/src/Util/Common.php b/src/Util/Common.php index 93bda6a5d0..4337b3a9f7 100644 --- a/src/Util/Common.php +++ b/src/Util/Common.php @@ -39,7 +39,7 @@ abstract class Common */ public static function config(string $section, string $setting) { - return DB::find('\App\Entity\Config', ['section' => $section, 'setting' => $setting]); + return DB::find('config', ['section' => $section, 'setting' => $setting]); } /** @@ -47,7 +47,7 @@ abstract class Common */ public static function set_config(string $section, string $setting, mixed $value): void { - $ojb = DB::getPatialReference('\App\Entity\Config', ['section' => $section, 'setting' => $setting]); + $ojb = DB::getPartialReference('config', ['section' => $section, 'setting' => $setting]); $obj->setValue(serialize($value)); DB::persist($obj); DB::flush();