diff --git a/CHANGELOG.md b/CHANGELOG.md index ab1ecee..1b5fca7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Stripe +## 1.2.0.1 - 2024-11-07 + +- Fixed an infinite loop that could occur when querying for a user. + ## 1.2.0 - 2024-11-06 > [!NOTE] diff --git a/src/Plugin.php b/src/Plugin.php index 857f8b8..3eb79c7 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -575,14 +575,14 @@ function(DefineMenuItemsEvent $event) { private function handleUserElementChanges(): void { // if email address got changed - update stripe - Event::on(UserRecord::class, UserRecord::EVENT_BEFORE_UPDATE, function(ModelEvent $event) { - $userRecord = $event->sender; + Event::on(User::class, User::EVENT_BEFORE_SAVE, function(ModelEvent $event) { /** @var User|StripeCustomerBehavior $user */ - $user = Craft::$app->getUsers()->getUserById($userRecord->id); + $user = $event->sender; + $userRecord = UserRecord::findOne($user->id); $settings = $this->getSettings(); if ($user->isCredentialed && $settings['syncChangedUserEmailsToStripe']) { - $oldEmail = $userRecord->getOldAttribute('email'); - $newEmail = $userRecord->getAttribute('email'); + $oldEmail = $userRecord->getAttribute('email'); + $newEmail = $user->email; if ($oldEmail != $newEmail) { $customers = $user->getStripeCustomers(); if ($customers->isNotEmpty()) { @@ -671,7 +671,6 @@ public function getCpNavItem(): ?array ]; } - return $ret; }