Skip to content
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

Also migrate the "useFolderUrl" setting #1987

Merged
merged 6 commits into from
Jul 26, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 23 additions & 3 deletions core-bundle/src/Migration/Version410/RoutingMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace Contao\CoreBundle\Migration\Version410;

use Contao\Config;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\CoreBundle\Migration\AbstractMigration;
use Contao\CoreBundle\Migration\MigrationResult;
use Doctrine\DBAL\Connection;
Expand All @@ -29,6 +31,11 @@ class RoutingMigration extends AbstractMigration
*/
private $connection;

/**
* @var ContaoFramework
*/
private $framework;

/**
* @var string
*/
Expand All @@ -39,9 +46,10 @@ class RoutingMigration extends AbstractMigration
*/
private $prependLocale;

public function __construct(Connection $connection, string $urlSuffix = '.html', bool $prependLocale = false)
public function __construct(Connection $connection, ContaoFramework $framework, string $urlSuffix = '.html', bool $prependLocale = false)
fritzmg marked this conversation as resolved.
Show resolved Hide resolved
{
$this->connection = $connection;
$this->framework = $framework;
$this->urlSuffix = $urlSuffix;
$this->prependLocale = $prependLocale;
}
Expand All @@ -56,7 +64,7 @@ public function shouldRun(): bool

$columns = $schemaManager->listTableColumns('tl_page');

return !isset($columns['urlprefix']) && !isset($columns['urlsuffix']);
return !isset($columns['urlprefix']) && !isset($columns['urlsuffix']) && !isset($columns['usefolderurl']);
}

public function run(): MigrationResult
Expand All @@ -67,7 +75,10 @@ public function run(): MigrationResult
$urlSuffix = new Column('urlSuffix', new StringType());
$urlSuffix->setColumnDefinition("varchar(16) NOT NULL default '.html'");

$diff = new TableDiff('tl_page', [$urlPrefix, $urlSuffix]);
$useFolderUrl = new Column('useFolderUrl', new StringType());
$useFolderUrl->setColumnDefinition("char(1) NOT NULL default ''");

$diff = new TableDiff('tl_page', [$urlPrefix, $urlSuffix, $useFolderUrl]);
$sql = $this->connection->getDatabasePlatform()->getAlterTableSQL($diff);

foreach ($sql as $statement) {
Expand All @@ -81,6 +92,15 @@ public function run(): MigrationResult
->execute(['suffix' => $this->urlSuffix])
;

$this->framework->initialize();

/** @var Config $config */
$config = $this->framework->getAdapter(Config::class);

if ($config->get('folderUrl')) {
$this->connection->update('tl_page', ['useFolderUrl' => '1'], ['type' => 'root']);
}

return $this->createResult(true);
}
}
7 changes: 7 additions & 0 deletions core-bundle/src/Resources/config/migrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ services:
Contao\CoreBundle\Migration\Version410\OrderFieldMigration:
arguments:
- '@database_connection'

Contao\CoreBundle\Migration\Version410\RoutingMigration:
arguments:
- '@database_connection'
- '@contao.framework'
- '%contao.url_suffix%'
- '%contao.prepend_locale%'
22 changes: 22 additions & 0 deletions core-bundle/tests/DependencyInjection/ContaoCoreExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
use Contao\CoreBundle\Menu\BackendMenuBuilder;
use Contao\CoreBundle\Migration\MigrationCollection;
use Contao\CoreBundle\Migration\Version409\CeAccessMigration;
use Contao\CoreBundle\Migration\Version410\RoutingMigration;
use Contao\CoreBundle\Monolog\ContaoTableHandler;
use Contao\CoreBundle\Monolog\ContaoTableProcessor;
use Contao\CoreBundle\OptIn\OptIn;
Expand Down Expand Up @@ -3739,6 +3740,27 @@ public function testRegistersTheVersion409CeAccessMigration(): void
);
}

public function testRegistersTheVersion410RoutingMigration(): void
{
$container = $this->getContainerBuilder();

$this->assertTrue($container->has(RoutingMigration::class));

$definition = $container->getDefinition(RoutingMigration::class);

$this->assertTrue($definition->isPrivate());

$this->assertEquals(
[
new Reference('database_connection'),
new Reference('contao.framework'),
'%contao.url_suffix%',
'%contao.prepend_locale%',
],
$definition->getArguments()
);
}

public function testRegistersThePredefinedImageSizes(): void
{
$container = $this->getContainerBuilder();
Expand Down