php - 使用 PHP EWS 删除循环日历项?

标签 php exchangewebservices php-ews

这两天我一直在学习使用 PHP-EWS class用于阅读/更新/删除日历条目。我已经能够创建单个事件,读取一天的所有日历事件并删除事件。我的问题是我找不到关于删除整个系列的重复事件的任何信息。当我删除一个事件时,我的代码只删除了 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 文件,然后包含它们,因此我不必加载每个类型文件。

最佳答案

您首先需要找到循环系列的主约会 ID,然后删除该主。

我不“做”PHP,但这些是真正的 SOAP 调用。也许它们可以帮助您重回正轨:

从事件中获取循环主 ID(和一些数据):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:mes="http://schemas.microsoft.com/exchange/services/2006/messages">
   <soapenv:Header>
      <typ:RequestServerVersion Version="Exchange2007_SP1"/>
   </soapenv:Header>
   <soapenv:Body>
      <mes:GetItem>
         <mes:ItemShape>
            <typ:BaseShape>IdOnly</typ:BaseShape>
            <typ:AdditionalProperties>
              <typ:FieldURI FieldURI="item:Subject" /> 
              <typ:FieldURI FieldURI="item:Categories" />
              <typ:FieldURI FieldURI="item:DateTimeCreated" />
              <typ:FieldURI FieldURI="item:LastModifiedTime" />
              <typ:FieldURI FieldURI="item:Sensitivity" />
              <typ:FieldURI FieldURI="item:ItemClass" />
              <typ:FieldURI FieldURI="calendar:Start" />
              <typ:FieldURI FieldURI="calendar:End" />
              <typ:FieldURI FieldURI="calendar:CalendarItemType" />
              <typ:FieldURI FieldURI="calendar:IsRecurring" />
              <typ:FieldURI FieldURI="calendar:Recurrence" />
              <typ:FieldURI FieldURI="calendar:FirstOccurrence" />
              <typ:FieldURI FieldURI="calendar:LastOccurrence" />
              <typ:FieldURI FieldURI="calendar:ModifiedOccurrences" />
              <typ:FieldURI FieldURI="calendar:DeletedOccurrences" />
            </typ:AdditionalProperties>
         </mes:ItemShape>
         <mes:ItemIds>
            <typ:RecurringMasterItemId OccurrenceId="AAMkADkyZT[snip]kgAAEA=="/>
         </mes:ItemIds>
      </mes:GetItem>
   </soapenv:Body>
</soapenv:Envelope>

删除项目:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:mes="http://schemas.microsoft.com/exchange/services/2006/messages">
   <soapenv:Header>
      <typ:RequestServerVersion Version="Exchange2007_SP1"/>
      <typ:MailboxCulture>en-US</typ:MailboxCulture>
      <typ:TimeZoneContext>
        <typ:TimeZoneDefinition Id="W. Europe Standard Time"/>
      </typ:TimeZoneContext>
   </soapenv:Header>
   <soapenv:Body>
      <mes:DeleteItem DeleteType="HardDelete" SendMeetingCancellations="SendToNone">
         <mes:ItemIds>
            <!--You have a CHOICE of the next 3 items at this level-->
            <typ:ItemId Id="AQMkADkyZTQxNjUzLTcwZTQtNGRlNS04M2VmLWMxYmIBNWJiADUwZTYARgAAA4Kt4mOTlXZJrZx0v5cQm8IHAISmF1hx/2pAhQBTVUBmYgoAAAMhAAAAhKYXWHH/akCFAFNVQGZiCgAB57O2JwAAAA=="/>
            <!--typ:OccurrenceItemId RecurringMasterId="?" InstanceIndex="?"/>
            <typ:RecurringMasterItemId OccurrenceId="?"/-->
         </mes:ItemIds>
      </mes:DeleteItem>
   </soapenv:Body>
</soapenv:Envelope>

关于php - 使用 PHP EWS 删除循环日历项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16222319/

相关文章:

php - CodeIgniter 负载 Controller View

javascript - Laravel 5 中的空可重复字段

php - 在 5 或 10 英里的邮政编码范围内进行搜索

directory - 如何查找收件箱中是否存在文件夹,如果不存在则创建

powershell - 在Exchange联系人中查找附件的CID引用

PHPEWS 在公共(public)日历上创建事件

PHP-EWS - 订阅/推送通知 - 完整示例

基于 PHP 的搜索框架

javascript - 来自 javascript 的 EWS GetUserAvailabilityRequest - 如何设置时区信息

PHP-EWS "Soap client returned status of 404"