| ... | ... |
@@ -9,6 +9,9 @@ use Contao\CoreBundle\Migration\MigrationResult; |
| 9 | 9 |
use Doctrine\DBAL\Connection; |
| 10 | 10 |
use Doctrine\DBAL\Schema\Schema; |
| 11 | 11 |
|
| 12 |
+/** |
|
| 13 |
+ * Migration to move secure downloads configuration from tl_page to tl_memberfiles_config |
|
| 14 |
+ */ |
|
| 12 | 15 |
class MemberfilesConfigMigration extends AbstractMigration |
| 13 | 16 |
{
|
| 14 | 17 |
private Connection $connection; |
| ... | ... |
@@ -22,18 +25,18 @@ class MemberfilesConfigMigration extends AbstractMigration |
| 22 | 25 |
{
|
| 23 | 26 |
$schemaManager = $this->connection->createSchemaManager(); |
| 24 | 27 |
|
| 25 |
- // Prüfen ob die Quelltabelle existiert |
|
| 28 |
+ // Check if source table exists |
|
| 26 | 29 |
if (!$schemaManager->tablesExist(['tl_page'])) {
|
| 27 | 30 |
return false; |
| 28 | 31 |
} |
| 29 | 32 |
|
| 30 |
- // Prüfen ob die notwendige Spalte in tl_page existiert |
|
| 33 |
+ // Check if required column exists in tl_page |
|
| 31 | 34 |
$columns = $schemaManager->listTableColumns('tl_page');
|
| 32 | 35 |
if (!isset($columns['securedownloadsenabled'])) {
|
| 33 | 36 |
return false; |
| 34 | 37 |
} |
| 35 | 38 |
|
| 36 |
- // Prüfen ob es Einträge gibt, die migriert werden müssen |
|
| 39 |
+ // Check if there are entries that need to be migrated |
|
| 37 | 40 |
$result = $this->connection->fetchOne( |
| 38 | 41 |
"SELECT COUNT(*) FROM tl_page WHERE secureDownloadsEnabled='1'" |
| 39 | 42 |
); |
| ... | ... |
@@ -45,7 +48,7 @@ class MemberfilesConfigMigration extends AbstractMigration |
| 45 | 48 |
{
|
| 46 | 49 |
$schemaManager = $this->connection->createSchemaManager(); |
| 47 | 50 |
|
| 48 |
- // Erstelle die Zieltabelle, falls sie nicht existiert |
|
| 51 |
+ // Create target table if it doesn't exist |
|
| 49 | 52 |
if (!$schemaManager->tablesExist(['tl_memberfiles_config'])) {
|
| 50 | 53 |
$this->createMemberfilesConfigTable(); |
| 51 | 54 |
} |
| ... | ... |
@@ -76,16 +79,19 @@ class MemberfilesConfigMigration extends AbstractMigration |
| 76 | 79 |
|
| 77 | 80 |
return new MigrationResult( |
| 78 | 81 |
true, |
| 79 |
- sprintf('Erfolgreich %d Secure Downloads Konfigurationen von tl_page nach tl_memberfiles_config migriert.', count($pages))
|
|
| 82 |
+ sprintf('Successfully migrated %d secure downloads configurations from tl_page to tl_memberfiles_config.', count($pages))
|
|
| 80 | 83 |
); |
| 81 | 84 |
} |
| 82 | 85 |
|
| 86 |
+ /** |
|
| 87 |
+ * Create the tl_memberfiles_config table |
|
| 88 |
+ */ |
|
| 83 | 89 |
private function createMemberfilesConfigTable(): void |
| 84 | 90 |
{
|
| 85 | 91 |
$schema = new Schema(); |
| 86 | 92 |
$table = $schema->createTable('tl_memberfiles_config');
|
| 87 | 93 |
|
| 88 |
- // Pflichtfelder |
|
| 94 |
+ // Define table columns |
|
| 89 | 95 |
$table->addColumn('id', 'integer', ['unsigned' => true, 'autoincrement' => true]);
|
| 90 | 96 |
$table->addColumn('tstamp', 'integer', ['unsigned' => true, 'default' => 0]);
|
| 91 | 97 |
$table->addColumn('title', 'string', ['length' => 255, 'default' => '']);
|
| ... | ... |
@@ -97,10 +103,10 @@ class MemberfilesConfigMigration extends AbstractMigration |
| 97 | 103 |
$table->addColumn('notification', 'integer', ['unsigned' => true, 'default' => 0]);
|
| 98 | 104 |
$table->addColumn('enabled', 'string', ['length' => 1, 'fixed' => true, 'default' => '']);
|
| 99 | 105 |
|
| 100 |
- // Primary Key |
|
| 106 |
+ // Set primary key |
|
| 101 | 107 |
$table->setPrimaryKey(['id']); |
| 102 | 108 |
|
| 103 |
- // Schema anwenden |
|
| 109 |
+ // Apply schema changes |
|
| 104 | 110 |
$queries = $schema->toSql($this->connection->getDatabasePlatform()); |
| 105 | 111 |
foreach ($queries as $query) {
|
| 106 | 112 |
$this->connection->executeStatement($query); |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,109 @@ |
| 1 |
+<?php |
|
| 2 |
+ |
|
| 3 |
+declare(strict_types=1); |
|
| 4 |
+ |
|
| 5 |
+namespace vonRotenberg\MemberfilesBundle\Migration; |
|
| 6 |
+ |
|
| 7 |
+use Contao\CoreBundle\Migration\AbstractMigration; |
|
| 8 |
+use Contao\CoreBundle\Migration\MigrationResult; |
|
| 9 |
+use Doctrine\DBAL\Connection; |
|
| 10 |
+use Doctrine\DBAL\Schema\Schema; |
|
| 11 |
+ |
|
| 12 |
+class MemberfilesConfigMigration extends AbstractMigration |
|
| 13 |
+{
|
|
| 14 |
+ private Connection $connection; |
|
| 15 |
+ |
|
| 16 |
+ public function __construct(Connection $connection) |
|
| 17 |
+ {
|
|
| 18 |
+ $this->connection = $connection; |
|
| 19 |
+ } |
|
| 20 |
+ |
|
| 21 |
+ public function shouldRun(): bool |
|
| 22 |
+ {
|
|
| 23 |
+ $schemaManager = $this->connection->createSchemaManager(); |
|
| 24 |
+ |
|
| 25 |
+ // Prüfen ob die Quelltabelle existiert |
|
| 26 |
+ if (!$schemaManager->tablesExist(['tl_page'])) {
|
|
| 27 |
+ return false; |
|
| 28 |
+ } |
|
| 29 |
+ |
|
| 30 |
+ // Prüfen ob die notwendige Spalte in tl_page existiert |
|
| 31 |
+ $columns = $schemaManager->listTableColumns('tl_page');
|
|
| 32 |
+ if (!isset($columns['securedownloadsenabled'])) {
|
|
| 33 |
+ return false; |
|
| 34 |
+ } |
|
| 35 |
+ |
|
| 36 |
+ // Prüfen ob es Einträge gibt, die migriert werden müssen |
|
| 37 |
+ $result = $this->connection->fetchOne( |
|
| 38 |
+ "SELECT COUNT(*) FROM tl_page WHERE secureDownloadsEnabled='1'" |
|
| 39 |
+ ); |
|
| 40 |
+ |
|
| 41 |
+ return $result > 0; |
|
| 42 |
+ } |
|
| 43 |
+ |
|
| 44 |
+ public function run(): MigrationResult |
|
| 45 |
+ {
|
|
| 46 |
+ $schemaManager = $this->connection->createSchemaManager(); |
|
| 47 |
+ |
|
| 48 |
+ // Erstelle die Zieltabelle, falls sie nicht existiert |
|
| 49 |
+ if (!$schemaManager->tablesExist(['tl_memberfiles_config'])) {
|
|
| 50 |
+ $this->createMemberfilesConfigTable(); |
|
| 51 |
+ } |
|
| 52 |
+ |
|
| 53 |
+ $pages = $this->connection->fetchAllAssociative( |
|
| 54 |
+ "SELECT id, title, secureDownloadsSRC, secureDownloadsTarget, " . |
|
| 55 |
+ "secureDownloadsRegExp, secureDownloadsFields, sd_nc_enable, sd_nc_notification " . |
|
| 56 |
+ "FROM tl_page WHERE secureDownloadsEnabled='1'" |
|
| 57 |
+ ); |
|
| 58 |
+ |
|
| 59 |
+ foreach ($pages as $page) {
|
|
| 60 |
+ $this->connection->insert('tl_memberfiles_config', [
|
|
| 61 |
+ 'tstamp' => time(), |
|
| 62 |
+ 'title' => $page['title'] . ' (migriert von Seite ID ' . $page['id'] . ')', |
|
| 63 |
+ 'source' => $page['secureDownloadsSRC'], |
|
| 64 |
+ 'target' => $page['secureDownloadsTarget'], |
|
| 65 |
+ '`regexp`' => $page['secureDownloadsRegExp'], |
|
| 66 |
+ 'fields' => $page['secureDownloadsFields'], |
|
| 67 |
+ 'hasNotification' => $page['sd_nc_enable'], |
|
| 68 |
+ 'notification' => $page['sd_nc_notification'], |
|
| 69 |
+ 'enabled' => '1' |
|
| 70 |
+ ]); |
|
| 71 |
+ |
|
| 72 |
+ $this->connection->update('tl_page', ['secureDownloadsEnabled' => ''], ['id' => $page['id']]);
|
|
| 73 |
+ } |
|
| 74 |
+ |
|
| 75 |
+ |
|
| 76 |
+ |
|
| 77 |
+ return new MigrationResult( |
|
| 78 |
+ true, |
|
| 79 |
+ sprintf('Erfolgreich %d Secure Downloads Konfigurationen von tl_page nach tl_memberfiles_config migriert.', count($pages))
|
|
| 80 |
+ ); |
|
| 81 |
+ } |
|
| 82 |
+ |
|
| 83 |
+ private function createMemberfilesConfigTable(): void |
|
| 84 |
+ {
|
|
| 85 |
+ $schema = new Schema(); |
|
| 86 |
+ $table = $schema->createTable('tl_memberfiles_config');
|
|
| 87 |
+ |
|
| 88 |
+ // Pflichtfelder |
|
| 89 |
+ $table->addColumn('id', 'integer', ['unsigned' => true, 'autoincrement' => true]);
|
|
| 90 |
+ $table->addColumn('tstamp', 'integer', ['unsigned' => true, 'default' => 0]);
|
|
| 91 |
+ $table->addColumn('title', 'string', ['length' => 255, 'default' => '']);
|
|
| 92 |
+ $table->addColumn('source', 'binary', ['length' => 16, 'fixed' => true, 'notnull' => false]);
|
|
| 93 |
+ $table->addColumn('target', 'binary', ['length' => 16, 'fixed' => true, 'notnull' => false]);
|
|
| 94 |
+ $table->addColumn('regexp', 'string', ['length' => 64, 'notnull' => true, 'default' => '']);
|
|
| 95 |
+ $table->addColumn('fields', 'blob', ['notnull' => false]);
|
|
| 96 |
+ $table->addColumn('hasNotification', 'string', ['length' => 1, 'fixed' => true, 'default' => '']);
|
|
| 97 |
+ $table->addColumn('notification', 'integer', ['unsigned' => true, 'default' => 0]);
|
|
| 98 |
+ $table->addColumn('enabled', 'string', ['length' => 1, 'fixed' => true, 'default' => '']);
|
|
| 99 |
+ |
|
| 100 |
+ // Primary Key |
|
| 101 |
+ $table->setPrimaryKey(['id']); |
|
| 102 |
+ |
|
| 103 |
+ // Schema anwenden |
|
| 104 |
+ $queries = $schema->toSql($this->connection->getDatabasePlatform()); |
|
| 105 |
+ foreach ($queries as $query) {
|
|
| 106 |
+ $this->connection->executeStatement($query); |
|
| 107 |
+ } |
|
| 108 |
+ } |
|
| 109 |
+} |