Browse Source

[ENTITY][Actor] Fix issue with deleting a self tag

remotes/upstream/experimental
Hugo Sales 8 months ago
parent
commit
21e598d877
Signed by: someonewithpc <hugo@hsal.es> GPG Key ID: 7D0C7EAFC9D835A0
1 changed files with 5 additions and 5 deletions
  1. +5
    -5
      src/Entity/Actor.php

+ 5
- 5
src/Entity/Actor.php View File

@@ -244,22 +244,22 @@ class Actor extends Entity
public function getSelfTags(bool $_test_force_recompute = false): array
{
return Cache::get('selftags-' . $this->id,
function () {
return DB::findBy('actor_tag', ['tagger' => $this->id, 'tagged' => $this->id]);
}, beta: $_test_force_recompute ? INF : 1.0);
fn () => DB::findBy('actor_tag', ['tagger' => $this->id, 'tagged' => $this->id]),
beta: $_test_force_recompute ? INF : 1.0);
}

public function setSelfTags(array $tags, array $existing): void
{
$tag_existing = F\map($existing, function ($pt) { return $pt->getTag(); });
$tag_existing = F\map($existing, fn ($pt) => $pt->getTag());
$tag_to_add = array_diff($tags, $tag_existing);
$tag_to_remove = array_diff($tag_existing, $tags);
$pt_to_remove = F\filter($existing, function ($pt) use ($tag_to_remove) { return in_array($pt->getTag(), $tag_to_remove); });
$pt_to_remove = F\filter($existing, fn ($pt) => in_array($pt->getTag(), $tag_to_remove));
foreach ($tag_to_add as $tag) {
$pt = ActorTag::create(['tagger' => $this->id, 'tagged' => $this->id, 'tag' => $tag]);
DB::persist($pt);
}
foreach ($pt_to_remove as $pt) {
DB::persist($pt);
DB::remove($pt);
}
Cache::delete('selftags-' . $this->id);


Loading…
Cancel
Save