Skip to content

Commit

Permalink
add euf_hero migration
Browse files Browse the repository at this point in the history
  • Loading branch information
denniserdmann committed Jun 15, 2023
1 parent 18e20bd commit 9274df5
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
7 changes: 7 additions & 0 deletions config/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
_defaults:
autoconfigure: true

Nutshell\Herolement\Migration\EufHeroMigration:
arguments: [ '@database_connection' ]
tags: [ 'contao.migration' ]
28 changes: 28 additions & 0 deletions src/DependencyInjection/NutshellHeroElementExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

/*
* Card Element for Contao Open Source CMS.
*
* @copyright Copyright (c) 2022, Erdmann & Freunde
* @author Erdmann & Freunde <https://erdmann-freunde.de>
* @license MIT
* @link http://github.com/nutshell-framework/hero-element
*/

namespace Nutshell\HeroElement\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

class NutshellHeroElementExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../../config'));
$loader->load('services.yml');
}
}
73 changes: 73 additions & 0 deletions src/Migration/EufHeroMigration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

/*
* Card Element for Contao Open Source CMS.
*
* @copyright Copyright (c) 2022, Erdmann & Freunde
* @author Erdmann & Freunde <https://erdmann-freunde.de>
* @license MIT
* @link http://github.com/nutshell-framework/hero-element
*/

namespace Nutshell\HeroElement\Migration;

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

class EufHeroMigration extends AbstractMigration
{
/**
* @var Connection
*/
private $connection;

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

public function shouldRun(): bool
{
$schemaManager = $this->connection->getSchemaManager();

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

return
isset($columns['singleSRC']) &&
!isset($columns['heroBackgroundImage']);

return
$this->connection->fetchOne(
"SELECT COUNT(*) FROM tl_content WHERE type = 'hero'"
) > 0;
}

public function run(): MigrationResult
{
$this->connection->executeQuery("
ALTER TABLE
tl_content
ADD heroBackgroundImage binary(16) NULL,
ADD heroSize varchar(128) NOT NULL default ''
");

$stmt = $this->connection->prepare('
UPDATE
tl_content
SET
heroBackgroundImage = singleSRC,
heroSize = size,
WHERE
type = :type
');

$stmt->bindValue('type', 'card');
$stmt->execute();

return $this->createResult(true, 'Migrate euf_hero to hero-element');
}
}

0 comments on commit 9274df5

Please sign in to comment.