Просмотр исходного кода

- Improved backup/restore module

maziggy 9 месяцев назад
Родитель
Сommit
b024880cb6
1 измененных файлов с 13 добавлено и 0 удалено
  1. 13 0
      backend/app/api/routes/settings.py

+ 13 - 0
backend/app/api/routes/settings.py

@@ -21,6 +21,7 @@ from backend.app.models.filament import Filament
 from backend.app.models.maintenance import MaintenanceType, PrinterMaintenance, MaintenanceHistory
 from backend.app.models.maintenance import MaintenanceType, PrinterMaintenance, MaintenanceHistory
 from backend.app.models.archive import PrintArchive
 from backend.app.models.archive import PrintArchive
 from backend.app.schemas.settings import AppSettings, AppSettingsUpdate
 from backend.app.schemas.settings import AppSettings, AppSettingsUpdate
+from backend.app.services.printer_manager import printer_manager
 
 
 
 
 router = APIRouter(prefix="/settings", tags=["settings"])
 router = APIRouter(prefix="/settings", tags=["settings"])
@@ -806,6 +807,18 @@ async def import_backup(
 
 
     await db.commit()
     await db.commit()
 
 
+    # If printers were in the backup (restored, updated, or skipped), reconnect all active printers
+    # This ensures connections are re-established after restore, even if printers were skipped
+    if "printers" in backup:
+        # Fetch all active printers and connect them
+        result = await db.execute(
+            select(Printer).where(Printer.is_active == True)
+        )
+        active_printers = result.scalars().all()
+        for printer in active_printers:
+            # This will disconnect existing connection (if any) and reconnect
+            await printer_manager.connect_printer(printer)
+
     # Build summary message
     # Build summary message
     restored_parts = []
     restored_parts = []
     for key, count in restored.items():
     for key, count in restored.items():