[DATABASE][WRAPPER] Update DATABASE wrapper so entity names are provided without the namespace

This commit is contained in:
Hugo Sales 2020-07-18 02:16:18 +00:00 committed by Hugo Sales
parent 0615adbb51
commit 643a937152
Signed by untrusted user: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
4 changed files with 13 additions and 5 deletions

View File

@ -1,6 +1,7 @@
<?php
// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
@ -15,6 +16,7 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
/**
@ -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();

View File

@ -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);
}
}

View File

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

View File

@ -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();