Skip to content

Commit

Permalink
Fix wrapper installer failing on deeper var folder structures (defaul…
Browse files Browse the repository at this point in the history
…t on v2) (#158)

Change what was done in #125 to check on global folder instead of IO dir,
as IO dir can be (and is on v2) "web/var/site/storage". So deleting storage
folder would still cause symlink code below to fail as the folder still
contained a folder.
  • Loading branch information
andrerom authored Aug 12, 2018
1 parent afa769f commit f49ac16
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions bundle/Command/LegacyWrapperInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Finder\Finder;
use FilesystemIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

class LegacyWrapperInstallCommand extends ContainerAwareCommand
{
Expand Down Expand Up @@ -53,12 +56,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
*/
$filesystem = $this->getContainer()->get('filesystem');
$legacyRootDir = rtrim($this->getContainer()->getParameter('ezpublish_legacy.root_dir'), '/');
$defaultIoRootDir = $this->getContainer()->getParameter('ezsettings.default.io.root_dir');

// Removes empty IO root folder which is created by IO Services
if (count(glob("$defaultIoRootDir/*", GLOB_NOSORT)) === 0) {
$filesystem->remove($defaultIoRootDir);
}

$output->writeln(sprintf("Installing eZ Publish legacy assets from $legacyRootDir using the <comment>%s</comment> option", $input->getOption('symlink') ? 'symlink' : 'hard copy'));
$symlink = $input->getOption('symlink');
Expand All @@ -70,9 +67,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$originDir = "$legacyRootDir/$folder";

// Check if directory exists (not link) and is not empty to avoid removing things that should be backed up
if (!$force && !is_link($targetDir) && is_dir($targetDir) && count(glob("$targetDir/*", GLOB_NOSORT)) > 0) {
if (!$force && !is_link($targetDir) && is_dir($targetDir) && !$this->isDirectoryEmpty($targetDir)) {
$output->writeln(<<<EOT
Skipping: The folder "$targetDir" already exists and seems to contain content!
<warning>Skipping: The folder "$targetDir" already exists and seems to contain content!</warning>
Make sure to backup this content and move it into corresponding legacy folder which will be setup to symlink / copy
to this folder before you remove it, then re-run this command.
Expand Down Expand Up @@ -147,4 +144,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
$filesystem->dumpFile($newFrontController, $code);
}
}

private function isDirectoryEmpty($path)
{
$directory = new RecursiveDirectoryIterator(
$path,
FilesystemIterator::FOLLOW_SYMLINKS | FilesystemIterator::SKIP_DOTS
);
$iterator = new RecursiveIteratorIterator($directory);

foreach ($iterator as $item) {
return false;
}

return true;
}
}

0 comments on commit f49ac16

Please sign in to comment.