From 00a6e1c238a09dea9ca020c4cf221ec9f9f031b5 Mon Sep 17 00:00:00 2001 From: bsiggel Date: Sat, 24 Jan 2026 00:10:18 +0100 Subject: [PATCH] Enhance rebuild process with Docker support; update cache handling and fallback logic --- custom/scripts/validate_and_rebuild.py | 93 +++++++++++++++++++++++++- data/config.php | 4 +- 2 files changed, 93 insertions(+), 4 deletions(-) diff --git a/custom/scripts/validate_and_rebuild.py b/custom/scripts/validate_and_rebuild.py index 830f90c7..d8ae98ab 100755 --- a/custom/scripts/validate_and_rebuild.py +++ b/custom/scripts/validate_and_rebuild.py @@ -383,15 +383,104 @@ class EntityValidator: """Führe den EspoCRM Rebuild aus.""" print_header("7. ESPOCRM REBUILD") + # Prüfe ob wir in einem Docker-Volume sind + is_docker_volume = '/docker/volumes/' in str(self.base_path) + + if is_docker_volume: + # Versuche Docker-Container zu finden + try: + result = subprocess.run( + ['docker', 'ps', '--format', '{{.Names}}'], + capture_output=True, + text=True, + timeout=5 + ) + + containers = result.stdout.strip().split('\n') + espo_container = None + + # Suche nach EspoCRM Container (meist "espocrm" ohne Suffix) + for container in containers: + if container.lower() in ['espocrm', 'espocrm-app']: + espo_container = container + break + + if not espo_container: + # Fallback: erster Container mit "espo" im Namen + for container in containers: + if 'espo' in container.lower() and 'websocket' not in container.lower() and 'daemon' not in container.lower() and 'db' not in container.lower(): + espo_container = container + break + + if espo_container: + print_info(f"Docker-Container erkannt: {espo_container}") + + # Schritt 1: Cache löschen + print_info("Lösche Cache...") + cache_result = subprocess.run( + ['docker', 'exec', espo_container, 'php', 'command.php', 'clear-cache'], + capture_output=True, + text=True, + timeout=30 + ) + + if cache_result.returncode == 0: + print_success("Cache erfolgreich gelöscht") + else: + print_warning("Cache-Löschung fehlgeschlagen, fahre trotzdem fort...") + + # Schritt 2: Rebuild + print_info("Starte Rebuild (kann 10-30 Sekunden dauern)...") + result = subprocess.run( + ['docker', 'exec', espo_container, 'php', 'command.php', 'rebuild'], + capture_output=True, + text=True, + timeout=60 + ) + + if result.returncode == 0: + print_success("Rebuild erfolgreich abgeschlossen") + if result.stdout: + print(f" {result.stdout.strip()}") + return True + else: + print_error("Rebuild fehlgeschlagen:") + if result.stderr: + print(f"\n{result.stderr}") + return False + else: + print_warning("Kein EspoCRM Docker-Container gefunden") + print_info("Versuche lokalen Rebuild...") + except Exception as e: + print_warning(f"Docker-Erkennung fehlgeschlagen: {e}") + print_info("Versuche lokalen Rebuild...") + + # Lokaler Rebuild (Fallback) rebuild_script = self.base_path / "rebuild.php" if not rebuild_script.exists(): print_error(f"rebuild.php nicht gefunden in {self.base_path}") return False try: - print_info("Starte Rebuild (kann 10-30 Sekunden dauern)...") + # Schritt 1: Cache löschen + print_info("Lösche Cache...") + cache_result = subprocess.run( + ['php', 'command.php', 'clear-cache'], + cwd=str(self.base_path), + capture_output=True, + text=True, + timeout=30 + ) + + if cache_result.returncode == 0: + print_success("Cache erfolgreich gelöscht") + else: + print_warning("Cache-Löschung fehlgeschlagen, fahre trotzdem fort...") + + # Schritt 2: Rebuild + print_info("Starte lokalen Rebuild (kann 10-30 Sekunden dauern)...") result = subprocess.run( - ['php', str(rebuild_script)], + ['php', 'command.php', 'rebuild'], cwd=str(self.base_path), capture_output=True, text=True, diff --git a/data/config.php b/data/config.php index 108e0a77..e1cf9124 100644 --- a/data/config.php +++ b/data/config.php @@ -359,8 +359,8 @@ return [ 0 => 'youtube.com', 1 => 'google.com' ], - 'cacheTimestamp' => 1769208633, - 'microtime' => 1769208633.477855, + 'cacheTimestamp' => 1769209783, + 'microtime' => 1769209783.769122, 'siteUrl' => 'https://crm.bitbylaw.com', 'fullTextSearchMinLength' => 4, 'appTimestamp' => 1768843902,