]> Raphaël G. Git Repositories - airbundle/commitdiff
Fix subscriber user add/remove from inverse side
authorRaphaël Gertz <git@rapsys.eu>
Tue, 27 Feb 2024 15:31:55 +0000 (16:31 +0100)
committerRaphaël Gertz <git@rapsys.eu>
Tue, 27 Feb 2024 15:31:55 +0000 (16:31 +0100)
Entity/User.php

index 387b1964e33963ef4356d1d838add7238ce3890e..807fecececcbae08ceaf8626904a327c31cbf7f4 100644 (file)
@@ -347,6 +347,9 @@ class User extends BaseUser {
         * @return User
         */
        public function addSubscriber(User $subscriber): User {
         * @return User
         */
        public function addSubscriber(User $subscriber): User {
+               //Add from owning side
+               $subscriber->addSubscription($this);
+
                $this->subscribers[] = $subscriber;
 
                return $this;
                $this->subscribers[] = $subscriber;
 
                return $this;
@@ -358,6 +361,13 @@ class User extends BaseUser {
         * @param User $subscriber
         */
        public function removeSubscriber(User $subscriber): bool {
         * @param User $subscriber
         */
        public function removeSubscriber(User $subscriber): bool {
+               if (!$this->subscriptions->contains($subscriber)) {
+                       return true;
+               }
+
+               //Remove from owning side
+               $subscriber->removeSubscription($this);
+
                return $this->subscribers->removeElement($subscriber);
        }
 
                return $this->subscribers->removeElement($subscriber);
        }
 
@@ -378,9 +388,6 @@ class User extends BaseUser {
         * @return User
         */
        public function addSubscription(User $subscription): User {
         * @return User
         */
        public function addSubscription(User $subscription): User {
-               //Add from owning side
-               $subscription->addSubscriber($this);
-
                $this->subscriptions[] = $subscription;
 
                return $this;
                $this->subscriptions[] = $subscription;
 
                return $this;
@@ -392,13 +399,6 @@ class User extends BaseUser {
         * @param User $subscription
         */
        public function removeSubscription(User $subscription): bool {
         * @param User $subscription
         */
        public function removeSubscription(User $subscription): bool {
-               if (!$this->users->contains($user)) {
-                       return true;
-               }
-
-               //Remove from owning side
-               $subscription->removeSubscriber($this);
-
                return $this->subscriptions->removeElement($subscription);
        }
 
                return $this->subscriptions->removeElement($subscription);
        }