-
Notifications
You must be signed in to change notification settings - Fork 34
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
Command sylius:theme:assets:install --symlink --relative
sometimes remove origin files
#79
Comments
I made some time to look at stuff today, and honestly, I'm a bit confused by this bundle's asset installer, especially when comparing it to the The FrameworkBundle's command installs by either symlinking or copying (based on the provided options) the bundle's public directory. The |
I think I have a quite same problem. When I execute As a matter of fact, the file was there before the command. And after, the file has been modified as a symbolic link to himself. |
We also ran into this problem - specifically with the friendsofsymfony/jsrouting-bundle... |
same problem here after composer update
|
Same problem here with ckeditor-bundle (friendsofsymfony/ckeditor-bundle/src/Resources/public/adapters/jquery.js is removed) and pagerfanta-bundle (babdev/pagerfanta-bundle/public/css/pagerfanta.css is removed) |
same problem here with pimcore (/vendor/pimcore/admin-ui-classic-bundle/public/assets/imageEditor.js is removed) |
FYI for all who run into this kind of problem: We solved the issue by just not using the command provided by sylius. We implement 2 different ways in our projects which basically do the same as the command from sylius. Depending on the project we choose version 1 or 2. Version 1symlink via composer.json scripts Pro: simple to set up "scripts": {
"post-install-cmd": [
"@theme-scripts"
],
"post-update-cmd": [
"@theme-scripts"
],
"theme-scripts": [
"rm -rf web/_themes",
"mkdir -p public/_themes/dachcom-digital/default && ln -s ../../../bundles public/_themes/dachcom-digital/default/bundles",
"mkdir -p public/_themes/dachcom-digital/XY && ln -s ../../../bundles public/_themes/dachcom-digital/XY/bundles"
]
} Version 2Via EventListener - hooks into the Pro: Highly dynamic; copies all assets the same way you executed the default (symfony) Expand Code<?php
declare(strict_types=1);
namespace App\EventListener\Console;
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;
use Symfony\Bundle\FrameworkBundle\Command\AssetsInstallCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
class CommandExecutionListener implements EventSubscriberInterface
{
public function __construct(
private string $projectDir,
private Filesystem $filesystem,
private ThemeRepositoryInterface $themeRepository
) { }
public static function getSubscribedEvents(): array
{
return [
ConsoleEvents::TERMINATE => 'installThemeAssets'
];
}
public function installThemeAssets(ConsoleTerminateEvent $event): void
{
$command = $event->getCommand();
$input = $event->getInput();
$output = $event->getOutput();
$bundlesDir = $this->projectDir . '/public/bundles';
$destDirTpl = $this->projectDir . '/public/_themes/%s/default/bundles';
if ($command::class !== AssetsInstallCommand::class) {
return;
}
if ($event->getExitCode() !== Command::SUCCESS) {
$output->writeln('<info>[THEME] Skipping Sylius asset installation due to failure of "assets:install" command.</info>');
}
$output->writeln('<info>[THEME] Installing assets for SyliusThemeBundle...</info>');
$symlink = $input->getOption('symlink');
foreach ($this->themeRepository->findAll() as $theme) {
$pathParts = explode('/', $theme->getPath());
$themeDirName = $pathParts[array_key_last($pathParts)];
$destDir = sprintf($destDirTpl, $themeDirName);
if ($symlink) {
$this->symlink($bundlesDir, $destDir, true);
} else {
$this->hardCopy($bundlesDir, $destDir);
}
$output->writeln(sprintf('<info>[THEME] Installed assets for theme "%s" as %s.</info>', $theme->getName(), $symlink ? 'symlink' : 'hard copy'));
}
}
/**
* @throws IOException
*/
private function symlink(string $originDir, string $targetDir, bool $relative = false): void
{
if ($relative) {
$this->filesystem->mkdir(\dirname($targetDir));
$originDir = $this->filesystem->makePathRelative($originDir, realpath(\dirname($targetDir)));
}
$this->filesystem->symlink($originDir, $targetDir);
if (!file_exists($targetDir)) {
throw new IOException(sprintf('Symbolic link "%s" was created but appears to be broken.', $targetDir), 0, null, $targetDir);
}
}
private function hardCopy(string $originDir, string $targetDir): void
{
$this->filesystem->mkdir($targetDir, 0777);
$this->filesystem->mirror($originDir, $targetDir, Finder::create()->ignoreDotFiles(false)->in($originDir));
}
} |
Problem
Command
sylius:theme:assets:install --symlink --relative
removes some origin files when executed after executing the standardassets:install --symlink --relative
command.I think the problem is originated when
$target
is a symlink to$origin
at:SyliusThemeBundle/src/Asset/Installer/AssetsInstaller.php
Line 126 in 0785bbb
Not sure how to fix.
Reproducer
Output
user@host:/tmp$ composer create-project symfony/website-skeleton foobar ^4
user@host:/tmp$ cd foobar
user@host:/tmp/foobar$ sed -i 's/assets:install/assets:install --symlink --relative/g' composer.json
user@host:/tmp/foobar$ sed -i 's/"allow-contrib": false/"allow-contrib": true/g' composer.json
user@host:/tmp/foobar$ composer require friendsofsymfony/jsrouting-bundle
user@host:/tmp/foobar$ composer require sylius/theme-bundle
user@host:/tmp/foobar$ bin/console sylius:theme:assets:install --symlink --relative
The text was updated successfully, but these errors were encountered: