mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-01-23 17:22:56 -05:00
Merge branch 'mealie-next' into feat/filter-shopping-lists
This commit is contained in:
@@ -14,6 +14,7 @@ from mealie.schema.reports.reports import (
|
||||
ReportCategory,
|
||||
ReportCreate,
|
||||
ReportEntryCreate,
|
||||
ReportEntryOut,
|
||||
ReportOut,
|
||||
ReportSummary,
|
||||
ReportSummaryStatus,
|
||||
@@ -91,6 +92,7 @@ class BaseMigrator(BaseService):
|
||||
is_success = True
|
||||
is_failure = True
|
||||
|
||||
new_entries: list[ReportEntryOut] = []
|
||||
for entry in self.report_entries:
|
||||
if is_failure and entry.success:
|
||||
is_failure = False
|
||||
@@ -98,7 +100,7 @@ class BaseMigrator(BaseService):
|
||||
if is_success and not entry.success:
|
||||
is_success = False
|
||||
|
||||
self.db.group_report_entries.create(entry)
|
||||
new_entries.append(self.db.group_report_entries.create(entry))
|
||||
|
||||
if is_success:
|
||||
self.report.status = ReportSummaryStatus.success
|
||||
@@ -109,6 +111,7 @@ class BaseMigrator(BaseService):
|
||||
if not is_success and not is_failure:
|
||||
self.report.status = ReportSummaryStatus.partial
|
||||
|
||||
self.report.entries = new_entries
|
||||
self.db.group_reports.update(self.report.id, self.report)
|
||||
|
||||
def migrate(self, report_name: str) -> ReportSummary:
|
||||
|
||||
@@ -5,6 +5,7 @@ import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
from mealie.schema.recipe.recipe import Recipe
|
||||
from mealie.schema.reports.reports import ReportEntryCreate
|
||||
|
||||
from ._migration_base import BaseMigrator
|
||||
from .utils.migration_alias import MigrationAlias
|
||||
@@ -55,20 +56,28 @@ class MealieAlphaMigrator(BaseMigrator):
|
||||
zip_file.extractall(tmpdir)
|
||||
|
||||
temp_path = Path(tmpdir)
|
||||
|
||||
recipe_lookup: dict[str, Path] = {}
|
||||
recipes_as_dicts = []
|
||||
|
||||
for x in temp_path.rglob("**/recipes/**/[!.]*.json"):
|
||||
if (y := MigrationReaders.json(x)) is not None:
|
||||
recipes_as_dicts.append(y)
|
||||
slug = y["slug"]
|
||||
recipe_lookup[slug] = x.parent
|
||||
|
||||
recipes = [self._convert_to_new_schema(x) for x in recipes_as_dicts]
|
||||
recipes: list[Recipe] = []
|
||||
for recipe_json_path in temp_path.rglob("**/recipes/**/[!.]*.json"):
|
||||
try:
|
||||
if (recipe_as_dict := MigrationReaders.json(recipe_json_path)) is not None:
|
||||
recipe = self._convert_to_new_schema(recipe_as_dict)
|
||||
recipes.append(recipe)
|
||||
slug = recipe_as_dict["slug"]
|
||||
recipe_lookup[slug] = recipe_json_path.parent
|
||||
except Exception as e:
|
||||
self.logger.exception(e)
|
||||
self.report_entries.append(
|
||||
ReportEntryCreate(
|
||||
report_id=self.report_id,
|
||||
success=False,
|
||||
message=f"Failed to import {recipe_json_path.name}",
|
||||
exception=f"{e.__class__.__name__}: {e}",
|
||||
)
|
||||
)
|
||||
|
||||
results = self.import_recipes_to_database(recipes)
|
||||
|
||||
for slug, recipe_id, status in results:
|
||||
if not status:
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user