Skip to content

Commit

Permalink
Move migrations to core bundle (see #2545)
Browse files Browse the repository at this point in the history
Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes #2364

Commits
-------

1d6f417 Move migrations to core bundle
20dfde3 Fix missing globals array
51fb5c7 PHPStan
5034731 Pass the filesystem as dependency and remove the Contao 3 migrations
  • Loading branch information
ausi committed Dec 7, 2020
1 parent 8605bc4 commit 244d845
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 266 deletions.
Expand Up @@ -10,7 +10,7 @@
* @license LGPL-3.0-or-later
*/

namespace Contao\InstallationBundle\Database;
namespace Contao\CoreBundle\Migration\Version400;

use Contao\CoreBundle\Migration\AbstractMigration;
use Contao\CoreBundle\Migration\MigrationResult;
Expand Down
Expand Up @@ -10,8 +10,9 @@
* @license LGPL-3.0-or-later
*/

namespace Contao\InstallationBundle\Database;
namespace Contao\CoreBundle\Migration\Version401;

use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\CoreBundle\Migration\AbstractMigration;
use Contao\CoreBundle\Migration\MigrationResult;
use Doctrine\DBAL\Connection;
Expand All @@ -26,9 +27,15 @@ class Version410Update extends AbstractMigration
*/
private $connection;

public function __construct(Connection $connection)
/**
* @var ContaoFramework
*/
private $framework;

public function __construct(Connection $connection, ContaoFramework $framework)
{
$this->connection = $connection;
$this->framework = $framework;
}

public function getName(): string
Expand All @@ -51,6 +58,8 @@ public function shouldRun(): bool

public function run(): MigrationResult
{
$this->framework->initialize();

$crop = $GLOBALS['TL_CROP'];

if (empty($crop)) {
Expand Down
Expand Up @@ -10,7 +10,7 @@
* @license LGPL-3.0-or-later
*/

namespace Contao\InstallationBundle\Database;
namespace Contao\CoreBundle\Migration\Version403;

use Contao\CoreBundle\Migration\AbstractMigration;
use Contao\CoreBundle\Migration\MigrationResult;
Expand Down
Expand Up @@ -10,7 +10,7 @@
* @license LGPL-3.0-or-later
*/

namespace Contao\InstallationBundle\Database;
namespace Contao\CoreBundle\Migration\Version404;

use Contao\CoreBundle\Migration\AbstractMigration;
use Contao\CoreBundle\Migration\MigrationResult;
Expand Down
Expand Up @@ -10,7 +10,7 @@
* @license LGPL-3.0-or-later
*/

namespace Contao\InstallationBundle\Database;
namespace Contao\CoreBundle\Migration\Version404;

use Contao\CoreBundle\Migration\AbstractMigration;
use Contao\CoreBundle\Migration\MigrationResult;
Expand Down
Expand Up @@ -10,7 +10,7 @@
* @license LGPL-3.0-or-later
*/

namespace Contao\InstallationBundle\Database;
namespace Contao\CoreBundle\Migration\Version405;

use Contao\CoreBundle\Migration\AbstractMigration;
use Contao\CoreBundle\Migration\MigrationResult;
Expand Down
Expand Up @@ -10,7 +10,7 @@
* @license LGPL-3.0-or-later
*/

namespace Contao\InstallationBundle\Database;
namespace Contao\CoreBundle\Migration\Version406;

use Contao\CoreBundle\Migration\AbstractMigration;
use Contao\CoreBundle\Migration\MigrationResult;
Expand Down
Expand Up @@ -10,7 +10,7 @@
* @license LGPL-3.0-or-later
*/

namespace Contao\InstallationBundle\Database;
namespace Contao\CoreBundle\Migration\Version407;

use Contao\CoreBundle\Migration\AbstractMigration;
use Contao\CoreBundle\Migration\MigrationResult;
Expand Down
Expand Up @@ -10,13 +10,14 @@
* @license LGPL-3.0-or-later
*/

namespace Contao\InstallationBundle\Database;
namespace Contao\CoreBundle\Migration\Version408;

use Contao\CoreBundle\Migration\AbstractMigration;
use Contao\CoreBundle\Migration\MigrationResult;
use Contao\File;
use Contao\StringUtil;
use Doctrine\DBAL\Connection;
use Symfony\Component\Filesystem\Filesystem;

/**
* @internal
Expand All @@ -28,14 +29,20 @@ class Version480Update extends AbstractMigration
*/
private $connection;

/**
* @var Filesystem
*/
private $filesystem;

/**
* @var string
*/
private $projectDir;

public function __construct(Connection $connection, string $projectDir)
public function __construct(Connection $connection, Filesystem $filesystem, string $projectDir)
{
$this->connection = $connection;
$this->filesystem = $filesystem;
$this->projectDir = $projectDir;
}

Expand Down Expand Up @@ -153,7 +160,7 @@ public function run(): MigrationResult

// Convert the important part to relative values as fractions
while (false !== ($file = $statement->fetch(\PDO::FETCH_OBJ))) {
if (!file_exists($this->projectDir.'/'.$file->path) || is_dir($this->projectDir.'/'.$file->path)) {
if (!$this->filesystem->exists($this->projectDir.'/'.$file->path) || is_dir($this->projectDir.'/'.$file->path)) {
continue;
}

Expand Down
43 changes: 43 additions & 0 deletions core-bundle/src/Resources/config/migrations.yml
Expand Up @@ -4,6 +4,49 @@ services:

Contao\CoreBundle\Migration\MigrationCollection: ~

Contao\CoreBundle\Migration\Version400\Version400Update:
arguments:
- '@database_connection'

Contao\CoreBundle\Migration\Version401\Version410Update:
arguments:
- '@database_connection'
- '@contao.framework'

Contao\CoreBundle\Migration\Version403\Version430Update:
arguments:
- '@database_connection'

Contao\CoreBundle\Migration\Version404\Version440Update:
arguments:
- '@database_connection'

Contao\CoreBundle\Migration\Version404\Version447Update:
arguments:
- '@database_connection'
- '@translator'

Contao\CoreBundle\Migration\Version405\Version450Update:
arguments:
- '@database_connection'

Contao\CoreBundle\Migration\Version406\Version460Update:
arguments:
- '@database_connection'

Contao\CoreBundle\Migration\Version407\Version470Update:
arguments:
- '@database_connection'
- '@filesystem'
- '%contao.upload_path%'
- '%kernel.project_dir%'

Contao\CoreBundle\Migration\Version408\Version480Update:
arguments:
- '@database_connection'
- '@filesystem'
- '%kernel.project_dir%'

Contao\CoreBundle\Migration\Version409\CeAccessMigration:
arguments:
- '@database_connection'
Expand Down
98 changes: 0 additions & 98 deletions installation-bundle/src/Database/Version330Update.php

This file was deleted.

81 changes: 0 additions & 81 deletions installation-bundle/src/Database/Version350Update.php

This file was deleted.

Expand Up @@ -29,6 +29,5 @@ public function load(array $configs, ContainerBuilder $container): void
$loader->load('commands.yml');
$loader->load('listener.yml');
$loader->load('services.yml');
$loader->load('migrations.yml');
}
}

0 comments on commit 244d845

Please sign in to comment.