Skip to content

Commit

Permalink
fix: fix import vcard photo (#5577)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Oct 8, 2021
1 parent 4370b81 commit 741f5a7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
3 changes: 2 additions & 1 deletion app/Http/Controllers/DAV/Backend/CalDAV/CalDAVBirthdays.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function getExtension()
*/
public function prepareData($obj)
{
$calendardata = null;
if ($obj instanceof SpecialDate) {
try {
$calendardata = $this->refreshObject($obj);
Expand All @@ -65,7 +66,7 @@ public function prepareData($obj)
'lastmodified' => $obj->updated_at->timestamp,
];
} catch (\Exception $e) {
Log::debug(__CLASS__.' prepareData: '.(string) $e);
Log::debug(__CLASS__.' prepareData: '.(string) $e, [$e, 'calendardata' => $calendardata]);
}
}

Expand Down
7 changes: 4 additions & 3 deletions app/Http/Controllers/DAV/Backend/CalDAV/CalDAVTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function getExtension()
*/
public function prepareData($obj)
{
$calendardata = null;
if ($obj instanceof Task) {
try {
$calendardata = $this->refreshObject($obj);
Expand All @@ -94,7 +95,7 @@ public function prepareData($obj)
'lastmodified' => $obj->updated_at->timestamp,
];
} catch (\Exception $e) {
Log::debug(__CLASS__.' prepareData: '.(string) $e);
Log::debug(__CLASS__.' prepareData: '.(string) $e, [$e, 'calendardata' => $calendardata]);
}
}

Expand Down Expand Up @@ -163,7 +164,7 @@ public function updateOrCreateCalendarObject($calendarId, $objectUri, $calendarD
return $calendar['etag'];
}
} catch (\Exception $e) {
Log::debug(__CLASS__.' updateOrCreateCalendarObject: '.(string) $e);
Log::debug(__CLASS__.' updateOrCreateCalendarObject: '.(string) $e, [$e, 'calendarId' => $calendarId, 'objectUri' => $objectUri, 'calendarData' => $calendarData]);
}

return null;
Expand All @@ -189,7 +190,7 @@ public function deleteCalendarObject($objectUri)
'task_id' => $task->id,
]);
} catch (\Exception $e) {
Log::debug(__CLASS__.' deleteCalendarObject: '.(string) $e);
Log::debug(__CLASS__.' deleteCalendarObject: '.(string) $e, [$e, 'objectUri' => $objectUri]);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/DAV/Backend/CardDAV/CardDAVBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public function getChangesForAddressBook($addressBookId, $syncToken, $syncLevel,
*/
public function prepareCard($contact): array
{
$carddata = $contact->vcard;
try {
$carddata = $contact->vcard;
if (empty($carddata)) {
$vcard = app(ExportVCard::class)
->execute([
Expand All @@ -202,7 +202,7 @@ public function prepareCard($contact): array
'lastmodified' => $contact->updated_at->timestamp,
];
} catch (\Exception $e) {
Log::debug(__CLASS__.' prepareCard: '.(string) $e);
Log::debug(__CLASS__.' prepareCard: '.(string) $e, [$e, 'carddata' => $carddata, 'contact_id' => $contact->id]);
throw $e;
}
}
Expand Down Expand Up @@ -396,7 +396,7 @@ public function updateCard($addressBookId, $cardUri, $cardData): ?string
return '"'.md5($contact->vcard).'"';
}
} catch (\Exception $e) {
Log::debug(__CLASS__.' updateCard: '.(string) $e);
Log::debug(__CLASS__.' updateCard: '.(string) $e, [$e]);
throw $e;
}

Expand Down
27 changes: 17 additions & 10 deletions app/Services/VCard/ImportVCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
use Sabre\VObject\ParseException;
use Sabre\VObject\Component\VCard;
use App\Models\Account\AddressBook;
use Illuminate\Support\Facades\Log;
use App\Models\Contact\ContactField;
use App\Services\Contact\Tag\DetachTag;
use App\Models\Contact\ContactFieldType;
use App\Services\Contact\Tag\AssociateTag;
use App\Services\Account\Photo\UploadPhoto;
use App\Services\Contact\Avatar\UpdateAvatar;
use Illuminate\Validation\ValidationException;
use App\Services\Contact\Address\CreateAddress;
use App\Services\Contact\Address\UpdateAddress;
use App\Services\Contact\Contact\CreateContact;
Expand Down Expand Up @@ -809,18 +811,23 @@ private function importPhoto(Contact $contact, VCard $entry): void
$array['extension'] = $type->getValue();
}

$photo = app(UploadPhoto::class)->execute($array);
try {
$photo = app(UploadPhoto::class)
->execute($array);
if (! $photo) {
return;
}

if (! $photo) {
return;
app(UpdateAvatar::class)->execute([
'account_id' => $contact->account_id,
'contact_id' => $contact->id,
'source' => 'photo',
'photo_id' => $photo->id,
]);
} catch (ValidationException $e) {
// wrong data
Log::debug(__CLASS__.' importPhoto: ERROR when UploadPhoto: '.implode(', ', $e->errors()).', PHOTO='.$array['data'], [$e, $array, 'contact_id' => $contact->id]);
}

app(UpdateAvatar::class)->execute([
'account_id' => $contact->account_id,
'contact_id' => $contact->id,
'source' => 'photo',
'photo_id' => $photo->id,
]);
}
}
}
Expand Down

0 comments on commit 741f5a7

Please sign in to comment.