Skip to content

Commit

Permalink
Update WpUserSyncHandler.php
Browse files Browse the repository at this point in the history
  • Loading branch information
adrolli committed Sep 7, 2024
1 parent db4afa7 commit 9be92cd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/press/src/Handlers/WpUserSyncHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ protected function deleteModel()
protected function syncMainRecord()
{
$mainTableData = $this->getMainTableData();
$mainTableData = $this->ensureAllFieldsHaveValue($mainTableData);

$idField = $this->getIdField();

DB::table($this->tableName)->updateOrInsert(
Expand All @@ -47,20 +49,27 @@ protected function syncMainRecord()
protected function syncMetaData($mainRecordId)
{
$metaData = $this->getMetaData();
$metaData = $this->ensureAllFieldsHaveValue($metaData);
$foreignKeyName = $this->getForeignKeyName();

foreach ($metaData as $key => $value) {
$serializedValue = is_array($value) ? serialize($value) : $value;
DB::table($this->metaTableName)->updateOrInsert(
[
$foreignKeyName => $mainRecordId,
'meta_key' => $key,
],
['meta_value' => $serializedValue]
['meta_value' => $value]
);
}
}

protected function ensureAllFieldsHaveValue(array $data): array
{
return array_map(function ($value) {
return $value ?? '';
}, $data);
}

protected function getMainTableData(): array
{
$mainFields = $this->getMainFields();
Expand Down

0 comments on commit 9be92cd

Please sign in to comment.