Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable26] lighter name update #1436

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions lib/Command/CirclesSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

$output->writeln('<comment>This process requires a lot of memory.</comment>');
$output->writeln('<comment>If it crash, please restart it and it will continue where it stopped.</comment>');
$output->writeln('');

$sync = $this->filterSync($input);
$this->syncService->sync($sync);

Expand Down
21 changes: 21 additions & 0 deletions lib/Db/AccountsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,29 @@ class AccountsRequest extends AccountsRequestBuilder {
use TStringTools;



public function getAccountData(string $userId): array {
$qb = $this->getAccountsSelectSql();

$this->limitToDBField($qb, 'uid', $userId);

$cursor = $qb->execute();
$data = $cursor->fetch();
$cursor->closeCursor();

if ($data === false) {
return [];
}

return $this->parseAccountsSelectSql($data);
}



/**
* @param string $userId
*
* @deprecated
* @return array
* @throws MemberDoesNotExistException
*/
Expand All @@ -58,6 +78,7 @@ public function getFromUserId(string $userId): array {


/**
* @deprecated
* @return array
*/
public function getAll(): array {
Expand Down
21 changes: 13 additions & 8 deletions lib/Search/LocalUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@

namespace OCA\Circles\Search;

use OCA\Circles\Tools\Traits\TArrayTools;
use OCA\Circles\ISearch;
use OCA\Circles\Model\DeprecatedMember;
use OCA\Circles\Model\Member;
use OCA\Circles\Model\SearchResult;
use OCA\Circles\Service\ConfigService;
use OCA\Circles\Tools\Traits\TArrayTools;
use OCP\Collaboration\Collaborators\ISearch as ICollaboratorSearch;
use OCP\Share\IShare;

Expand All @@ -51,7 +51,10 @@ class LocalUsers implements ISearch {
* @param ICollaboratorSearch $search
* @param ConfigService $configService
*/
public function __construct(ICollaboratorSearch $search, ConfigService $configService) {
public function __construct(
ICollaboratorSearch $search,
ConfigService $configService
) {
$this->search = $search;
$this->configService = $configService;
}
Expand All @@ -70,10 +73,12 @@ public function search($needle): array {

$users = $userManager->search($needle);
foreach ($users as $user) {
$result[] =
new SearchResult(
$user->getUID(), DeprecatedMember::TYPE_USER, '', ['display' => $user->getDisplayName()]
);
$result[] = new SearchResult(
$user->getUID(),
Member::TYPE_USER,
'',
['display' => $userManager->getDisplayName($user->getUID())]
);
}

return $result;
Expand All @@ -94,7 +99,7 @@ private function searchFromCollaborator($search): array {
$parsed[] =
new SearchResult(
$this->get('value.shareWith', $entry),
DeprecatedMember::TYPE_USER,
Member::TYPE_USER,
'',
['display' => $this->get('label', $entry)]
);
Expand Down
18 changes: 14 additions & 4 deletions lib/Service/FederatedUserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Exception;
use OC;
use OCA\Circles\AppInfo\Application;
use OCA\Circles\Db\AccountsRequest;
use OCA\Circles\Db\CircleRequest;
use OCA\Circles\Db\MemberRequest;
use OCA\Circles\Exceptions\CircleNotFoundException;
Expand Down Expand Up @@ -108,6 +109,9 @@ class FederatedUserService {
/** @var IUserManager */
private $userManager;

/** @var AccountsRequest */
private $accountRequest;

/** @var IGroupManager */
private $groupManager;

Expand Down Expand Up @@ -185,6 +189,7 @@ public function __construct(
ICacheFactory $cacheFactory,
FederatedEventService $federatedEventService,
MembershipService $membershipService,
AccountsRequest $accountRequest,
CircleRequest $circleRequest,
MemberRequest $memberRequest,
RemoteService $remoteService,
Expand All @@ -198,6 +203,7 @@ public function __construct(
$this->groupManager = $groupManager;
$this->federatedEventService = $federatedEventService;
$this->membershipService = $membershipService;
$this->accountRequest = $accountRequest;
$this->circleRequest = $circleRequest;
$this->memberRequest = $memberRequest;
$this->remoteService = $remoteService;
Expand Down Expand Up @@ -517,20 +523,24 @@ public function hasRemoteInstance(): bool {
* @throws RequestBuilderException
* @throws SingleCircleNotFoundException
*/
public function getLocalFederatedUser(string $userId, bool $check = true): FederatedUser {
public function getLocalFederatedUser(string $userId, bool $check = true, bool $generate = false): FederatedUser {
$displayName = $userId;
if ($check) {
$user = $this->userManager->get($userId);
if ($user === null) {
throw new FederatedUserNotFoundException('user ' . $userId . ' not found');
}
$userId = $user->getUID();
$displayName = $user->getDisplayName();
$displayName = $this->userManager->getDisplayName($userId);
} else {
$accountData = $this->accountRequest->getAccountData($userId);
if (array_key_exists('displayName', $accountData)) {
$displayName = $accountData['displayName'];
}
}

$federatedUser = new FederatedUser();
$federatedUser->set($userId, '', Member::TYPE_USER, $displayName);
$this->fillSingleCircleId($federatedUser, $check);
$this->fillSingleCircleId($federatedUser, ($check || $generate));

return $federatedUser;
}
Expand Down
15 changes: 11 additions & 4 deletions lib/Service/MaintenanceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
namespace OCA\Circles\Service;

use Exception;
use OCA\Circles\Db\AccountsRequest;
use OCA\Circles\Db\CircleRequest;
use OCA\Circles\Db\MemberRequest;
use OCA\Circles\Db\ShareWrapperRequest;
Expand All @@ -56,7 +57,6 @@
class MaintenanceService {
use TNCLogger;


public const TIMEOUT = 18000;

public static $DELAY =
Expand All @@ -75,6 +75,9 @@ class MaintenanceService {
/** @var IGroupManager */
private $groupManager;

/** @var AccountsRequest */
private $accountRequest;

/** @var CircleRequest */
private $circleRequest;

Expand Down Expand Up @@ -129,6 +132,7 @@ public function __construct(
IUserManager $userManager,
IGroupManager $groupManager,
CircleRequest $circleRequest,
AccountsRequest $accountRequest,
MemberRequest $memberRequest,
ShareWrapperRequest $shareWrapperRequest,
SyncService $syncService,
Expand All @@ -142,6 +146,7 @@ public function __construct(
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->circleRequest = $circleRequest;
$this->accountRequest = $accountRequest;
$this->memberRequest = $memberRequest;
$this->shareWrapperRequest = $shareWrapperRequest;
$this->syncService = $syncService;
Expand Down Expand Up @@ -421,9 +426,11 @@ private function refreshDisplayName(bool $forceRefresh = false): void {
}

if ($owner->getUserType() === Member::TYPE_USER) {
$user = $this->userManager->get($owner->getUserId());
$this->memberRequest->updateDisplayName($owner->getSingleId(), $user->getDisplayName());
$this->circleRequest->updateDisplayName($owner->getSingleId(), $user->getDisplayName());
$accountData = $this->accountRequest->getAccountData($owner->getUserId());
if (array_key_exists('displayName', $accountData)) {
$this->memberRequest->updateDisplayName($owner->getSingleId(), $accountData['displayName']);
$this->circleRequest->updateDisplayName($owner->getSingleId(), $accountData['displayName']);
}
}
}
}
Expand Down
26 changes: 15 additions & 11 deletions lib/Service/SyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

namespace OCA\Circles\Service;

use OCA\Circles\Tools\Traits\TNCLogger;
use OCA\Circles\Tools\Traits\TStringTools;
use Exception;
use OCA\Circles\AppInfo\Application;
use OCA\Circles\Db\CircleRequest;
Expand Down Expand Up @@ -61,6 +59,8 @@
use OCA\Circles\Model\FederatedUser;
use OCA\Circles\Model\ManagedModel;
use OCA\Circles\Model\Member;
use OCA\Circles\Tools\Traits\TNCLogger;
use OCA\Circles\Tools\Traits\TStringTools;
use OCP\IGroupManager;
use OCP\IUserManager;

Expand Down Expand Up @@ -248,7 +248,7 @@ public function syncNextcloudUsers(): void {
public function syncNextcloudUser(string $userId): FederatedUser {
$this->outputService->output('Syncing Nextcloud Account \'' . $userId . '\'', true);

return $this->federatedUserService->getLocalFederatedUser($userId);
return $this->federatedUserService->getLocalFederatedUser($userId, false, true);
}


Expand Down Expand Up @@ -293,9 +293,21 @@ public function syncNextcloudGroup(string $groupId): Circle {
$this->outputService->output('Syncing Nextcloud Group \'' . $groupId . '\'', true);

$circle = $this->federatedUserService->getGroupCircle($groupId);
$members = array_map(function (Member $member): string {
return $member->getSingleId();
}, $this->memberRequest->getMembers($circle->getSingleId()));

$group = $this->groupManager->get($groupId);
if ($group->count() <= count($members)) {
return $circle;
}

foreach ($group->getUsers() as $user) {
$member = $this->generateGroupMember($circle, $user->getUID());
if (in_array($member->getSingleId(), $members)) {
continue;
}

$event = new FederatedEvent(SingleMemberAdd::class);
$event->setCircle($circle);
$event->setMember($member);
Expand All @@ -304,12 +316,8 @@ public function syncNextcloudGroup(string $groupId): Circle {
$this->federatedEventService->newEvent($event);
} catch (Exception $e) {
}

// $this->memberRequest->insertOrUpdate($member);
}

// $this->membershipService->onUpdate($circle->getSingleId());

return $circle;
}

Expand Down Expand Up @@ -452,10 +460,6 @@ public function groupMemberAdded(string $groupId, string $userId): void {
$event->setCircle($circle);
$event->setMember($member);
$this->federatedEventService->newEvent($event);

// $this->memberRequest->insertOrUpdate($member);

// $this->membershipService->onUpdate($member->getSingleId());
}


Expand Down
Loading