-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace runonce with Contao migrations, fixes #76
- Loading branch information
Showing
5 changed files
with
126 additions
and
171 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,27 @@ | ||
<?php | ||
/* | ||
* Copyright MADE/YOUR/DAY OG <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace MadeYourDay\RockSolidSlider\DependencyInjection; | ||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
|
||
class RockSolidSliderExtension extends Extension | ||
{ | ||
public function load(array $configs, ContainerBuilder $container): void | ||
{ | ||
$loader = new YamlFileLoader( | ||
$container, | ||
new FileLocator(__DIR__.'/../Resources/config') | ||
); | ||
|
||
$loader->load('migrations.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,91 @@ | ||
<?php | ||
/* | ||
* Copyright MADE/YOUR/DAY OG <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace MadeYourDay\RockSolidSlider\Migration; | ||
|
||
use Contao\CoreBundle\Framework\ContaoFramework; | ||
use Contao\CoreBundle\Migration\AbstractMigration; | ||
use Contao\CoreBundle\Migration\MigrationResult; | ||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Types\BlobType; | ||
use Doctrine\DBAL\Types\Type; | ||
use Doctrine\DBAL\Types\Types; | ||
use MadeYourDay\RockSolidSlider\Slider; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
class SliderPermissionsMigration extends AbstractMigration | ||
{ | ||
/** | ||
* @var Connection | ||
*/ | ||
private $connection; | ||
|
||
/** | ||
* @var ContaoFramework | ||
*/ | ||
private $framework; | ||
|
||
public function __construct(Connection $connection, ContaoFramework $framework) | ||
{ | ||
$this->connection = $connection; | ||
$this->framework = $framework; | ||
} | ||
|
||
public function shouldRun(): bool | ||
{ | ||
$schemaManager = $this->connection->getSchemaManager(); | ||
|
||
if ( | ||
!$schemaManager->tablesExist('tl_rocksolid_slider') | ||
|| !$schemaManager->tablesExist('tl_user') | ||
|| !$schemaManager->tablesExist('tl_user_group') | ||
) { | ||
return false; | ||
} | ||
|
||
$columnsUser = $schemaManager->listTableColumns('tl_user'); | ||
$columnsGroup = $schemaManager->listTableColumns('tl_user_group'); | ||
|
||
if ( | ||
isset($columnsUser['rsts_sliders']) | ||
|| isset($columnsUser['rsts_permissions']) | ||
|| isset($columnsGroup['rsts_sliders']) | ||
|| isset($columnsGroup['rsts_permissions']) | ||
) { | ||
return false; | ||
} | ||
|
||
$this->framework->initialize(); | ||
|
||
return Slider::checkLicense(); | ||
} | ||
|
||
public function run(): MigrationResult | ||
{ | ||
$defaultPermissions = serialize(['create', 'delete']); | ||
$defaultSliders = serialize(array_values($this->connection->fetchFirstColumn("SELECT id FROM tl_rocksolid_slider"))); | ||
|
||
foreach (['tl_user', 'tl_user_group'] as $table) { | ||
foreach ([ | ||
"ALTER TABLE $table ADD rsts_permissions BLOB DEFAULT NULL", | ||
"ALTER TABLE $table ADD rsts_sliders BLOB DEFAULT NULL", | ||
] as $query) { | ||
$this->connection->executeStatement($query); | ||
} | ||
$this->connection->executeStatement( | ||
"UPDATE $table SET rsts_permissions = ?, rsts_sliders = ?", | ||
[$defaultPermissions, $defaultSliders], | ||
[Types::BLOB, Types::BLOB] | ||
); | ||
} | ||
|
||
return $this->createResult(true); | ||
} | ||
} |
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,8 @@ | ||
services: | ||
_defaults: | ||
autoconfigure: true | ||
|
||
MadeYourDay\RockSolidSlider\Migration\SliderPermissionsMigration: | ||
arguments: | ||
- '@database_connection' | ||
- '@contao.framework' |
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
This file was deleted.
Oops, something went wrong.