[CORE][DB][ENTITY][Actor] Add `DB::removeBy` and use it in `Actor->setSelfTags`

This commit is contained in:
Hugo Sales 2021-11-28 12:13:30 +00:00 committed by Diogo Peralta Cordeiro
parent 66ff3c594d
commit fc81f7301c
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
2 changed files with 12 additions and 8 deletions

View File

@ -50,13 +50,13 @@ use Functional as F;
* @mixin EntityManager * @mixin EntityManager
* @template T * @template T
* *
* @method static T find(string $class, array<string, mixed> $values) // Finds an Entity by its identifier. * @method static T find(string $class, array<string, mixed> $values) // Finds an Entity by its identifier.
* @method static T getReference(string $class, array<string, mixed> $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 T getReference(string $class, array<string, mixed> $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 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 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 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 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 flush() // Flushes the in-memory state of persisted objects to the database.
*/ */
class DB 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) public static function count(string $table, array $criteria)
{ {
/** @var EntityRepository */ /** @var EntityRepository */

View File

@ -365,8 +365,7 @@ class Actor extends Entity
$actor_tag = DB::findOneBy('actor_tag', ['tagger' => $this->getId(), 'tagged' => $this->getId(), 'tag' => $actor_circle->getTag()]); $actor_tag = DB::findOneBy('actor_tag', ['tagger' => $this->getId(), 'tagged' => $this->getId(), 'tag' => $actor_circle->getTag()]);
DB::persist($actor_tag); DB::persist($actor_tag);
DB::remove($actor_tag); DB::remove($actor_tag);
// TODO: use DB::removeBy when implemented DB::removeBy('actor_circle', ['id' => $actor_circle->getId()]);
DB::remove(DB::getReference('actor_circle', ['id' => $actor_circle->getId()]));
} }
Cache::delete("selftags-{$this->getId()}"); Cache::delete("selftags-{$this->getId()}");
Cache::delete("othertags-{$this->getId()}-by-{$this->getId()}"); Cache::delete("othertags-{$this->getId()}-by-{$this->getId()}");