Skip to content

Commit

Permalink
Rename blog_post_locales table and columns to more general locales
Browse files Browse the repository at this point in the history
Column `id_blog_post_locale` has been renamed to `id_locale` only.

SQL queries:
ALTER TABLE `blog_post_locales` RENAME TO `locales`;
ALTER TABLE `locales` CHANGE `id_blog_post_locale` `id_locale` int unsigned NOT NULL AUTO_INCREMENT FIRST;
ALTER TABLE `locales` COLLATE 'utf8mb4_general_ci';
  • Loading branch information
spaze committed Aug 8, 2023
1 parent a158e4e commit d317fde
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
24 changes: 12 additions & 12 deletions site/app/Articles/Articles.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getAll(?int $limit = null): array
UNION ALL
SELECT
bp.id_blog_post,
l.id_blog_post_locale,
l.id_locale,
bp.key_translation_group,
l.locale,
bp.title,
Expand All @@ -89,8 +89,8 @@ public function getAll(?int $limit = null): array
null AS twitterCardId,
bp.omit_exports AS omitExports
FROM blog_posts bp
LEFT JOIN blog_post_locales l
ON l.id_blog_post_locale = bp.key_locale
LEFT JOIN locales l
ON l.id_locale = bp.key_locale
WHERE bp.published IS NOT NULL
AND bp.published <= ?
AND l.locale = ?
Expand All @@ -115,7 +115,7 @@ public function getAllByTags(array $tags, ?int $limit = null): array
{
$query = 'SELECT
bp.id_blog_post AS id,
l.id_blog_post_locale AS localeId,
l.id_locale AS localeId,
bp.key_translation_group AS translationGroupId,
l.locale,
bp.title AS titleTexy,
Expand All @@ -136,8 +136,8 @@ public function getAllByTags(array $tags, ?int $limit = null): array
null AS twitterCardId,
bp.omit_exports AS omitExports
FROM blog_posts bp
LEFT JOIN blog_post_locales l
ON l.id_blog_post_locale = bp.key_locale
LEFT JOIN locales l
ON l.id_locale = bp.key_locale
WHERE
JSON_CONTAINS(bp.slug_tags, ?)
AND bp.published IS NOT NULL
Expand All @@ -162,8 +162,8 @@ public function getAllTags(): array
bp.slug_tags AS slugTags,
bp.published
FROM blog_posts bp
LEFT JOIN blog_post_locales l
ON l.id_blog_post_locale = bp.key_locale
LEFT JOIN locales l
ON l.id_locale = bp.key_locale
WHERE
bp.tags IS NOT NULL
AND bp.published IS NOT NULL
Expand Down Expand Up @@ -197,8 +197,8 @@ public function getLabelByTag(string $tag): ?string
bp.tags,
bp.slug_tags AS slugTags
FROM blog_posts bp
LEFT JOIN blog_post_locales l
ON l.id_blog_post_locale = bp.key_locale
LEFT JOIN locales l
ON l.id_locale = bp.key_locale
WHERE
JSON_CONTAINS(bp.slug_tags, ?)
AND bp.published IS NOT NULL
Expand Down Expand Up @@ -230,7 +230,7 @@ public function getNearestPublishDate(): ?DateTime
$query = 'SELECT a.date FROM articles a WHERE a.date > ?
UNION ALL
SELECT bp.published FROM blog_posts bp
LEFT JOIN blog_post_locales l ON l.id_blog_post_locale = bp.key_locale
LEFT JOIN locales l ON l.id_locale = bp.key_locale
WHERE bp.published IS NOT NULL AND bp.published > ? AND l.locale = ?
ORDER BY date
LIMIT 1';
Expand All @@ -253,7 +253,7 @@ public function getNearestPublishDate(): ?DateTime
public function getNearestPublishDateByTags(array $tags): ?DateTime
{
$query = 'SELECT bp.published FROM blog_posts bp
LEFT JOIN blog_post_locales l ON l.id_blog_post_locale = bp.key_locale
LEFT JOIN locales l ON l.id_locale = bp.key_locale
WHERE JSON_CONTAINS(bp.slug_tags, ?)
AND bp.published IS NOT NULL
AND bp.published > ?
Expand Down
6 changes: 3 additions & 3 deletions site/app/Articles/Blog/BlogPostLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function fetch(string $post, ?string $previewKey = null): ?Row
$result = $this->database->fetch(
'SELECT
bp.id_blog_post AS postId,
l.id_blog_post_locale AS localeId,
l.id_locale AS localeId,
bp.key_translation_group AS translationGroupId,
l.locale,
bp.slug,
Expand All @@ -66,8 +66,8 @@ public function fetch(string $post, ?string $previewKey = null): ?Row
tct.card AS twitterCard,
tct.title AS twitterCardTitle
FROM blog_posts bp
LEFT JOIN blog_post_locales l
ON l.id_blog_post_locale = bp.key_locale
LEFT JOIN locales l
ON l.id_locale = bp.key_locale
LEFT JOIN twitter_card_types tct
ON tct.id_twitter_card_type = bp.key_twitter_card_type
WHERE bp.slug = ?
Expand Down
4 changes: 2 additions & 2 deletions site/app/Articles/Blog/BlogPostLocaleUrls.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public function get(string $slug): array
bp.slug_tags AS slugTags
FROM
blog_posts bp
LEFT JOIN blog_post_locales l ON l.id_blog_post_locale = bp.key_locale
LEFT JOIN locales l ON l.id_locale = bp.key_locale
WHERE bp.key_translation_group = (SELECT key_translation_group FROM blog_posts WHERE slug = ?)
OR bp.slug = ?
ORDER BY l.id_blog_post_locale';
ORDER BY l.id_locale';
foreach ($this->database->fetchAll($sql, $slug, $slug) as $row) {
$post = new BlogPost();
$post->locale = $row->locale;
Expand Down
14 changes: 7 additions & 7 deletions site/app/Articles/Blog/BlogPosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function getById(int $id): BlogPost
$result = $this->database->fetch(
'SELECT
bp.id_blog_post AS postId,
l.id_blog_post_locale AS localeId,
l.id_locale AS localeId,
bp.key_translation_group AS translationGroupId,
l.locale,
bp.slug,
Expand All @@ -120,8 +120,8 @@ public function getById(int $id): BlogPost
tct.card AS twitterCard,
tct.title AS twitterCardTitle
FROM blog_posts bp
LEFT JOIN blog_post_locales l
ON l.id_blog_post_locale = bp.key_locale
LEFT JOIN locales l
ON l.id_locale = bp.key_locale
LEFT JOIN twitter_card_types tct
ON tct.id_twitter_card_type = bp.key_twitter_card_type
WHERE bp.id_blog_post = ?',
Expand All @@ -146,7 +146,7 @@ public function getAll(): array
$posts = [];
$sql = 'SELECT
bp.id_blog_post AS postId,
l.id_blog_post_locale AS localeId,
l.id_locale AS localeId,
bp.key_translation_group AS translationGroupId,
l.locale,
bp.slug,
Expand All @@ -166,8 +166,8 @@ public function getAll(): array
null AS twitterCardId
FROM
blog_posts bp
LEFT JOIN blog_post_locales l
ON l.id_blog_post_locale = bp.key_locale
LEFT JOIN locales l
ON l.id_locale = bp.key_locale
ORDER BY
published, slug';
foreach ($this->database->fetchAll($sql) as $row) {
Expand Down Expand Up @@ -320,7 +320,7 @@ public function update(BlogPost $post): void
public function getAllLocales(): array
{
if ($this->locales === null) {
$this->locales = $this->database->fetchPairs('SELECT id_blog_post_locale, locale FROM blog_post_locales ORDER BY id_blog_post_locale');
$this->locales = $this->database->fetchPairs('SELECT id_locale, locale FROM locales ORDER BY id_locale');
}
return $this->locales;
}
Expand Down

0 comments on commit d317fde

Please sign in to comment.