feat: post-fill hook

This commit is contained in:
Maxime 2024-04-17 13:06:48 +02:00
parent 9d17dacae2
commit abce313193
4 changed files with 18 additions and 0 deletions

View File

@ -4,6 +4,7 @@ namespace Bluesquare\Connect\Commands;
use Bluesquare\Connect\Connect; use Bluesquare\Connect\Connect;
use Bluesquare\Connect\ConnectException; use Bluesquare\Connect\ConnectException;
use Bluesquare\Connect\Traits\HasConnectData;
use Bluesquare\Connect\Traits\HasConnectTokens; use Bluesquare\Connect\Traits\HasConnectTokens;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@ -32,6 +33,10 @@ class Sync extends Command
$data = $connect->getUserData($model->connect_access_token); $data = $connect->getUserData($model->connect_access_token);
$connect->updateUserData($model, $data); $connect->updateUserData($model, $data);
$model->save(); $model->save();
if (in_array(HasConnectData::class, class_uses($model))) {
$model->postFillConnectData($data);
}
} }
} }
catch (\Exception $exception) { catch (\Exception $exception) {

View File

@ -224,6 +224,10 @@ class Connect
} else { } else {
$this->updateUserData($model, $data); $this->updateUserData($model, $data);
$model->save(); $model->save();
if (in_array(HasConnectData::class, class_uses($model))) {
$model->postFillConnectData($data);
}
} }
return $model; return $model;

View File

@ -44,4 +44,9 @@ trait HasConnectData
foreach ($touched as $model) foreach ($touched as $model)
$model->save(); $model->save();
} }
public function postFillConnectData(array $data)
{
// Intended for post-processing / relationship handling
}
} }

View File

@ -18,6 +18,10 @@ trait HasConnectWebhook
} }
$this->save(); $this->save();
if (in_array(HasConnectData::class, class_uses(self::class))) {
$this->postFillConnectData($data);
}
} }
public function onConnectDelete(array $data) public function onConnectDelete(array $data)