fix: address PR review findings — error handling and data integrity

- Add missing language field to batch-generated records
- Wrap batch insert in try-catch to handle duplicate key races
- Add logging to all empty catch blocks (script.php, MokoOG license check)
- Guard loadShopProduct() with try-catch for missing MokoSuiteShop tables
- Guard reviews query in JsonLdBuilder for missing #__mokoshop_reviews
This commit is contained in:
Jonathan Miller
2026-06-21 16:26:13 -05:00
parent 38af92b876
commit 46e30c950b
4 changed files with 63 additions and 41 deletions
@@ -90,6 +90,7 @@ class BatchController extends BaseController
$articles = $db->loadObjectList();
$created = 0;
$skipped = 0;
$now = Factory::getDate()->toSql();
foreach ($articles as $article) {
@@ -98,23 +99,28 @@ class BatchController extends BaseController
$ogImage = $this->extractImage($article);
$record = (object) [
'content_type' => 'com_content',
'content_id' => (int) $article->id,
'og_title' => $ogTitle,
'og_description' => $ogDescription,
'og_image' => $ogImage,
'og_type' => 'article',
'seo_title' => '',
'content_type' => 'com_content',
'content_id' => (int) $article->id,
'og_title' => $ogTitle,
'og_description' => $ogDescription,
'og_image' => $ogImage,
'og_type' => 'article',
'seo_title' => '',
'meta_description' => $article->metadesc ?: '',
'robots' => '',
'canonical_url' => '',
'published' => 1,
'created' => $now,
'modified' => $now,
'robots' => '',
'canonical_url' => '',
'language' => '*',
'published' => 1,
'created' => $now,
'modified' => $now,
];
$db->insertObject('#__mokoog_tags', $record);
$created++;
try {
$db->insertObject('#__mokoog_tags', $record);
$created++;
} catch (\RuntimeException $e) {
$skipped++;
}
}
echo new JsonResponse([