Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,55 @@ public function getFolder($identifier, $options = [])
return $response;
}


/**
* Apply a set of field changes to a folder.
*
* $foldersFields are the contents of the <Updates> element, e.g.
* [
* 'FieldURI' => ['FieldURI' => 'folder:DisplayName'],
* 'Folder' =>['DisplayName' => 'New Folder Name'],
* ];
*
* @param BaseFolderIdType $folderId
* @param array $foldersFields
* @param array $options
* @return Type\BaseFolderType[]|Type
*/
public function updateFolder(BaseFolderIdType $folderId, $foldersFields, $options = [])
{
$folderChange = $folderId->toArray(true);
$folderChange['Updates'] =['SetFolderField' => $foldersFields];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second, it's still only handling SetFolderField. To really match how updateItems() works, it would need to support DeleteFolderField and AppendToFolderField too, and ideally more than one field change per call. Right now it's wider than before but still a step short of that.

$request = [
'FolderChanges' => [
'FolderChange' => $folderChange
]
];

$request = array_replace_recursive($request, $options);

$request = Type::buildFromArray($request);

try {
$response = $this->getClient()->UpdateFolder($request);
} catch (API\Exception $e) {
// Exchange renames the folder but returns ErrorInternalServerError
// ("Value cannot be null. (Parameter 'participantResolver')") on
// cold/app-only mailboxes. The write succeeds, so verify the folder
// instead of failing outright; rethrow anything else.
if (stripos($e->getMessage(), 'internal server error') === false) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last one, the try/catch around "internal server error" worries me a bit. Matching on a string inside the exception message and then treating it as a success feels risky, that same message could show up for a real failure too and we'd silently swallow it. Can you say more about when you're hitting that error? Might be better to fix the actual cause than catch around it.

throw $e;
}

return Utilities\ensureIsArray($this->getFolder($folderId->toArray(true)));
}

if ($response instanceof FolderInfoResponseMessageType) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jboomer007 thanks for the new commit. A few small things still need to be sorted out before we ask for another review from @Garethp

First, there's a bug here: you check $response instanceof FolderInfoResponseMessageType but I don't see that class imported anywhere at the top of API.php. That will throw a "class not found" or similar error the first time an update actually succeeds, you will need to add use garethp\ews\API\Message\FolderInfoResponseMessageType;.

return $response->getFolders();
}
return Utilities\ensureIsArray($response);
}

/**
* Get a folder by it's distinguishedId
*
Expand Down