Skip to content
Merged
Show file tree
Hide file tree
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
fix code style
Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed Feb 11, 2022
commit 28b5f0ccce3e92426953a35dd6ce1dd0d0ac0358
50 changes: 24 additions & 26 deletions apps/user_ldap/lib/Command/UpdateUUID.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
use function sprintf;

class UuidUpdateReport {
const UNCHANGED = 0;
const UNKNOWN = 1;
const UNREADABLE = 2;
const UPDATED = 3;
const UNWRITABLE = 4;
const UNMAPPED = 5;
public const UNCHANGED = 0;
public const UNKNOWN = 1;
public const UNREADABLE = 2;
public const UPDATED = 3;
public const UNWRITABLE = 4;
public const UNMAPPED = 5;

public $id = '';
public $dn = '';
Expand Down Expand Up @@ -140,7 +140,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$entriesToUpdate = $this->estimateNumberOfUpdates($input);
$progress = new ProgressBar($output);
$progress->start($entriesToUpdate);
foreach($this->handleUpdates($input) as $_) {
foreach ($this->handleUpdates($input) as $_) {
$progress->advance();
}
$progress->finish();
Expand Down Expand Up @@ -178,7 +178,7 @@ protected function printReport(OutputInterface $output): void {
if (!empty($report->id)) {
$output->writeln(sprintf(' %s: %s',
$report->isUser ? 'User' : 'Group', $report->id));
} else if (!empty($report->dn)) {
} elseif (!empty($report->dn)) {
$output->writeln(sprintf(' DN: %s', $report->dn));
}
}
Expand Down Expand Up @@ -219,37 +219,37 @@ protected function printReport(OutputInterface $output): void {

protected function handleUpdates(InputInterface $input): \Generator {
if ($input->getOption('all')) {
foreach($this->handleMappingBasedUpdates(false) as $_) {
foreach ($this->handleMappingBasedUpdates(false) as $_) {
yield;
}
} else if ($input->getOption('userId')
} elseif ($input->getOption('userId')
|| $input->getOption('groupId')
|| $input->getOption('dn')
) {
foreach($this->handleUpdatesByUserId($input->getOption('userId')) as $_) {
foreach ($this->handleUpdatesByUserId($input->getOption('userId')) as $_) {
yield;
}
foreach($this->handleUpdatesByGroupId($input->getOption('groupId')) as $_) {
foreach ($this->handleUpdatesByGroupId($input->getOption('groupId')) as $_) {
yield;
}
foreach($this->handleUpdatesByDN($input->getOption('dn')) as $_) {
foreach ($this->handleUpdatesByDN($input->getOption('dn')) as $_) {
yield;
}
} else {
foreach($this->handleMappingBasedUpdates(true) as $_) {
foreach ($this->handleMappingBasedUpdates(true) as $_) {
yield;
}
}
}

protected function handleUpdatesByUserId(array $userIds): \Generator {
foreach($this->handleUpdatesByEntryId($userIds, $this->userMapping) as $_) {
foreach ($this->handleUpdatesByEntryId($userIds, $this->userMapping) as $_) {
yield;
}
}

protected function handleUpdatesByGroupId(array $groupIds): \Generator {
foreach($this->handleUpdatesByEntryId($groupIds, $this->groupMapping) as $_) {
foreach ($this->handleUpdatesByEntryId($groupIds, $this->groupMapping) as $_) {
yield;
}
}
Expand All @@ -272,10 +272,10 @@ protected function handleUpdatesByDN(array $dns): \Generator {
$this->reports[UuidUpdateReport::UNMAPPED][] = new UuidUpdateReport('', $dn, true, UuidUpdateReport::UNMAPPED);
yield;
}
foreach($this->handleUpdatesByList($this->userMapping, $userList) as $_) {
foreach ($this->handleUpdatesByList($this->userMapping, $userList) as $_) {
yield;
}
foreach($this->handleUpdatesByList($this->groupMapping, $groupList) as $_) {
foreach ($this->handleUpdatesByList($this->groupMapping, $groupList) as $_) {
yield;
}
}
Expand All @@ -284,7 +284,7 @@ protected function handleUpdatesByEntryId(array $ids, AbstractMapping $mapping):
$isUser = $mapping instanceof UserMapping;
$list = [];
while ($id = array_pop($ids)) {
if(!$dn = $mapping->getDNByName($id)) {
if (!$dn = $mapping->getDNByName($id)) {
$this->reports[UuidUpdateReport::UNMAPPED][] = new UuidUpdateReport($id, '', $isUser, UuidUpdateReport::UNMAPPED);
yield;
continue;
Expand All @@ -293,21 +293,21 @@ protected function handleUpdatesByEntryId(array $ids, AbstractMapping $mapping):
$uuid = $mapping->getUUIDByDN($dn);
$list[] = ['name' => $id, 'uuid' => $uuid];
}
foreach($this->handleUpdatesByList($mapping, $list) as $_) {
foreach ($this->handleUpdatesByList($mapping, $list) as $_) {
yield;
}
}

protected function handleMappingBasedUpdates(bool $invalidatedOnly): \Generator {
$limit = 1000;
/** @var AbstractMapping $mapping*/
foreach([$this->userMapping, $this->groupMapping] as $mapping) {
foreach ([$this->userMapping, $this->groupMapping] as $mapping) {
$offset = 0;
do {
$list = $mapping->getList($offset, $limit, $invalidatedOnly);
$offset += $limit;

foreach($this->handleUpdatesByList($mapping, $list) as $tick) {
foreach ($this->handleUpdatesByList($mapping, $list) as $tick) {
yield; // null, for it only advances progress counter
}
} while (count($list) === $limit);
Expand All @@ -326,8 +326,7 @@ protected function handleUpdatesByList(AbstractMapping $mapping, array $list): \
foreach ($list as $row) {
$access = $backendProxy->getLDAPAccess($row['name']);
if ($access instanceof Access
&& $dn = $mapping->getDNByName($row['name']))
{
&& $dn = $mapping->getDNByName($row['name'])) {
if ($uuid = $access->getUUID($dn, $isUser)) {
if ($uuid !== $row['uuid']) {
if ($this->dryRun || $mapping->setUUIDbyDN($uuid, $dn)) {
Expand Down Expand Up @@ -359,7 +358,7 @@ protected function handleUpdatesByList(AbstractMapping $mapping, array $list): \
protected function estimateNumberOfUpdates(InputInterface $input): int {
if ($input->getOption('all')) {
return $this->userMapping->count() + $this->groupMapping->count();
} else if ($input->getOption('userId')
} elseif ($input->getOption('userId')
|| $input->getOption('groupId')
|| $input->getOption('dn')
) {
Expand All @@ -370,5 +369,4 @@ protected function estimateNumberOfUpdates(InputInterface $input): int {
return $this->userMapping->countInvalidated() + $this->groupMapping->countInvalidated();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
$table->addUniqueIndex(['directory_uuid'], 'ldap_user_directory_uuid');
$changeSchema = true;
}
} else if (!$schema->hasTable('ldap_group_mapping_backup')) {
} elseif (!$schema->hasTable('ldap_group_mapping_backup')) {
// We need to copy the table twice to be able to change primary key, prepare the backup table
$table2 = $schema->createTable('ldap_group_mapping_backup');
$table2->addColumn('ldap_dn', Types::STRING, [
Expand Down Expand Up @@ -260,7 +260,7 @@ protected function getNextcloudIdsByUuid(string $table, string $uuid): array {
* @return Generator<string>
* @throws \OCP\DB\Exception
*/
protected function getDuplicatedUuids(string $table): Generator{
protected function getDuplicatedUuids(string $table): Generator {
$select = $this->dbc->getQueryBuilder();
$select->select('directory_uuid')
->from($table)
Expand Down