protected function execute(InputInterface $input, OutputInterface $output)
{
$commandConfig = $this->getCommandConfig();
$this->detectMagento($output);
$finder = new Finder();
$finder->files()->followLinks(true)->in($this->getApplication()->getMagentoRootFolder() . DIRECTORY_SEPARATOR . 'media');
if ($input->getOption('strip')) {
$finder->exclude($commandConfig['strip']['folders']);
}
$filename = (string) $input->getArgument('filename');
if (is_dir($filename)) {
// support for dot dir
$filename = realpath($filename);
$filename .= '/';
}
if (empty($filename) || is_dir($filename)) {
$filename .= 'media_' . date('Ymd_his') . '.zip';
}
$zip = new ZipArchive();
$zip->open($filename, ZIPARCHIVE::CREATE);
$zip->addEmptyDir('media');
$lastFolder = '';
foreach ($finder as $file) {
/* @var $file SplFileInfo */
$currentFolder = pathinfo($file->getRelativePathname(), PATHINFO_DIRNAME);
if ($currentFolder != $lastFolder) {
$output->writeln(sprintf('<info>Compress directory:</info> <comment>media/%s</comment>', $currentFolder));
}
$zip->addFile($file->getPathname(), 'media' . DIRECTORY_SEPARATOR . $file->getRelativePathname());
$lastFolder = $currentFolder;
}
$zip->close();
}