N98\Magento\Command\Media\DumpCommand::execute PHP Method

execute() protected method

protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) : integer | null | void
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
return integer | null | void
    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();
    }