diff --git a/examples/Settings.php b/examples/Settings.php index 44459806..be8bfc3a 100644 --- a/examples/Settings.php +++ b/examples/Settings.php @@ -1,14 +1,14 @@ "https://mediadev23.sharepoint.com", - 'OneDriveUrl' => "https://mediadev23-my.SharePoint.com", + 'Url' => "https://mediadev88.sharepoint.com", + 'OneDriveUrl' => "https://mediadev88-my.SharePoint.com", 'Password' => "P@ssw0rd", - 'UserName' => "mattim@mediadev23.onmicrosoft.com" + 'UserName' => "mattim@mediadev88.onmicrosoft.com" ); $AppSettings = array( - 'TenantName' => "mediadev23.onmicrosoft.com", + 'TenantName' => "mediadev88.onmicrosoft.com", 'ClientId' => "d426369e-c84b-47db-b6b1-b9c824ac2ea2", 'ClientSecret' => "wrizJBW41]|=@govNEDR059", 'Title' => "Office365 Graph explorer", diff --git a/examples/data/SharePoint User Guide - 2007.docx b/examples/data/SharePoint User Guide - 2007.docx deleted file mode 100644 index 98750977..00000000 Binary files a/examples/data/SharePoint User Guide - 2007.docx and /dev/null differ diff --git a/examples/data/SharePoint User Guide - 2010.docx b/examples/data/SharePoint User Guide - 2010.docx deleted file mode 100644 index 90b32b32..00000000 Binary files a/examples/data/SharePoint User Guide - 2010.docx and /dev/null differ diff --git a/src/OutlookServices/Message.php b/src/OutlookServices/Message.php index aeddd9d5..b7e47176 100644 --- a/src/OutlookServices/Message.php +++ b/src/OutlookServices/Message.php @@ -21,7 +21,7 @@ public function reply($comment) { $parameter = new ClientValueObject(); $parameter->setProperty("Comment",$comment); - $qry = new InvokePostMethodQuery($this,"Reply",null,$parameter); + $qry = new InvokePostMethodQuery($this->getResourcePath(),"Reply",null,$parameter); $this->getContext()->addQuery($qry); } @@ -34,7 +34,7 @@ public function replyAll($comment) { $parameter = new ClientValueObject(); $parameter->setProperty("Comment",$comment); - $qry = new InvokePostMethodQuery($this,"ReplyAll",null,$parameter); + $qry = new InvokePostMethodQuery($this->getResourcePath(),"ReplyAll",null,$parameter); $this->getContext()->addQuery($qry); } @@ -49,7 +49,7 @@ public function forward($comment,$toRecipients) $parameter = new ClientValueObject(); $parameter->setProperty("Comment",$comment); $parameter->setProperty("ToRecipients",$toRecipients); - $qry = new InvokePostMethodQuery($this,"Forward",null,$parameter); + $qry = new InvokePostMethodQuery($this->getResourcePath(),"Forward",null,$parameter); $this->getContext()->addQuery($qry); } @@ -62,7 +62,7 @@ public function forward($comment,$toRecipients) public function move($destinationId){ $parameter = new ClientValueObject(); $parameter->setProperty("DestinationId",$destinationId); - $qry = new InvokePostMethodQuery($this,"Move",null,$parameter); + $qry = new InvokePostMethodQuery($this->getResourcePath(),"Move",null,$parameter); $this->getContext()->addQuery($qry); } diff --git a/src/OutlookServices/User.php b/src/OutlookServices/User.php index 49311e77..b93bbade 100644 --- a/src/OutlookServices/User.php +++ b/src/OutlookServices/User.php @@ -75,7 +75,7 @@ public function sendEmail(Message $message, $saveToSentItems) $payload = new ClientValueObject(); $payload->setProperty("Message", $message); $payload->setProperty("SaveToSentItems", $saveToSentItems); - $action = new InvokePostMethodQuery($this, "SendMail",null,$payload); + $action = new InvokePostMethodQuery($this->getResourcePath(), "SendMail",null,$payload); $this->getContext()->addQuery($action); } diff --git a/src/Runtime/Auth/SamlTokenProvider.php b/src/Runtime/Auth/SamlTokenProvider.php index 8b6f27e1..183db0f7 100644 --- a/src/Runtime/Auth/SamlTokenProvider.php +++ b/src/Runtime/Auth/SamlTokenProvider.php @@ -53,8 +53,11 @@ public function getAuthenticationCookie() return 'FedAuth=' . $this->FedAuth . '; rtFa=' . $this->rtFa; } - + /** + * @param $parameters + * @throws Exception + */ public function acquireToken($parameters) { $token = $this->acquireSecurityToken($parameters['username'], $parameters['password']); diff --git a/src/Runtime/ContextResourcePath.php b/src/Runtime/ContextResourcePath.php new file mode 100644 index 00000000..b07ef9e8 --- /dev/null +++ b/src/Runtime/ContextResourcePath.php @@ -0,0 +1,23 @@ +getResourcePath(),null,null,$entity); } } \ No newline at end of file diff --git a/src/Runtime/DeleteEntityQuery.php b/src/Runtime/DeleteEntityQuery.php index 4ce3c9e8..aac1bf8f 100644 --- a/src/Runtime/DeleteEntityQuery.php +++ b/src/Runtime/DeleteEntityQuery.php @@ -13,6 +13,6 @@ class DeleteEntityQuery extends InvokePostMethodQuery */ public function __construct(ClientObject $clientObject) { - parent::__construct($clientObject); + parent::__construct($clientObject->getResourcePath()); } } \ No newline at end of file diff --git a/src/Runtime/InvokeMethodQuery.php b/src/Runtime/InvokeMethodQuery.php index 6ce28d45..b4815d9b 100644 --- a/src/Runtime/InvokeMethodQuery.php +++ b/src/Runtime/InvokeMethodQuery.php @@ -11,16 +11,16 @@ class InvokeMethodQuery extends ClientAction /** * InvokeMethodQuery constructor. - * @param ClientObject $parentClientObject + * @param ResourcePath $resourcePath * @param string $methodName * @param array|ISchemaType $methodParameters */ - public function __construct(ClientObject $parentClientObject, $methodName=null, $methodParameters=null) + public function __construct(ResourcePath $resourcePath, $methodName=null, $methodParameters=null) { $path = new ResourcePathServiceOperation( - $parentClientObject->getContext(), - $parentClientObject->getResourcePath(), + $resourcePath->getContext(), + $resourcePath, $methodName, $methodParameters ); diff --git a/src/Runtime/InvokePostMethodQuery.php b/src/Runtime/InvokePostMethodQuery.php index 02828aed..208eb3dd 100644 --- a/src/Runtime/InvokePostMethodQuery.php +++ b/src/Runtime/InvokePostMethodQuery.php @@ -7,18 +7,17 @@ class InvokePostMethodQuery extends InvokeMethodQuery { - /** * ClientActionUpdateMethod constructor. - * @param ClientObject $parentClientObject + * @param ResourcePath $resourcePath * @param string $methodName * @param array $methodParameters * @param string|ISchemaType $methodPayload */ - public function __construct(ClientObject $parentClientObject, $methodName = null,$methodParameters=null,$methodPayload=null) + public function __construct(ResourcePath $resourcePath, $methodName = null,$methodParameters=null,$methodPayload=null) { $this->MethodPayload = $methodPayload; - parent::__construct($parentClientObject,$methodName, $methodParameters); + parent::__construct($resourcePath,$methodName, $methodParameters); } diff --git a/src/Runtime/OData/ODataRequest.php b/src/Runtime/OData/ODataRequest.php index a8c57783..6efa99e9 100644 --- a/src/Runtime/OData/ODataRequest.php +++ b/src/Runtime/OData/ODataRequest.php @@ -260,6 +260,8 @@ public function buildRequest(ClientAction $query) $request->Method = HttpMethod::Post; if (is_string($query->MethodPayload)) $request->Data = $query->MethodPayload; + if (is_array($query->MethodPayload)) + $request->Data = json_encode($query->MethodPayload); else if ($query->MethodPayload instanceof ISchemaType) { //build request payload $payload = $this->normalizePayload($query->MethodPayload); diff --git a/src/Runtime/ResourcePath.php b/src/Runtime/ResourcePath.php index 3984f438..a728e531 100644 --- a/src/Runtime/ResourcePath.php +++ b/src/Runtime/ResourcePath.php @@ -43,7 +43,8 @@ public function toUrl() $paths = array(); $current = clone $this; while (isset($current)) { - array_unshift($paths, $current->toString()); + if(!is_null($current->toString())) + array_unshift($paths, $current->toString()); $current = $current->parent; } return implode("/", $paths); diff --git a/src/Runtime/ResourcePathServiceOperation.php b/src/Runtime/ResourcePathServiceOperation.php index 5ba9c8a1..5b34d8ba 100644 --- a/src/Runtime/ResourcePathServiceOperation.php +++ b/src/Runtime/ResourcePathServiceOperation.php @@ -13,11 +13,11 @@ class ResourcePathServiceOperation extends ResourcePath implements ICSOMCallable /** * ResourcePathMethod constructor. * @param ClientRuntimeContext $context - * @param ResourcePath $parent + * @param ResourcePath|null $parent * @param string $methodName * @param array $methodParameters */ - public function __construct(ClientRuntimeContext $context, ResourcePath $parent, $methodName, $methodParameters = null) + public function __construct(ClientRuntimeContext $context, ResourcePath $parent=null, $methodName, $methodParameters = null) { parent::__construct($context, $parent); $this->methodName = $methodName; diff --git a/src/Runtime/UpdateEntityQuery.php b/src/Runtime/UpdateEntityQuery.php index ca5a9dba..1eceab40 100644 --- a/src/Runtime/UpdateEntityQuery.php +++ b/src/Runtime/UpdateEntityQuery.php @@ -13,7 +13,7 @@ class UpdateEntityQuery extends InvokePostMethodQuery */ public function __construct(ClientObject $entity) { - parent::__construct($entity,null,null,$entity); + parent::__construct($entity->getResourcePath(),null,null,$entity); } diff --git a/src/SharePoint/AttachmentCollection.php b/src/SharePoint/AttachmentCollection.php index f39f79bb..3529f045 100644 --- a/src/SharePoint/AttachmentCollection.php +++ b/src/SharePoint/AttachmentCollection.php @@ -18,7 +18,7 @@ public function add(AttachmentCreationInformation $information) { $attachment = new Attachment($this->getContext(),$this->getResourcePath()); $qry = new InvokePostMethodQuery( - $this, + $this->getResourcePath(), "add", array("FileName" =>rawurlencode($information->FileName)), $information->ContentStream); diff --git a/src/SharePoint/ContentTypeCollection.php b/src/SharePoint/ContentTypeCollection.php index e76e4cf1..3d47afe1 100644 --- a/src/SharePoint/ContentTypeCollection.php +++ b/src/SharePoint/ContentTypeCollection.php @@ -33,7 +33,7 @@ public function getById($id) public function add(ContentTypeCreationInformation $information) { $contentType = new ContentType($this->getContext()); - $qry = new InvokePostMethodQuery($this,null,null,$information); + $qry = new InvokePostMethodQuery($this->getResourcePath(),null,null,$information); $this->getContext()->addQuery($qry,$contentType); $this->addChild($contentType); return $contentType; diff --git a/src/SharePoint/Field.php b/src/SharePoint/Field.php index 566f6de8..745374e9 100644 --- a/src/SharePoint/Field.php +++ b/src/SharePoint/Field.php @@ -31,7 +31,7 @@ public function deleteObject() */ public function setShowInDisplayForm($value){ $qry = new InvokePostMethodQuery( - $this, + $this->getResourcePath(), "setShowInDisplayForm", array($value) ); diff --git a/src/SharePoint/FieldCollection.php b/src/SharePoint/FieldCollection.php index 843aa5b5..c6609461 100644 --- a/src/SharePoint/FieldCollection.php +++ b/src/SharePoint/FieldCollection.php @@ -20,7 +20,7 @@ class FieldCollection extends ClientObjectCollection public function add(FieldCreationInformation $parameters) { $field = new Field($this->getContext(),$this->getResourcePath()); - $qry = new InvokePostMethodQuery($this,null,null,$parameters); + $qry = new InvokePostMethodQuery($this->getResourcePath(),null,null,$parameters); $this->getContext()->addQuery($qry,$field); $this->addChild($field); return $field; diff --git a/src/SharePoint/File.php b/src/SharePoint/File.php index a1e98aa4..218188ee 100644 --- a/src/SharePoint/File.php +++ b/src/SharePoint/File.php @@ -21,7 +21,7 @@ class File extends SecurableObject * Checks out the file from a document library based on the check-out type. */ public function checkOut(){ - $qry = new InvokePostMethodQuery($this,"checkout"); + $qry = new InvokePostMethodQuery($this->getResourcePath(),"checkout"); $this->getContext()->addQuery($qry); } @@ -30,7 +30,7 @@ public function checkOut(){ * Reverts an existing checkout for the file. */ public function undoCheckout(){ - $qry = new InvokePostMethodQuery($this,"undocheckout"); + $qry = new InvokePostMethodQuery($this->getResourcePath(),"undocheckout"); $this->getContext()->addQuery($qry); } @@ -40,7 +40,7 @@ public function undoCheckout(){ * @param string $comment A comment for the check-in. Its length must be <= 1023. */ public function checkIn($comment){ - $qry = new InvokePostMethodQuery($this,"checkIn",array( + $qry = new InvokePostMethodQuery($this->getResourcePath(),"checkIn",array( "comment" =>$comment, "checkintype" =>0 )); @@ -53,7 +53,7 @@ public function checkIn($comment){ * @param string $comment The comment for the approval. */ public function approve($comment){ - $qry = new InvokePostMethodQuery($this,"approve",array( + $qry = new InvokePostMethodQuery($this->getResourcePath(),"approve",array( "comment" =>$comment )); $this->getContext()->addQuery($qry); @@ -64,7 +64,7 @@ public function approve($comment){ * @param string $comment The comment for the denial. */ public function deny($comment){ - $qry = new InvokePostMethodQuery($this, "deny",array( + $qry = new InvokePostMethodQuery($this->getResourcePath(), "deny",array( "comment" =>$comment )); $this->getContext()->addQuery($qry); @@ -75,7 +75,7 @@ public function deny($comment){ * @param string $comment The comment for the published file. Its length must be <= 1023. */ public function publish($comment){ - $qry = new InvokePostMethodQuery($this, "publish",array( + $qry = new InvokePostMethodQuery($this->getResourcePath(), "publish",array( "comment" =>$comment )); $this->getContext()->addQuery($qry); @@ -87,7 +87,7 @@ public function publish($comment){ * @param string $comment The comment for the unpublish operation. Its length must be <= 1023. */ public function unpublish($comment){ - $qry = new InvokePostMethodQuery($this,"unpublish", array( + $qry = new InvokePostMethodQuery($this->getResourcePath(),"unpublish", array( "comment" => $comment )); $this->getContext()->addQuery($qry); @@ -100,7 +100,7 @@ public function unpublish($comment){ * @param bool $bOverWrite true to overwrite a file with the same name in the same location; otherwise false. */ public function copyTo($strNewUrl,$bOverWrite){ - $qry = new InvokePostMethodQuery($this, "copyto", array( + $qry = new InvokePostMethodQuery($this->getResourcePath(), "copyto", array( "strnewurl"=>$strNewUrl, "boverwrite"=>$bOverWrite )); @@ -113,7 +113,7 @@ public function copyTo($strNewUrl,$bOverWrite){ * @param int $flags The bitwise SP.MoveOperations value for how to move the file. Overwrite = 1; AllowBrokenThickets (move even if supporting files are separated from the file) = 8. */ public function moveTo($newUrl,$flags){ - $qry = new InvokePostMethodQuery($this, "moveto", array( + $qry = new InvokePostMethodQuery($this->getResourcePath(), "moveto", array( "newurl"=>$newUrl, "flags"=>$flags )); @@ -125,7 +125,7 @@ public function moveTo($newUrl,$flags){ * Moves the file to the Recycle Bin and returns the identifier of the new Recycle Bin item. */ public function recycle(){ - $qry = new InvokePostMethodQuery($this, "recycle"); + $qry = new InvokePostMethodQuery($this->getResourcePath(), "recycle"); $this->getContext()->addQuery($qry); } diff --git a/src/SharePoint/FileCollection.php b/src/SharePoint/FileCollection.php index ccd10212..900884d7 100644 --- a/src/SharePoint/FileCollection.php +++ b/src/SharePoint/FileCollection.php @@ -22,7 +22,7 @@ public function add(FileCreationInformation $fileCreationInformation) { $file = new File($this->getContext(),$this->getResourcePath()); $qry = new InvokePostMethodQuery( - $this, + $this->getResourcePath(), "add", array("overwrite"=>$fileCreationInformation->Overwrite,"url"=>rawurlencode($fileCreationInformation->Url)), $fileCreationInformation->Content @@ -43,7 +43,7 @@ public function addTemplateFile($urlOfFile,$templateFileType) { $file = new File($this->getContext(),$this->getResourcePath()); $qry = new InvokePostMethodQuery( - $this, + $this->getResourcePath(), "addTemplateFile", array( "urlOfFile" => $urlOfFile, diff --git a/src/SharePoint/Folder.php b/src/SharePoint/Folder.php index e7cec1e0..0d242b93 100644 --- a/src/SharePoint/Folder.php +++ b/src/SharePoint/Folder.php @@ -39,7 +39,7 @@ public function rename($name){ * Moves the list folder to the Recycle Bin and returns the identifier of the new Recycle Bin item. */ public function recycle(){ - $qry = new InvokePostMethodQuery($this,"recycle"); + $qry = new InvokePostMethodQuery($this->getResourcePath(),"recycle"); $this->getContext()->addQuery($qry); } diff --git a/src/SharePoint/GroupCollection.php b/src/SharePoint/GroupCollection.php index 9de097b6..884a50d0 100644 --- a/src/SharePoint/GroupCollection.php +++ b/src/SharePoint/GroupCollection.php @@ -23,7 +23,7 @@ class GroupCollection extends ClientObjectCollection public function add(GroupCreationInformation $parameters) { $group = new Group($this->getContext(), $this->getResourcePath()); - $qry = new InvokePostMethodQuery($this,null,null, $parameters); + $qry = new InvokePostMethodQuery($this->getResourcePath(),null,null, $parameters); $this->getContext()->addQuery($qry, $group); $this->addChild($group); return $group; @@ -66,7 +66,7 @@ public function getByName($name) */ public function removeById($id) { - $qry = new InvokePostMethodQuery($this, "removebyid", array($id)); + $qry = new InvokePostMethodQuery($this->getResourcePath(), "removebyid", array($id)); $this->getContext()->addQuery($qry); } @@ -77,7 +77,7 @@ public function removeById($id) */ public function removeByLoginName($groupName) { - $qry = new InvokePostMethodQuery($this, "removeByLoginName", array($groupName)); + $qry = new InvokePostMethodQuery($this->getResourcePath(), "removeByLoginName", array($groupName)); $this->getContext()->addQuery($qry); } } diff --git a/src/SharePoint/ListCollection.php b/src/SharePoint/ListCollection.php index 794da253..26b60306 100644 --- a/src/SharePoint/ListCollection.php +++ b/src/SharePoint/ListCollection.php @@ -46,7 +46,7 @@ public function getById($id) public function add(ListCreationInformation $properties) { $list = new SPList($this->getContext()); - $qry = new InvokePostMethodQuery($this,null,null,$properties); + $qry = new InvokePostMethodQuery($this->getResourcePath(),null,null,$properties); $this->getContext()->addQuery($qry,$list); $this->addChild($list); return $list; diff --git a/src/SharePoint/Portal/GroupSiteManager.php b/src/SharePoint/Portal/GroupSiteManager.php index 46340188..b277b99b 100644 --- a/src/SharePoint/Portal/GroupSiteManager.php +++ b/src/SharePoint/Portal/GroupSiteManager.php @@ -42,7 +42,7 @@ public function createGroupEx($displayName,$alias,$isPublic,$description="",$add } $info = new GroupSiteInfo(); - $qry = new InvokePostMethodQuery($this,"CreateGroupEx",null,$payload); + $qry = new InvokePostMethodQuery($this->getResourcePath(),"CreateGroupEx",null,$payload); $this->getContext()->addQuery($qry,$info); return $info; } diff --git a/src/SharePoint/SPList.php b/src/SharePoint/SPList.php index 42b80b2a..ab271f2c 100644 --- a/src/SharePoint/SPList.php +++ b/src/SharePoint/SPList.php @@ -61,7 +61,7 @@ public function getItems(CamlQuery $camlQuery = null) $items = new ListItemCollection($this->getContext(),new ResourcePathEntity($this->getContext(),$this->getResourcePath(),"items")); if(isset($camlQuery)){ $qry = new InvokePostMethodQuery( - $this, + $this->getResourcePath(), "GetItems", null, $camlQuery @@ -101,7 +101,7 @@ public function getUserEffectivePermissions($loginName) { $permissions = new BasePermissions(); $qry = new InvokeMethodQuery( - $this, + $this->getResourcePath(), "GetUserEffectivePermissions", array(rawurlencode($loginName)) ); @@ -118,7 +118,7 @@ public function getListItemChangesSinceToken(ChangeLogItemQuery $query) { $result = new ListItemCollection($this->getContext()); $qry = new InvokePostMethodQuery( - $this, + $this->getResourcePath(), "getListItemChangesSinceToken", null, $query @@ -136,7 +136,7 @@ public function getChanges(ChangeQuery $query) { $changes = new ChangeCollection($this->getContext()); $qry = new InvokePostMethodQuery( - $this, + $this->getResourcePath(), "GetChanges", null, $query diff --git a/src/SharePoint/SecurableObject.php b/src/SharePoint/SecurableObject.php index 41badc5d..85a0ddf7 100644 --- a/src/SharePoint/SecurableObject.php +++ b/src/SharePoint/SecurableObject.php @@ -17,7 +17,7 @@ class SecurableObject extends ClientObject */ public function breakRoleInheritance($copyRoleAssignments) { - $qry = new InvokePostMethodQuery($this,"breakroleinheritance",array( + $qry = new InvokePostMethodQuery($this->getResourcePath(),"breakroleinheritance",array( $copyRoleAssignments )); $this->getContext()->addQuery($qry); diff --git a/src/SharePoint/Site.php b/src/SharePoint/Site.php index 59b9429b..00d2a7d2 100644 --- a/src/SharePoint/Site.php +++ b/src/SharePoint/Site.php @@ -18,7 +18,7 @@ class Site extends ClientObject public function openWebById($webId) { $web = new Web($this->getContext(),$this->getResourcePath()); - $qry = new InvokePostMethodQuery($this,"openWebById",array($webId)); + $qry = new InvokePostMethodQuery($this->getResourcePath(),"openWebById",array($webId)); $this->getContext()->addQuery($qry,$web); return $web; } diff --git a/src/SharePoint/UserCollection.php b/src/SharePoint/UserCollection.php index 2380608c..85c042f4 100644 --- a/src/SharePoint/UserCollection.php +++ b/src/SharePoint/UserCollection.php @@ -52,7 +52,7 @@ public function getByLoginName($loginName) */ public function removeById($id) { - $qry = new InvokePostMethodQuery($this,"removebyid",array($id)); + $qry = new InvokePostMethodQuery($this->getResourcePath(),"removebyid",array($id)); $this->getContext()->addQuery($qry); } @@ -63,7 +63,7 @@ public function removeById($id) public function removeByLoginName($loginName) { $qry = new InvokePostMethodQuery( - $this, + $this->getResourcePath(), "removebyloginname", array(rawurlencode($loginName))); $this->getContext()->addQuery($qry); diff --git a/src/SharePoint/UserProfiles/PeopleManager.php b/src/SharePoint/UserProfiles/PeopleManager.php index df4225b6..8a0f2c38 100644 --- a/src/SharePoint/UserProfiles/PeopleManager.php +++ b/src/SharePoint/UserProfiles/PeopleManager.php @@ -30,7 +30,7 @@ public function __construct(ClientRuntimeContext $ctx) */ public function amIFollowedBy ($accountName){ $result = new ClientResult("AmIFollowedBy"); - $qry = new InvokeMethodQuery($this, "AmIFollowedBy",array(rawurlencode($accountName))); + $qry = new InvokeMethodQuery($this->getResourcePath(), "AmIFollowedBy",array(rawurlencode($accountName))); $this->getContext()->addQuery($qry,$result); return $result; } @@ -64,7 +64,7 @@ public function getMyFollowers(){ * @param string $accountName */ public function follow($accountName){ - $qry = new InvokePostMethodQuery($this, "follow",array(rawurlencode($accountName))); + $qry = new InvokePostMethodQuery($this->getResourcePath(), "follow",array(rawurlencode($accountName))); $this->getContext()->addQuery($qry); } @@ -76,7 +76,7 @@ public function follow($accountName){ */ public function stopFollowing ($accountName){ $result = new ClientResult("StopFollowing"); - $qry = new InvokePostMethodQuery($this, "StopFollowing",array(rawurlencode($accountName))); + $qry = new InvokePostMethodQuery($this->getResourcePath(), "StopFollowing",array(rawurlencode($accountName))); $this->getContext()->addQuery($qry,$result); return $result; } @@ -90,7 +90,7 @@ public function stopFollowing ($accountName){ public function amIFollowing ($accountName){ $result = new ClientResult("AmIFollowing"); $qry = new InvokeMethodQuery( - $this, + $this->getResourcePath(), "AmIFollowing", array(rawurlencode($accountName)) ); @@ -122,7 +122,7 @@ public function getUserProfilePropertyFor ($accountName,$propertyName) { $clientResult = new ClientResult("GetUserProfilePropertyFor"); $qry = new InvokeMethodQuery( - $this, + $this->getResourcePath(), "GetUserProfilePropertyFor", array( "accountname" => rawurlencode($accountName), diff --git a/src/SharePoint/UserProfiles/UserProfile.php b/src/SharePoint/UserProfiles/UserProfile.php index a48839ce..0bb5a94c 100644 --- a/src/SharePoint/UserProfiles/UserProfile.php +++ b/src/SharePoint/UserProfiles/UserProfile.php @@ -21,7 +21,7 @@ public function __construct(ClientRuntimeContext $ctx) */ public function createPersonalSiteEnque(){ $qry = new InvokePostMethodQuery( - $this, + $this->getResourcePath(), "createpersonalsiteenque", array(false) ); diff --git a/src/SharePoint/View.php b/src/SharePoint/View.php index 0e41b6aa..86ca243f 100644 --- a/src/SharePoint/View.php +++ b/src/SharePoint/View.php @@ -51,7 +51,7 @@ public function deleteObject() */ public function renderAsHtml(){ $qry = new InvokeMethodQuery( - $this, + $this->getResourcePath(), "renderashtml" ); $this->getContext()->addQuery($qry); diff --git a/src/SharePoint/ViewCollection.php b/src/SharePoint/ViewCollection.php index 5f36e6d0..3dffe29c 100644 --- a/src/SharePoint/ViewCollection.php +++ b/src/SharePoint/ViewCollection.php @@ -46,7 +46,7 @@ public function getById($id) public function add(ViewCreationInformation $properties) { $view = new View($this->getContext(),$this->getResourcePath()); - $qry = new InvokePostMethodQuery($this,null,null,$properties); + $qry = new InvokePostMethodQuery($this->getResourcePath(),null,null,$properties); $this->getContext()->addQuery($qry,$view); $this->addChild($view); return $view; diff --git a/src/SharePoint/Web.php b/src/SharePoint/Web.php index f02bbe87..06306876 100644 --- a/src/SharePoint/Web.php +++ b/src/SharePoint/Web.php @@ -3,6 +3,9 @@ namespace Office365\PHP\Client\SharePoint; use Office365\PHP\Client\Runtime\ClientAction; use Office365\PHP\Client\Runtime\ClientResult; +use Office365\PHP\Client\Runtime\ClientRuntimeContext; +use Office365\PHP\Client\Runtime\ClientValueObject; +use Office365\PHP\Client\Runtime\ContextResourcePath; use Office365\PHP\Client\Runtime\DeleteEntityQuery; use Office365\PHP\Client\Runtime\InvokePostMethodQuery; use Office365\PHP\Client\Runtime\UpdateEntityQuery; @@ -20,6 +23,50 @@ class Web extends SecurableObject { + /** + * @param ClientRuntimeContext $context + * @param string $url + * @param boolean $isEditLink + * @return ClientResult + */ + public static function createAnonymousLink($context, $url, $isEditLink) + { + $result = new ClientResult("CreateAnonymousLink"); + $rootPath = new ContextResourcePath($context); + $qry = new InvokePostMethodQuery($rootPath, + "SP.Web.CreateAnonymousLink", + null, + array( + "url" => $url, + "isEditLink" => $isEditLink + )); + $context->addQuery($qry,$result); + return $result; + } + + /** + * @param ClientRuntimeContext $context + * @param string $url + * @param boolean $isEditLink + * @param string $expirationString + * @return ClientResult + */ + public static function createAnonymousLinkWithExpiration($context, $url, $isEditLink,$expirationString) + { + $result = new ClientResult("CreateAnonymousLinkWithExpiration"); + $rootPath = new ContextResourcePath($context); + $qry = new InvokePostMethodQuery($rootPath, + "SP.Web.CreateAnonymousLinkWithExpiration", + null, + array( + "url" => $url, + "isEditLink" => $isEditLink, + "expirationString" => $expirationString + )); + $context->addQuery($qry,$result); + return $result; + } + public function update() { $qry = new UpdateEntityQuery($this); @@ -43,7 +90,7 @@ public function getChanges(ChangeQuery $query) { $changes = new ChangeCollection($this->getContext()); $qry = new InvokePostMethodQuery( - $this, + $this->getResourcePath(), "GetChanges", null, $query diff --git a/src/SharePoint/WebCollection.php b/src/SharePoint/WebCollection.php index b44ba1ee..658a87d7 100644 --- a/src/SharePoint/WebCollection.php +++ b/src/SharePoint/WebCollection.php @@ -20,7 +20,7 @@ public function add(WebCreationInformation $webCreationInformation) { $web = new Web($this->getContext(),$this->getResourcePath()); $qry = new InvokePostMethodQuery( - $this, + $this->getResourcePath(), "Add", null, $webCreationInformation diff --git a/src/SharePoint/WebParts/LimitedWebPartManager.php b/src/SharePoint/WebParts/LimitedWebPartManager.php index 47d9b68c..f3c4a1f9 100644 --- a/src/SharePoint/WebParts/LimitedWebPartManager.php +++ b/src/SharePoint/WebParts/LimitedWebPartManager.php @@ -23,7 +23,7 @@ public function importWebPart($webPartXml) $payload->setProperty("webPartXml",$webPartXml); $webPartDefinition = new WebPartDefinition($this->getContext()); $qry = new InvokePostMethodQuery( - $this, + $this->getResourcePath(), "ImportWebPart", null, $payload diff --git a/src/SharePoint/WebParts/WebPartDefinition.php b/src/SharePoint/WebParts/WebPartDefinition.php index 0d11986a..ef6d132e 100644 --- a/src/SharePoint/WebParts/WebPartDefinition.php +++ b/src/SharePoint/WebParts/WebPartDefinition.php @@ -12,7 +12,7 @@ class WebPartDefinition extends ClientObject public function saveWebPartChanges(){ $qry = new InvokePostMethodQuery( - $this, + $this->getResourcePath(), "SaveWebPartChanges" ); $this->getContext()->addQuery($qry); @@ -21,7 +21,7 @@ public function saveWebPartChanges(){ public function closeWebPart() { $qry = new InvokePostMethodQuery( - $this, + $this->getResourcePath(), "CloseWebPart" ); $this->getContext()->addQuery($qry); diff --git a/tests/FileTest.php b/tests/FileTest.php index 05b45819..15782f60 100644 --- a/tests/FileTest.php +++ b/tests/FileTest.php @@ -1,6 +1,8 @@ Content = file_get_contents($filename); @@ -37,11 +40,32 @@ public function testUploadFiles(){ $uploadFile = self::$targetList->getRootFolder()->getFiles()->add($fileCreationInformation); self::$context->executeQuery(); $this->assertEquals($uploadFile->getProperty("Name"),$fileCreationInformation->Url); - + $results[] = $uploadFile; } self::assertTrue(true); + return $results[0]; } + /** + * @depends testUploadFiles + * @param $uploadFile + */ + public function testUploadedFileCreateAnonymousLink(\Office365\PHP\Client\SharePoint\File $uploadFile) + { + $listItem = $uploadFile->getListItemAllFields(); + self::$context->load($listItem,array("EncodedAbsUrl")); + self::$context->executeQuery(); + + $fileUrl = $listItem->getProperty("EncodedAbsUrl"); + $result = Web::createAnonymousLink(self::$context,$fileUrl,false); + self::$context->executeQuery(); + self::assertNotEmpty($result->Value); + + $expireDate = new \DateTime('now +1 day'); + $result = Web::createAnonymousLinkWithExpiration(self::$context,$fileUrl,false,$expireDate->format(DateTime::ATOM)); + self::$context->executeQuery(); + self::assertNotEmpty($result->Value); + } public function testGetFileVersions() { diff --git a/tests/PeopleManagerTest.php b/tests/PeopleManagerTest.php index ee7ad878..453c4b5f 100644 --- a/tests/PeopleManagerTest.php +++ b/tests/PeopleManagerTest.php @@ -11,7 +11,7 @@ class PeopleManagerTest extends SharePointTestCase { - private static $accountName = "i:0#.f|membership|vgrem@mediadev20.onmicrosoft.com"; + private static $accountName = "i:0#.f|membership|vgrem@mediadev88.onmicrosoft.com"; public function testGetMyProperties(){ $peopleManager = new PeopleManager(self::$context); diff --git a/tests/WebTest.php b/tests/WebTest.php index c7180486..53a8d097 100644 --- a/tests/WebTest.php +++ b/tests/WebTest.php @@ -11,7 +11,6 @@ class WebTest extends SharePointTestCase { - public function testGetWebProperties() { $result = self::$context->getWeb()->getSupportedUILanguageIds();