/** * @param string $path * * @return bool */ private function emptyDirectory($path) { $errors = array(); $dir = new FilesystemIterator($path); foreach ($dir as $file => $info) { if ($info->isDir()) { $this->verbose('<debug>Filesystem::recursiveRemoveDirectory() <comment>' . $file . '</comment></debug>'); if (!isset($fs)) { $fs = new Filesystem(); } if (!$fs->recursiveRemoveDirectory($file)) { $errors[] = $file; } } else { $this->verbose('<debug>unlink() <comment>' . $file . '</comment></debug>'); if (!unlink($file)) { $errors[] = $file; } } } if (!$errors) { return true; } $message = sprintf("Failed to empty directory %s, unable to remove:\n", var_export($path, true)); foreach ($errors as $error) { $message .= sprintf(" - %s\n", var_export($error, true)); } throw new RuntimeException($message); }
public function testExecute() { $application = $this->getApplication(); $application->add(new ListCommand()); $command = $this->getApplication()->find('dev:module:create'); $root = getcwd(); // delete old module if (is_dir($root . '/N98Magerun_UnitTest')) { $filesystem = new Filesystem(); $filesystem->recursiveRemoveDirectory($root . '/N98Magerun_UnitTest'); clearstatcache(); } $commandTester = new CommandTester($command); $commandTester->execute(array('command' => $command->getName(), '--add-all' => true, '--add-setup' => true, '--add-readme' => true, '--add-composer' => true, '--modman' => true, '--description' => 'Unit Test Description', '--author-name' => 'Unit Test', '--author-email' => '*****@*****.**', 'vendorNamespace' => 'N98Magerun', 'moduleName' => 'UnitTest')); $this->assertFileExists($root . '/N98Magerun_UnitTest/composer.json'); $this->assertFileExists($root . '/N98Magerun_UnitTest/readme.md'); $moduleBaseFolder = $root . '/N98Magerun_UnitTest/src/app/code/local/N98Magerun/UnitTest/'; $this->assertFileExists($moduleBaseFolder . 'etc/config.xml'); $this->assertFileExists($moduleBaseFolder . 'Block'); $this->assertFileExists($moduleBaseFolder . 'Model'); $this->assertFileExists($moduleBaseFolder . 'Helper'); $this->assertFileExists($moduleBaseFolder . 'data/n98magerun_unittest_setup'); $this->assertFileExists($moduleBaseFolder . 'sql/n98magerun_unittest_setup'); // delete old module if (is_dir($root . '/N98Magerun_UnitTest')) { $filesystem = new Filesystem(); $filesystem->recursiveRemoveDirectory($root . '/N98Magerun_UnitTest'); clearstatcache(); } }
/** * @param $root * @return bool|Filesystem */ protected function _deleteOldModule($root) { // delete old module $filesystem = false; if (is_dir($root . '/N98Magerun_UnitTest')) { $filesystem = new Filesystem(); $filesystem->recursiveRemoveDirectory($root . '/N98Magerun_UnitTest'); clearstatcache(); } return $filesystem; }
/** * @return void */ public function execute() { if (is_dir(getcwd() . '/vendor')) { $finder = new Finder(); $finder->files()->depth(3)->in(getcwd() . '/vendor'); if ($finder->count() == 0) { $filesystem = new Filesystem(); $filesystem->recursiveRemoveDirectory(getcwd() . '/vendor'); } } }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|void */ protected function execute(InputInterface $input, OutputInterface $output) { $this->detectMagento($output); $finder = Finder::create()->directories()->depth(0)->in($this->getApplication()->getMagentoRootFolder() . '/var/generation'); $vendorNameToFilter = $input->getArgument('vendorName'); $filesystem = new Filesystem(); foreach ($finder as $directory) { if (!empty($vendorNameToFilter) && $directory->getBasename() != $vendorNameToFilter) { continue; } /* @var $directory \Symfony\Component\Finder\SplFileInfo */ $filesystem->recursiveRemoveDirectory($directory->getPathname()); $output->writeln('<info>Removed <comment>' . $directory->getBasename() . '</comment> folder</info>'); } }
/** * @param InputInterface $input * @param OutputInterface $output * * @throws RuntimeException * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $this->detectMagento($output); if ($this->initMagento()) { $fileName = $input->getArgument('log_filename'); if ($fileName === null) { $path = $this->askLogFile($output); } else { $path = $this->getLogDir() . DIRECTORY_SEPARATOR . $fileName; } if ($this->logfileExists(basename($path))) { $size = @filesize($path); if ($size === false) { throw new RuntimeException('Couldn\\t detect filesize.'); } } else { $size = 0; } if ($input->getOption('human')) { $output->writeln(\N98\Util\Filesystem::humanFileSize($size)); } else { $output->writeln("{$size}"); } } }
/** * @param InputInterface $input * @param OutputInterface $output * * @return int|void */ protected function execute(InputInterface $input, OutputInterface $output) { $this->chooseInstallationFolder($input, $output); $this->detectMagento($output); $this->getApplication()->setAutoExit(false); /* @var $dialog DialogHelper */ $dialog = $this->getHelper('dialog'); $shouldUninstall = $input->getOption('force'); if (!$shouldUninstall) { $shouldUninstall = $dialog->askConfirmation($output, '<question>Really uninstall ?</question> <comment>[n]</comment>: ', false); } if ($shouldUninstall) { $input = new StringInput('db:drop --force'); $this->getApplication()->run($input, $output); $fileSystem = new Filesystem(); $output->writeln('<info>Remove directory </info><comment>' . $this->_magentoRootFolder . '</comment>'); try { $fileSystem->recursiveRemoveDirectory($this->_magentoRootFolder); } catch (Exception $e) { $output->writeln('<error>' . $e->getMessage() . '</error>'); } $output->writeln('<info>Done</info>'); } }
/** * @param array $vars * * @return array */ protected function formatVariables(array $vars) { $rounding = (int) $this->_input->getOption('rounding'); if ($rounding > -1) { foreach ($vars as $k => &$v) { if (true === $this->allowRounding($k)) { $v = Filesystem::humanFileSize($v, $rounding); } if (isset($this->_specialFormat[$k])) { $v = $this->{$this->_specialFormat[$k]}($v); } } unset($v); } $maxWidth = $this->getMaxValueWidth($vars); // align=right foreach ($vars as &$v) { $v = str_pad($v, $maxWidth, ' ', STR_PAD_LEFT); } return $vars; }
/** * Remove empty composer extraction folder */ protected function removeEmptyFolders() { if (is_dir(getcwd() . '/vendor')) { $finder = new Finder(); $finder->files()->depth(3)->in(getcwd() . '/vendor'); if ($finder->count() == 0) { $filesystem = new Filesystem(); $filesystem->recursiveRemoveDirectory(getcwd() . '/vendor'); } } }
/** * @param InputInterface $input * @param OutputInterface $output * @return bool */ public function downloadMagento(InputInterface $input, OutputInterface $output) { try { $package = $this->createComposerPackageByConfig($this->config['magentoVersionData']); $this->config['magentoPackage'] = $package; if (file_exists($this->config['installationFolder'] . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Mage.php')) { $output->writeln('<error>A magento installation already exists in this folder </error>'); return false; } $composer = $this->getComposer($input, $output); $targetFolder = $this->getTargetFolderByType($composer, $package, $this->config['installationFolder']); $this->config['magentoPackage'] = $this->downloadByComposerConfig($input, $output, $package, $targetFolder, true); if ($this->isSourceTypeRepository($package->getSourceType())) { $filesystem = new \N98\Util\Filesystem(); $filesystem->recursiveCopy($targetFolder, $this->config['installationFolder'], array('.git', '.hg')); } else { $filesystem = new \Composer\Util\Filesystem(); $filesystem->copyThenRemove($this->config['installationFolder'] . '/_n98_magerun_download', $this->config['installationFolder']); } if (version_compare(PHP_VERSION, '5.4.0') >= 0) { // Patch installer $this->patchMagentoInstallerForPHP54($this->config['installationFolder']); } } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . '</error>'); return false; } return true; }
/** * @param int $bytes * @param int $decimalPlaces * @param string $expected * @dataProvider convertedBytesProvider */ public function testConvertBytesToHumanReadable($bytes, $decimalPlaces, $expected) { $res = Filesystem::humanFileSize($bytes, $decimalPlaces); $this->assertSame($expected, $res); }