From 3cc70290a8a9b9ef6e525185fc2b0773bbb5c0f5 Mon Sep 17 00:00:00 2001 From: jboomer007 Date: Sun, 2 Jul 2023 23:23:07 -0500 Subject: [PATCH 1/3] Update API.php Added Updated Folder Method --- src/API.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/API.php b/src/API.php index 2bef1718..757695fc 100644 --- a/src/API.php +++ b/src/API.php @@ -307,6 +307,28 @@ public function getFolder($identifier, $options = []) return $response; } + public function updateFolder(BaseFolderIdType $folderId, $changes, $options = []) + { + $request = ['FolderChanges' => [ + 'FolderChange' => [ + 'FolderId' => $folderId->toArray(), + 'Updates' =>[ + 'SetFolderField'=>[ + 'FieldURI'=>['FieldURI'=>'folder:DisplayName'], + 'Folder'=>[ + 'DisplayName'=>$changes + ], + ], + ], + ], + ], + ]; + $request = array_replace_recursive($request, $options); + $request = Type::buildFromArray($request); + $response = $this->getClient()->UpdateFolder($request); + return $response; + } + /** * Get a folder by it's distinguishedId * From 88a31a3d50391e84cf7c478222138730595fe0eb Mon Sep 17 00:00:00 2001 From: jboomer007 Date: Sun, 2 Jul 2023 23:35:00 -0500 Subject: [PATCH 2/3] Update API.php --- src/API.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/API.php b/src/API.php index 757695fc..d1b12845 100644 --- a/src/API.php +++ b/src/API.php @@ -307,6 +307,15 @@ public function getFolder($identifier, $options = []) return $response; } + /** + * Update a folder by it's distinguishedId + * + * @param string $distinguishedId + * @param string $changes + * @param array $options + * @return Type\BaseFolderType + */ + public function updateFolder(BaseFolderIdType $folderId, $changes, $options = []) { $request = ['FolderChanges' => [ From cc1ab11601171fcdd5812cf46b54654d2f7cd0d2 Mon Sep 17 00:00:00 2001 From: jboomer007 Date: Tue, 23 Jun 2026 08:43:34 -0500 Subject: [PATCH 3/3] Update API.php --- src/API.php | 66 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/src/API.php b/src/API.php index d1b12845..3a330a5c 100644 --- a/src/API.php +++ b/src/API.php @@ -307,37 +307,55 @@ public function getFolder($identifier, $options = []) return $response; } + /** - * Update a folder by it's distinguishedId + * Apply a set of field changes to a folder. * - * @param string $distinguishedId - * @param string $changes + * $foldersFields are the contents of the element, e.g. + * [ + * 'FieldURI' => ['FieldURI' => 'folder:DisplayName'], + * 'Folder' =>['DisplayName' => 'New Folder Name'], + * ]; + * + * @param BaseFolderIdType $folderId + * @param array $foldersFields * @param array $options - * @return Type\BaseFolderType + * @return Type\BaseFolderType[]|Type */ + public function updateFolder(BaseFolderIdType $folderId, $foldersFields, $options = []) + { + $folderChange = $folderId->toArray(true); + $folderChange['Updates'] =['SetFolderField' => $foldersFields]; + $request = [ + 'FolderChanges' => [ + 'FolderChange' => $folderChange + ] + ]; + + $request = array_replace_recursive($request, $options); - public function updateFolder(BaseFolderIdType $folderId, $changes, $options = []) - { - $request = ['FolderChanges' => [ - 'FolderChange' => [ - 'FolderId' => $folderId->toArray(), - 'Updates' =>[ - 'SetFolderField'=>[ - 'FieldURI'=>['FieldURI'=>'folder:DisplayName'], - 'Folder'=>[ - 'DisplayName'=>$changes - ], - ], - ], - ], - ], - ]; - $request = array_replace_recursive($request, $options); $request = Type::buildFromArray($request); - $response = $this->getClient()->UpdateFolder($request); - return $response; + + 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) { + throw $e; + } + + return Utilities\ensureIsArray($this->getFolder($folderId->toArray(true))); + } + + if ($response instanceof FolderInfoResponseMessageType) { + return $response->getFolders(); + } + return Utilities\ensureIsArray($response); } - + /** * Get a folder by it's distinguishedId *