Dev #9

Merged
LordSchmackes merged 13 commits from dev into main 2026-05-23 21:30:54 +00:00
2 changed files with 15 additions and 11 deletions
Showing only changes of commit b338e2bc30 - Show all commits
-4
View File
@@ -332,9 +332,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'delet
], ],
]; ];
if ($featured) {
clear_featured_recipes();
}
if ($slugOriginal && $slugOriginal !== $slug) { if ($slugOriginal && $slugOriginal !== $slug) {
delete_recipe($slugOriginal); delete_recipe($slugOriginal);
} }
@@ -663,6 +660,5 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'delet
<button type="submit" class="button" style="width: fit-content;"><?php echo $editing ? 'Save changes' : 'Save recipe'; ?></button> <button type="submit" class="button" style="width: fit-content;"><?php echo $editing ? 'Save changes' : 'Save recipe'; ?></button>
</form> </form>
<?php endif; ?> <?php endif; ?>
</body> </body>
</html> </html>
+15 -7
View File
15
@@ -258,6 +258,10 @@ function save_recipe(array $recipe, ?PDO $pdo = null): bool {
try { try {
$pdo->beginTransaction(); $pdo->beginTransaction();
if (!empty($recipe['featured'])) {
github-actions[bot] commented 2026-05-23 21:30:29 +00:00 (Migrated from github.com)
Review

This function handles saving a recipe to the database, including its translations and related items. It uses transactions for atomicity, which is excellent. However, the repeated calls to DELETE for all related tables before inserting new data can be inefficient for updates. If a recipe is updated frequently, consider an UPSERT approach or more targeted updates for related data rather than full deletes and re-inserts.

This function handles saving a recipe to the database, including its translations and related items. It uses transactions for atomicity, which is excellent. However, the repeated calls to `DELETE` for all related tables before inserting new data can be inefficient for updates. If a recipe is updated frequently, consider an `UPSERT` approach or more targeted updates for related data rather than full deletes and re-inserts.
clear_featured_recipes($pdo);
}
$stmt = $pdo->prepare( $stmt = $pdo->prepare(
'INSERT INTO recipes ( 'INSERT INTO recipes (
slug, hero, prep_time, cook_time, total_time, servings, slug, hero, prep_time, cook_time, total_time, servings,
2
@@ -329,30 +333,34 @@ function save_recipe(array $recipe, ?PDO $pdo = null): bool {
$block['difficulty'] ?? '', $block['difficulty'] ?? '',
]); ]);
foreach (array_values($block['tags'] ?? []) as $i => $tag) { $tagOrder = 0;
foreach (array_values($block['tags'] ?? []) as $tag) {
github-actions[bot] commented 2026-05-23 21:30:29 +00:00 (Migrated from github.com)
Review

Hardcoding languages en and de might become problematic if more languages are added. It would be more maintainable to fetch the list of supported languages from a configuration or a dedicated table if the application grows.

Hardcoding languages `en` and `de` might become problematic if more languages are added. It would be more maintainable to fetch the list of supported languages from a configuration or a dedicated table if the application grows.
$tag = trim((string) $tag); $tag = trim((string) $tag);
if ($tag !== '') { if ($tag !== '') {
$tagStmt->execute([$slug, $lang, $tag, $i]); $tagStmt->execute([$slug, $lang, $tag, $tagOrder++]);
} }
} }
foreach (array_values($block['ingredients'] ?? []) as $i => $line) { $ingredientOrder = 0;
foreach (array_values($block['ingredients'] ?? []) as $line) {
$line = trim((string) $line); $line = trim((string) $line);
if ($line !== '') { if ($line !== '') {
$ingredientStmt->execute([$slug, $lang, $line, $i]); $ingredientStmt->execute([$slug, $lang, $line, $ingredientOrder++]);
} }
} }
foreach (array_values($block['utensils'] ?? []) as $i => $line) { $utensilOrder = 0;
foreach (array_values($block['utensils'] ?? []) as $line) {
$line = trim((string) $line); $line = trim((string) $line);
if ($line !== '') { if ($line !== '') {
$utensilStmt->execute([$slug, $lang, $line, $i]); $utensilStmt->execute([$slug, $lang, $line, $utensilOrder++]);
} }
} }
$steps = array_values($block['steps'] ?? []); $steps = array_values($block['steps'] ?? []);
$videos = array_values($block['step_videos'] ?? []); $videos = array_values($block['step_videos'] ?? []);
$timers = array_values($block['step_timers'] ?? []); $timers = array_values($block['step_timers'] ?? []);
$stepOrder = 0;
foreach ($steps as $i => $step) { foreach ($steps as $i => $step) {
$step = trim((string) $step); $step = trim((string) $step);
if ($step === '') { if ($step === '') {
@@ -361,7 +369,7 @@ function save_recipe(array $recipe, ?PDO $pdo = null): bool {
$video = trim((string) ($videos[$i] ?? '')); $video = trim((string) ($videos[$i] ?? ''));
$timerRaw = $timers[$i] ?? ''; $timerRaw = $timers[$i] ?? '';
$timerMinutes = ($timerRaw !== '' && is_numeric($timerRaw)) ? (int) $timerRaw : null; $timerMinutes = ($timerRaw !== '' && is_numeric($timerRaw)) ? (int) $timerRaw : null;
$stepStmt->execute([$slug, $lang, $step, $video, $timerMinutes, $i]); $stepStmt->execute([$slug, $lang, $step, $video, $timerMinutes, $stepOrder++]);
} }
} }
1