addArgument( 'file', InputArgument::REQUIRED, 'Path to the update file' ); } protected function execute( InputInterface $input, OutputInterface $output ): int { $file = $input->getArgument('file'); $zip = new ZipArchive; if ($zip->open($file) !== true) { throw new InvalidArgumentException('Could not open file'); } $backupDir = $this->rootDir . '/var/update/' . Uuid::uuid4()->toString(); // Take backup for folowing files and folders $paths = ['locale', 'LICENSE']; foreach ($paths as $path) { if ($this->fs->fileExists($path)) { $this->fs->copy('/' . $path, $backupDir . '/' . $path); continue; } if ($this->fs->directoryExists($path)) { $files = $this->fs->listContents($path, true); foreach ($files as $f) { if ($f->isDir()) { continue; } $this->fs->copy($f->path(), $backupDir . '/' . $f->path()); } } } // Extract files $zip->extractTo($this->rootDir); $zip->close(); // Migrate DB $in = new ArrayInput([]); $in->setInteractive(false); $cmd = new MigrateCommand($this->df); $cmd->run($in, $output); // Reinstall plugins $packages = []; /** @var PluginWrapper */ foreach ($this->repo as $pw) { $packages[] = $pw->context->name->value; } $this->helper->require($packages, $output); // Move back backup files foreach ($paths as $path) { if ($this->fs->fileExists($backupDir . '/' . $path)) { $this->fs->copy('/' . $backupDir . '/' . $path, $path); $this->fs->delete($backupDir . '/' . $path); continue; } if ($this->fs->directoryExists($backupDir . '/' . $path)) { $files = $this->fs->listContents($backupDir . '/' . $path, true); foreach ($files as $f) { if ($f->isDir()) { continue; } $this->fs->copy($f->path(), substr($f->path(), strlen($backupDir))); } $this->fs->deleteDirectory($backupDir . '/' . $path); } } // Remove backup directory $this->fs->deleteDirectory($backupDir); // Extract locales /** @var ExtractLocaleMessagesCommand */ $cmd = $this->container->get(ExtractLocaleMessagesCommand::class); $cmd->run(new ArrayInput([]), $output); // Clear cache $this->cache->clearCache(); return Command::SUCCESS; } }