1
|
|
|
<?php |
2
|
|
|
namespace Dkd\PhpCmis\Bindings\Browser; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* This file is part of php-cmis-lib. |
6
|
|
|
* |
7
|
|
|
* (c) Sascha Egerer <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
use Dkd\PhpCmis\Constants; |
14
|
|
|
use Dkd\PhpCmis\Data\AclInterface; |
15
|
|
|
use Dkd\PhpCmis\PropertyIds; |
16
|
|
|
use GuzzleHttp\Stream\StreamInterface; |
17
|
|
|
use Dkd\PhpCmis\Data\ExtensionDataInterface; |
18
|
|
|
use Dkd\PhpCmis\Data\ObjectDataInterface; |
19
|
|
|
use Dkd\PhpCmis\Data\PropertiesInterface; |
20
|
|
|
use Dkd\PhpCmis\VersioningServiceInterface; |
21
|
|
|
use Dkd\PhpCmis\Enum\IncludeRelationships; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Versioning Service Browser Binding client. |
25
|
|
|
*/ |
26
|
|
|
class VersioningService extends AbstractBrowserBindingService implements VersioningServiceInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Reverses the effect of a check-out. |
30
|
|
|
* |
31
|
|
|
* @param string $repositoryId the identifier for the repository |
32
|
|
|
* @param string $objectId the identifier for the PWC |
33
|
|
|
* @param ExtensionDataInterface|null $extension |
34
|
|
|
* @return ObjectDataInterface|null |
35
|
|
|
*/ |
36
|
|
|
public function cancelCheckOut($repositoryId, $objectId, ExtensionDataInterface $extension = null) |
37
|
|
|
{ |
38
|
|
|
return $this->getJsonConverter()->convertObject( |
39
|
|
|
$this->post( |
40
|
|
|
$this->getObjectUrl($repositoryId, $objectId), |
41
|
|
|
$this->createQueryArray( |
42
|
|
|
Constants::CMISACTION_CANCEL_CHECK_OUT, |
43
|
|
|
array(), |
44
|
|
|
$extension |
45
|
|
|
) |
46
|
|
|
)->json() |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Checks-in the private working copy (PWC) document. |
52
|
|
|
* |
53
|
|
|
* @param string $repositoryId the identifier for the repository |
54
|
|
|
* @param string $objectId input: the identifier for the PWC, |
55
|
|
|
* output: the identifier for the newly created version document |
56
|
|
|
* @param boolean $major indicator if the new version should become a major (<code>true</code>) or minor |
57
|
|
|
* (<code>false</code>) version |
58
|
|
|
* @param PropertiesInterface|null $properties the property values that must be applied to the |
59
|
|
|
* newly created document object |
60
|
|
|
* @param StreamInterface|null $contentStream the content stream that must be stored |
61
|
|
|
* for the newly created document object |
62
|
|
|
* @param string|null $checkinComment a version comment |
63
|
|
|
* @param string[] $policies a list of policy IDs that must be applied to the newly created document object |
64
|
|
|
* @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object |
65
|
|
|
* @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object |
66
|
|
|
* @param ExtensionDataInterface|null $extension |
67
|
|
|
* @return ObjectDataInterface|null |
68
|
|
|
*/ |
69
|
|
|
public function checkIn( |
70
|
|
|
$repositoryId, |
71
|
|
|
$objectId, |
72
|
|
|
$major = true, |
73
|
|
|
PropertiesInterface $properties = null, |
74
|
|
|
StreamInterface $contentStream = null, |
75
|
|
|
$checkinComment = null, |
76
|
|
|
array $policies = array(), |
77
|
|
|
AclInterface $addAces = null, |
78
|
|
|
AclInterface $removeAces = null, |
79
|
|
|
ExtensionDataInterface $extension = null |
80
|
|
|
) { |
81
|
|
|
$queryArray = $this->createQueryArray( |
82
|
|
|
Constants::CMISACTION_CHECK_IN, |
83
|
|
|
array( |
84
|
|
|
Constants::PARAM_MAJOR => $major ? 'true' : 'false', |
85
|
|
|
), |
86
|
|
|
$extension |
87
|
|
|
); |
88
|
|
|
if ($properties) { |
89
|
|
|
$queryArray = array_replace( |
90
|
|
|
$queryArray, |
91
|
|
|
$this->convertPropertiesToQueryArray($properties) |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
if ($checkinComment) { |
|
|
|
|
95
|
|
|
$queryArray[Constants::PARAM_CHECKIN_COMMENT] = $checkinComment; |
96
|
|
|
} |
97
|
|
|
if (!empty($policies)) { |
98
|
|
|
$queryArray = array_replace( |
99
|
|
|
$queryArray, |
100
|
|
|
$this->convertPolicyIdArrayToQueryArray($policies) |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
View Code Duplication |
if (!empty($removeAces)) { |
|
|
|
|
104
|
|
|
$queryArray = array_replace($queryArray, $this->convertAclToQueryArray( |
105
|
|
|
$removeAces, |
106
|
|
|
Constants::CONTROL_REMOVE_ACE_PRINCIPAL, |
107
|
|
|
Constants::CONTROL_REMOVE_ACE_PERMISSION |
108
|
|
|
)); |
109
|
|
|
} |
110
|
|
View Code Duplication |
if (!empty($addAces)) { |
|
|
|
|
111
|
|
|
$queryArray = array_replace($queryArray, $this->convertAclToQueryArray( |
112
|
|
|
$addAces, |
113
|
|
|
Constants::CONTROL_ADD_ACE_PRINCIPAL, |
114
|
|
|
Constants::CONTROL_ADD_ACE_PERMISSION |
115
|
|
|
)); |
116
|
|
|
} |
117
|
|
|
if ($contentStream) { |
118
|
|
|
$queryArray['content'] = $contentStream; |
119
|
|
|
} |
120
|
|
|
return $this->getJsonConverter()->convertObject( |
121
|
|
|
$this->post( |
122
|
|
|
$this->getObjectUrl($repositoryId, $objectId), |
123
|
|
|
$queryArray |
124
|
|
|
)->json() |
125
|
|
|
); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Create a private working copy of the document. |
130
|
|
|
* |
131
|
|
|
* @param string $repositoryId the identifier for the repository |
132
|
|
|
* @param string $objectId input: the identifier for the document that should be checked out, |
133
|
|
|
* output: the identifier for the newly created PWC |
134
|
|
|
* @param ExtensionDataInterface|null $extension |
135
|
|
|
* @param boolean|null $contentCopied output: indicator if the content of the original |
136
|
|
|
* document has been copied to the PWC |
137
|
|
|
* @return ObjectDataInterface|null |
138
|
|
|
*/ |
139
|
|
|
public function checkOut( |
140
|
|
|
$repositoryId, |
141
|
|
|
& $objectId, |
142
|
|
|
ExtensionDataInterface $extension = null, |
143
|
|
|
$contentCopied = null |
144
|
|
|
) { |
145
|
|
|
$objectData = $this->getJsonConverter()->convertObject( |
146
|
|
|
$this->post( |
147
|
|
|
$this->getObjectUrl($repositoryId, $objectId), |
148
|
|
|
$this->createQueryArray( |
149
|
|
|
Constants::CMISACTION_CHECK_OUT, |
150
|
|
|
array(), |
151
|
|
|
$extension |
152
|
|
|
) |
153
|
|
|
)->json() |
154
|
|
|
); |
155
|
|
|
$objectId = $objectData->getId(); |
156
|
|
|
return $objectData; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Returns the list of all document objects in the specified version series, |
161
|
|
|
* sorted by the property "cmis:creationDate" descending. |
162
|
|
|
* |
163
|
|
|
* @param string $repositoryId the identifier for the repository |
164
|
|
|
* @param string $objectId the identifier for the object |
165
|
|
|
* @param string $versionSeriesId the identifier for the object |
166
|
|
|
* @param string|null $filter a comma-separated list of query names that defines which properties must be |
167
|
|
|
* returned by the repository (default is repository specific) |
168
|
|
|
* @param boolean $includeAllowableActions if <code>true</code>, then the repository must return the allowable |
169
|
|
|
* actions for the objects (default is <code>false</code>) |
170
|
|
|
* @param ExtensionDataInterface|null $extension |
171
|
|
|
* @return ObjectDataInterface[] the complete version history of the version series |
172
|
|
|
*/ |
173
|
|
|
public function getAllVersions( |
174
|
|
|
$repositoryId, |
175
|
|
|
$objectId, |
176
|
|
|
$versionSeriesId, |
177
|
|
|
$filter = null, |
178
|
|
|
$includeAllowableActions = false, |
179
|
|
|
ExtensionDataInterface $extension = null |
180
|
|
|
) { |
181
|
|
|
return $this->getJsonConverter()->convertObjectList( |
182
|
|
|
array( |
183
|
|
|
'objects' => $this->read( |
184
|
|
|
$this->getObjectUrl($repositoryId, $objectId, Constants::SELECTOR_VERSIONS) |
185
|
|
|
)->json() |
186
|
|
|
) |
187
|
|
|
)->getObjects(); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Get the latest document object in the version series. |
192
|
|
|
* |
193
|
|
|
* @param string $repositoryId the identifier for the repository |
194
|
|
|
* @param string $objectId |
195
|
|
|
* @param string $versionSeriesId |
196
|
|
|
* @param boolean $major |
197
|
|
|
* @param string|null $filter a comma-separated list of query names that defines which properties must be |
198
|
|
|
* returned by the repository (default is repository specific) |
199
|
|
|
* @param boolean $includeAllowableActions |
200
|
|
|
* @param IncludeRelationships|null $includeRelationships indicates what relationships in which the objects |
201
|
|
|
* participate must be returned (default is <code>IncludeRelationships::NONE</code>) |
202
|
|
|
* @param string $renditionFilter indicates what set of renditions the repository must return whose kind |
203
|
|
|
* matches this filter (default is "cmis:none") |
204
|
|
|
* @param boolean $includePolicyIds if <code>true</code>, then the repository must return the policy ids for |
205
|
|
|
* the object (default is <code>false</code>) |
206
|
|
|
* @param boolean $includeAcl if <code>true</code>, then the repository must return the ACL for the object |
207
|
|
|
* (default is <code>false</code>) |
208
|
|
|
* @param ExtensionDataInterface|null $extension |
209
|
|
|
* @return ObjectDataInterface |
210
|
|
|
*/ |
211
|
|
|
public function getObjectOfLatestVersion( |
212
|
|
|
$repositoryId, |
213
|
|
|
$objectId, |
214
|
|
|
$versionSeriesId, |
215
|
|
|
$major = false, |
216
|
|
|
$filter = null, |
217
|
|
|
$includeAllowableActions = false, |
218
|
|
|
IncludeRelationships $includeRelationships = null, |
219
|
|
|
$renditionFilter = Constants::RENDITION_NONE, |
220
|
|
|
$includePolicyIds = false, |
221
|
|
|
$includeAcl = false, |
222
|
|
|
ExtensionDataInterface $extension = null |
223
|
|
|
) { |
224
|
|
|
return $this->getJsonConverter()->convertObject( |
225
|
|
|
reset( |
226
|
|
|
$this->read( |
|
|
|
|
227
|
|
|
$this->getObjectUrl($repositoryId, $objectId, Constants::SELECTOR_VERSIONS) |
228
|
|
|
)->json() |
229
|
|
|
) |
230
|
|
|
); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Get a subset of the properties for the latest document object in the version series. |
235
|
|
|
* |
236
|
|
|
* @param string $repositoryId the identifier for the repository |
237
|
|
|
* @param string $objectId The identifier for the object |
238
|
|
|
* @param string $versionSeriesId The identifier for the version series. |
239
|
|
|
* @param boolean $major If <code>true</code>, then the repository MUST return the properties for the latest |
240
|
|
|
* major version object in the version series. |
241
|
|
|
* If <code>false</code>, the repository MUST return the properties for the latest |
242
|
|
|
* (major or non-major) version object in the version series. |
243
|
|
|
* @param string|null $filter a comma-separated list of query names that defines which properties must be |
244
|
|
|
* returned by the repository (default is repository specific) |
245
|
|
|
* @param ExtensionDataInterface|null $extension |
246
|
|
|
* @return PropertiesInterface |
247
|
|
|
*/ |
248
|
|
|
public function getPropertiesOfLatestVersion( |
249
|
|
|
$repositoryId, |
250
|
|
|
$objectId, |
251
|
|
|
$versionSeriesId, |
252
|
|
|
$major = false, |
253
|
|
|
$filter = null, |
254
|
|
|
ExtensionDataInterface $extension = null |
255
|
|
|
) { |
256
|
|
|
return $this->getObjectOfLatestVersion( |
257
|
|
|
$repositoryId, |
258
|
|
|
$objectId, |
259
|
|
|
$versionSeriesId, |
260
|
|
|
$major, |
261
|
|
|
$filter, |
262
|
|
|
$extension |
|
|
|
|
263
|
|
|
)->getProperties(); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @param string $action |
268
|
|
|
* @param array $parameters |
269
|
|
|
* @param ExtensionDataInterface $extension |
|
|
|
|
270
|
|
|
* @return array |
271
|
|
|
*/ |
272
|
|
|
protected function createQueryArray( |
273
|
|
|
$action, |
274
|
|
|
array $parameters = array(), |
275
|
|
|
ExtensionDataInterface $extension = null |
|
|
|
|
276
|
|
|
) { |
277
|
|
|
$queryArray = array_replace( |
278
|
|
|
$parameters, |
279
|
|
|
array( |
280
|
|
|
Constants::CONTROL_CMISACTION => $action, |
281
|
|
|
Constants::PARAM_SUCCINCT => $this->getSuccinct() ? 'true' : 'false', |
282
|
|
|
) |
283
|
|
|
); |
284
|
|
|
return $queryArray; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
} |
288
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: