From: Julien Veyssier Date: Mon, 5 Jun 2023 09:28:22 +0000 (+0200) Subject: shorten oauth2 client names before resizing the column X-Git-Tag: v26.0.3rc1~27^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=793d5320c38a1016ff7fb8a8dfefb0a9777a4ca8;p=nextcloud-server.git shorten oauth2 client names before resizing the column Signed-off-by: Julien Veyssier --- diff --git a/lib/private/Repair/Owncloud/MigrateOauthTables.php b/lib/private/Repair/Owncloud/MigrateOauthTables.php index 0b54793ebe2..5bf0816d8de 100644 --- a/lib/private/Repair/Owncloud/MigrateOauthTables.php +++ b/lib/private/Repair/Owncloud/MigrateOauthTables.php @@ -77,6 +77,27 @@ class MigrateOauthTables implements IRepairStep { $schema = new SchemaWrapper($this->db); $table = $schema->getTable('oauth2_clients'); if ($table->getColumn('name')->getLength() !== 64) { + // shorten existing values before resizing the column + $qb = $this->db->getQueryBuilder(); + $qb->update('oauth2_clients') + ->set('name', $qb->createParameter('shortenedName')) + ->where($qb->expr()->eq('id', $qb->createParameter('theId'))); + + $qbSelect = $this->db->getQueryBuilder(); + $qbSelect->select('id', 'name') + ->from('oauth2_clients'); + + $result = $qbSelect->executeQuery(); + while ($row = $result->fetch()) { + $id = $row['id']; + $shortenedName = mb_substr($row['name'], 0, 64); + $qb->setParameter('theId', $id, IQueryBuilder::PARAM_INT); + $qb->setParameter('shortenedName', $shortenedName, IQueryBuilder::PARAM_STR); + $qb->executeStatement(); + } + $result->closeCursor(); + + // safely set the new column length $table->getColumn('name')->setLength(64); } if ($table->hasColumn('allow_subdomains')) {