diff --git a/lib/Command/CirclesSync.php b/lib/Command/CirclesSync.php
index 20e591a62..a90736550 100644
--- a/lib/Command/CirclesSync.php
+++ b/lib/Command/CirclesSync.php
@@ -138,6 +138,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}
+ $output->writeln('This process requires a lot of memory.');
+ $output->writeln('If it crash, please restart it and it will continue where it stopped.');
+ $output->writeln('');
+
$sync = $this->filterSync($input);
$this->syncService->sync($sync);
diff --git a/lib/Db/AccountsRequest.php b/lib/Db/AccountsRequest.php
index 20557d98c..55c327b27 100644
--- a/lib/Db/AccountsRequest.php
+++ b/lib/Db/AccountsRequest.php
@@ -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
*/
@@ -58,6 +78,7 @@ public function getFromUserId(string $userId): array {
/**
+ * @deprecated
* @return array
*/
public function getAll(): array {
diff --git a/lib/Search/LocalUsers.php b/lib/Search/LocalUsers.php
index b6f01b50e..83c6acf84 100644
--- a/lib/Search/LocalUsers.php
+++ b/lib/Search/LocalUsers.php
@@ -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;
@@ -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;
}
@@ -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;
@@ -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)]
);
diff --git a/lib/Service/FederatedUserService.php b/lib/Service/FederatedUserService.php
index 7a30e81f7..8aec3be57 100644
--- a/lib/Service/FederatedUserService.php
+++ b/lib/Service/FederatedUserService.php
@@ -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;
@@ -108,6 +109,9 @@ class FederatedUserService {
/** @var IUserManager */
private $userManager;
+ /** @var AccountsRequest */
+ private $accountRequest;
+
/** @var IGroupManager */
private $groupManager;
@@ -185,6 +189,7 @@ public function __construct(
ICacheFactory $cacheFactory,
FederatedEventService $federatedEventService,
MembershipService $membershipService,
+ AccountsRequest $accountRequest,
CircleRequest $circleRequest,
MemberRequest $memberRequest,
RemoteService $remoteService,
@@ -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;
@@ -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;
}
diff --git a/lib/Service/MaintenanceService.php b/lib/Service/MaintenanceService.php
index 70edcb7d0..a96f24b24 100644
--- a/lib/Service/MaintenanceService.php
+++ b/lib/Service/MaintenanceService.php
@@ -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;
@@ -56,7 +57,6 @@
class MaintenanceService {
use TNCLogger;
-
public const TIMEOUT = 18000;
public static $DELAY =
@@ -75,6 +75,9 @@ class MaintenanceService {
/** @var IGroupManager */
private $groupManager;
+ /** @var AccountsRequest */
+ private $accountRequest;
+
/** @var CircleRequest */
private $circleRequest;
@@ -129,6 +132,7 @@ public function __construct(
IUserManager $userManager,
IGroupManager $groupManager,
CircleRequest $circleRequest,
+ AccountsRequest $accountRequest,
MemberRequest $memberRequest,
ShareWrapperRequest $shareWrapperRequest,
SyncService $syncService,
@@ -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;
@@ -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']);
+ }
}
}
}
diff --git a/lib/Service/SyncService.php b/lib/Service/SyncService.php
index daca4668f..c29e4fde1 100644
--- a/lib/Service/SyncService.php
+++ b/lib/Service/SyncService.php
@@ -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;
@@ -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;
@@ -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);
}
@@ -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);
@@ -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;
}
@@ -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());
}