Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/diagnostics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

steps:
- name: Pull source
uses: actions/checkout@v4
uses: actions/checkout@v6

- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
Expand All @@ -29,15 +29,15 @@ jobs:

# setup caches
- name: Cache composer cache directory
uses: actions/cache@v4
uses: actions/cache@v5
env:
cache-name: composer-cache-dir
with:
path: ~/.cache/composer
key: ${{ runner.os }}-${{ matrix.php }}-build-${{ env.cache-name }}

- name: Cache vendor directory
uses: actions/cache@v4
uses: actions/cache@v5
env:
cache-name: vendor
with:
Expand All @@ -47,7 +47,7 @@ jobs:
${{ runner.os }}-${{ matrix.php }}-${{ matrix.contao }}-build-${{ env.cache-name }}-

- name: Cache phpcq directory
uses: actions/cache@v4
uses: actions/cache@v5
env:
cache-name: phpcq
with:
Expand All @@ -69,7 +69,7 @@ jobs:
run: ./vendor/bin/phpcq run -v ${{ matrix.output }}

- name: Upload build directory to artifact
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
if: success() || failure()
with:
name: phpcq-builds-php-${{ matrix.php }}-${{ matrix.contao }}
Expand Down
2 changes: 0 additions & 2 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<TooManyArguments>
<errorLevel type="suppress">
<referencedFunction name="Doctrine\DBAL\Query\QueryBuilder::select"/>
<file name="src/Helper/UpgradeHandler.php"/>
<file name="src/Render/Setting/Collection.php"/>
</errorLevel>
</TooManyArguments>
Expand Down Expand Up @@ -271,7 +270,6 @@
<file name="src/Helper/TableManipulation.php"/>
<file name="src/Helper/TableManipulator.php"/>
<file name="src/Helper/ToolboxFile.php"/>
<file name="src/Helper/UpgradeHandler.php"/>
<file name="src/Information/AttributeInformation.php"/>
<file name="src/Information/MetaModelCollection.php"/>
<file name="src/Information/MetaModelInformation.php"/>
Expand Down
23 changes: 0 additions & 23 deletions runonce/runonce.php

This file was deleted.

106 changes: 106 additions & 0 deletions src/CoreBundle/Migration/DcaSettingPublishedMigration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

/**
* This file is part of MetaModels/core.
*
* (c) 2012-2026 The MetaModels team.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* This project is provided in good faith and hope to be usable by anyone.
*
* @package MetaModels/core
* @author Ingolf Steinhardt <info@e-spin.de>
* @copyright 2012-2026 The MetaModels team.
* @license https://github.com/MetaModels/core/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/

declare(strict_types=1);

namespace MetaModels\CoreBundle\Migration;

use Contao\CoreBundle\Migration\AbstractMigration;
use Contao\CoreBundle\Migration\MigrationResult;
use Doctrine\DBAL\Connection;

use function array_intersect;
use function array_keys;
use function array_map;
use function array_values;
use function count;
use function in_array;

/**
* Adds the "published" column to "tl_metamodel_dcasetting" and sets all existing
* rows to published=1 to preserve the prior behaviour (everything was published).
*
* Introduced: MetaModels 1.0.1.
*/
final class DcaSettingPublishedMigration extends AbstractMigration
{
/**
* The database connection.
*
* @var Connection
*/
private Connection $connection;

/** @var list<string> */
private array $existsCache = [];

/**
* Create a new instance.
*
* @param Connection $connection The database connection.
*/
public function __construct(Connection $connection)
{
$this->connection = $connection;
}

#[\Override]
public function getName(): string
{
return 'MetaModels: Add "published" column to "tl_metamodel_dcasetting".';
}

#[\Override]
public function shouldRun(): bool
{
if (!$this->tablesExist(['tl_metamodel_dcasetting'])) {
return false;
}

$columnNames = array_keys(
$this->connection->createSchemaManager()->listTableColumns('tl_metamodel_dcasetting')
);

return !in_array('published', $columnNames, true);
}

#[\Override]
public function run(): MigrationResult
{
$this->connection->executeStatement(
"ALTER TABLE `tl_metamodel_dcasetting` ADD COLUMN `published` char(1) NOT NULL default ''"
);
$this->connection->executeStatement(
'UPDATE `tl_metamodel_dcasetting` SET `published`=1'
);

return new MigrationResult(true, 'Added "published" column to "tl_metamodel_dcasetting".');
}

private function tablesExist(array $tableNames): bool
{
if ([] === $this->existsCache) {
$this->existsCache = array_values($this->connection->createSchemaManager()->listTableNames());
}

return count($tableNames) === count(
array_intersect($tableNames, array_map('strtolower', $this->existsCache))
);
}
}
196 changes: 196 additions & 0 deletions src/CoreBundle/Migration/InputScreenFlagMigration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
<?php

/**
* This file is part of MetaModels/core.
*
* (c) 2012-2026 The MetaModels team.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* This project is provided in good faith and hope to be usable by anyone.
*
* @package MetaModels/core
* @author Ingolf Steinhardt <info@e-spin.de>
* @copyright 2012-2026 The MetaModels team.
* @license https://github.com/MetaModels/core/blob/master/LICENSE LGPL-3.0-or-later
* @filesource
*/

declare(strict_types=1);

namespace MetaModels\CoreBundle\Migration;

use Contao\CoreBundle\Migration\AbstractMigration;
use Contao\CoreBundle\Migration\MigrationResult;
use Doctrine\DBAL\Connection;

use function array_intersect;
use function array_keys;
use function array_map;
use function array_values;
use function count;
use function in_array;
use function sprintf;
use function time;

/**
* Converts the legacy "flag" column in "tl_metamodel_dca" into proper sort-group
* entries in "tl_metamodel_dca_sortgroup" and drops the column afterwards.
*
* The flag value encodes both the grouping type and sort direction; odd values
* sort ascending, even values sort descending.
*
* Flag mapping:
* 1–2 → char grouping, length 1
* 3–4 → char grouping, length 2
* 5–6 → day grouping
* 7–8 → month grouping
* 9–10 → year grouping
* 11–12 → digit grouping
* other → no grouping
*/
final class InputScreenFlagMigration extends AbstractMigration
{
/**
* The database connection.
*
* @var Connection
*/
private Connection $connection;

/** @var list<string> */
private array $existsCache = [];

/**
* Create a new instance.
*
* @param Connection $connection The database connection.
*/
public function __construct(Connection $connection)
{
$this->connection = $connection;
}

#[\Override]
public function getName(): string
{
return 'MetaModels: Migrate "flag" column to sort-group entries in "tl_metamodel_dca_sortgroup".';
}

#[\Override]
public function shouldRun(): bool
{
if (!$this->tablesExist(['tl_metamodel_dca'])) {
return false;
}

$columnNames = array_keys(
$this->connection->createSchemaManager()->listTableColumns('tl_metamodel_dca')
);

return in_array('flag', $columnNames, true);
}

#[\Override]
public function run(): MigrationResult
{
$this->ensureSortGroupTableExists();

$dcaRows = $this->connection->fetchAllAssociative('SELECT * FROM `tl_metamodel_dca`');
$count = 0;
foreach ($dcaRows as $dca) {
[$renderGroupType, $renderGroupLen] = $this->resolveGroupType((int) $dca['flag']);

$this->connection->insert(
'tl_metamodel_dca_sortgroup',
[
'pid' => (int) $dca['id'],
'sorting' => 128,
'tstamp' => time(),
'name' => null,
'isdefault' => '1',
'ismanualsort' => '1',
'rendergrouptype' => $renderGroupType,
'rendergrouplen' => $renderGroupLen,
'rendergroupattr' => 0,
'rendersort' => in_array((int) $dca['flag'], [2, 4, 6, 8, 10, 12], true) ? 'desc' : 'asc',
'rendersortattr' => 0,
]
);
$count++;
}

$this->connection->executeStatement(
'ALTER TABLE `tl_metamodel_dca` DROP COLUMN `flag`'
);

return new MigrationResult(
true,
sprintf('Created %d sort-group row(s) and dropped "flag" column from "tl_metamodel_dca".', $count)
);
}

/**
* Returns [renderGroupType, renderGroupLen] for the given flag value.
*
* @return array{string, int}
*/
private function resolveGroupType(int $flag): array
{
if (in_array($flag, [1, 2, 3, 4], true)) {
return ['char', in_array($flag, [1, 2], true) ? 1 : 2];
}
if (in_array($flag, [5, 6], true)) {
return ['day', 0];
}
if (in_array($flag, [7, 8], true)) {
return ['month', 0];
}
if (in_array($flag, [9, 10], true)) {
return ['year', 0];
}
if (in_array($flag, [11, 12], true)) {
return ['digit', 0];
}

return ['none', 0];
}

private function ensureSortGroupTableExists(): void
{
if ($this->tablesExist(['tl_metamodel_dca_sortgroup'])) {
return;
}

$this->connection->executeStatement(
'CREATE TABLE `tl_metamodel_dca_sortgroup` (
`id` int(10) unsigned NOT NULL auto_increment,
`pid` int(10) unsigned NOT NULL default \'0\',
`sorting` int(10) unsigned NOT NULL default \'0\',
`tstamp` int(10) unsigned NOT NULL default \'0\',
`name` text NULL,
`isdefault` char(1) NOT NULL default \'\',
`ismanualsort` char(1) NOT NULL default \'\',
`rendergrouptype` varchar(10) NOT NULL default \'none\',
`rendergrouplen` int(10) unsigned NOT NULL default \'1\',
`rendergroupattr` int(10) unsigned NOT NULL default \'0\',
`rendersort` varchar(10) NOT NULL default \'asc\',
`rendersortattr` int(10) unsigned NOT NULL default \'0\',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4'
);
$this->existsCache = [];
}

private function tablesExist(array $tableNames): bool
{
if ([] === $this->existsCache) {
$this->existsCache = array_values($this->connection->createSchemaManager()->listTableNames());
}

return count($tableNames) === count(
array_intersect($tableNames, array_map('strtolower', $this->existsCache))
);
}
}
Loading