Skip to content

Commit

Permalink
Update PressSyncHandler.php
Browse files Browse the repository at this point in the history
  • Loading branch information
adrolli committed Sep 4, 2024
1 parent 47910d6 commit 78e4e50
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions packages/sync/src/Handlers/PressSyncHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ protected function syncMainRecord()
$mainTableData = $this->getMainTableData();
$idField = $this->getIdField();

$this->logDebug('Main table data before processing', ['mainTableData' => $mainTableData]);

// Handle user_registered for WpUser
if ($this->modelClass === \Moox\Press\Models\WpUser::class) {
if (! isset($mainTableData['user_registered']) || $mainTableData['user_registered'] === '0000-00-00 00:00:00') {
Expand All @@ -59,12 +61,7 @@ protected function syncMainRecord()
}
}

$this->logDebug('Syncing main record', [
'model_class' => $this->modelClass,
'id_field' => $idField,
'id_value' => $this->modelData[$idField],
'main_table_data' => $mainTableData,
]);
$this->logDebug('Main table data after processing', ['mainTableData' => $mainTableData]);

try {
$model = $this->modelClass::updateOrCreate(
Expand Down Expand Up @@ -171,6 +168,12 @@ protected function syncMetaData(Model $mainRecord)
$metaData = $this->getMetaData();
$metaModel = $this->getMetaModel($mainRecord);

$this->logDebug('Syncing meta data', [
'mainRecordId' => $mainRecord->getKey(),
'metaData' => $metaData,
'metaModel' => $metaModel,
]);

foreach ($metaData as $key => $value) {
$metaModel::updateOrCreate(
[
Expand All @@ -179,6 +182,11 @@ protected function syncMetaData(Model $mainRecord)
],
['meta_value' => $value]
);

$this->logDebug('Meta data synced', [
'key' => $key,
'value' => $value,
]);
}
}

Expand All @@ -190,8 +198,14 @@ protected function syncTaxonomies(Model $mainRecord)
protected function getMainTableData(): array
{
$mainFields = $this->getMainFields();
$mainTableData = array_intersect_key($this->modelData, array_flip($mainFields));

$this->logDebug('Main table data extracted', [
'mainFields' => $mainFields,
'mainTableData' => $mainTableData,
]);

return array_intersect_key($this->modelData, array_flip($mainFields));
return $mainTableData;
}

protected function getMetaData(): array
Expand Down

0 comments on commit 78e4e50

Please sign in to comment.