From bd7ba379320c51c7deca5335ce1f8fe161ee6acf Mon Sep 17 00:00:00 2001 From: "vvgrem@gmail.com" Date: Sat, 15 May 2021 11:20:52 +0300 Subject: [PATCH] Support for submit a query along with handling transient failures, Outlook namespace fluent api improvements --- src/Common/UnmuteParticipantOperation.php | 12 -- src/OutlookServices/Attachment.php | 2 +- src/OutlookServices/AttachmentItem.php | 2 +- src/OutlookServices/Attendee.php | 2 +- src/OutlookServices/AttendeeAvailability.php | 2 +- src/OutlookServices/AttendeeBase.php | 2 +- src/OutlookServices/Calendar.php | 2 +- src/OutlookServices/CalendarGroup.php | 2 +- src/OutlookServices/CalendarPermission.php | 2 +- .../CalendarSharingMessage.php | 2 +- .../CalendarSharingMessageAction.php | 2 +- src/OutlookServices/Contact.php | 140 ++++++++---------- src/OutlookServices/ContactFolder.php | 2 +- src/OutlookServices/Contract.php | 2 +- .../CustomTimeZone.php | 8 +- src/OutlookServices/EmailAddress.php | 2 +- src/OutlookServices/EventMessage.php | 2 +- src/OutlookServices/EventMessageRequest.php | 2 +- src/OutlookServices/EventMessageResponse.php | 2 +- src/OutlookServices/FileAttachment.php | 16 +- src/OutlookServices/ItemAttachment.php | 2 +- src/OutlookServices/ItemBody.php | 2 +- .../LocationConstraint.php | 2 +- .../LocationConstraintItem.php | 2 +- src/OutlookServices/MailFolder.php | 2 +- src/OutlookServices/MailSearchFolder.php | 2 +- src/OutlookServices/MailboxSettings.php | 3 +- src/OutlookServices/Message.php | 2 +- src/OutlookServices/MessageRule.php | 2 +- src/OutlookServices/MessageRuleActions.php | 2 +- src/OutlookServices/MessageRulePredicates.php | 2 +- src/OutlookServices/OpenShift.php | 2 +- .../OpenShiftChangeRequest.php | 2 +- src/OutlookServices/OpenShiftItem.php | 2 +- src/OutlookServices/OutlookCategory.php | 2 +- src/OutlookServices/OutlookItem.php | 2 +- src/OutlookServices/OutlookUser.php | 2 +- src/OutlookServices/Post.php | 2 +- src/OutlookServices/Recipient.php | 2 +- src/OutlookServices/ReferenceAttachment.php | 2 +- src/OutlookServices/ResponseStatus.php | 2 +- .../TimeConstraint.php | 2 +- src/{Common => OutlookServices}/TimeRange.php | 2 +- src/{Common => OutlookServices}/TimeSlot.php | 3 +- .../TimeZoneBase.php | 2 +- .../TimeZoneInformation.php | 2 +- .../WorkingHours.php | 2 +- src/Runtime/ClientObject.php | 13 ++ src/Runtime/ClientRequest.php | 8 +- src/Runtime/ClientRuntimeContext.php | 34 ++++- src/SharePoint/Field.php | 33 ----- src/SharePoint/File.php | 5 +- .../PickerEntityInformation.php | 13 +- src/SharePoint/Utilities/Utility.php | 7 +- src/Teams/UnmuteParticipantOperation.php | 13 ++ tests/sharepoint/UtilityTest.php | 6 +- tests/teams/TeamsTest.php | 5 +- 57 files changed, 194 insertions(+), 207 deletions(-) delete mode 100644 src/Common/UnmuteParticipantOperation.php rename src/{Common => OutlookServices}/CustomTimeZone.php (61%) rename src/{Common => OutlookServices}/LocationConstraint.php (87%) rename src/{Common => OutlookServices}/LocationConstraintItem.php (84%) rename src/{Common => OutlookServices}/TimeConstraint.php (78%) rename src/{Common => OutlookServices}/TimeRange.php (77%) rename src/{Common => OutlookServices}/TimeSlot.php (76%) rename src/{Common => OutlookServices}/TimeZoneBase.php (83%) rename src/{Common => OutlookServices}/TimeZoneInformation.php (87%) rename src/{Common => OutlookServices}/WorkingHours.php (84%) create mode 100644 src/Teams/UnmuteParticipantOperation.php diff --git a/src/Common/UnmuteParticipantOperation.php b/src/Common/UnmuteParticipantOperation.php deleted file mode 100644 index 0b636f85..00000000 --- a/src/Common/UnmuteParticipantOperation.php +++ /dev/null @@ -1,12 +0,0 @@ -getProperty("GivenName"); } + /** * The contact's given name. + * + * @return self * @var string */ public function setGivenName($value) { - $this->setProperty("GivenName", $value, true); + return $this->setProperty("GivenName", $value, true); } /** * The contact's initials. @@ -86,13 +88,16 @@ public function getInitials() { return $this->getProperty("Initials"); } + /** * The contact's initials. + * + * @return self * @var string */ public function setInitials($value) { - $this->setProperty("Initials", $value, true); + return $this->setProperty("Initials", $value, true); } /** * The contact's middle name. @@ -102,13 +107,16 @@ public function getMiddleName() { return $this->getProperty("MiddleName"); } + /** * The contact's middle name. + * + * @return self * @var string */ public function setMiddleName($value) { - $this->setProperty("MiddleName", $value, true); + return $this->setProperty("MiddleName", $value, true); } /** * The contact's nickname. @@ -118,13 +126,16 @@ public function getNickName() { return $this->getProperty("NickName"); } + /** * The contact's nickname. + * + * @return self * @var string */ public function setNickName($value) { - $this->setProperty("NickName", $value, true); + return $this->setProperty("NickName", $value, true); } /** * The contact's surname. @@ -143,8 +154,7 @@ public function getSurname() */ public function setSurname($value) { - $this->setProperty("Surname", $value, true); - return $this; + return $this->setProperty("Surname", $value, true); } /** * The contact's title. @@ -154,13 +164,16 @@ public function getTitle() { return $this->getProperty("Title"); } + /** * The contact's title. + * + * @return self * @var string */ public function setTitle($value) { - $this->setProperty("Title", $value, true); + return $this->setProperty("Title", $value, true); } /** * The phonetic Japanese given name (first name) of the contact. @@ -200,9 +213,6 @@ public function setYomiSurname($value) */ public function getYomiCompanyName() { - if (!$this->isPropertyAvailable("YomiCompanyName")) { - return null; - } return $this->getProperty("YomiCompanyName"); } /** @@ -219,9 +229,6 @@ public function setYomiCompanyName($value) */ public function getGeneration() { - if (!$this->isPropertyAvailable("Generation")) { - return null; - } return $this->getProperty("Generation"); } /** @@ -238,9 +245,6 @@ public function setGeneration($value) */ public function getImAddresses() { - if (!$this->isPropertyAvailable("ImAddresses")) { - return null; - } return $this->getProperty("ImAddresses"); } /** @@ -257,18 +261,18 @@ public function setImAddresses($value) */ public function getJobTitle() { - if (!$this->isPropertyAvailable("JobTitle")) { - return null; - } return $this->getProperty("JobTitle"); } + /** * The contact’s job title. + * + * @return self * @var string */ public function setJobTitle($value) { - $this->setProperty("JobTitle", $value, true); + return $this->setProperty("JobTitle", $value, true); } /** * The name of the contact's company. @@ -276,18 +280,18 @@ public function setJobTitle($value) */ public function getCompanyName() { - if (!$this->isPropertyAvailable("CompanyName")) { - return null; - } return $this->getProperty("CompanyName"); } + /** * The name of the contact's company. + * + * @return self * @var string */ public function setCompanyName($value) { - $this->setProperty("CompanyName", $value, true); + return $this->setProperty("CompanyName", $value, true); } /** * The contact's department. @@ -295,18 +299,18 @@ public function setCompanyName($value) */ public function getDepartment() { - if (!$this->isPropertyAvailable("Department")) { - return null; - } return $this->getProperty("Department"); } + /** * The contact's department. + * + * @return self * @var string */ public function setDepartment($value) { - $this->setProperty("Department", $value, true); + return $this->setProperty("Department", $value, true); } /** * The location of the contact's office. @@ -314,9 +318,6 @@ public function setDepartment($value) */ public function getOfficeLocation() { - if (!$this->isPropertyAvailable("OfficeLocation")) { - return null; - } return $this->getProperty("OfficeLocation"); } /** @@ -333,18 +334,18 @@ public function setOfficeLocation($value) */ public function getProfession() { - if (!$this->isPropertyAvailable("Profession")) { - return null; - } return $this->getProperty("Profession"); } + /** * The contact's profession. + * + * @return self * @var string */ public function setProfession($value) { - $this->setProperty("Profession", $value, true); + return $this->setProperty("Profession", $value, true); } /** * The business home page of the contact. @@ -352,9 +353,6 @@ public function setProfession($value) */ public function getBusinessHomePage() { - if (!$this->isPropertyAvailable("BusinessHomePage")) { - return null; - } return $this->getProperty("BusinessHomePage"); } /** @@ -371,9 +369,6 @@ public function setBusinessHomePage($value) */ public function getAssistantName() { - if (!$this->isPropertyAvailable("AssistantName")) { - return null; - } return $this->getProperty("AssistantName"); } /** @@ -390,18 +385,18 @@ public function setAssistantName($value) */ public function getManager() { - if (!$this->isPropertyAvailable("Manager")) { - return null; - } return $this->getProperty("Manager"); } + /** * The name of the contact's manager. + * + * @return self * @var string */ public function setManager($value) { - $this->setProperty("Manager", $value, true); + return $this->setProperty("Manager", $value, true); } /** * The contact's home phone numbers. @@ -409,9 +404,6 @@ public function setManager($value) */ public function getHomePhones() { - if (!$this->isPropertyAvailable("HomePhones")) { - return null; - } return $this->getProperty("HomePhones"); } /** @@ -428,18 +420,18 @@ public function setHomePhones($value) */ public function getMobilePhone() { - if (!$this->isPropertyAvailable("MobilePhone")) { - return null; - } return $this->getProperty("MobilePhone"); } + /** * The contact's mobile phone number. + * + * @return self * @var string */ public function setMobilePhone($value) { - $this->setProperty("MobilePhone", $value, true); + return $this->setProperty("MobilePhone", $value, true); } /** * The contact's business phone numbers. @@ -449,13 +441,16 @@ public function getBusinessPhones() { return $this->getProperty("BusinessPhones"); } + /** * The contact's business phone numbers. + * + * @return self * @var array */ public function setBusinessPhones($value) { - $this->setProperty("BusinessPhones", $value, true); + return $this->setProperty("BusinessPhones", $value, true); } /** * The name of the contact's spouse/partner. @@ -463,18 +458,18 @@ public function setBusinessPhones($value) */ public function getSpouseName() { - if (!$this->isPropertyAvailable("SpouseName")) { - return null; - } return $this->getProperty("SpouseName"); } + /** * The name of the contact's spouse/partner. + * + * @return self * @var string */ public function setSpouseName($value) { - $this->setProperty("SpouseName", $value, true); + return $this->setProperty("SpouseName", $value, true); } /** * The user's notes about the contact. @@ -482,18 +477,18 @@ public function setSpouseName($value) */ public function getPersonalNotes() { - if (!$this->isPropertyAvailable("PersonalNotes")) { - return null; - } return $this->getProperty("PersonalNotes"); } + /** * The user's notes about the contact. + * + * @return self * @var string */ public function setPersonalNotes($value) { - $this->setProperty("PersonalNotes", $value, true); + return $this->setProperty("PersonalNotes", $value, true); } /** * The names of the contact's children. @@ -501,9 +496,6 @@ public function setPersonalNotes($value) */ public function getChildren() { - if (!$this->isPropertyAvailable("Children")) { - return null; - } return $this->getProperty("Children"); } /** @@ -520,10 +512,8 @@ public function setChildren($value) */ public function getPhoto() { - if (!$this->isPropertyAvailable("Photo")) { - $this->setProperty("Photo", new ProfilePhoto($this->getContext(), new ResourcePath("Photo", $this->getResourcePath()))); - } - return $this->getProperty("Photo"); + return $this->getProperty("Photo", + new ProfilePhoto($this->getContext(), new ResourcePath("Photo", $this->getResourcePath()))); } /** * The contact's home address. @@ -531,10 +521,7 @@ public function getPhoto() */ public function getHomeAddress() { - if (!$this->isPropertyAvailable("HomeAddress")) { - return null; - } - return $this->getProperty("HomeAddress"); + return $this->getProperty("HomeAddress", new PhysicalAddress()); } /** * The contact's home address. @@ -550,10 +537,7 @@ public function setHomeAddress($value) */ public function getBusinessAddress() { - if (!$this->isPropertyAvailable("BusinessAddress")) { - return null; - } - return $this->getProperty("BusinessAddress"); + return $this->getProperty("BusinessAddress", new PhysicalAddress()); } /** * The contact's business address. diff --git a/src/OutlookServices/ContactFolder.php b/src/OutlookServices/ContactFolder.php index 12836a8f..6cd33c7d 100644 --- a/src/OutlookServices/ContactFolder.php +++ b/src/OutlookServices/ContactFolder.php @@ -1,7 +1,7 @@ isPropertyAvailable("ContentId")) { - return null; - } return $this->getProperty("ContentId"); } /** @@ -35,9 +32,6 @@ public function setContentId($value) */ public function getContentLocation() { - if (!$this->isPropertyAvailable("ContentLocation")) { - return null; - } return $this->getProperty("ContentLocation"); } /** @@ -54,17 +48,17 @@ public function setContentLocation($value) */ public function getContentBytes() { - if (!$this->isPropertyAvailable("ContentBytes")) { - return null; - } return $this->getProperty("ContentBytes"); } + /** * The base64-encoded contents of the file. + * + * @return self * @var string */ public function setContentBytes($value) { - $this->setProperty("ContentBytes", $value, true); + return $this->setProperty("ContentBytes", $value, true); } } \ No newline at end of file diff --git a/src/OutlookServices/ItemAttachment.php b/src/OutlookServices/ItemAttachment.php index b8259846..6e0efba0 100644 --- a/src/OutlookServices/ItemAttachment.php +++ b/src/OutlookServices/ItemAttachment.php @@ -1,7 +1,7 @@ getContext()->executeQueryRetry($retryCount,$delaySecs); + return $this; + } + /** * @return ODataQueryOptions */ diff --git a/src/Runtime/ClientRequest.php b/src/Runtime/ClientRequest.php index 6d5d0125..97a10731 100644 --- a/src/Runtime/ClientRequest.php +++ b/src/Runtime/ClientRequest.php @@ -90,10 +90,14 @@ public function getCurrentQuery(){ /** * Add query into request queue * @param ClientAction $query + * @param bool $toBegin */ - public function addQuery(ClientAction $query) + public function addQuery(ClientAction $query,$toBegin=false) { - $this->queries[] = $query; + if($toBegin) + array_unshift($this->queries , $query); + else + $this->queries[] = $query; $this->currentQuery = $query; } diff --git a/src/Runtime/ClientRuntimeContext.php b/src/Runtime/ClientRuntimeContext.php index 0aca1fad..c62a3c73 100644 --- a/src/Runtime/ClientRuntimeContext.php +++ b/src/Runtime/ClientRuntimeContext.php @@ -5,6 +5,7 @@ use Exception; use Office365\Runtime\Actions\ClientAction; use Office365\Runtime\Actions\ReadEntityQuery; +use Office365\Runtime\Http\RequestException; use Office365\Runtime\Http\Response; use Office365\Runtime\Http\RequestOptions; @@ -77,15 +78,15 @@ public function addQueryAndResultObject(ClientAction $query, $resultObject) /** * @param ClientAction $query + * @param bool $toBegin */ - public function addQuery(ClientAction $query) + public function addQuery(ClientAction $query,$toBegin=false) { - $this->getPendingRequest()->addQuery($query); + $this->getPendingRequest()->addQuery($query,$toBegin); } /** * Submit a client request - * */ public function executeQuery() { @@ -94,6 +95,33 @@ public function executeQuery() } } + + /** + * Submit a query along with handling transient failures + * @param int $retryCount + * @param int $delaySecs + * @throws Exception + */ + public function executeQueryRetry($retryCount,$delaySecs) + { + $currentRetry = 0; + for(;;){ + try{ + $this->executeQuery(); + break; + } + catch(Exception $ex) { + $this->addQuery($this->getPendingRequest()->getCurrentQuery(),true); + $currentRetry++; + if ($currentRetry > $retryCount || !($ex instanceof RequestException)) + { + throw $ex; + } + sleep($delaySecs); + } + } + } + /** * @param RequestOptions $options * @return Response diff --git a/src/SharePoint/Field.php b/src/SharePoint/Field.php index 29e0306e..ac52e6d6 100644 --- a/src/SharePoint/Field.php +++ b/src/SharePoint/Field.php @@ -61,9 +61,6 @@ public function setAutoIndexed($value) */ public function getCanBeDeleted() { - if (!$this->isPropertyAvailable("CanBeDeleted")) { - return null; - } return $this->getProperty("CanBeDeleted"); } /** @@ -83,9 +80,6 @@ public function setCanBeDeleted($value) */ public function getClientSideComponentId() { - if (!$this->isPropertyAvailable("ClientSideComponentId")) { - return null; - } return $this->getProperty("ClientSideComponentId"); } /** @@ -292,9 +286,6 @@ public function setEnforceUniqueValues($value) */ public function getEntityPropertyName() { - if (!$this->isPropertyAvailable("EntityPropertyName")) { - return null; - } return $this->getProperty("EntityPropertyName"); } /** @@ -668,9 +659,6 @@ public function setScope($value) */ public function getSealed() { - if (!$this->isPropertyAvailable("Sealed")) { - return null; - } return $this->getProperty("Sealed"); } /** @@ -690,9 +678,6 @@ public function setSealed($value) */ public function getShowInFiltersPane() { - if (!$this->isPropertyAvailable("ShowInFiltersPane")) { - return null; - } return $this->getProperty("ShowInFiltersPane"); } /** @@ -712,9 +697,6 @@ public function setShowInFiltersPane($value) */ public function getSortable() { - if (!$this->isPropertyAvailable("Sortable")) { - return null; - } return $this->getProperty("Sortable"); } /** @@ -737,9 +719,6 @@ public function setSortable($value) */ public function getStaticName() { - if (!$this->isPropertyAvailable("StaticName")) { - return null; - } return $this->getProperty("StaticName"); } /** @@ -762,9 +741,6 @@ public function setStaticName($value) */ public function getTitle() { - if (!$this->isPropertyAvailable("Title")) { - return null; - } return $this->getProperty("Title"); } /** @@ -811,9 +787,6 @@ public function setFieldTypeKind($value) */ public function getTypeAsString() { - if (!$this->isPropertyAvailable("TypeAsString")) { - return null; - } return $this->getProperty("TypeAsString"); } /** @@ -836,9 +809,6 @@ public function setTypeAsString($value) */ public function getTypeDisplayName() { - if (!$this->isPropertyAvailable("TypeDisplayName")) { - return null; - } return $this->getProperty("TypeDisplayName"); } /** @@ -883,9 +853,6 @@ public function setTypeShortDescription($value) */ public function getValidationFormula() { - if (!$this->isPropertyAvailable("ValidationFormula")) { - return null; - } return $this->getProperty("ValidationFormula"); } /** diff --git a/src/SharePoint/File.php b/src/SharePoint/File.php index e89eb3d4..48d42ffa 100644 --- a/src/SharePoint/File.php +++ b/src/SharePoint/File.php @@ -174,6 +174,7 @@ public function moveTo($newUrl, $flags) { $qry = new InvokePostMethodQuery($this, "moveto", array("newurl" => rawurlencode($newUrl), "flags" => $flags)); $this->getContext()->addQuery($qry); + return $this; } /** * Moves the file to the Recycle Bin and returns the identifier of the new Recycle Bin item. @@ -182,6 +183,7 @@ public function recycle() { $qry = new InvokePostMethodQuery($this, "recycle"); $this->getContext()->addQuery($qry); + return $this; } /** * Opens the file @@ -664,9 +666,6 @@ public function setPageRenderType($value) */ public function getServerRelativeUrl() { - if (!$this->isPropertyAvailable("ServerRelativeUrl")) { - return null; - } return $this->getProperty("ServerRelativeUrl"); } /** diff --git a/src/SharePoint/UI/ApplicationPages/PickerEntityInformation.php b/src/SharePoint/UI/ApplicationPages/PickerEntityInformation.php index 871a0c78..9fe98738 100644 --- a/src/SharePoint/UI/ApplicationPages/PickerEntityInformation.php +++ b/src/SharePoint/UI/ApplicationPages/PickerEntityInformation.php @@ -15,26 +15,23 @@ class PickerEntityInformation extends BaseEntity */ public function getEntity() { - if (!$this->isPropertyAvailable("Entity")) { - return null; - } - return $this->getProperty("Entity"); + return $this->getProperty("Entity", new PickerEntityInformationRequest()); } + /** + * + * @return self * @var PickerEntityInformationRequest */ public function setEntity($value) { - $this->setProperty("Entity", $value, true); + return $this->setProperty("Entity", $value, true); } /** * @return integer */ public function getTotalMemberCount() { - if (!$this->isPropertyAvailable("TotalMemberCount")) { - return null; - } return $this->getProperty("TotalMemberCount"); } /** diff --git a/src/SharePoint/Utilities/Utility.php b/src/SharePoint/Utilities/Utility.php index 5d310f5b..7f8cd57e 100644 --- a/src/SharePoint/Utilities/Utility.php +++ b/src/SharePoint/Utilities/Utility.php @@ -48,9 +48,7 @@ public static function createNewDiscussionReply(ListItem $discussionItem,$subjec $ctx = $discussionItem->getContext(); $list = $discussionItem->getParentList(); - $contentTypes = $list->getContentTypes(); - $ctx->load($contentTypes); - $ctx->executeQuery(); + $contentTypes = $list->getContentTypes()->get()->executeQuery(); $result = $contentTypes->findItems( function (ContentType $item){ return $item->getProperty("Name") === "Message"; @@ -64,8 +62,7 @@ function (ContentType $item){ "FileSystemObjectType" => 0, "ContentTypeId" => $result[0]->getProperty("Id") ); - $messageItem = $list->addItem($messagePayload); - $ctx->executeQuery(); + $messageItem = $list->addItem($messagePayload)->executeQuery(); //move message into discussion folder $ctx->load($discussionItem,array("FileRef")); $ctx->load($messageItem,array("FileRef","FileDirRef")); diff --git a/src/Teams/UnmuteParticipantOperation.php b/src/Teams/UnmuteParticipantOperation.php new file mode 100644 index 00000000..41daad2f --- /dev/null +++ b/src/Teams/UnmuteParticipantOperation.php @@ -0,0 +1,13 @@ +getWeb(), $listTitle, ListTemplateType::DiscussionBoard); } public static function tearDownAfterClass() { - self::$discussionsList->deleteObject()->executeQuery(); + //self::$discussionsList->deleteObject()->executeQuery(); parent::tearDownAfterClass(); } @@ -47,7 +47,7 @@ public function testCreateNewDiscussion() public function testCreateNewDiscussionReply(ListItem $discussion) { $messageTitle = self::createUniqueName("Reply"); - Utility::createNewDiscussionReply($discussion,$messageTitle); + Utility::createNewDiscussionReply($discussion,$messageTitle)->executeQuery(); $discussionFolder = $discussion->getFolder(); self::$context->load($discussionFolder,array("ItemCount")); self::$context->executeQuery(); diff --git a/tests/teams/TeamsTest.php b/tests/teams/TeamsTest.php index a295d303..e8391aa4 100644 --- a/tests/teams/TeamsTest.php +++ b/tests/teams/TeamsTest.php @@ -31,11 +31,12 @@ public function testCreateTeam() /** * @depends testCreateTeam * @param Team $team + * @throws \Exception */ public function testDeleteTeam(Team $team) { - sleep(20); - $team->deleteObject()->executeQuery(); + $teamToDel = $team->get()->executeQueryRetry(); + $teamToDel->deleteObject()->executeQuery(); } } \ No newline at end of file