Skip to content

Commit

Permalink
Sync 9
Browse files Browse the repository at this point in the history
  • Loading branch information
adrolli committed Sep 5, 2024
1 parent 6fd0a0d commit 67ed312
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
8 changes: 8 additions & 0 deletions packages/sync/src/Handlers/PressSyncHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ protected function getMainTableData(): array
$mainFields = $this->getMainFields();
$mainTableData = array_intersect_key($this->modelData, array_flip($mainFields));

// Ensure all required fields are present, even if empty
foreach ($mainFields as $field) {
if (! isset($mainTableData[$field])) {
$mainTableData[$field] = '';
}
}

// Ensure user_url and user_activation_key are not null
$mainTableData['user_url'] = $mainTableData['user_url'] ?? '';
$mainTableData['user_activation_key'] = $mainTableData['user_activation_key'] ?? '';

Expand Down
21 changes: 5 additions & 16 deletions packages/sync/src/Http/Controllers/SyncWebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,17 @@ class SyncWebhookController extends Controller

public function __construct()
{
$this->logDebug('SyncWebhookController instantiated');
$this->logInfo('Moox Sync: WebhookController instantiated');
}

public function handle(Request $request)
{
$this->logDebug('SyncWebhookController handle method entered', ['full_request_data' => $request->all()]);
$this->logInfo('Moox Sync: WebhookController handle method entered', ['full_request_data' => $request->all()]);

try {
$validatedData = $this->validateRequest($request);

$this->logDebug('SyncWebhookController validated request', ['validated_data' => $validatedData]);

// Log specific fields we're interested in
$this->logDebug('Important fields from validated data', [
'event_type' => $validatedData['event_type'],
'model_class' => $validatedData['model_class'],
'user_registered' => $validatedData['model']['user_registered'] ?? 'not set',
'capabilities' => $validatedData['model']['jku8u_capabilities'] ?? 'not set',
'description' => $validatedData['model']['description'] ?? 'not set',
// Add any other fields you want to check
]);
$this->logDebug('Moox Sync: WebhookController validated request', ['validated_data' => $validatedData]);

$sourcePlatform = Platform::where('domain', $validatedData['platform']['domain'])->first();

Expand All @@ -47,8 +37,7 @@ public function handle(Request $request)
throw new \Exception('Model ID not found in the request data');
}

// Log the exact data being passed to SyncJob
$this->logDebug('Data being passed to SyncJob', [
$this->logInfo('Data being passed to SyncJob', [
'model_class' => $validatedData['model_class'],
'model_data' => $validatedData['model'],
'event_type' => $validatedData['event_type'],
Expand Down Expand Up @@ -82,7 +71,7 @@ public function handle(Request $request)

protected function validateRequest(Request $request)
{
$this->logDebug('SyncWebhookController validating request', ['raw_request_data' => $request->all()]);
$this->logInfo('SyncWebhookController validating request', ['raw_request_data' => $request->all()]);

$validatedData = $request->validate([
'event_type' => 'required|string|in:created,updated,deleted',
Expand Down
11 changes: 8 additions & 3 deletions packages/sync/src/Jobs/SyncJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Moox\Core\Traits\LogLevel;
use Moox\Sync\Handlers\PressSyncHandler;
use Moox\Sync\Models\Platform;
Expand Down Expand Up @@ -42,14 +43,18 @@ protected function getModelId()
];
}
}
throw new \Exception('No suitable ID field found for model');

Log::error('Moox Sync: No suitable ID field found for model', [
'model_class' => $this->modelClass,
'model_data' => $this->modelData,
]);
}

public function handle()
{
try {
$modelId = $this->getModelId();
$this->logDebug('Syncing model', [
$this->logInfo('Moox Sync: Syncing model', [
'model_class' => $this->modelClass,
'model_id_field' => $modelId['field'],
'model_id_value' => $modelId['value'],
Expand All @@ -62,7 +67,7 @@ public function handle()
$this->syncModel($modelId);
}
} catch (\Exception $e) {
$this->logDebug('Error syncing model', [
Log::error('Moox Sync: Error syncing model', [
'model_class' => $this->modelClass,
'error' => $e->getMessage(),
'trace' => $e->getTraceAsString(),
Expand Down

0 comments on commit 67ed312

Please sign in to comment.