在过去的几天里,我一直在学习使用PHP-EWS 类来读取/更新/删除日历条目。我已经能够创建单个事件、读取一天的所有日历事件并删除事件。我的问题是我找不到有关删除整个系列重复事件的任何信息。当我删除一个事件时,我的代码只删除了 1 个事件的条目,而不是所有重复的实例。
不确定我是否只是将错误的 Id 和 ChangeKey 传递给删除代码,或者是否有特殊代码来处理重复事件。
我删除事件的代码如下:
<?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);
?>
更新:
我创建了一个类来处理我的大部分 EWS 命令。这是我创建的用于处理获取主事件 ID 的函数。
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;
}
LoadTypes() 函数只是循环遍历所需的 EWSType 文件,然后包含它们,因此我不必加载每个类型文件。