Skip to content

Commit

Permalink
Added method to temporarily ignore activity
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk authored Feb 14, 2024
1 parent 911e9b0 commit 70010f2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Entity/Subscribers/ActivitySubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

class ActivitySubscriber implements EventSubscriber
{
private static array $ignored = [];

private bool $isFlushing = false;
private array $items = [];
private ?Identity $user;
Expand All @@ -40,6 +42,12 @@ final public function __construct(
}


public static function setIgnored(object $target, bool $ignore = true): void
{
self::$ignored[spl_object_hash($target)] = $ignore;
}


final public function getSubscribedEvents()
{
return [
Expand Down Expand Up @@ -85,6 +93,7 @@ public function postFlush(EventArgs $event): void
return;
}

$this->items = array_diff_key($this->items, array_filter(self::$ignored));
$this->isFlushing = true;

foreach ($this->items as [$target, $action, $params, $targetId]) {
Expand Down Expand Up @@ -112,13 +121,14 @@ public function postFlush(EventArgs $event): void

$this->entityManager->flush();
$this->isFlushing = false;
$this->items = [];
$this->items = self::$ignored = [];
}


private function process(Action $action, object $target): void
{
$changes = $this->findChanges($action, $target);
$hash = spl_object_hash($target);

if ($target instanceof Collection) {
$target = $target->getOwner();
Expand All @@ -134,7 +144,7 @@ private function process(Action $action, object $target): void
return;
}

$this->items[spl_object_id($target)] = [
$this->items[$hash] = [
$target,
$action,
$changes,
Expand Down

0 comments on commit 70010f2

Please sign in to comment.