]> source.dussan.org Git - nextcloud-server.git/commitdiff
shorten oauth2 client names before resizing the column 38672/head
authorJulien Veyssier <julien-nc@posteo.net>
Mon, 5 Jun 2023 09:28:22 +0000 (11:28 +0200)
committerJulien Veyssier <julien-nc@posteo.net>
Wed, 7 Jun 2023 13:32:28 +0000 (15:32 +0200)
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
lib/private/Repair/Owncloud/MigrateOauthTables.php

index 0b54793ebe26c02991451d27232681bc80b00c15..5bf0816d8deb1199b7de455323544ef30256d82a 100644 (file)
@@ -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')) {