kernel = $kernel; parent::__construct(); } protected function configure() { $this ->setDescription('Cleanup runs') ->setHelp('This command cleans the runs table'); } protected function execute(InputInterface $input, OutputInterface $output) { global $kernel; $zip = $kernel->getCacheDir() . 'website.zip'; $mddir = $kernel->getCacheDir() . 'pages'; $assetdir = $kernel->getProjectDir() . '/public/assets/'; file_put_contents($zip, file_get_contents($_ENV['DATADIR'])); $zipobj = new \ZipArchive(); $res = $zipobj->open($zip); if ($res === TRUE) { if(is_dir($mddir)) $this->recursiveRemoveDirectory($mddir); if(is_dir($assetdir)) $this->recursiveRemoveDirectory($assetdir); $zipobj->extractTo($kernel->getCacheDir()); $zipobj->close(); rename($kernel->getCacheDir() . 'Website/assets', $assetdir); rename($kernel->getCacheDir() . 'Website', $mddir); return Command::SUCCESS; } return Command::FAILURE; } function recursiveRemoveDirectory($directory) { foreach(glob($directory . "/*") as $file) { if(is_dir($file)) { $this->recursiveRemoveDirectory($file); } else { unlink($file); } } rmdir($directory); } }