Skip to content
Closed
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
Next Next commit
Fix ldap:update-uuid
Generators cannot be iterated with while or returned by an other
 generator, using foreach instead.
And a few other problems.

Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc authored and backportbot[bot] committed Feb 10, 2022
commit 11a7f066c2c8920ae07fff9938abdaf01be4663c
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,7 @@ private function detectUuidAttribute($dn, $isUser = true, $force = false, array
* @param string $dn
* @param bool $isUser
* @param null $ldapRecord
* @return bool|string
* @return false|string
* @throws ServerNotAvailableException
*/
public function getUUID($dn, $isUser = true, $ldapRecord = null) {
Expand Down
45 changes: 27 additions & 18 deletions apps/user_ldap/lib/Command/UpdateUUID.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @copyright Copyright (c) 2021 Arthur Schiwon <[email protected]>
*
* @author Arthur Schiwon <[email protected]>
* @author Côme Chilliet <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
Expand Down Expand Up @@ -55,7 +56,7 @@ class UuidUpdateReport {
public $oldUuid = '';
public $newUuid = '';

public function __construct(string $id, string $dn, bool $isUser, int $state, $oldUuid = '', $newUuid = '') {
public function __construct(string $id, string $dn, bool $isUser, int $state, string $oldUuid = '', string $newUuid = '') {
$this->id = $id;
$this->dn = $dn;
$this->isUser = $isUser;
Expand All @@ -74,7 +75,7 @@ class UpdateUUID extends Command {
private $userProxy;
/** @var Group_Proxy */
private $groupProxy;
/** @var array<UuidUpdateReport> */
/** @var array<UuidUpdateReport[]> */
protected $reports = [];
/** @var LoggerInterface */
private $logger;
Expand Down Expand Up @@ -136,10 +137,14 @@ protected function configure(): void {

protected function execute(InputInterface $input, OutputInterface $output): int {
$this->dryRun = $input->getOption('dry-run');
$entriesToUpdates = $this->estimateNumberOfUpdates($input);
$progressBar = new ProgressBar($output);
$progressBar->iterate($this->handleUpdates($input), $entriesToUpdates);
$this->printReport($input, $output);
$entriesToUpdate = $this->estimateNumberOfUpdates($input);
$progress = new ProgressBar($output);
$progress->start($entriesToUpdate);
foreach($this->handleUpdates($input) as $_) {
$progress->advance();
}
$progress->finish();
$output->writeln('');
$this->printReport($output);
return count($this->reports[UuidUpdateReport::UNMAPPED]) === 0
&& count($this->reports[UuidUpdateReport::UNREADABLE]) === 0
Expand All @@ -148,7 +153,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
: 1;
}

protected function printReport(OutputInterface $output) {
protected function printReport(OutputInterface $output): void {
if ($output->isQuiet()) {
return;
}
Expand Down Expand Up @@ -214,33 +219,37 @@ protected function printReport(OutputInterface $output) {

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

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

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

protected function estimateNumberOfUpdates(InputInterface $input) {
protected function estimateNumberOfUpdates(InputInterface $input): int {
if ($input->getOption('all')) {
return $this->userMapping->count() + $this->groupMapping->count();
} else if ($input->getOption('userId')
Expand Down
4 changes: 2 additions & 2 deletions apps/user_ldap/lib/Mapping/AbstractMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,12 @@ public function getUUIDByDN($dn) {
return $this->getXbyY('directory_uuid', 'ldap_dn_hash', $this->getDNHash($dn));
}

public function getList(int $offset = null, int $limit = null, $invalidatedOnly = false): array {
public function getList(int $offset = 0, int $limit = null, bool $invalidatedOnly = false): array {
$select = $this->dbc->getQueryBuilder();
$select->selectAlias('ldap_dn', 'dn')
->selectAlias('owncloud_name', 'name')
->selectAlias('directory_uuid', 'uuid')
->from($this->getTableName(false))
->from($this->getTableName())
->setMaxResults($limit)
->setFirstResult($offset);

Expand Down