diff --git a/composer.lock b/composer.lock index 1d0c3c2b..2b373640 100644 --- a/composer.lock +++ b/composer.lock @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/daita/my-small-php-tools.git", - "reference": "3c0a95f97b8f09cab26f18a4c37b3ad73a0b96a2" + "reference": "23d37b41c4d492604e545c05e0d6abe35eb38cc0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/3c0a95f97b8f09cab26f18a4c37b3ad73a0b96a2", - "reference": "3c0a95f97b8f09cab26f18a4c37b3ad73a0b96a2", + "url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/23d37b41c4d492604e545c05e0d6abe35eb38cc0", + "reference": "23d37b41c4d492604e545c05e0d6abe35eb38cc0", "shasum": "" }, "require": { @@ -40,7 +40,7 @@ } ], "description": "My small PHP Tools", - "time": "2019-10-04T12:32:13+00:00" + "time": "2020-01-08T12:11:53+00:00" } ], "packages-dev": [], diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 8b1152d9..288ff37c 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -157,7 +157,7 @@ class Application extends App { try { /** @var ConfigService $configService */ $configService = OC::$server->query(ConfigService::class); - if ($configService->getAppValue(ConfigService::CIRCLES_CONTACT_BACKEND) !== '1') { + if (!$configService->isContactsBackend()) { return; } diff --git a/lib/Command/SyncContact.php b/lib/Command/SyncContact.php index 5fa4b686..a8c8bacb 100644 --- a/lib/Command/SyncContact.php +++ b/lib/Command/SyncContact.php @@ -29,6 +29,7 @@ namespace OCA\Circles\Command; +use Exception; use OC\Core\Command\Base; use OCA\Circles\Exceptions\CommandMissingArgumentException; use OCA\Circles\Exceptions\FakeException; @@ -63,11 +64,18 @@ class SyncContact extends Base { protected function configure() { parent::configure(); - $this->setName('circles:sync') + $this->setName('circles:contacts:sync') ->setDescription('sync contacts, when using the Circles app as a backend of the Contact app'); } + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|void|null + * @throws Exception + */ protected function execute(InputInterface $input, OutputInterface $output) { $this->davService->migration(); diff --git a/lib/Cron/ContactsExistingShares.php b/lib/Cron/ContactsExistingShares.php index d8d25f2a..609874d0 100644 --- a/lib/Cron/ContactsExistingShares.php +++ b/lib/Cron/ContactsExistingShares.php @@ -124,7 +124,7 @@ class ContactsExistingShares extends TimedJob { $this->configService = $c->query(ConfigService::class); $this->miscService = $c->query(MiscService::class); - if ($this->configService->getAppValue(ConfigService::CIRCLES_CONTACT_BACKEND) !== '1') { + if (!$this->configService->isContactsBackend()) { return; } diff --git a/lib/Db/TokensRequestBuilder.php b/lib/Db/TokensRequestBuilder.php index bd965e71..074d3752 100644 --- a/lib/Db/TokensRequestBuilder.php +++ b/lib/Db/TokensRequestBuilder.php @@ -81,7 +81,7 @@ class TokensRequestBuilder extends CoreRequestBuilder { $qb = $this->dbConnection->getQueryBuilder(); /** @noinspection PhpMethodParametersCountMismatchInspection */ - $qb->select('t.user_id', 't.circle_id', 't.share_id', 't.token') + $qb->select('t.user_id', 't.circle_id', 't.member_id', 't.share_id', 't.token', 't.accepted') ->from(self::TABLE_TOKENS, 't'); $this->default_select_alias = 't'; diff --git a/lib/Model/SharesToken.php b/lib/Model/SharesToken.php index 4e8b4bc8..8bea3766 100644 --- a/lib/Model/SharesToken.php +++ b/lib/Model/SharesToken.php @@ -29,6 +29,7 @@ namespace OCA\Circles\Model; use daita\MySmallPhpTools\Traits\TArrayTools; use JsonSerializable; +use OCP\Share\IShare; /** @@ -45,6 +46,12 @@ class SharesToken implements JsonSerializable { /** @var string */ private $circleId = ''; + /** @var string */ + private $memberId = ''; + + /** @var int */ + private $accepted = IShare::STATUS_PENDING; + /** @var string */ private $userId = ''; @@ -81,6 +88,25 @@ class SharesToken implements JsonSerializable { } + /** + * @return string + */ + public function getMemberId(): string { + return $this->memberId; + } + + /** + * @param string $memberId + * + * @return SharesToken + */ + public function setMemberId(string $memberId): self { + $this->memberId = $memberId; + + return $this; + } + + /** * @return string */ @@ -138,11 +164,32 @@ class SharesToken implements JsonSerializable { } + /** + * @return int + */ + public function getAccepted(): int { + return $this->accepted; + } + + /** + * @param int $accepted + * + * @return SharesToken + */ + public function setAccepted(int $accepted): self { + $this->accepted = $accepted; + + return $this; + } + + /** * @param array $data */ function import(array $data) { $this->setCircleId($this->get('circle_id', $data, '')); + $this->setMemberId($this->get('member_id', $data, '')); + $this->setAccepted($this->getInt('accepted', $data, IShare::STATUS_PENDING)); $this->setUserId($this->get('user_id', $data, '')); $this->setShareId($this->get('share_id', $data, '')); $this->setToken($this->get('token', $data, '')); @@ -155,9 +202,11 @@ class SharesToken implements JsonSerializable { function jsonSerialize(): array { return [ 'circleId' => $this->getCircleId(), + 'memberId' => $this->getMemberId(), 'userId' => $this->getUserId(), 'shareId' => $this->getShareId(), - 'token' => $this->getToken() + 'token' => $this->getToken(), + 'accepted' => $this->getAccepted() ]; } diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index fcca6229..c1497c7a 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -371,6 +371,19 @@ class ConfigService { } + /** + * @return bool + */ + public function isContactsBackend(): bool { + return ($this->getAppValue(ConfigService::CIRCLES_CONTACT_BACKEND) !== '0'); + } + + + public function contactsBackendType(): int { + return (int)$this->getAppValue(ConfigService::CIRCLES_CONTACT_BACKEND); + } + + /** * @return bool */ diff --git a/lib/Service/DavService.php b/lib/Service/DavService.php index 46a6b136..6b41bccc 100644 --- a/lib/Service/DavService.php +++ b/lib/Service/DavService.php @@ -160,6 +160,8 @@ class DavService { $this->miscService->log('Deleting Card: ' . json_encode($davCard), 1); $this->membersRequest->removeMembersByContactId($davCard->getUniqueId(), Member::TYPE_USER); + $this->manageDeprecatedCircles($davCard->getAddressBookId()); + $this->manageDeprecatedMembers($davCard); } @@ -244,7 +246,6 @@ class DavService { * @param DavCard $davCard */ private function manageDeprecatedMembers(DavCard $davCard) { - // TODO: Check this. $circles = array_map( function(Circle $circle) { return $circle->getUniqueId(); @@ -389,7 +390,8 @@ class DavService { continue; } - $circle = new Circle(Circle::CIRCLES_PUBLIC, $group . ' - ' . $this->uuid(5)); + $user = $this->userManager->get($davCard->getOwner()); + $circle = new Circle($this->configService->contactsBackendType(), $group . ' - ' . $user->getDisplayName()); $circle->setContactAddressBook($davCard->getAddressBookId()); $circle->setContactGroupName($group); @@ -480,7 +482,7 @@ class DavService { * @throws Exception */ public function migration() { - if ($this->configService->getAppValue(ConfigService::CIRCLES_CONTACT_BACKEND) !== '1') { + if (!$this->configService->isContactsBackend()) { throw new Exception('Circles needs to be set as Contacts App Backend first'); } diff --git a/lib/ShareByCircleProvider.php b/lib/ShareByCircleProvider.php index d569b34a..5a2e2b81 100644 --- a/lib/ShareByCircleProvider.php +++ b/lib/ShareByCircleProvider.php @@ -458,6 +458,7 @@ class ShareByCircleProvider extends CircleProviderRequest implements IShareProvi public function getSharesByPath(Node $path) { $qb = $this->getBaseSelectSql(); $this->limitToFiles($qb, [$path->getId()]); + $cursor = $qb->execute(); $shares = []; diff --git a/screenshots/contacts_backend.png b/screenshots/contacts_backend.png new file mode 100644 index 00000000..435cb1ae Binary files /dev/null and b/screenshots/contacts_backend.png differ