Skip to content

Commit

Permalink
Improved excemption handling if a collection is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
ksainc committed Jan 23, 2024
1 parent 0dea32f commit 01cfc5c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
19 changes: 13 additions & 6 deletions lib/Service/ContactsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,19 @@ public function performHarmonization($correlation) : object {
return $statistics;
}
// delete and skip collection correlation if remote collection is missing
$rcollection = $this->RemoteContactsService->fetchCollection($rcid);
if (!isset($rcollection) || ($rcollection->Id != $rcid)) {
$this->CorrelationsService->deleteByAffiliationId($this->Configuration->UserId, $caid);
$this->CorrelationsService->delete($correlation);
$this->logger->debug('EWS - Deleted contacts collection correlation for ' . $this->Configuration->UserId . ' due to missing Remote Collection');
return $statistics;
try {
$rcollection = $this->RemoteContactsService->fetchCollection($rcid);
}
catch (\Throwable $th) {
if (str_contains($th->getMessage(), 'Remote Error: ErrorItemNotFound')) {
$this->CorrelationsService->deleteByAffiliationId($this->Configuration->UserId, $caid);
$this->CorrelationsService->delete($correlation);
$this->logger->debug('EWS - Deleted contacts collection correlation for ' . $this->Configuration->UserId . ' due to missing Remote Collection');
return $statistics;
}
else {
throw $th;
}
}
// retrieve list of local changed objects
$lCollectionChanges = $this->LocalContactsService->fetchCollectionChanges($correlation->getloid(), (string) $correlation->getlostate());
Expand Down
19 changes: 13 additions & 6 deletions lib/Service/EventsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,19 @@ public function performHarmonization($correlation) : object {
return $statistics;
}
// delete and skip collection correlation if remote collection is missing
$rcollection = $this->RemoteEventsService->fetchCollection($rcid);
if (!isset($rcollection) || ($rcollection->Id != $rcid)) {
$this->CorrelationsService->deleteByAffiliationId($this->Configuration->UserId, $caid);
$this->CorrelationsService->delete($correlation);
$this->logger->debug('EWS - Deleted Events collection correlation for ' . $this->Configuration->UserId . ' due to missing Remote Collection');
return $statistics;
try {
$rcollection = $this->RemoteEventsService->fetchCollection($rcid);
}
catch (\Throwable $th) {
if (str_contains($th->getMessage(), 'Remote Error: ErrorItemNotFound')) {
$this->CorrelationsService->deleteByAffiliationId($this->Configuration->UserId, $caid);
$this->CorrelationsService->delete($correlation);
$this->logger->debug('EWS - Deleted Events collection correlation for ' . $this->Configuration->UserId . ' due to missing Remote Collection');
return $statistics;
}
else {
throw $th;
}
}
// retrieve list of local changed objects
$lCollectionChanges = $this->LocalEventsService->fetchCollectionChanges($correlation->getloid(), (string) $correlation->getlostate());
Expand Down
19 changes: 13 additions & 6 deletions lib/Service/TasksService.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,19 @@ public function performHarmonization($correlation) : object {
return $statistics;
}
// delete and skip collection correlation if remote collection is missing
$rcollection = $this->RemoteTasksService->fetchCollection($rcid);
if (!isset($rcollection) || ($rcollection->Id != $rcid)) {
$this->CorrelationsService->deleteByAffiliationId($this->Configuration->UserId, $caid);
$this->CorrelationsService->delete($correlation);
$this->logger->debug('EWS - Deleted tasks collection correlation for ' . $this->Configuration->UserId . ' due to missing Remote Collection');
return $statistics;
try {
$rcollection = $this->RemoteTasksService->fetchCollection($rcid);
}
catch (\Throwable $th) {
if (str_contains($th->getMessage(), 'Remote Error: ErrorItemNotFound')) {
$this->CorrelationsService->deleteByAffiliationId($this->Configuration->UserId, $caid);
$this->CorrelationsService->delete($correlation);
$this->logger->debug('EWS - Deleted tasks collection correlation for ' . $this->Configuration->UserId . ' due to missing Remote Collection');
return $statistics;
}
else {
throw $th;
}
}
// retrieve list of local changed objects
$lCollectionChanges = $this->LocalTasksService->fetchCollectionChanges($correlation->getloid(), (string) $correlation->getlostate());
Expand Down

0 comments on commit 01cfc5c

Please sign in to comment.