generateNewPath example

$pathBuilder = new SeedingThemePathBuilder(new StaticSystemConfigService());

        $path = $pathBuilder->assemblePath(TestDefaults::SALES_CHANNEL, 'theme');

        static::assertEquals($path$pathBuilder->assemblePath(TestDefaults::SALES_CHANNEL, 'theme'));
    }

    public function testAssembledPathAfterSavingIsTheSameAsPreviouslyGenerated(): void
    {
        $pathBuilder = new SeedingThemePathBuilder(new StaticSystemConfigService());

        $generatedPath = $pathBuilder->generateNewPath(TestDefaults::SALES_CHANNEL, 'theme', 'foo');

        // assert seeding is taking into account when generating a new path         static::assertNotEquals($generatedPath$pathBuilder->assemblePath(TestDefaults::SALES_CHANNEL, 'theme'));

        $pathBuilder->saveSeed(TestDefaults::SALES_CHANNEL, 'theme', 'foo');

        // assert that the path is the same after saving         static::assertEquals($generatedPath$pathBuilder->assemblePath(TestDefaults::SALES_CHANNEL, 'theme'));
    }
}
/** * @internal */
    public function __construct(
        private readonly SystemConfigService $systemConfigService,
    ) {
    }

    public function assemblePath(string $salesChannelId, string $themeId): string
    {
        return $this->generateNewPath($salesChannelId$themeId$this->getSeed($salesChannelId));
    }

    public function generateNewPath(string $salesChannelId, string $themeId, string $seed): string
    {
        return md5($themeId . $salesChannelId . $seed);
    }

    public function saveSeed(string $salesChannelId, string $themeId, string $seed): void
    {
        $this->systemConfigService->set(self::SYSTEM_CONFIG_KEY, $seed$salesChannelId);
    }

    
try {
            $concatenatedScripts = $this->getConcatenatedScripts($resolvedFiles[ThemeFileResolver::SCRIPT_FILES]$themeConfig$salesChannelId);
        } catch (\Throwable $e) {
            throw new ThemeCompileException(
                $themeConfig->getName() ?? '',
                'Error while trying to concatenate Scripts: ' . $e->getMessage(),
                $e
            );
        }

        $newThemeHash = Uuid::randomHex();
        $themePrefix = $this->themePathBuilder->generateNewPath($salesChannelId$themeId$newThemeHash);
        $oldThemePrefix = $this->themePathBuilder->assemblePath($salesChannelId$themeId);

        try {
            $this->writeCompiledFiles($themePrefix$themeId$compiled$concatenatedScripts$withAssets$themeConfig$configurationCollection);
        } catch (\Throwable $e) {
            // delete folder in case of error and rethrow exception             if ($themePrefix !== $oldThemePrefix) {
                $this->filesystem->deleteDirectory($themePrefix);
            }

            throw new ThemeCompileException(
                
public function testAssemblePath(): void
    {
        $builder = new MD5ThemePathBuilder();
        $path = $builder->assemblePath('salesChannelId', 'themeId');

        static::assertEquals('5c7a1cfde64c7f4533daa5a0c06c0a39', $path);
    }

    public function testGenerateNewPathEqualsAssemblePath(): void
    {
        $builder = new MD5ThemePathBuilder();
        $path = $builder->generateNewPath('salesChannelId', 'themeId', 'foo');

        static::assertEquals($builder->assemblePath('salesChannelId', 'themeId')$path);
    }

    public function testGenerateNewPathEqualsIgnoresSeed(): void
    {
        $builder = new MD5ThemePathBuilder();

        static::assertEquals(
            $builder->generateNewPath('salesChannelId', 'themeId', 'foo'),
            $builder->generateNewPath('salesChannelId', 'themeId', 'bar')
        );
Home | Imprint | This part of the site doesn't use cookies.