Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
shorten oauth2 client names before resizing the column
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
  • Loading branch information
julien-nc committed Jun 6, 2023
commit 633e9513e2a98f5271ed6a58f771334c53184c50
21 changes: 21 additions & 0 deletions lib/private/Repair/Owncloud/MigrateOauthTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,27 @@ public function run(IOutput $output) {
$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')) {
Expand Down