Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/App/src/Fixture/AuthorLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ public function load(ObjectManager $manager): void
continue;
}

$wpAuthorId = $authorData['github'];
if (isset($seenAuthorIds[$wpAuthorId])) {
$name = $authorData['display_name'];
if (isset($seenAuthorIds[$name])) {
continue;
}
$seenAuthorIds[$wpAuthorId] = true;
$seenAuthorIds[$name] = true;

$name = $authorData['display_name'];
$github = $authorData['github'];
$github = $authorData['github'] ?: null;
$slug = $this->slugify($name);

$author = $repository->findOneBy(['name' => $name]);
Expand All @@ -71,7 +70,7 @@ public function load(ObjectManager $manager): void
echo $changed ? "UPDATE: {$name}\n" : "UNCHANGED: {$name}\n";
}

$this->addReference('author_' . $wpAuthorId, $author);
$this->addReference('author_' . $slug, $author);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/App/src/Fixture/CategoryLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function load(ObjectManager $manager): void
$contents = file_get_contents($jsonFile);

if ($contents === false) {
throw new RuntimeException("Unable to read file: {$jsonFile}");
throw new RuntimeException("Unable to read file: $jsonFile");
}

$categories = json_decode($contents, true);
Expand All @@ -41,7 +41,6 @@ public function load(ObjectManager $manager): void

$category->setName($cat['name']);
$category->setVisibility($cat['isVisible'] ?? true);

$this->addReference('category_' . $cat['slug'], $category);
}

Expand Down
7 changes: 4 additions & 3 deletions src/App/src/Fixture/PostLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ public function load(ObjectManager $manager): void
$category = $this->getReference('category_' . $cat['slug'], Category::class);

foreach ($cat['articles'] as $articleData) {
$wpAuthorId = $articleData['author']['github'] ?? null;
if (! $wpAuthorId || ! $this->hasReference('author_' . $wpAuthorId, Author::class)) {
$authorName = $articleData['author']['display_name'] ?? null;
$authorSlug = $authorName ? $this->slugify($authorName) : null;
if (! $authorSlug || ! $this->hasReference('author_' . $authorSlug, Author::class)) {
echo "SKIP (no author): {$articleData['post_title']}\n";
continue;
}

/** @var Author $author */
$author = $this->getReference('author_' . $wpAuthorId, Author::class);
$author = $this->getReference('author_' . $authorSlug, Author::class);
$title = html_entity_decode($articleData['post_title'], ENT_QUOTES, 'UTF-8');
$slug = $this->slugify($title);

Expand Down
Loading