Commit 4c947478 authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

Vidage du cache lors d'un ose update

parent 1a374c93
Loading
Loading
Loading
Loading
Loading
+39
Changes for module/Administration/src/Command/UpdateCommand.php: 39 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -67,6 +67,12 @@ class UpdateCommand extends Command
        $bin = getcwd()."/bin/ose";

        passthru("$bin update-code $args");

        // Purge brute du cache : la config fusionnée mise en cache par l'ancienne version peut référencer
        // des classes qui n'existent plus après le composer install, ce qui empêcherait update-bdd de démarrer
        // (clear-cache ne peut pas servir ici, puisqu'il a lui-même besoin de démarrer l'application)
        $this->purgeCache($io, getcwd() . '/cache');

        passthru("$bin update-bdd");

        //Conclusion
@@ -78,4 +84,37 @@ class UpdateCommand extends Command
        return Command::SUCCESS;
    }



    private function purgeCache(SymfonyStyle $io, string $cacheDir): void
    {
        if (!is_dir($cacheDir)) {
            return;
        }

        $io->section('Purge du cache');

        $iterator = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator($cacheDir, \FilesystemIterator::SKIP_DOTS),
            \RecursiveIteratorIterator::CHILD_FIRST
        );

        $echecs = [];
        foreach ($iterator as $item) {
            $path = $item->getPathname();
            $ok   = ($item->isDir() && !$item->isLink()) ? @rmdir($path) : @unlink($path);
            if (!$ok) {
                $echecs[] = $path;
            }
        }

        if (empty($echecs)) {
            $io->writeln('Cache purgé');
        } else {
            $io->warning(
                count($echecs) . ' élément(s) du répertoire cache n\'ont pas pu être supprimés (droits ?), '
                . 'par exemple ' . $echecs[0] . '. Si la suite de la mise à jour échoue, videz manuellement le répertoire cache.'
            );
        }
    }
}
 No newline at end of file