0

我正在使用 EWS(Exchange Web 服务)从我的 Exchange 2013 测试服务器访问数据。我正在使用 PHP 和(有些过时的)php-ews 存储库来执行此操作:github-jamesiarmes-php-ews和更新且支持作曲家的版本:github-deakin-php-ews

我可以按照“jamesiarmes”的 wiki 中所述对 Exchange 服务进行基本调用,但是当我尝试使用 GroupBy 方法时遇到了一些麻烦:如何:在 Exchange 中使用 EWS 执行分组搜索

正如您在 How-to 指南的 XML 响应中看到的那样,通常该<Groups>元素应包含零个或多个<GroupItems>然后将包含项目(在我的情况下为 CalendarItems)。但是我从测试服务器返回的是<Group>元素,而不是<GroupItems>导致我的 $response 对象不完整。

我使用的代码:

$request = new FindItemType();
$request->Traversal = ItemQueryTraversalType::SHALLOW;
$request->ItemShape = new ItemResponseShapeType();
$request->ItemShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES;

// Define the time frame to load calendar items
$request->CalendarView = new CalendarViewType();
$request->CalendarView->StartDate = '2014-01-12T15:18:34+03:00';
$request->CalendarView->EndDate = '2015-01-12T15:18:34+03:00';

// Find events from a certain folders
$request->ParentFolderIds = new NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->FolderId = new FolderIdType();
$request->ParentFolderIds->FolderId->Id = $calendarFolderUID;

// Group the events by date
$request->GroupBy = new GroupByType();
$request->GroupBy->Order = 'Ascending';
$request->GroupBy->FieldURI = new FieldURIOrConstantType();
$request->GroupBy->FieldURI->FieldURI = 'calendar:Start';
$request->GroupBy->AggregateOn = new AggregateOnType();
$request->GroupBy->AggregateOn->Aggregate = 'Minimum';
$request->GroupBy->AggregateOn->FieldURI = new FieldURIOrConstantType();
$request->GroupBy->AggregateOn->FieldURI->FieldURI = 'calendar:End';

$response = $this->soapService->FindItem($request);

这是var_dump()来自$response

object(stdClass)#685 (1) {
  ["ResponseMessages"]=>
  object(stdClass)#690 (1) {
    ["FindItemResponseMessage"]=>
    object(stdClass)#714 (3) {
      ["ResponseCode"]=>
      string(7) "NoError"
      ["ResponseClass"]=>
      string(7) "Success"
      ["RootFolder"]=>
      object(stdClass)#715 (3) {
        ["Groups"]=>
        object(stdClass)#716 (0) {
        }
        ["IncludesLastItemInRange"]=>
        bool(true)
        ["TotalItemsInView"]=>
        int(4)
      }
    }
  }
}

我设法使用__getLastResponse()PHP 文档)收集 XML 响应,发现它确实获得了所有想要的项目,但是在<Group>元素中而不是<GroupItems>在 SoapClient 中为<Groups>元素返回一个空对象。

现在我想知道问题出在哪里:

  1. 操作指南是否已过时?我在 EWS 的其他文档中没有找到对这个<Group>元素的任何引用,所以我认为这不是问题。
  2. 我的 Exchange 服务器是在使用另一个 XML 架构还是很奇怪?
  3. php-ews 模式是否已过时?我应该用最终的解决方案来分叉“deakin”回购吗?

我已经找到了一种通过调整 php-ews 模式来使其工作的方法,但是如果问题出在我的测试服务器上,我就不需要费心制作一个 fork 了……我也会在下面发布我当前的解决方案。

我将不胜感激对此的任何意见....

4

1 回答 1

0

正如我所提到的,我想出了一个解决方案,但我不知道是否值得分叉 php-ews 存储库。

我在 StackOverflow 上发现了类似的问题(SOAP Client 接收空的 stdclass),但仅禁用 SOAP 缓存显然并不能解决问题。但是我确实注意到我的解决方案需要禁用缓存才能正常工作。

我最终做的是从 php-ews 更改 types.xsd 架构:

  <xs:complexType name="ArrayOfGroupedItemsType">
    <xs:choice>
      <xs:element name="Group" type="t:GroupedItemsType" minOccurs="0" maxOccurs="unbounded"/>
      <xs:element name="GroupedItems" type="t:GroupedItemsType" minOccurs="0" maxOccurs="unbounded"/>
    </xs:choice>
  </xs:complexType>

奇怪的是,我不必更改任何 EWSTypes 类,我希望我必须更改 to 的属性$GroupedItems,但事实并非如此。ArrayOfGroupedItemsType$Groups

如果我没有得到更好的解决方案,我会 fork php-ews repo 并将其发布在这里...

干杯

于 2014-10-22T14:33:43.410 回答