Skip to content

Commit

Permalink
be conservative when reading from fresh created column
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Mar 3, 2022
1 parent 787f4f0 commit e6a67c1
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions apps/user_ldap/lib/Migration/Version1130Date20211102154716.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class Version1130Date20211102154716 extends SimpleMigrationStep {
private $dbc;
/** @var LoggerInterface */
private $logger;
/** @var string[] */
private $hashColumnAddedToTables = [];

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

protected function getSelectQuery(string $table): IQueryBuilder {
$qb = $this->dbc->getQueryBuilder();
$qb->select('owncloud_name', 'ldap_dn', 'ldap_dn_hash')
->from($table)
->where($qb->expr()->isNull('ldap_dn_hash'));
$qb->select('owncloud_name', 'ldap_dn')
->from($table);

// when added we may run into risk that it's read from a DB node
// where the column is not present. Then the where clause is also
// not necessary since all rows qualifiy.
if (!in_array($table, $this->hashColumnAddedToTables)) {
$qb->where($qb->expr()->isNull('ldap_dn_hash'));
}

return $qb;
}

Expand Down

0 comments on commit e6a67c1

Please sign in to comment.