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)