From abce313193525a44e4b9989ef61a8729d6e99b86 Mon Sep 17 00:00:00 2001 From: Maxime Renou Date: Wed, 17 Apr 2024 13:06:48 +0200 Subject: [PATCH] feat: post-fill hook --- src/Commands/Sync.php | 5 +++++ src/Connect.php | 4 ++++ src/Traits/HasConnectData.php | 5 +++++ src/Traits/HasConnectWebhook.php | 4 ++++ 4 files changed, 18 insertions(+) diff --git a/src/Commands/Sync.php b/src/Commands/Sync.php index 2adefc8..612d9fc 100644 --- a/src/Commands/Sync.php +++ b/src/Commands/Sync.php @@ -4,6 +4,7 @@ namespace Bluesquare\Connect\Commands; use Bluesquare\Connect\Connect; use Bluesquare\Connect\ConnectException; +use Bluesquare\Connect\Traits\HasConnectData; use Bluesquare\Connect\Traits\HasConnectTokens; use Illuminate\Console\Command; @@ -32,6 +33,10 @@ class Sync extends Command $data = $connect->getUserData($model->connect_access_token); $connect->updateUserData($model, $data); $model->save(); + + if (in_array(HasConnectData::class, class_uses($model))) { + $model->postFillConnectData($data); + } } } catch (\Exception $exception) { diff --git a/src/Connect.php b/src/Connect.php index 644cb2b..df37bb4 100644 --- a/src/Connect.php +++ b/src/Connect.php @@ -224,6 +224,10 @@ class Connect } else { $this->updateUserData($model, $data); $model->save(); + + if (in_array(HasConnectData::class, class_uses($model))) { + $model->postFillConnectData($data); + } } return $model; diff --git a/src/Traits/HasConnectData.php b/src/Traits/HasConnectData.php index c949cf9..0525c84 100644 --- a/src/Traits/HasConnectData.php +++ b/src/Traits/HasConnectData.php @@ -44,4 +44,9 @@ trait HasConnectData foreach ($touched as $model) $model->save(); } + + public function postFillConnectData(array $data) + { + // Intended for post-processing / relationship handling + } } diff --git a/src/Traits/HasConnectWebhook.php b/src/Traits/HasConnectWebhook.php index d9e124f..a0af5b5 100644 --- a/src/Traits/HasConnectWebhook.php +++ b/src/Traits/HasConnectWebhook.php @@ -18,6 +18,10 @@ trait HasConnectWebhook } $this->save(); + + if (in_array(HasConnectData::class, class_uses(self::class))) { + $this->postFillConnectData($data); + } } public function onConnectDelete(array $data)