Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix import vcard photo #5577

Merged
merged 4 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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