The past couple of days I have been learning to use the PHP-EWS class for reading/updating/deleting calendar entries. I have been able to create single events, read all calendar events for a day and remove events. My problem is that I cannot find any information in regards to deleting an entire series of recurring events. When I delete an event the code I have only deletes the entry of 1 event and not all instances of the recurrence.
Not sure if I am just passing the wrong Id and ChangeKey to the delete code or if there is special code to handle recurring events.
My code for deleting events is as follows:
<?php
// Define the delete item class
$request = new EWSType_DeleteItemType();
// Send to trash can, or use EWSType_DisposalType::HARD_DELETE instead to bypass the bin directly
$request->DeleteType = EWSType_DisposalType::MOVE_TO_DELETED_ITEMS;
$request->SendMeetingCancellations = EWSType_CalendarItemCreateOrDeleteOperationType::SEND_ONLY_TO_ALL;
$items = new EWSType_NonEmptyArrayOfBaseItemIdsType();
foreach ($IDs as $id) {
// Set the item to be deleted
$item = new EWSType_ItemIdType();
$item->Id = $id['Id'];
$item->ChangeKey = $id['ChangeKey'];
$items->ItemId[] = $item;
}
$request->ItemIds = $items;
// Send the request
$response = $this->ews->DeleteItem($request);
?>
UPDATE:
I have created a class to handle most of my EWS commands. Here is a function I created to handle getting the master event IDs.
public function GetMasterEventID($EventID)
{
if (empty($EventID)) {
return false;
}
$types = array('GetItemType', 'ItemQueryTraversalType', 'ItemResponseShapeType',
'DefaultShapeNamesType', 'NonEmptyArrayOfPathsToElementType', 'PathToUnindexedFieldType',
'NonEmptyArrayOfBaseItemIdsType', 'RecurringMasterItemIdType');
$this->LoadTypes($types);
$request = new EWSType_GetItemType();
$request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW;
$request->ItemShape = new EWSType_ItemResponseShapeType();
$request->ItemShape->BaseShape = EWSType_DefaultShapeNamesType::ID_ONLY;
$properties = array('item:Subject', 'item:Categories', 'item:DateTimeCreated',
'item:LastModifiedTime', 'item:Sensitivity', 'item:ItemClass',
'calendar:Start', 'calendar:End', 'calendar:CalendarItemType',
'calendar:IsRecurring', 'calendar:Recurrence', 'calendar:FirstOccurrence',
'calendar:LastOccurrence', 'calendar:ModifiedOccurrences', 'calendar:DeletedOccurrences');
$request->ItemShape->AdditionalProperties = new EWSType_NonEmptyArrayOfPathsToElementType();
foreach ($properties as $p) {
$entry = new EWSType_PathToUnindexedFieldType();
$entry->FieldURI = $p;
$request->ItemShape->AdditionalProperties->FieldURI[] = $entry;
}
$request->ItemIds = new EWSType_NonEmptyArrayOfBaseItemIdsType();
$request->ItemIds->RecurringMasterItemId = new EWSType_RecurringMasterItemIdType();
$request->ItemIds->RecurringMasterItemId->OccurrenceId = $EventID;
$response = $this->ews->GetItem($request);
return $response;
}
The LoadTypes() function just loops through the EWSType files that are required and then includes them so I don't have to load every type file.