Skip to content

Commit

Permalink
Migration for missing article-spacing-*
Browse files Browse the repository at this point in the history
  • Loading branch information
zoglo committed Jan 22, 2024
1 parent 7e33d18 commit e231504
Show file tree
Hide file tree
Showing 10 changed files with 401 additions and 8 deletions.
12 changes: 11 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
"symfony/filesystem": "^5.4 || ^6.0"
},
"require-dev": {
"contao/manager-plugin": "^2.3.1"
"contao/manager-plugin": "^2.3.1",
"contao/test-case": "^5.1",
"phpunit/phpunit": "^9.5.19",
"symfony/phpunit-bridge": "^5.4 || ^6.0"
},
"suggest": {
"contao-thememanager/ctm-tiny-slider": "For integrating the well known tiny-slider into the thememanager"
Expand Down Expand Up @@ -74,5 +77,12 @@
"dev-main": "2.0.x-dev"
},
"contao-manager-plugin": "ContaoThemeManager\\Core\\ContaoManager\\Plugin"
},
"config": {
"allow-plugins": {
"contao-components/installer": true,
"php-http/discovery": true,
"contao/manager-plugin": true
}
}
}
7 changes: 7 additions & 0 deletions config/migrations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ services:
- '@contao.framework'
tags:
- { name: contao.migration, priority: 0 }

ContaoThemeManager\Core\Migration\ThemeConfigurationMigration:
arguments:
- '@database_connection'
- '@contao.framework'
tags:
- { name: contao.migration, priority: 0 }
24 changes: 24 additions & 0 deletions contao/languages/de/tl_thememanager.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -3240,6 +3240,14 @@
<target>Hier können Sie das horizontale Polster (padding) von Artikeln für den Bruchpunkt 's' einstellen.</target>
</trans-unit>

<trans-unit id="tl_thememanager.article-spacing-small.0">
<source>$article-spacing-small</source>
<target>$article-spacing-small</target>
</trans-unit>
<trans-unit id="tl_thememanager.article-spacing-small.1">
<source>Here you can set the small vertical padding for articles for mobile devices.</source>
<target>Hier können Sie das kleine vertikale Polster (padding) von Artikeln für mobile Geräte einstellen.</target>
</trans-unit>
<trans-unit id="tl_thememanager.article-spacing-xs-small.0">
<source>$article-spacing-xs-small</source>
<target>$article-spacing-xs-small</target>
Expand Down Expand Up @@ -3281,6 +3289,14 @@
<target>Hier können Sie das kleine vertikale Polster (padding) von Artikeln auf sehr großen Geräten einstellen.</target>
</trans-unit>

<trans-unit id="tl_thememanager.article-spacing-medium.0">
<source>$article-spacing-medium</source>
<target>$article-spacing-medium</target>
</trans-unit>
<trans-unit id="tl_thememanager.article-spacing-medium.1">
<source>Here you can set the medium vertical padding for articles for mobile devices.</source>
<target>Hier können Sie das mittlere vertikale Polster (padding) von Artikeln für mobile Geräte einstellen.</target>
</trans-unit>
<trans-unit id="tl_thememanager.article-spacing-xs-medium.0">
<source>$article-spacing-xs-medium</source>
<target>$article-spacing-xs-medium</target>
Expand Down Expand Up @@ -3322,6 +3338,14 @@
<target>Hier können Sie das mittlere vertikale Polster (padding) von Artikeln auf sehr großen Geräten einstellen.</target>
</trans-unit>

<trans-unit id="tl_thememanager.article-spacing-large.0">
<source>$article-spacing-large</source>
<target>$article-spacing-large</target>
</trans-unit>
<trans-unit id="tl_thememanager.article-spacing-large.1">
<source>Here you can set the large vertical padding for articles for mobile devices.</source>
<target>Hier können Sie das große vertikale Polster (padding) von Artikeln für mobile Geräte einstellen.</target>
</trans-unit>
<trans-unit id="tl_thememanager.article-spacing-xs-large.0">
<source>$article-spacing-xs-large</source>
<target>$article-spacing-xs-large</target>
Expand Down
18 changes: 18 additions & 0 deletions contao/languages/en/tl_thememanager.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2459,6 +2459,12 @@
<source>Here you can set the horizontal article padding for the 's'-breakpoint.</source>
</trans-unit>

<trans-unit id="tl_thememanager.article-spacing-small.0">
<source>$article-spacing-small</source>
</trans-unit>
<trans-unit id="tl_thememanager.article-spacing-small.1">
<source>Here you can set the small vertical padding for articles for mobile devices.</source>
</trans-unit>
<trans-unit id="tl_thememanager.article-spacing-xs-small.0">
<source>$article-spacing-xs-small</source>
</trans-unit>
Expand Down Expand Up @@ -2490,6 +2496,12 @@
<source>Here you can set the small vertical padding for articles for extra large devices.</source>
</trans-unit>

<trans-unit id="tl_thememanager.article-spacing-medium.0">
<source>$article-spacing-medium</source>
</trans-unit>
<trans-unit id="tl_thememanager.article-spacing-medium.1">
<source>Here you can set the medium vertical padding for articles for mobile devices.</source>
</trans-unit>
<trans-unit id="tl_thememanager.article-spacing-xs-medium.0">
<source>$article-spacing-xs-medium</source>
</trans-unit>
Expand Down Expand Up @@ -2521,6 +2533,12 @@
<source>Here you can set the medium vertical padding for articles for extra large devices.</source>
</trans-unit>

<trans-unit id="tl_thememanager.article-spacing-large.0">
<source>$article-spacing-large</source>
</trans-unit>
<trans-unit id="tl_thememanager.article-spacing-large.1">
<source>Here you can set the large vertical padding for articles for mobile devices.</source>
</trans-unit>
<trans-unit id="tl_thememanager.article-spacing-xs-large.0">
<source>$article-spacing-xs-large</source>
</trans-unit>
Expand Down
23 changes: 23 additions & 0 deletions phpunit.xml.dist
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>
15 changes: 8 additions & 7 deletions public/framework/scss/ctm_layout/_article-spacing.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Y-spacings (vertical top and bottom)
$spacings-list-init: (
1: $article-spacing-xs-small, 2: $article-spacing-xs-medium, 3: $article-spacing-xs-large
1: $article-spacing-small, 2: $article-spacing-medium, 3: $article-spacing-large
);

$spacings-list-bp: (
xs: (1: $article-spacing-xs-small, 2: $article-spacing-xs-medium, 3: $article-spacing-xs-large),
s: (1: $article-spacing-s-small, 2: $article-spacing-s-medium, 3: $article-spacing-s-large),
m: (1: $article-spacing-m-small, 2: $article-spacing-m-medium, 3: $article-spacing-m-large),
l: (1: $article-spacing-l-small, 2: $article-spacing-l-medium, 3: $article-spacing-l-large),
Expand Down Expand Up @@ -50,9 +51,9 @@ main .article_inside {

:root {
--art-ox:#{$article-outer-padding};
--art-py-1:#{$article-spacing-xs-small};
--art-py-2:#{$article-spacing-xs-medium};
--art-py-3:#{$article-spacing-xs-large};
--art-py-1:#{$article-spacing-small};
--art-py-2:#{$article-spacing-medium};
--art-py-3:#{$article-spacing-large};
}

@each $size, $spacing in $spacings-list-init {
Expand Down Expand Up @@ -98,11 +99,11 @@ main .article_inside {
}
}
@include media-breakpoint($bp) {
@if ($bp == 'xs') {:root {--art-ox:#{$article-outer-padding-xs};}}
@if map-has-key($spacings-list-bp, $bp) {
:root {
@if ($bp == 's') {--art-ox:#{$article-outer-padding-s};}
@if ($bp == 'm') {--art-ox:0px;}
@if ($bp == 'xs') {--art-ox:#{$article-outer-padding-xs};}
@if ($bp == 's') {--art-ox:#{$article-outer-padding-s};}
@if ($bp == 'm') {--art-ox:0px;}
@each $size, $spacing in $list {--art-py-#{$size}:#{$spacing};}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/EventListener/DataContainer/DataContainerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
use Contao\ContentModel;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\CoreBundle\Security\ContaoCorePermissions;
use Contao\Database;
use Contao\DataContainer;
use Contao\Input;
use Contao\StringUtil;
use Contao\System;
use ContaoThemeManager\Core\Migration\ThemeConfigurationMigration;
use Doctrine\DBAL\Connection;
use Symfony\Component\Security\Core\Security;
use Contao\Message;
Expand Down
99 changes: 99 additions & 0 deletions src/Migration/ThemeConfigurationMigration.php
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;
}
}
}
32 changes: 32 additions & 0 deletions tests/ContaoManager/PluginTest.php
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());
}
}
Loading

0 comments on commit e231504

Please sign in to comment.