Garethp / php-ews

PHP Exchange Web Services
BSD 3-Clause "New" or "Revised" License
112 stars 45 forks source link

Checking if an item exists (by $itemId and $changeKey) results in FATAL ERROR if the object is not found - How to handle this? #258

Closed Lxxrxns closed 10 months ago

Lxxrxns commented 10 months ago

So I made a script that can create, edit and delete events. To find an event that I previously created, I save the $itemId and the $changeKey locally, and then get the event later on using:

$item= $calendar->getCalendarItem($itemId, $changeKey);

The problem however is that if the event no longer exists, this results in a FATAL ERROR.

Uncaught garethp\ews\API\Exception\ExchangeException: The specified object was not found in the store., The process failed to get the correct properties.

So what I need is to first check if the item still exists, before trying to do getCalendarItem().

I do not want to do getCalendarItems($start, $end) on the "surrounding dates" to see if an event still exists, that would be too slow. Is there any other way to not make the script return a FATAL ERROR when no objects are found?

Lxxrxns commented 10 months ago

Managed to figure it out by wrapping everything in try {} catch {}.