Skip to content

Commit c509087

Browse files
authored
Merge pull request #33 from rsf123/master
Add rename/replace behavior to upload and createFolder
2 parents 4fe9a0c + 3419c5b commit c509087

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

changelog.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,20 @@ Added files import for MsGraphAdmin
302302

303303
## Added
304304

305-
- added commands `msgraphadmin:keep-alive` and `msgraph:keep-alive` to allow refresh tokens to be automated by running these commands on a schedule
305+
- added commands `msgraphadmin:keep-alive` and `msgraph:keep-alive` to allow refresh tokens to be automated by running these commands on a schedule
306+
307+
### 3.1.5
308+
309+
Added support in Files.php to support replace/rename behavior on createFolder and file upload functions. Default behavior is to rename.
310+
311+
Usage for createFolder:
312+
```php
313+
MsGraph::files()->createFolder($name, $path, $type = 'me', $behavior='rename')
314+
```
315+
Where $behavior is either rename or replace
316+
317+
Usage for upload:
318+
```php
319+
MsGraph::files()->upload($name, $uploadPath, $path=null, $type='me',$behavior='rename')
320+
```
321+
Where $behavior is either rename or replace

src/Resources/Files.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ public function deleteFile($id, $type = 'me')
4141
return MsGraph::delete($type."/drive/items/$id");
4242
}
4343

44-
public function createFolder($name, $path, $type = 'me')
44+
public function createFolder($name, $path, $type = 'me', $behavior = 'rename')
4545
{
4646
$path = $path === null ? $type.'/drive/root/children' : $type.'/drive/root:'.$this->forceStartingSlash($path).':/children';
4747

4848
return MsGraph::post($path, [
4949
'name' => $name,
5050
'folder' => new \stdClass(),
51-
'@microsoft.graph.conflictBehavior' => 'rename',
51+
'@microsoft.graph.conflictBehavior' => $behavior,
5252
]);
5353
}
5454

@@ -66,9 +66,9 @@ public function rename($name, $id, $type = 'me')
6666
]);
6767
}
6868

69-
public function upload($name, $uploadPath, $path = null, $type = 'me')
69+
public function upload($name, $uploadPath, $path = null, $type = 'me', $behavior = 'rename')
7070
{
71-
$uploadSession = $this->createUploadSession($name, $path, $type);
71+
$uploadSession = $this->createUploadSession($name, $path, $type, $behavior);
7272
$uploadUrl = $uploadSession['uploadUrl'];
7373

7474
$fragSize = 320 * 1024;
@@ -110,13 +110,13 @@ public function upload($name, $uploadPath, $path = null, $type = 'me')
110110
}
111111
}
112112

113-
protected function createUploadSession($name, $path = null, $type = 'me')
113+
protected function createUploadSession($name, $path = null, $type = 'me', $behavior = 'rename')
114114
{
115115
$path = $path === null ? $type."/drive/root:/$name:/createUploadSession" : $type.'/drive/root:'.$this->forceStartingSlash($path)."/$name:/createUploadSession";
116116

117117
return MsGraph::post($path, [
118118
'item' => [
119-
'@microsoft.graph.conflictBehavior' => 'rename',
119+
'@microsoft.graph.conflictBehavior' => $behavior,
120120
'name' => $name,
121121
],
122122
]);

0 commit comments

Comments
 (0)