aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Service/DefaultContactService.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib/Service/DefaultContactService.php')
-rw-r--r--apps/dav/lib/Service/DefaultContactService.php77
1 files changed, 0 insertions, 77 deletions
diff --git a/apps/dav/lib/Service/DefaultContactService.php b/apps/dav/lib/Service/DefaultContactService.php
deleted file mode 100644
index 24e55ef7b69..00000000000
--- a/apps/dav/lib/Service/DefaultContactService.php
+++ /dev/null
@@ -1,77 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-
-namespace OCA\DAV\Service;
-
-use OCA\DAV\AppInfo\Application;
-use OCA\DAV\CardDAV\CardDavBackend;
-use OCP\App\IAppManager;
-use OCP\Files\AppData\IAppDataFactory;
-use OCP\IAppConfig;
-use Psr\Log\LoggerInterface;
-use Symfony\Component\Uid\Uuid;
-
-class DefaultContactService {
- public function __construct(
- private CardDavBackend $cardDav,
- private IAppManager $appManager,
- private IAppDataFactory $appDataFactory,
- private IAppConfig $config,
- private LoggerInterface $logger,
- ) {
- }
-
- public function createDefaultContact(int $addressBookId): void {
- $enableDefaultContact = $this->config->getValueString(Application::APP_ID, 'enableDefaultContact', 'yes');
- if ($enableDefaultContact !== 'yes') {
- return;
- }
- $appData = $this->appDataFactory->get('dav');
- try {
- $folder = $appData->getFolder('defaultContact');
- $defaultContactFile = $folder->getFile('defaultContact.vcf');
- $data = $defaultContactFile->getContent();
- } catch (\Exception $e) {
- $this->logger->error('Couldn\'t get default contact file', ['exception' => $e]);
- return;
- }
-
- // Make sure the UID is unique
- $newUid = Uuid::v4()->toRfc4122();
- $newRev = date('Ymd\THis\Z');
- $vcard = \Sabre\VObject\Reader::read($data, \Sabre\VObject\Reader::OPTION_FORGIVING);
- if ($vcard->UID) {
- $vcard->UID->setValue($newUid);
- } else {
- $vcard->add('UID', $newUid);
- }
- if ($vcard->REV) {
- $vcard->REV->setValue($newRev);
- } else {
- $vcard->add('REV', $newRev);
- }
-
- // Level 3 means that the document is invalid
- // https://sabre.io/vobject/vcard/#validating-vcard
- $level3Warnings = array_filter($vcard->validate(), function ($warning) {
- return $warning['level'] === 3;
- });
-
- if (!empty($level3Warnings)) {
- $this->logger->error('Default contact is invalid', ['warnings' => $level3Warnings]);
- return;
- }
- try {
- $this->cardDav->createCard($addressBookId, 'default', $vcard->serialize(), false);
- } catch (\Exception $e) {
- $this->logger->error($e->getMessage(), ['exception' => $e]);
- }
-
- }
-}