-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migration for missing
article-spacing-*
- Loading branch information
Showing
10 changed files
with
401 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" colors="true" bootstrap="vendor/autoload.php"> | ||
<coverage> | ||
<include> | ||
<directory>./src</directory> | ||
</include> | ||
</coverage> | ||
<php> | ||
<ini name="error_reporting" value="-1"/> | ||
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0"/> | ||
<env name="SYMFONY_PATCH_TYPE_DECLARATIONS" value="deprecations=0"/> | ||
<env name="APP_SECRET" value="foobar"/> | ||
<env name="DATABASE_URL" value="mysql://root@localhost:3306/ctm_core"/> | ||
</php> | ||
<testsuites> | ||
<testsuite name="contao-thememanager"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<listeners> | ||
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/> | ||
</listeners> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of Contao ThemeManager Core. | ||
* | ||
* (c) https://www.oveleon.de/ | ||
*/ | ||
|
||
namespace ContaoThemeManager\Core\Migration; | ||
|
||
use Contao\CoreBundle\Migration\AbstractMigration; | ||
use Contao\CoreBundle\Migration\MigrationResult; | ||
use Contao\StringUtil; | ||
use Contao\System; | ||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Exception; | ||
|
||
class ThemeConfigurationMigration extends AbstractMigration | ||
{ | ||
public function __construct(private readonly Connection $connection) | ||
{ | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function shouldRun(): bool | ||
{ | ||
$schemaManager = $this->connection->createSchemaManager(); | ||
|
||
if (!$schemaManager->tablesExist('tl_theme')) | ||
{ | ||
return false; | ||
} | ||
|
||
// ToDo: Rewrite | ||
/*$columns = $schemaManager->listTableColumns('tl_theme'); | ||
if (!isset($columns['themeConfig'])) { | ||
return false; | ||
}*/ | ||
|
||
try { | ||
$test = $this->connection->fetchOne("SELECT TRUE FROM tl_theme WHERE `themeConfig` NOT LIKE '%article-spacing-small%' LIMIT 1"); | ||
} catch (\Exception) { | ||
return false; | ||
} | ||
|
||
if (false !== $test) | ||
{ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function run(): MigrationResult | ||
{ | ||
$values = $this->connection->fetchAllKeyValue(" | ||
SELECT id, `themeConfig` | ||
FROM tl_theme | ||
WHERE `themeConfig` NOT LIKE '%article-spacing-small%' | ||
"); | ||
|
||
foreach ($values as $id => $value) | ||
{ | ||
$config = StringUtil::deserialize($value, true); | ||
|
||
$update = [ | ||
'article-spacing-xs-small' => 'article-spacing-small', | ||
'article-spacing-xs-medium' => 'article-spacing-medium', | ||
'article-spacing-xs-large' => 'article-spacing-large' | ||
]; | ||
|
||
foreach ($update as $old => $new) | ||
{ | ||
$this->setAndUpdateConfigVariable($new, $old, $config); | ||
} | ||
|
||
$this->connection->update('tl_theme', ['themeConfig' => serialize($config)], ['id' => (int) $id]); | ||
} | ||
|
||
return $this->createResult(true); | ||
} | ||
|
||
private function setAndUpdateConfigVariable(string $newKey, string $oldKey, array &$config): void | ||
{ | ||
if (isset($config[$oldKey]) && !isset($config[$newKey])) | ||
{ | ||
$config[$newKey] = $config[$oldKey]; | ||
$config[$oldKey] = '$'.$newKey; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ContaoManager; | ||
|
||
use Contao\CoreBundle\ContaoCoreBundle; | ||
use Contao\ManagerPlugin\Bundle\Config\BundleConfig; | ||
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface; | ||
use ContaoThemeManager\Core\ContaoManager\Plugin; | ||
use Oveleon\ContaoComponentStyleManager\ContaoComponentStyleManager; | ||
use Oveleon\ContaoThemeCompilerBundle\ContaoThemeCompilerBundle; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class PluginTest extends TestCase | ||
{ | ||
public function testReturnsTheBundles(): void | ||
{ | ||
/** @var BundleConfig $config */ | ||
$config = (new Plugin())->getBundles($this->createMock(ParserInterface::class))[0]; | ||
|
||
$plugins = [ | ||
ContaoCoreBundle::class, | ||
ContaoComponentStyleManager::class, | ||
ContaoThemeCompilerBundle::class, | ||
]; | ||
|
||
$this->assertInstanceOf(BundleConfig::class, $config); | ||
$this->assertSame($plugins, $config->getLoadAfter()); | ||
$this->assertSame(['contao-thememanager'], $config->getReplace()); | ||
} | ||
} |
Oops, something went wrong.