doukuiqian5345 2013-04-25 18:42
浏览 78
已采纳

使用PHP EWS删除定期日历项目?

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.

  • 写回答

1条回答 默认 最新

  • douwo8358 2013-04-26 06:47
    关注

    You first need to find the ID of the master appointment of the recurring series, then delete that master.

    I don't 'do' PHP, but these are the actual SOAP calls doing the trick. Maybe they help you back on track:

    Get recurring master ID (and some data) from an occurrence:

    <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>
    

    Delete item:

    <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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿