Skip to content

Commit

Permalink
Fix issues with seeded data
Browse files Browse the repository at this point in the history
  • Loading branch information
driftingly committed Jun 26, 2024
1 parent 2999dc0 commit c0cac8d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
14 changes: 6 additions & 8 deletions app/Repositories/ArtworkRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,14 @@ public function prepareFieldsBeforeCreate(array $fields): array
$apiFields['floor'] = $galleryFields['floor'] ?? null;
}

$artist = Str::of($apiFields['artist_title'] ?: $apiFields['artist_display'])
->before("\n")->trim()->__toString();
if (! data_get($fields, "artist.en")) {
$artist = Str::of($apiFields['artist_title'] ?: $apiFields['artist_display'])
->before("\n")->trim()->__toString();

$translatedFields = [
'artist' => [
'en' => $artist,
],
];
data_set($fields, "artist.en", $artist);
}

return parent::prepareFieldsBeforeCreate([...$fields, ...$apiFields, ...$translatedFields]);
return parent::prepareFieldsBeforeCreate([...$fields, ...$apiFields]);
}

public function afterSave(TwillModelContract $model, array $fields): void
Expand Down
8 changes: 4 additions & 4 deletions database/seeders/ArtworkSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function run(ThemePrompt $themePrompt, array $artworks): void
'en' => [
'title' => $rawArtwork['title'],
'artist' => $rawArtwork['artist'],
'location_directions' => $rawArtwork['locationDirections'] ?? null,
'locationDirections' => $rawArtwork['locationDirections'] ?? null,
],
])->merge($rawArtwork['translations'])->map(
fn ($translation, $locale) => [
Expand All @@ -70,9 +70,9 @@ public function run(ThemePrompt $themePrompt, array $artworks): void

$themePromptArtworkData = collect([
'en' => [
'detail_narrative' => $rawArtwork['detailNarrative'] ?? null,
'viewing_description' => $rawArtwork['viewingDescription'] ?? null,
'activity_instructions' => $rawArtwork['activityInstructions'] ?? null,
'detailNarrative' => $rawArtwork['detailNarrative'] ?? null,
'viewingDescription' => $rawArtwork['viewingDescription'] ?? null,
'activityInstructions' => $rawArtwork['activityInstructions'] ?? null,
],
])->merge($rawArtwork['translations'])->map(
fn ($translation, $locale) => [
Expand Down

0 comments on commit c0cac8d

Please sign in to comment.