Skip to content

Commit

Permalink
Merge tag v2.4.0 into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Dec 6, 2024
1 parent 1ba7ed0 commit 311cee1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 166 deletions.
24 changes: 12 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@
"prefer-stable": true,
"require": {
"php": ">=8.2",
"roadiz/core-bundle": "2.4.x-dev",
"roadiz/openid": "2.4.x-dev",
"roadiz/core-bundle": "2.4.*",
"roadiz/openid": "2.4.*",
"symfony/framework-bundle": "6.4.*"
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.4",
"phpstan/phpstan": "^1.5.3",
"phpstan/phpstan-doctrine": "^1.3",
"phpstan/phpstan-symfony": "^1.1.8",
"roadiz/doc-generator": "2.4.x-dev",
"roadiz/documents": "2.4.x-dev",
"roadiz/dts-generator": "2.4.x-dev",
"roadiz/entity-generator": "2.4.x-dev",
"roadiz/jwt": "2.4.x-dev",
"roadiz/markdown": "2.4.x-dev",
"roadiz/models": "2.4.x-dev",
"roadiz/random": "2.4.x-dev"
"roadiz/doc-generator": "2.4.*",
"roadiz/documents": "2.4.*",
"roadiz/dts-generator": "2.4.*",
"roadiz/entity-generator": "2.4.*",
"roadiz/jwt": "2.4.*",
"roadiz/markdown": "2.4.*",
"roadiz/models": "2.4.*",
"roadiz/random": "2.4.*"
},
"config": {
"optimize-autoloader": true,
Expand All @@ -56,8 +56,8 @@
},
"extra": {
"branch-alias": {
"dev-main": "2.3.x-dev",
"dev-develop": "2.4.x-dev"
"dev-main": "2.4.x-dev",
"dev-develop": "2.5.x-dev"
}
}
}
17 changes: 5 additions & 12 deletions src/Theme/StaticThemeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,14 @@

class StaticThemeResolver implements ThemeResolverInterface
{
/**
* @var array<Theme>
*/
protected array $themes;
protected Stopwatch $stopwatch;
protected bool $installMode = false;

/**
* @param array<Theme> $themes
*/
public function __construct(array $themes, Stopwatch $stopwatch, bool $installMode = false)
{
$this->stopwatch = $stopwatch;
$this->installMode = $installMode;
$this->themes = $themes;
public function __construct(
protected array $themes,
protected readonly Stopwatch $stopwatch,
protected readonly bool $installMode = false,
) {
usort($this->themes, [static::class, 'compareThemePriority']);
}

Expand Down
146 changes: 4 additions & 142 deletions src/Theme/ThemeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,164 +4,26 @@

namespace RZ\Roadiz\CompatBundle\Theme;

use Doctrine\Common\Collections\ArrayCollection;
use Psr\Log\LoggerInterface;
use RZ\Roadiz\CoreBundle\Cache\Clearer\OPCacheClearer;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\Process\Process;

class ThemeGenerator
{
public const METHOD_COPY = 'copy';
public const METHOD_ABSOLUTE_SYMLINK = 'absolute symlink';
public const METHOD_RELATIVE_SYMLINK = 'relative symlink';
public const REPOSITORY = 'https://github.com/roadiz/BaseTheme.git';

protected Filesystem $filesystem;
protected string $projectDir;
protected string $publicDir;
protected string $cacheDir;
protected LoggerInterface $logger;

public function __construct(
string $projectDir,
string $publicDir,
string $cacheDir,
LoggerInterface $logger,
protected readonly string $projectDir,
protected readonly string $publicDir,
protected readonly string $cacheDir,
protected readonly LoggerInterface $logger,
) {
$this->filesystem = new Filesystem();
$this->projectDir = $projectDir;
$this->publicDir = $publicDir;
$this->cacheDir = $cacheDir;
$this->logger = $logger;
}

/**
* @return $this
*/
public function downloadTheme(ThemeInfo $themeInfo, string $branch = 'master'): ThemeGenerator
{
if (!$themeInfo->exists()) {
/*
* Clone BaseTheme
*/
$process = new Process(
['git', 'clone', '-b', $branch, static::REPOSITORY, $themeInfo->getThemePath()]
);
$process->run();
$this->logger->info('BaseTheme cloned into '.$themeInfo->getThemePath());
} else {
$this->logger->info($themeInfo->getClassname().' already exists.');
}

return $this;
}

/**
* @return $this
*/
public function renameTheme(ThemeInfo $themeInfo): ThemeGenerator
{
if (!$themeInfo->exists()) {
throw new FileException($themeInfo->getThemePath().' theme does not exist.');
}
if ($themeInfo->isProtected()) {
throw new \InvalidArgumentException($themeInfo->getThemeName().' is protected and cannot renamed.');
}
/*
* Remove existing Git history.
*/
$this->filesystem->remove($themeInfo->getThemePath().'/.git');
$this->logger->info('Remove Git history.');

/*
* Rename main theme class.
*/
$mainClassFile = $themeInfo->getThemePath().'/'.$themeInfo->getThemeName().'App.php';
if (!$this->filesystem->exists($mainClassFile)) {
$this->filesystem->rename(
$themeInfo->getThemePath().'/BaseThemeApp.php',
$mainClassFile
);
/*
* Force Zend OPcache to reset file
*/
if (function_exists('opcache_invalidate')) {
opcache_invalidate($mainClassFile, true);
}
if (function_exists('apcu_clear_cache')) {
apcu_clear_cache();
}
$this->logger->info('Rename main theme class.');
}

$serviceProviderFile = $themeInfo->getThemePath().
'/Services/'.$themeInfo->getThemeName().'ServiceProvider.php';
if (!$this->filesystem->exists($serviceProviderFile)) {
$this->filesystem->rename(
$themeInfo->getThemePath().'/Services/BaseThemeServiceProvider.php',
$serviceProviderFile
);
/*
* Force Zend OPcache to reset file
*/
if (function_exists('opcache_invalidate')) {
opcache_invalidate($serviceProviderFile, true);
}
if (function_exists('apcu_clear_cache')) {
apcu_clear_cache();
}
$this->logger->info('Rename theme service provider class.');
}

/*
* Rename every occurrence of BaseTheme in your theme.
*/
$processes = new ArrayCollection();
$processes->add(new Process(
[
'find', $themeInfo->getThemePath(), '-type', 'f', '-exec', 'sed', '-i.bak',
'-e', 's/BaseTheme/'.$themeInfo->getThemeName().'/g', '{}', ';',
],
null,
['LC_ALL' => 'C']
));
$processes->add(new Process(
[
'find', $themeInfo->getThemePath(), '-type', 'f', '-exec', 'sed', '-i.bak',
'-e', 's/Base theme/'.$themeInfo->getName().' theme/g', '{}', ';',
],
null,
['LC_ALL' => 'C']
));
$processes->add(new Process(
[
'find', $themeInfo->getThemePath().'/static', '-type', 'f', '-exec', 'sed', '-i.bak',
'-e', 's/Base/'.$themeInfo->getName().'/g', '{}', ';',
],
null,
['LC_ALL' => 'C']
));
$processes->add(new Process(
[
'find', $themeInfo->getThemePath(), '-type', 'f', '-name', '*.bak', '-exec', 'rm', '-f', '{}', ';',
],
null,
['LC_ALL' => 'C']
));
$this->logger->info('Rename every occurrences of BaseTheme in your theme.');
/** @var Process $process */
foreach ($processes as $process) {
$process->run();
}

$cacheClearer = new OPCacheClearer();
$cacheClearer->clear();

return $this;
}

public function installThemeAssets(ThemeInfo $themeInfo, string $expectedMethod): ?string
Expand Down

0 comments on commit 311cee1

Please sign in to comment.