From 417e76cd2d413005d978f994f0b4b6f949d34219 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Thu, 13 Jan 2022 12:20:57 +0100 Subject: [PATCH] Fix user_ldap migration for long DNs support MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../Version1130Date20211102154716.php | 78 +++++++------------ .../Version1130Date20220110154718.php | 2 +- 2 files changed, 31 insertions(+), 49 deletions(-) diff --git a/apps/user_ldap/lib/Migration/Version1130Date20211102154716.php b/apps/user_ldap/lib/Migration/Version1130Date20211102154716.php index f464b132133..05c41760d6d 100644 --- a/apps/user_ldap/lib/Migration/Version1130Date20211102154716.php +++ b/apps/user_ldap/lib/Migration/Version1130Date20211102154716.php @@ -73,11 +73,12 @@ class Version1130Date20211102154716 extends SimpleMigrationStep { $changeSchema = true; } $column = $table->getColumn('ldap_dn'); - if ($column->getLength() < 4096) { - $column->setLength(4096); - $changeSchema = true; - } if ($tableName === 'ldap_user_mapping') { + if ($column->getLength() < 4096) { + $column->setLength(4096); + $changeSchema = true; + } + if ($table->hasIndex('ldap_dn_users')) { $table->dropIndex('ldap_dn_users'); $changeSchema = true; @@ -91,50 +92,31 @@ class Version1130Date20211102154716 extends SimpleMigrationStep { $changeSchema = true; } } else { - if ($table->hasIndex('owncloud_name_groups')) { - $table->dropIndex('owncloud_name_groups'); - $changeSchema = true; - } - if (!$table->hasIndex('ldap_group_dn_hashes')) { - $table->addUniqueIndex(['ldap_dn_hash'], 'ldap_group_dn_hashes'); - $changeSchema = true; - } - if (!$table->hasIndex('ldap_group_directory_uuid')) { - $table->addUniqueIndex(['directory_uuid'], 'ldap_group_directory_uuid'); - $changeSchema = true; - } - if (!$table->hasPrimaryKey()) { - $table->setPrimaryKey(['owncloud_name']); - $changeSchema = true; - } - - if ($table->getPrimaryKeyColumns() !== ['owncloud_name']) { - // We need to copy the table twice to be able to change primary key, prepare the backup table - $table2 = $schema->createTable('ldap_group_mapping_backup'); - $table2->addColumn('ldap_dn', Types::STRING, [ - 'notnull' => true, - 'length' => 255, - 'default' => '', - ]); - $table2->addColumn('owncloud_name', Types::STRING, [ - 'notnull' => true, - 'length' => 64, - 'default' => '', - ]); - $table2->addColumn('directory_uuid', Types::STRING, [ - 'notnull' => true, - 'length' => 255, - 'default' => '', - ]); - $table2->addColumn('ldap_dn_hash', Types::STRING, [ - 'notnull' => false, - 'length' => 64, - ]); - $table2->setPrimaryKey(['owncloud_name']); - $table2->addUniqueIndex(['ldap_dn_hash'], 'ldap_group_dn_hashes'); - $table2->addUniqueIndex(['directory_uuid'], 'ldap_group_directory_uuid'); - $changeSchema = true; - } + // We need to copy the table twice to be able to change primary key, prepare the backup table + $table2 = $schema->createTable('ldap_group_mapping_backup'); + $table2->addColumn('ldap_dn', Types::STRING, [ + 'notnull' => true, + 'length' => 4096, + 'default' => '', + ]); + $table2->addColumn('owncloud_name', Types::STRING, [ + 'notnull' => true, + 'length' => 64, + 'default' => '', + ]); + $table2->addColumn('directory_uuid', Types::STRING, [ + 'notnull' => true, + 'length' => 255, + 'default' => '', + ]); + $table2->addColumn('ldap_dn_hash', Types::STRING, [ + 'notnull' => false, + 'length' => 64, + ]); + $table2->setPrimaryKey(['owncloud_name'], 'lgm_backup_primary'); + $table2->addUniqueIndex(['ldap_dn_hash'], 'ldap_group_dn_hashes'); + $table2->addUniqueIndex(['directory_uuid'], 'ldap_group_directory_uuid'); + $changeSchema = true; } } diff --git a/apps/user_ldap/lib/Migration/Version1130Date20220110154718.php b/apps/user_ldap/lib/Migration/Version1130Date20220110154718.php index caadd9d9be2..5f146ab06a5 100644 --- a/apps/user_ldap/lib/Migration/Version1130Date20220110154718.php +++ b/apps/user_ldap/lib/Migration/Version1130Date20220110154718.php @@ -54,7 +54,7 @@ class Version1130Date20220110154718 extends GroupMappingMigration { $table = $schema->createTable('ldap_group_mapping'); $table->addColumn('ldap_dn', Types::STRING, [ 'notnull' => true, - 'length' => 255, + 'length' => 4096, 'default' => '', ]); $table->addColumn('owncloud_name', Types::STRING, [ -- 2.39.5