Skip to content

Commit 5b6b961

Browse files
committed
Fix fixtures (some authors had more posts than expected). Find some twig errors and fix them
1 parent cacb918 commit 5b6b961

9 files changed

Lines changed: 106 additions & 79 deletions

src/App/src/Fixture/AuthorLoader.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ public function load(ObjectManager $manager): void
3838
continue;
3939
}
4040

41-
$wpAuthorId = $authorData['github'];
42-
if (isset($seenAuthorIds[$wpAuthorId])) {
41+
$name = $authorData['display_name'];
42+
if (isset($seenAuthorIds[$name])) {
4343
continue;
4444
}
45-
$seenAuthorIds[$wpAuthorId] = true;
45+
$seenAuthorIds[$name] = true;
4646

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

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

74-
$this->addReference('author_' . $wpAuthorId, $author);
73+
$this->addReference('author_' . $slug, $author);
7574
}
7675
}
7776

src/App/src/Fixture/CategoryLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function load(ObjectManager $manager): void
4040
}
4141

4242
$category->setName($cat['name']);
43-
$category->setVisibility($cat['isVisible'] ?? true);
43+
$category->setVisibility((bool) ($cat['isVisible'] ?? true));
4444

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

src/App/src/Fixture/PostLoader.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ public function load(ObjectManager $manager): void
4444
$category = $this->getReference('category_' . $cat['slug'], Category::class);
4545

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

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

0 commit comments

Comments
 (0)