@@ -52,12 +52,27 @@ public function getCard(): ?string {
5252 return $ folder ->getFile ('defaultContact.vcf ' )->getContent ();
5353 }
5454
55- public function setCard (?string $ cardData = null ) {
55+ private function createInitialDefaultContact (): void {
56+ if ($ this ->defaultContactExists ()) {
57+ return ;
58+ }
5659 try {
57- $ folder = $ this ->appData ->getFolder ('defaultContact ' );
58- } catch (NotFoundException $ e ) {
5960 $ folder = $ this ->appData ->newFolder ('defaultContact ' );
61+ $ cardData = file_get_contents (__DIR__ . '/../ExampleContentFiles/exampleContact.vcf ' );
62+ if (!$ cardData ) {
63+ throw new \Exception ('Could not read exampleContact.vcf ' );
64+ }
65+ $ file = (!$ folder ->fileExists ('defaultContact.vcf ' )) ? $ folder ->newFile ('defaultContact.vcf ' ) : $ folder ->getFile ('defaultContact.vcf ' );
66+ $ file ->putContent ($ cardData );
67+ $ this ->appConfig ->setAppValueBool ('hasCustomDefaultContact ' , false );
68+
69+ } catch (\Exception $ e ) {
70+ $ this ->logger ->error ('Could not create initial default contact ' , ['exception ' => $ e ]);
6071 }
72+ }
73+
74+ public function setCard (?string $ cardData = null ) {
75+ $ folder = $ this ->appData ->getFolder ('defaultContact ' );
6176
6277 $ isCustom = true ;
6378 if (is_null ($ cardData )) {
@@ -69,7 +84,7 @@ public function setCard(?string $cardData = null) {
6984 throw new \Exception ('Could not read exampleContact.vcf ' );
7085 }
7186
72- $ file = (! $ folder -> fileExists ( ' defaultContact.vcf ' )) ? $ folder -> newFile ( ' defaultContact.vcf ' ) : $ folder ->getFile ('defaultContact.vcf ' );
87+ $ file = $ folder ->getFile ('defaultContact.vcf ' );
7388 $ file ->putContent ($ cardData );
7489
7590 $ this ->appConfig ->setAppValueBool ('hasCustomDefaultContact ' , $ isCustom );
@@ -89,6 +104,10 @@ public function createDefaultContact(int $addressBookId): void {
89104 return ;
90105 }
91106
107+ if (!$ this ->defaultContactExists ()) {
108+ $ this ->createInitialDefaultContact ();
109+ }
110+
92111 try {
93112 $ folder = $ this ->appData ->getFolder ('defaultContact ' );
94113 $ defaultContactFile = $ folder ->getFile ('defaultContact.vcf ' );
0 commit comments