[FAVOURITE] Temporary commit to fix exception in timeline

This commit is contained in:
Hugo Sales 2021-04-14 23:31:18 +00:00
parent 974bbe164e
commit 1687ecaa24
No known key found for this signature in database
GPG Key ID: 7D0C7EAFC9D835A0
2 changed files with 16 additions and 11 deletions

View File

@ -23,6 +23,7 @@ use App\Core\DB\DB;
use App\Core\Event; use App\Core\Event;
use App\Core\Form; use App\Core\Form;
use App\Core\Modules\Module; use App\Core\Modules\Module;
use App\Core\Router\RouteLoader;
use App\Entity\Note; use App\Entity\Note;
use App\Util\Common; use App\Util\Common;
use Plugin\Favourite\Entity\Favourite as Fave; use Plugin\Favourite\Entity\Favourite as Fave;
@ -54,7 +55,7 @@ class Favourite extends Module
$ret = self::noteActionHandle($request, $form, $note, 'favourite', function ($note, $data) use ($opts) { $ret = self::noteActionHandle($request, $form, $note, 'favourite', function ($note, $data) use ($opts) {
$fave = DB::find('favourite', $opts); $fave = DB::find('favourite', $opts);
if (!$data['is_set'] && ($fave == null)) { if (!$data['is_set'] && ($fave == null)) {
DB::persist(Fave::create($opts)); DB::persist(Entity\Favourite::create($opts));
DB::flush(); DB::flush();
} else { } else {
DB::remove($fave); DB::remove($fave);
@ -73,8 +74,8 @@ class Favourite extends Module
public function onAddRoute(RouteLoader $r) public function onAddRoute(RouteLoader $r)
{ {
$r->connect('actors', '/actors', [Controller\Directory::class, 'actors']); $r->connect('favourites', '/favourites', [Controller\Favourite::class, 'favourites']);
$r->connect('groups', '/groups', [Controller\Directory::class, 'groups']); $r->connect('reverse_favourites', '/reversefavs', [Controller\Favourite::class, 'reverseFavourites']);
return Event::next; return Event::next;
} }
} }

View File

@ -162,14 +162,18 @@ abstract class DB
*/ */
public static function __callStatic(string $name, array $args) public static function __callStatic(string $name, array $args)
{ {
// TODO Plugins if (($args[0] ?? '') == 'favourite') {
// If the method is one of the following and the first argument doesn't look like a FQCN, add the prefix $args[0] = 'Plugin\Favourite\Entity\Favourite';
$pref = '\App\Entity\\'; } else {
if (in_array($name, ['find', 'getReference', 'getPartialReference', 'getRepository']) // TODO Plugins
&& preg_match('/\\\\/', $args[0]) === 0 // If the method is one of the following and the first argument doesn't look like a FQCN, add the prefix
&& Formatting::startsWith($args[0], $pref) === false) { $pref = '\App\Entity\\';
$args[0] = $pref . ucfirst(Formatting::snakeCaseToCamelCase($args[0])); if (in_array($name, ['find', 'getReference', 'getPartialReference', 'getRepository'])
$args[0] = preg_replace('/Gsactor/', 'GSActor', $args[0]); && preg_match('/\\\\/', $args[0]) === 0
&& Formatting::startsWith($args[0], $pref) === false) {
$args[0] = $pref . ucfirst(Formatting::snakeCaseToCamelCase($args[0]));
$args[0] = preg_replace('/Gsactor/', 'GSActor', $args[0]);
}
} }
return self::$em->{$name}(...$args); return self::$em->{$name}(...$args);