Skip to content

[WCM] Updated the styles of the assets:install command #15975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Finder\Finder;

Expand Down Expand Up @@ -68,6 +69,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output = new SymfonyStyle($input, $output);
$targetArg = rtrim($input->getArgument('target'), '/');

if (!is_dir($targetArg)) {
Expand All @@ -81,23 +83,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
$filesystem->mkdir($bundlesDir, 0777);

// relative implies symlink
$symlink = $input->getOption('symlink') || $input->getOption('relative');

if ($symlink) {
$output->writeln('Trying to install assets as <comment>symbolic links</comment>.');
} else {
$output->writeln('Installing assets as <comment>hard copies</comment>.');
}
$useSymlinks = $input->getOption('symlink') || $input->getOption('relative');
$symlinksSupported = false;

foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) {
if (is_dir($originDir = $bundle->getPath().'/Resources/public')) {
$targetDir = $bundlesDir.preg_replace('/bundle$/', '', strtolower($bundle->getName()));

$output->writeln(sprintf('Installing assets for <comment>%s</comment> into <comment>%s</comment>', $bundle->getNamespace(), $targetDir));
$output->text(sprintf('Installing assets for <comment>%s</comment> into <comment>%s</comment>', $bundle->getNamespace(), $targetDir));

$filesystem->remove($targetDir);

if ($symlink) {
if ($useSymlinks) {
if ($input->getOption('relative')) {
$relativeOriginDir = $filesystem->makePathRelative($originDir, realpath($bundlesDir));
} else {
Expand All @@ -109,11 +106,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!file_exists($targetDir)) {
throw new IOException('Symbolic link is broken');
}
$output->writeln('The assets were installed using symbolic links.');
$output->comment('The assets were installed using symbolic links.');
$symlinksSupported = true;
} catch (IOException $e) {
if (!$input->getOption('relative')) {
$this->hardCopy($originDir, $targetDir);
$output->writeln('It looks like your system doesn\'t support symbolic links, so the assets were installed by copying them.');
$output->comment('It looks like your system doesn\'t support symbolic links, so the assets were installed by copying them.');
}

// try again without the relative option
Expand All @@ -122,17 +120,27 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!file_exists($targetDir)) {
throw new IOException('Symbolic link is broken');
}
$output->writeln('It looks like your system doesn\'t support relative symbolic links, so the assets were installed by using absolute symbolic links.');
$output->comment('It looks like your system doesn\'t support relative symbolic links, so the assets were installed by using absolute symbolic links.');
} catch (IOException $e) {
$this->hardCopy($originDir, $targetDir);
$output->writeln('It looks like your system doesn\'t support symbolic links, so the assets were installed by copying them.');
$output->comment('It looks like your system doesn\'t support symbolic links, so the assets were installed by copying them.');
}
}

$output->newLine();
} else {
$this->hardCopy($originDir, $targetDir);
}
}
}

if (!$useSymlinks) {
$output->success('Assets were installed as hard copies.');
} elseif ($useSymlinks && !$symlinksSupported) {
$output->warning('Assets were installed as hard copies because your system does not support symlinks.');
} else {
$output->success('Assets were installed as symlinks.');
}
}

/**
Expand Down