appData = $this->appDataFactory->get('dav'); } public function setEnableDefaultContact($allow) { if ($allow === 'yes' && !$this->defaultContactExists()) { try { $this->setCard(); } catch (\Exception $e) { $this->logger->error('Could not create default contact', ['exception' => $e]); return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); } } $this->config->setAppValue(Application::APP_ID, 'enableDefaultContact', $allow); return new JSONResponse([], Http::STATUS_OK); } public function setDefaultContact(?string $contactData = null) { if (!$this->config->getAppValue(Application::APP_ID, 'enableDefaultContact', 'no')) { return new JSONResponse([], Http::STATUS_FORBIDDEN); } $this->setCard($contactData); return new JSONResponse([], Http::STATUS_OK); } private function setCard(?string $cardData = null) { try { $folder = $this->appData->getFolder('defaultContact'); } catch (NotFoundException $e) { $folder = $this->appData->newFolder('defaultContact'); } if (is_null($cardData)) { $cardData = file_get_contents(__DIR__ . '/../ExampleContentFiles/exampleContact.vcf'); } if (!$cardData) { throw new \Exception('Could not read exampleContact.vcf'); } $file = (!$folder->fileExists('defaultContact.vcf')) ? $folder->newFile('defaultContact.vcf') : $folder->getFile('defaultContact.vcf'); $file->putContent($cardData); } private function defaultContactExists(): bool { try { $folder = $this->appData->getFolder('defaultContact'); } catch (NotFoundException $e) { return false; } return $folder->fileExists('defaultContact.vcf'); } }