From fc81f7301c1a777ed441fcb87cee040b668702cc Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sun, 28 Nov 2021 12:13:30 +0000 Subject: [PATCH] [CORE][DB][ENTITY][Actor] Add `DB::removeBy` and use it in `Actor->setSelfTags` --- src/Core/DB/DB.php | 17 +++++++++++------ src/Entity/Actor.php | 3 +-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Core/DB/DB.php b/src/Core/DB/DB.php index a3b0820557..bce5513d8f 100644 --- a/src/Core/DB/DB.php +++ b/src/Core/DB/DB.php @@ -50,13 +50,13 @@ use Functional as F; * @mixin EntityManager * @template T * - * @method static T find(string $class, array $values) // Finds an Entity by its identifier. + * @method static T find(string $class, array $values) // Finds an Entity by its identifier. * @method static T getReference(string $class, array $values) // Special cases: It's like find but does not load the object if it has not been loaded yet, it only returns a proxy to the object. (https://www.doctrine-project.org/projects/doctrine-orm/en/2.10/reference/unitofwork.html) - * @method static void remove(object $entity) // Removes an entity instance. - * @method static T merge(object $entity) // Merges the state of a detached entity into the persistence context - * @method static void persist(object $entity) // Tells the EntityManager to make an instance managed and persistent. - * @method static bool contains(object $entity) // Determines whether an entity instance is managed in this EntityManager. - * @method static void flush() // Flushes the in-memory state of persisted objects to the database. + * @method static void remove(object $entity) // Removes an entity instance. + * @method static T merge(object $entity) // Merges the state of a detached entity into the persistence context + * @method static void persist(object $entity) // Tells the EntityManager to make an instance managed and persistent. + * @method static bool contains(object $entity) // Determines whether an entity instance is managed in this EntityManager. + * @method static void flush() // Flushes the in-memory state of persisted objects to the database. */ class DB { @@ -224,6 +224,11 @@ class DB } } + public static function removeBy(string $table, array $criteria) + { + self::remove(self::getReference($table, $criteria)); + } + public static function count(string $table, array $criteria) { /** @var EntityRepository */ diff --git a/src/Entity/Actor.php b/src/Entity/Actor.php index 4ce71eb5ef..7ae2d5ccb8 100644 --- a/src/Entity/Actor.php +++ b/src/Entity/Actor.php @@ -365,8 +365,7 @@ class Actor extends Entity $actor_tag = DB::findOneBy('actor_tag', ['tagger' => $this->getId(), 'tagged' => $this->getId(), 'tag' => $actor_circle->getTag()]); DB::persist($actor_tag); DB::remove($actor_tag); - // TODO: use DB::removeBy when implemented - DB::remove(DB::getReference('actor_circle', ['id' => $actor_circle->getId()])); + DB::removeBy('actor_circle', ['id' => $actor_circle->getId()]); } Cache::delete("selftags-{$this->getId()}"); Cache::delete("othertags-{$this->getId()}-by-{$this->getId()}");