Skip to content

Commit 4d40a45

Browse files
authored
Merge pull request #31646 from nextcloud/backport/31436/stable21
[stable21] be conservative when reading from fresh created column
2 parents 2933ec9 + b62ac48 commit 4d40a45

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

apps/user_ldap/lib/Migration/Version1130Date20211102154716.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class Version1130Date20211102154716 extends SimpleMigrationStep {
4343
private $dbc;
4444
/** @var LoggerInterface */
4545
private $logger;
46+
/** @var string[] */
47+
private $hashColumnAddedToTables = [];
4648

4749
public function __construct(IDBConnection $dbc, LoggerInterface $logger) {
4850
$this->dbc = $dbc;
@@ -89,6 +91,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
8991
'length' => 64,
9092
]);
9193
$changeSchema = true;
94+
$this->hashColumnAddedToTables[] = $tableName;
9295
}
9396
$column = $table->getColumn('ldap_dn');
9497
if ($tableName === 'ldap_user_mapping') {
@@ -177,9 +180,16 @@ protected function handleDNHashes(string $table): void {
177180

178181
protected function getSelectQuery(string $table): IQueryBuilder {
179182
$qb = $this->dbc->getQueryBuilder();
180-
$qb->select('owncloud_name', 'ldap_dn', 'ldap_dn_hash')
181-
->from($table)
182-
->where($qb->expr()->isNull('ldap_dn_hash'));
183+
$qb->select('owncloud_name', 'ldap_dn')
184+
->from($table);
185+
186+
// when added we may run into risk that it's read from a DB node
187+
// where the column is not present. Then the where clause is also
188+
// not necessary since all rows qualify.
189+
if (!in_array($table, $this->hashColumnAddedToTables, true)) {
190+
$qb->where($qb->expr()->isNull('ldap_dn_hash'));
191+
}
192+
183193
return $qb;
184194
}
185195

0 commit comments

Comments
 (0)