Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 38 | class ContentService implements ContentServiceInterface |
||
| 39 | { |
||
| 40 | /** |
||
| 41 | * Aggregated service. |
||
| 42 | * |
||
| 43 | * @var \eZ\Publish\API\Repository\ContentService |
||
| 44 | */ |
||
| 45 | protected $service; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * SignalDispatcher. |
||
| 49 | * |
||
| 50 | * @var \eZ\Publish\Core\SignalSlot\SignalDispatcher |
||
| 51 | */ |
||
| 52 | protected $signalDispatcher; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Constructor. |
||
| 56 | * |
||
| 57 | * Construct service object from aggregated service and signal |
||
| 58 | * dispatcher |
||
| 59 | * |
||
| 60 | * @param \eZ\Publish\API\Repository\ContentService $service |
||
| 61 | * @param \eZ\Publish\Core\SignalSlot\SignalDispatcher $signalDispatcher |
||
| 62 | */ |
||
| 63 | public function __construct(ContentServiceInterface $service, SignalDispatcher $signalDispatcher) |
||
| 64 | { |
||
| 65 | $this->service = $service; |
||
| 66 | $this->signalDispatcher = $signalDispatcher; |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Loads a content info object. |
||
| 71 | * |
||
| 72 | * To load fields use loadContent |
||
| 73 | * |
||
| 74 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
| 75 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
| 76 | * |
||
| 77 | * @param int $contentId |
||
| 78 | * |
||
| 79 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 80 | */ |
||
| 81 | public function loadContentInfo($contentId) |
||
| 82 | { |
||
| 83 | return $this->service->loadContentInfo($contentId); |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Loads a content info object for the given remoteId. |
||
| 88 | * |
||
| 89 | * To load fields use loadContent |
||
| 90 | * |
||
| 91 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
| 92 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given remote id does not exist |
||
| 93 | * |
||
| 94 | * @param string $remoteId |
||
| 95 | * |
||
| 96 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 97 | */ |
||
| 98 | public function loadContentInfoByRemoteId($remoteId) |
||
| 99 | { |
||
| 100 | return $this->service->loadContentInfoByRemoteId($remoteId); |
||
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Loads a version info of the given content object. |
||
| 105 | * |
||
| 106 | * If no version number is given, the method returns the current version |
||
| 107 | * |
||
| 108 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 109 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 110 | * |
||
| 111 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 112 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 113 | * |
||
| 114 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 115 | */ |
||
| 116 | public function loadVersionInfo(ContentInfo $contentInfo, $versionNo = null) |
||
| 117 | { |
||
| 118 | return $this->service->loadVersionInfo($contentInfo, $versionNo); |
||
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Loads a version info of the given content object id. |
||
| 123 | * |
||
| 124 | * If no version number is given, the method returns the current version |
||
| 125 | * |
||
| 126 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 127 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 128 | * |
||
| 129 | * @param mixed $contentId |
||
| 130 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 131 | * |
||
| 132 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 133 | */ |
||
| 134 | public function loadVersionInfoById($contentId, $versionNo = null) |
||
| 135 | { |
||
| 136 | return $this->service->loadVersionInfoById($contentId, $versionNo); |
||
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Loads content in a version for the given content info object. |
||
| 141 | * |
||
| 142 | * If no version number is given, the method returns the current version |
||
| 143 | * |
||
| 144 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if version with the given number does not exist |
||
| 145 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 146 | * |
||
| 147 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 148 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 149 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 150 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 151 | * |
||
| 152 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 153 | */ |
||
| 154 | public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 155 | { |
||
| 156 | return $this->service->loadContentByContentInfo($contentInfo, $languages, $versionNo, $useAlwaysAvailable); |
||
| 157 | } |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Loads content in the version given by version info. |
||
| 161 | * |
||
| 162 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 163 | * |
||
| 164 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 165 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 166 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 167 | * |
||
| 168 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 169 | */ |
||
| 170 | public function loadContentByVersionInfo(VersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true) |
||
| 171 | { |
||
| 172 | return $this->service->loadContentByVersionInfo($versionInfo, $languages, $useAlwaysAvailable); |
||
| 173 | } |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Loads content in a version of the given content object. |
||
| 177 | * |
||
| 178 | * If no version number is given, the method returns the current version |
||
| 179 | * |
||
| 180 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content or version with the given id and languages does not exist |
||
| 181 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 182 | * |
||
| 183 | * @param int $contentId |
||
| 184 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 185 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 186 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 187 | * |
||
| 188 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 189 | */ |
||
| 190 | public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 191 | { |
||
| 192 | return $this->service->loadContent($contentId, $languages, $versionNo, $useAlwaysAvailable); |
||
| 193 | } |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Loads content in a version for the content object reference by the given remote id. |
||
| 197 | * |
||
| 198 | * If no version is given, the method returns the current version |
||
| 199 | * |
||
| 200 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given remote id does not exist |
||
| 201 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 202 | * |
||
| 203 | * @param string $remoteId |
||
| 204 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 205 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 206 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 207 | * |
||
| 208 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 209 | */ |
||
| 210 | public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 211 | { |
||
| 212 | return $this->service->loadContentByRemoteId($remoteId, $languages, $versionNo, $useAlwaysAvailable); |
||
| 213 | } |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Creates a new content draft assigned to the authenticated user. |
||
| 217 | * |
||
| 218 | * If a different userId is given in $contentCreateStruct it is assigned to the given user |
||
| 219 | * but this required special rights for the authenticated user |
||
| 220 | * (this is useful for content staging where the transfer process does not |
||
| 221 | * have to authenticate with the user which created the content object in the source server). |
||
| 222 | * The user has to publish the draft if it should be visible. |
||
| 223 | * In 4.x at least one location has to be provided in the location creation array. |
||
| 224 | * |
||
| 225 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location |
||
| 226 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is a provided remoteId which exists in the system |
||
| 227 | * or there is no location provided (4.x) or multiple locations |
||
| 228 | * are under the same parent or if the a field value is not accepted by the field type |
||
| 229 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid |
||
| 230 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing or is set to an empty value |
||
| 231 | * |
||
| 232 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 233 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content |
||
| 234 | * |
||
| 235 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 236 | */ |
||
| 237 | public function createContent(ContentCreateStruct $contentCreateStruct, array $locationCreateStructs = array()) |
||
| 238 | { |
||
| 239 | $returnValue = $this->service->createContent($contentCreateStruct, $locationCreateStructs); |
||
| 240 | $this->signalDispatcher->emit( |
||
| 241 | new CreateContentSignal( |
||
| 242 | array( |
||
| 243 | 'contentId' => $returnValue->getVersionInfo()->getContentInfo()->id, |
||
| 244 | 'versionNo' => $returnValue->getVersionInfo()->versionNo, |
||
| 245 | ) |
||
| 246 | ) |
||
| 247 | ); |
||
| 248 | |||
| 249 | return $returnValue; |
||
| 250 | } |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Updates the metadata. |
||
| 254 | * |
||
| 255 | * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent |
||
| 256 | * |
||
| 257 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data |
||
| 258 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists |
||
| 259 | * |
||
| 260 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 261 | * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct |
||
| 262 | * |
||
| 263 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes |
||
| 264 | */ |
||
| 265 | public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct) |
||
| 266 | { |
||
| 267 | $returnValue = $this->service->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct); |
||
| 268 | $this->signalDispatcher->emit( |
||
| 269 | new UpdateContentMetadataSignal( |
||
| 270 | array( |
||
| 271 | 'contentId' => $contentInfo->id, |
||
| 272 | ) |
||
| 273 | ) |
||
| 274 | ); |
||
| 275 | |||
| 276 | return $returnValue; |
||
| 277 | } |
||
| 278 | |||
| 279 | /** |
||
| 280 | * Deletes a content object including all its versions and locations including their subtrees. |
||
| 281 | * |
||
| 282 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to delete the content (in one of the locations of the given content object) |
||
| 283 | * |
||
| 284 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 285 | * |
||
| 286 | * @return mixed[] Affected Location Id's |
||
| 287 | */ |
||
| 288 | public function deleteContent(ContentInfo $contentInfo) |
||
| 289 | { |
||
| 290 | $returnValue = $this->service->deleteContent($contentInfo); |
||
| 291 | $this->signalDispatcher->emit( |
||
| 292 | new DeleteContentSignal( |
||
| 293 | array( |
||
| 294 | 'contentId' => $contentInfo->id, |
||
| 295 | 'affectedLocationIds' => $returnValue, |
||
| 296 | ) |
||
| 297 | ) |
||
| 298 | ); |
||
| 299 | |||
| 300 | return $returnValue; |
||
| 301 | } |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Creates a draft from a published or archived version. |
||
| 305 | * |
||
| 306 | * If no version is given, the current published version is used. |
||
| 307 | * 4.x: The draft is created with the initialLanguage code of the source version or if not present with the main language. |
||
| 308 | * It can be changed on updating the version. |
||
| 309 | * |
||
| 310 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the draft |
||
| 311 | * |
||
| 312 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 313 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 314 | * @param \eZ\Publish\API\Repository\Values\User\User $user if set given user is used to create the draft - otherwise the current user is used |
||
| 315 | * |
||
| 316 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 317 | */ |
||
| 318 | public function createContentDraft(ContentInfo $contentInfo, VersionInfo $versionInfo = null, User $user = null) |
||
| 319 | { |
||
| 320 | $returnValue = $this->service->createContentDraft($contentInfo, $versionInfo, $user); |
||
| 321 | $this->signalDispatcher->emit( |
||
| 322 | new CreateContentDraftSignal( |
||
| 323 | array( |
||
| 324 | 'contentId' => $contentInfo->id, |
||
| 325 | 'versionNo' => ($versionInfo !== null ? $versionInfo->versionNo : null), |
||
| 326 | 'userId' => ($user !== null ? $user->id : null), |
||
| 327 | ) |
||
| 328 | ) |
||
| 329 | ); |
||
| 330 | |||
| 331 | return $returnValue; |
||
| 332 | } |
||
| 333 | |||
| 334 | /** |
||
| 335 | * Loads drafts for a user. |
||
| 336 | * |
||
| 337 | * If no user is given the drafts for the authenticated user a returned |
||
| 338 | * |
||
| 339 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load the draft list |
||
| 340 | * |
||
| 341 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
| 342 | * |
||
| 343 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] the drafts ({@link VersionInfo}) owned by the given user |
||
| 344 | */ |
||
| 345 | public function loadContentDrafts(User $user = null) |
||
| 346 | { |
||
| 347 | return $this->service->loadContentDrafts($user); |
||
| 348 | } |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Translate a version. |
||
| 352 | * |
||
| 353 | * updates the destination version given in $translationInfo with the provided translated fields in $translationValues |
||
| 354 | * |
||
| 355 | * @example Examples/translation_5x.php |
||
| 356 | * |
||
| 357 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version |
||
| 358 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the given destination version is not a draft |
||
| 359 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set to an empty value |
||
| 360 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $translationValues is not valid |
||
| 361 | * |
||
| 362 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo |
||
| 363 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationValues $translationValues |
||
| 364 | * @param \eZ\Publish\API\Repository\Values\User\User $user If set, this user is taken as modifier of the version |
||
| 365 | * |
||
| 366 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the translated fields |
||
| 367 | * |
||
| 368 | * @since 5.0 |
||
| 369 | */ |
||
| 370 | public function translateVersion(TranslationInfo $translationInfo, TranslationValues $translationValues, User $user = null) |
||
| 371 | { |
||
| 372 | $returnValue = $this->service->translateVersion($translationInfo, $translationValues, $user); |
||
| 373 | $this->signalDispatcher->emit( |
||
| 374 | new TranslateVersionSignal( |
||
| 375 | array( |
||
| 376 | 'contentId' => $translationInfo->srcVersionInfo->contentInfo->id, |
||
| 377 | 'versionNo' => $translationInfo->srcVersionInfo->versionNo, |
||
| 378 | 'userId' => ($user !== null ? $user->id : null), |
||
| 379 | ) |
||
| 380 | ) |
||
| 381 | ); |
||
| 382 | |||
| 383 | return $returnValue; |
||
| 384 | } |
||
| 385 | |||
| 386 | /** |
||
| 387 | * Updates the fields of a draft. |
||
| 388 | * |
||
| 389 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version |
||
| 390 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 391 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentUpdateStruct is not valid |
||
| 392 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set to an empty value |
||
| 393 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a field value is not accepted by the field type |
||
| 394 | * |
||
| 395 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 396 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 397 | * |
||
| 398 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields |
||
| 399 | */ |
||
| 400 | View Code Duplication | public function updateContent(VersionInfo $versionInfo, ContentUpdateStruct $contentUpdateStruct) |
|
| 401 | { |
||
| 402 | $returnValue = $this->service->updateContent($versionInfo, $contentUpdateStruct); |
||
| 403 | $this->signalDispatcher->emit( |
||
| 404 | new UpdateContentSignal( |
||
| 405 | array( |
||
| 406 | 'contentId' => $versionInfo->getContentInfo()->id, |
||
| 407 | 'versionNo' => $versionInfo->versionNo, |
||
| 408 | ) |
||
| 409 | ) |
||
| 410 | ); |
||
| 411 | |||
| 412 | return $returnValue; |
||
| 413 | } |
||
| 414 | |||
| 415 | /** |
||
| 416 | * Publishes a content version. |
||
| 417 | * |
||
| 418 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version |
||
| 419 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 420 | * |
||
| 421 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 422 | * |
||
| 423 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 424 | */ |
||
| 425 | View Code Duplication | public function publishVersion(VersionInfo $versionInfo) |
|
| 426 | { |
||
| 427 | $returnValue = $this->service->publishVersion($versionInfo); |
||
| 428 | $this->signalDispatcher->emit( |
||
| 429 | new PublishVersionSignal( |
||
| 430 | array( |
||
| 431 | 'contentId' => $versionInfo->getContentInfo()->id, |
||
| 432 | 'versionNo' => $versionInfo->versionNo, |
||
| 433 | ) |
||
| 434 | ) |
||
| 435 | ); |
||
| 436 | |||
| 437 | return $returnValue; |
||
| 438 | } |
||
| 439 | |||
| 440 | /** |
||
| 441 | * Removes the given version. |
||
| 442 | * |
||
| 443 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in |
||
| 444 | * published state or is the last version of the Content |
||
| 445 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version |
||
| 446 | * |
||
| 447 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 448 | */ |
||
| 449 | View Code Duplication | public function deleteVersion(VersionInfo $versionInfo) |
|
| 450 | { |
||
| 451 | $returnValue = $this->service->deleteVersion($versionInfo); |
||
| 452 | $this->signalDispatcher->emit( |
||
| 453 | new DeleteVersionSignal( |
||
| 454 | array( |
||
| 455 | 'contentId' => $versionInfo->contentInfo->id, |
||
| 456 | 'versionNo' => $versionInfo->versionNo, |
||
| 457 | ) |
||
| 458 | ) |
||
| 459 | ); |
||
| 460 | |||
| 461 | return $returnValue; |
||
| 462 | } |
||
| 463 | |||
| 464 | /** |
||
| 465 | * Loads all versions for the given content. |
||
| 466 | * |
||
| 467 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions |
||
| 468 | * |
||
| 469 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 470 | * |
||
| 471 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date |
||
| 472 | */ |
||
| 473 | public function loadVersions(ContentInfo $contentInfo) |
||
| 474 | { |
||
| 475 | return $this->service->loadVersions($contentInfo); |
||
| 476 | } |
||
| 477 | |||
| 478 | /** |
||
| 479 | * Copies the content to a new location. If no version is given, |
||
| 480 | * all versions are copied, otherwise only the given version. |
||
| 481 | * |
||
| 482 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location |
||
| 483 | * |
||
| 484 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 485 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to |
||
| 486 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 487 | * |
||
| 488 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 489 | */ |
||
| 490 | public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, VersionInfo $versionInfo = null) |
||
| 491 | { |
||
| 492 | $returnValue = $this->service->copyContent($contentInfo, $destinationLocationCreateStruct, $versionInfo); |
||
| 493 | $this->signalDispatcher->emit( |
||
| 494 | new CopyContentSignal( |
||
| 495 | array( |
||
| 496 | 'srcContentId' => $contentInfo->id, |
||
| 497 | 'srcVersionNo' => ($versionInfo !== null ? $versionInfo->versionNo : null), |
||
| 498 | 'dstContentId' => $returnValue->getVersionInfo()->getContentInfo()->id, |
||
| 499 | 'dstVersionNo' => $returnValue->getVersionInfo()->versionNo, |
||
| 500 | 'dstParentLocationId' => $destinationLocationCreateStruct->parentLocationId, |
||
| 501 | ) |
||
| 502 | ) |
||
| 503 | ); |
||
| 504 | |||
| 505 | return $returnValue; |
||
| 506 | } |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Loads all outgoing relations for the given version. |
||
| 510 | * |
||
| 511 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 512 | * |
||
| 513 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 514 | * |
||
| 515 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 516 | */ |
||
| 517 | public function loadRelations(VersionInfo $versionInfo) |
||
| 518 | { |
||
| 519 | return $this->service->loadRelations($versionInfo); |
||
| 520 | } |
||
| 521 | |||
| 522 | /** |
||
| 523 | * Loads all incoming relations for a content object. |
||
| 524 | * |
||
| 525 | * The relations come only from published versions of the source content objects |
||
| 526 | * |
||
| 527 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 528 | * |
||
| 529 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 530 | * |
||
| 531 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 532 | */ |
||
| 533 | public function loadReverseRelations(ContentInfo $contentInfo) |
||
| 534 | { |
||
| 535 | return $this->service->loadReverseRelations($contentInfo); |
||
| 536 | } |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Adds a relation of type common. |
||
| 540 | * |
||
| 541 | * The source of the relation is the content and version |
||
| 542 | * referenced by $versionInfo. |
||
| 543 | * |
||
| 544 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version |
||
| 545 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 546 | * |
||
| 547 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 548 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation |
||
| 549 | * |
||
| 550 | * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation |
||
| 551 | */ |
||
| 552 | View Code Duplication | public function addRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent) |
|
| 553 | { |
||
| 554 | $returnValue = $this->service->addRelation($sourceVersion, $destinationContent); |
||
| 555 | $this->signalDispatcher->emit( |
||
| 556 | new AddRelationSignal( |
||
| 557 | array( |
||
| 558 | 'srcContentId' => $sourceVersion->contentInfo->id, |
||
| 559 | 'srcVersionNo' => $sourceVersion->versionNo, |
||
| 560 | 'dstContentId' => $destinationContent->id, |
||
| 561 | ) |
||
| 562 | ) |
||
| 563 | ); |
||
| 564 | |||
| 565 | return $returnValue; |
||
| 566 | } |
||
| 567 | |||
| 568 | /** |
||
| 569 | * Removes a relation of type COMMON from a draft. |
||
| 570 | * |
||
| 571 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version |
||
| 572 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 573 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination |
||
| 574 | * |
||
| 575 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 576 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent |
||
| 577 | */ |
||
| 578 | View Code Duplication | public function deleteRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent) |
|
| 579 | { |
||
| 580 | $returnValue = $this->service->deleteRelation($sourceVersion, $destinationContent); |
||
| 581 | $this->signalDispatcher->emit( |
||
| 582 | new DeleteRelationSignal( |
||
| 583 | array( |
||
| 584 | 'srcContentId' => $sourceVersion->contentInfo->id, |
||
| 585 | 'srcVersionNo' => $sourceVersion->versionNo, |
||
| 586 | 'dstContentId' => $destinationContent->id, |
||
| 587 | ) |
||
| 588 | ) |
||
| 589 | ); |
||
| 590 | |||
| 591 | return $returnValue; |
||
| 592 | } |
||
| 593 | |||
| 594 | /** |
||
| 595 | * Adds translation information to the content object. |
||
| 596 | * |
||
| 597 | * @example Examples/translation_5x.php |
||
| 598 | * |
||
| 599 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed add a translation info |
||
| 600 | * |
||
| 601 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo |
||
| 602 | * |
||
| 603 | * @since 5.0 |
||
| 604 | */ |
||
| 605 | public function addTranslationInfo(TranslationInfo $translationInfo) |
||
| 606 | { |
||
| 607 | $returnValue = $this->service->addTranslationInfo($translationInfo); |
||
| 608 | $this->signalDispatcher->emit( |
||
| 609 | new AddTranslationInfoSignal(array()) |
||
| 610 | ); |
||
| 611 | |||
| 612 | return $returnValue; |
||
| 613 | } |
||
| 614 | |||
| 615 | /** |
||
| 616 | * lists the translations done on this content object. |
||
| 617 | * |
||
| 618 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed read translation infos |
||
| 619 | * |
||
| 620 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 621 | * @param array $filter |
||
| 622 | * |
||
| 623 | * @todo TBD - filter by source version, destination version and languages |
||
| 624 | * |
||
| 625 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo[] |
||
| 626 | * |
||
| 627 | * @since 5.0 |
||
| 628 | */ |
||
| 629 | public function loadTranslationInfos(ContentInfo $contentInfo, array $filter = array()) |
||
| 630 | { |
||
| 631 | return $this->service->loadTranslationInfos($contentInfo, $filter); |
||
| 632 | } |
||
| 633 | |||
| 634 | /** |
||
| 635 | * Instantiates a new content create struct object. |
||
| 636 | * |
||
| 637 | * alwaysAvailable is set to the ContentType's defaultAlwaysAvailable |
||
| 638 | * |
||
| 639 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 640 | * @param string $mainLanguageCode |
||
| 641 | * |
||
| 642 | * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct |
||
| 643 | */ |
||
| 644 | public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode) |
||
| 648 | |||
| 649 | /** |
||
| 650 | * Instantiates a new content meta data update struct. |
||
| 651 | * |
||
| 652 | * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct |
||
| 653 | */ |
||
| 654 | public function newContentMetadataUpdateStruct() |
||
| 658 | |||
| 659 | /** |
||
| 660 | * Instantiates a new content update struct. |
||
| 661 | * |
||
| 662 | * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct |
||
| 663 | */ |
||
| 664 | public function newContentUpdateStruct() |
||
| 668 | |||
| 669 | /** |
||
| 670 | * Instantiates a new TranslationInfo object. |
||
| 671 | * |
||
| 672 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo |
||
| 673 | */ |
||
| 674 | public function newTranslationInfo() |
||
| 678 | |||
| 679 | /** |
||
| 680 | * Instantiates a Translation object. |
||
| 681 | * |
||
| 682 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationValues |
||
| 683 | */ |
||
| 684 | public function newTranslationValues() |
||
| 688 | } |
||
| 689 |