-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18e20bd
commit 9274df5
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |