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:
Complex classes like ContentService often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ContentService, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 50 | class ContentService implements ContentServiceInterface |
||
| 51 | { |
||
| 52 | /** |
||
| 53 | * @var \eZ\Publish\Core\Repository\Repository |
||
| 54 | */ |
||
| 55 | protected $repository; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var \eZ\Publish\SPI\Persistence\Handler |
||
| 59 | */ |
||
| 60 | protected $persistenceHandler; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var array |
||
| 64 | */ |
||
| 65 | protected $settings; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @var \eZ\Publish\Core\Repository\Helper\DomainMapper |
||
| 69 | */ |
||
| 70 | protected $domainMapper; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @var \eZ\Publish\Core\Repository\Helper\RelationProcessor |
||
| 74 | */ |
||
| 75 | protected $relationProcessor; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @var \eZ\Publish\Core\Repository\Helper\NameSchemaService |
||
| 79 | */ |
||
| 80 | protected $nameSchemaService; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @var \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry |
||
| 84 | */ |
||
| 85 | protected $fieldTypeRegistry; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Setups service with reference to repository object that created it & corresponding handler. |
||
| 89 | * |
||
| 90 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
| 91 | * @param \eZ\Publish\SPI\Persistence\Handler $handler |
||
| 92 | * @param \eZ\Publish\Core\Repository\Helper\DomainMapper $domainMapper |
||
| 93 | * @param \eZ\Publish\Core\Repository\Helper\RelationProcessor $relationProcessor |
||
| 94 | * @param \eZ\Publish\Core\Repository\Helper\NameSchemaService $nameSchemaService |
||
| 95 | * @param \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry $fieldTypeRegistry, |
||
|
|
|||
| 96 | * @param array $settings |
||
| 97 | */ |
||
| 98 | public function __construct( |
||
| 99 | RepositoryInterface $repository, |
||
| 100 | Handler $handler, |
||
| 101 | Helper\DomainMapper $domainMapper, |
||
| 102 | Helper\RelationProcessor $relationProcessor, |
||
| 103 | Helper\NameSchemaService $nameSchemaService, |
||
| 104 | Helper\FieldTypeRegistry $fieldTypeRegistry, |
||
| 105 | array $settings = array() |
||
| 106 | ) { |
||
| 107 | $this->repository = $repository; |
||
| 108 | $this->persistenceHandler = $handler; |
||
| 109 | $this->domainMapper = $domainMapper; |
||
| 110 | $this->relationProcessor = $relationProcessor; |
||
| 111 | $this->nameSchemaService = $nameSchemaService; |
||
| 112 | $this->fieldTypeRegistry = $fieldTypeRegistry; |
||
| 113 | // Union makes sure default settings are ignored if provided in argument |
||
| 114 | $this->settings = $settings + array( |
||
| 115 | // Version archive limit (0-50), only enforced on publish, not on un-publish. |
||
| 116 | 'default_version_archive_limit' => 5, |
||
| 117 | ); |
||
| 118 | } |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Loads a content info object. |
||
| 122 | * |
||
| 123 | * To load fields use loadContent |
||
| 124 | * |
||
| 125 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
| 126 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
| 127 | * |
||
| 128 | * @param int $contentId |
||
| 129 | * |
||
| 130 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 131 | */ |
||
| 132 | View Code Duplication | public function loadContentInfo($contentId) |
|
| 133 | { |
||
| 134 | $contentInfo = $this->internalLoadContentInfo($contentId); |
||
| 135 | if (!$this->repository->canUser('content', 'read', $contentInfo)) { |
||
| 136 | throw new UnauthorizedException('content', 'read', array('contentId' => $contentId)); |
||
| 137 | } |
||
| 138 | |||
| 139 | return $contentInfo; |
||
| 140 | } |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Loads a content info object. |
||
| 144 | * |
||
| 145 | * To load fields use loadContent |
||
| 146 | * |
||
| 147 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
| 148 | * |
||
| 149 | * @param mixed $id |
||
| 150 | * @param bool $isRemoteId |
||
| 151 | * |
||
| 152 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 153 | */ |
||
| 154 | public function internalLoadContentInfo($id, $isRemoteId = false) |
||
| 155 | { |
||
| 156 | try { |
||
| 157 | $method = $isRemoteId ? 'loadContentInfoByRemoteId' : 'loadContentInfo'; |
||
| 158 | |||
| 159 | return $this->domainMapper->buildContentInfoDomainObject( |
||
| 160 | $this->persistenceHandler->contentHandler()->$method($id) |
||
| 161 | ); |
||
| 162 | } catch (APINotFoundException $e) { |
||
| 163 | throw new NotFoundException( |
||
| 164 | 'Content', |
||
| 165 | $id, |
||
| 166 | $e |
||
| 167 | ); |
||
| 168 | } |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Loads a content info object for the given remoteId. |
||
| 173 | * |
||
| 174 | * To load fields use loadContent |
||
| 175 | * |
||
| 176 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
| 177 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given remote id does not exist |
||
| 178 | * |
||
| 179 | * @param string $remoteId |
||
| 180 | * |
||
| 181 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 182 | */ |
||
| 183 | View Code Duplication | public function loadContentInfoByRemoteId($remoteId) |
|
| 184 | { |
||
| 185 | $contentInfo = $this->internalLoadContentInfo($remoteId, true); |
||
| 186 | |||
| 187 | if (!$this->repository->canUser('content', 'read', $contentInfo)) { |
||
| 188 | throw new UnauthorizedException('content', 'read', array('remoteId' => $remoteId)); |
||
| 189 | } |
||
| 190 | |||
| 191 | return $contentInfo; |
||
| 192 | } |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Loads a version info of the given content object. |
||
| 196 | * |
||
| 197 | * If no version number is given, the method returns the current version |
||
| 198 | * |
||
| 199 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 200 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 201 | * |
||
| 202 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 203 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 204 | * |
||
| 205 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 206 | */ |
||
| 207 | public function loadVersionInfo(ContentInfo $contentInfo, $versionNo = null) |
||
| 208 | { |
||
| 209 | return $this->loadVersionInfoById($contentInfo->id, $versionNo); |
||
| 210 | } |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Loads a version info of the given content object id. |
||
| 214 | * |
||
| 215 | * If no version number is given, the method returns the current version |
||
| 216 | * |
||
| 217 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 218 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 219 | * |
||
| 220 | * @param mixed $contentId |
||
| 221 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 222 | * |
||
| 223 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 224 | */ |
||
| 225 | public function loadVersionInfoById($contentId, $versionNo = null) |
||
| 226 | { |
||
| 227 | if ($versionNo === null) { |
||
| 228 | $versionNo = $this->loadContentInfo($contentId)->currentVersionNo; |
||
| 229 | } |
||
| 230 | |||
| 231 | try { |
||
| 232 | $spiVersionInfo = $this->persistenceHandler->contentHandler()->loadVersionInfo( |
||
| 233 | $contentId, |
||
| 234 | $versionNo |
||
| 235 | ); |
||
| 236 | } catch (APINotFoundException $e) { |
||
| 237 | throw new NotFoundException( |
||
| 238 | 'VersionInfo', |
||
| 239 | array( |
||
| 240 | 'contentId' => $contentId, |
||
| 241 | 'versionNo' => $versionNo, |
||
| 242 | ), |
||
| 243 | $e |
||
| 244 | ); |
||
| 245 | } |
||
| 246 | |||
| 247 | $versionInfo = $this->domainMapper->buildVersionInfoDomainObject($spiVersionInfo); |
||
| 248 | |||
| 249 | if ($versionInfo->isPublished()) { |
||
| 250 | $function = 'read'; |
||
| 251 | } else { |
||
| 252 | $function = 'versionread'; |
||
| 253 | } |
||
| 254 | |||
| 255 | if (!$this->repository->canUser('content', $function, $versionInfo)) { |
||
| 256 | throw new UnauthorizedException('content', $function, array('contentId' => $contentId)); |
||
| 257 | } |
||
| 258 | |||
| 259 | return $versionInfo; |
||
| 260 | } |
||
| 261 | |||
| 262 | /** |
||
| 263 | * {@inheritdoc} |
||
| 264 | */ |
||
| 265 | public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 266 | { |
||
| 267 | // Change $useAlwaysAvailable to false to avoid contentInfo lookup if we know alwaysAvailable is disabled |
||
| 268 | if ($useAlwaysAvailable && !$contentInfo->alwaysAvailable) { |
||
| 269 | $useAlwaysAvailable = false; |
||
| 270 | } |
||
| 271 | |||
| 272 | // As we have content info we can avoid that current version is looked up using spi in loadContent() if not set |
||
| 273 | if ($versionNo === null) { |
||
| 274 | $versionNo = $contentInfo->currentVersionNo; |
||
| 275 | } |
||
| 276 | |||
| 277 | return $this->loadContent( |
||
| 278 | $contentInfo->id, |
||
| 279 | $languages, |
||
| 280 | $versionNo, |
||
| 281 | $useAlwaysAvailable |
||
| 282 | ); |
||
| 283 | } |
||
| 284 | |||
| 285 | /** |
||
| 286 | * {@inheritdoc} |
||
| 287 | */ |
||
| 288 | public function loadContentByVersionInfo(APIVersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true) |
||
| 289 | { |
||
| 290 | // Change $useAlwaysAvailable to false to avoid contentInfo lookup if we know alwaysAvailable is disabled |
||
| 291 | if ($useAlwaysAvailable && !$versionInfo->getContentInfo()->alwaysAvailable) { |
||
| 292 | $useAlwaysAvailable = false; |
||
| 293 | } |
||
| 294 | |||
| 295 | return $this->loadContent( |
||
| 296 | $versionInfo->getContentInfo()->id, |
||
| 297 | $languages, |
||
| 298 | $versionInfo->versionNo, |
||
| 299 | $useAlwaysAvailable |
||
| 300 | ); |
||
| 301 | } |
||
| 302 | |||
| 303 | /** |
||
| 304 | * {@inheritdoc} |
||
| 305 | */ |
||
| 306 | View Code Duplication | public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
|
| 307 | { |
||
| 308 | $content = $this->internalLoadContent($contentId, $languages, $versionNo, false, $useAlwaysAvailable); |
||
| 309 | |||
| 310 | if (!$this->repository->canUser('content', 'read', $content)) { |
||
| 311 | throw new UnauthorizedException('content', 'read', array('contentId' => $contentId)); |
||
| 312 | } |
||
| 313 | if ( |
||
| 314 | !$content->getVersionInfo()->isPublished() |
||
| 315 | && !$this->repository->canUser('content', 'versionread', $content) |
||
| 316 | ) { |
||
| 317 | throw new UnauthorizedException('content', 'versionread', array('contentId' => $contentId, 'versionNo' => $versionNo)); |
||
| 318 | } |
||
| 319 | |||
| 320 | return $content; |
||
| 321 | } |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Loads content in a version of the given content object. |
||
| 325 | * |
||
| 326 | * If no version number is given, the method returns the current version |
||
| 327 | * |
||
| 328 | * @internal |
||
| 329 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content or version with the given id and languages does not exist |
||
| 330 | * |
||
| 331 | * @param mixed $id |
||
| 332 | * @param array|null $languages A language priority, filters returned fields and is used as prioritized language code on |
||
| 333 | * returned value object. If not given all languages are returned. |
||
| 334 | * @param int|null $versionNo the version number. If not given the current version is returned |
||
| 335 | * @param bool $isRemoteId |
||
| 336 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 337 | * |
||
| 338 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 339 | */ |
||
| 340 | public function internalLoadContent($id, array $languages = null, $versionNo = null, $isRemoteId = false, $useAlwaysAvailable = true) |
||
| 341 | { |
||
| 342 | try { |
||
| 343 | // Get Content ID if lookup by remote ID |
||
| 344 | if ($isRemoteId) { |
||
| 345 | $spiContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfoByRemoteId($id); |
||
| 346 | $id = $spiContentInfo->id; |
||
| 347 | // Set $isRemoteId to false as the next loads will be for content id now that we have it (for exception use now) |
||
| 348 | $isRemoteId = false; |
||
| 349 | } |
||
| 350 | |||
| 351 | // Get current version if $versionNo is not defined |
||
| 352 | if ($versionNo === null) { |
||
| 353 | if (!isset($spiContentInfo)) { |
||
| 354 | $spiContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo($id); |
||
| 355 | } |
||
| 356 | |||
| 357 | $versionNo = $spiContentInfo->currentVersionNo; |
||
| 358 | } |
||
| 359 | |||
| 360 | $loadLanguages = $languages; |
||
| 361 | $alwaysAvailableLanguageCode = null; |
||
| 362 | // Set main language on $languages filter if not empty (all) and $useAlwaysAvailable being true |
||
| 363 | if (!empty($loadLanguages) && $useAlwaysAvailable) { |
||
| 364 | if (!isset($spiContentInfo)) { |
||
| 365 | $spiContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo($id); |
||
| 366 | } |
||
| 367 | |||
| 368 | if ($spiContentInfo->alwaysAvailable) { |
||
| 369 | $loadLanguages[] = $alwaysAvailableLanguageCode = $spiContentInfo->mainLanguageCode; |
||
| 370 | $loadLanguages = array_unique($loadLanguages); |
||
| 371 | } |
||
| 372 | } |
||
| 373 | |||
| 374 | $spiContent = $this->persistenceHandler->contentHandler()->load( |
||
| 375 | $id, |
||
| 376 | $versionNo, |
||
| 377 | $loadLanguages |
||
| 378 | ); |
||
| 379 | } catch (APINotFoundException $e) { |
||
| 380 | throw new NotFoundException( |
||
| 381 | 'Content', |
||
| 382 | array( |
||
| 383 | $isRemoteId ? 'remoteId' : 'id' => $id, |
||
| 384 | 'languages' => $languages, |
||
| 385 | 'versionNo' => $versionNo, |
||
| 386 | ), |
||
| 387 | $e |
||
| 388 | ); |
||
| 389 | } |
||
| 390 | |||
| 391 | return $this->domainMapper->buildContentDomainObject( |
||
| 392 | $spiContent, |
||
| 393 | null, |
||
| 394 | empty($languages) ? null : $languages, |
||
| 395 | $alwaysAvailableLanguageCode |
||
| 396 | ); |
||
| 397 | } |
||
| 398 | |||
| 399 | /** |
||
| 400 | * Loads content in a version for the content object reference by the given remote id. |
||
| 401 | * |
||
| 402 | * If no version is given, the method returns the current version |
||
| 403 | * |
||
| 404 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given remote id does not exist |
||
| 405 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the user has no access to read content and in case of un-published content: read versions |
||
| 406 | * |
||
| 407 | * @param string $remoteId |
||
| 408 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 409 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 410 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 411 | * |
||
| 412 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 413 | */ |
||
| 414 | View Code Duplication | public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
|
| 415 | { |
||
| 416 | $content = $this->internalLoadContent($remoteId, $languages, $versionNo, true, $useAlwaysAvailable); |
||
| 417 | |||
| 418 | if (!$this->repository->canUser('content', 'read', $content)) { |
||
| 419 | throw new UnauthorizedException('content', 'read', array('remoteId' => $remoteId)); |
||
| 420 | } |
||
| 421 | |||
| 422 | if ( |
||
| 423 | !$content->getVersionInfo()->isPublished() |
||
| 424 | && !$this->repository->canUser('content', 'versionread', $content) |
||
| 425 | ) { |
||
| 426 | throw new UnauthorizedException('content', 'versionread', array('remoteId' => $remoteId, 'versionNo' => $versionNo)); |
||
| 427 | } |
||
| 428 | |||
| 429 | return $content; |
||
| 430 | } |
||
| 431 | |||
| 432 | /** |
||
| 433 | * Creates a new content draft assigned to the authenticated user. |
||
| 434 | * |
||
| 435 | * If a different userId is given in $contentCreateStruct it is assigned to the given user |
||
| 436 | * but this required special rights for the authenticated user |
||
| 437 | * (this is useful for content staging where the transfer process does not |
||
| 438 | * have to authenticate with the user which created the content object in the source server). |
||
| 439 | * The user has to publish the draft if it should be visible. |
||
| 440 | * In 4.x at least one location has to be provided in the location creation array. |
||
| 441 | * |
||
| 442 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location |
||
| 443 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the provided remoteId exists in the system, required properties on |
||
| 444 | * struct are missing or invalid, or if multiple locations are under the |
||
| 445 | * same parent. |
||
| 446 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid, |
||
| 447 | * or if a required field is missing / set to an empty value. |
||
| 448 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType, |
||
| 449 | * or value is set for non-translatable field in language |
||
| 450 | * other than main. |
||
| 451 | * |
||
| 452 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 453 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content |
||
| 454 | * |
||
| 455 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 456 | */ |
||
| 457 | public function createContent(APIContentCreateStruct $contentCreateStruct, array $locationCreateStructs = array()) |
||
| 458 | { |
||
| 459 | if ($contentCreateStruct->mainLanguageCode === null) { |
||
| 460 | throw new InvalidArgumentException('$contentCreateStruct', "'mainLanguageCode' property must be set"); |
||
| 461 | } |
||
| 462 | |||
| 463 | if ($contentCreateStruct->contentType === null) { |
||
| 464 | throw new InvalidArgumentException('$contentCreateStruct', "'contentType' property must be set"); |
||
| 465 | } |
||
| 466 | |||
| 467 | $contentCreateStruct = clone $contentCreateStruct; |
||
| 468 | |||
| 469 | if ($contentCreateStruct->ownerId === null) { |
||
| 470 | $contentCreateStruct->ownerId = $this->repository->getCurrentUserReference()->getUserId(); |
||
| 471 | } |
||
| 472 | |||
| 473 | if ($contentCreateStruct->alwaysAvailable === null) { |
||
| 474 | $contentCreateStruct->alwaysAvailable = false; |
||
| 475 | } |
||
| 476 | |||
| 477 | $contentCreateStruct->contentType = $this->repository->getContentTypeService()->loadContentType( |
||
| 478 | $contentCreateStruct->contentType->id |
||
| 479 | ); |
||
| 480 | |||
| 481 | if (empty($contentCreateStruct->sectionId)) { |
||
| 482 | if (isset($locationCreateStructs[0])) { |
||
| 483 | $location = $this->repository->getLocationService()->loadLocation( |
||
| 484 | $locationCreateStructs[0]->parentLocationId |
||
| 485 | ); |
||
| 486 | $contentCreateStruct->sectionId = $location->contentInfo->sectionId; |
||
| 487 | } else { |
||
| 488 | $contentCreateStruct->sectionId = 1; |
||
| 489 | } |
||
| 490 | } |
||
| 491 | |||
| 492 | if (!$this->repository->canUser('content', 'create', $contentCreateStruct, $locationCreateStructs)) { |
||
| 493 | throw new UnauthorizedException( |
||
| 494 | 'content', |
||
| 495 | 'create', |
||
| 496 | array( |
||
| 497 | 'parentLocationId' => isset($locationCreateStructs[0]) ? |
||
| 498 | $locationCreateStructs[0]->parentLocationId : |
||
| 499 | null, |
||
| 500 | 'sectionId' => $contentCreateStruct->sectionId, |
||
| 501 | ) |
||
| 502 | ); |
||
| 503 | } |
||
| 504 | |||
| 505 | if (!empty($contentCreateStruct->remoteId)) { |
||
| 506 | try { |
||
| 507 | $this->loadContentByRemoteId($contentCreateStruct->remoteId); |
||
| 508 | |||
| 509 | throw new InvalidArgumentException( |
||
| 510 | '$contentCreateStruct', |
||
| 511 | "Another content with remoteId '{$contentCreateStruct->remoteId}' exists" |
||
| 512 | ); |
||
| 513 | } catch (APINotFoundException $e) { |
||
| 514 | // Do nothing |
||
| 515 | } |
||
| 516 | } else { |
||
| 517 | $contentCreateStruct->remoteId = $this->domainMapper->getUniqueHash($contentCreateStruct); |
||
| 518 | } |
||
| 519 | |||
| 520 | $spiLocationCreateStructs = $this->buildSPILocationCreateStructs($locationCreateStructs); |
||
| 521 | |||
| 522 | $languageCodes = $this->getLanguageCodesForCreate($contentCreateStruct); |
||
| 523 | $fields = $this->mapFieldsForCreate($contentCreateStruct); |
||
| 524 | |||
| 525 | $fieldValues = array(); |
||
| 526 | $spiFields = array(); |
||
| 527 | $allFieldErrors = array(); |
||
| 528 | $inputRelations = array(); |
||
| 529 | $locationIdToContentIdMapping = array(); |
||
| 530 | |||
| 531 | foreach ($contentCreateStruct->contentType->getFieldDefinitions() as $fieldDefinition) { |
||
| 532 | /** @var $fieldType \eZ\Publish\Core\FieldType\FieldType */ |
||
| 533 | $fieldType = $this->fieldTypeRegistry->getFieldType( |
||
| 534 | $fieldDefinition->fieldTypeIdentifier |
||
| 535 | ); |
||
| 536 | |||
| 537 | foreach ($languageCodes as $languageCode) { |
||
| 538 | $isEmptyValue = false; |
||
| 539 | $valueLanguageCode = $fieldDefinition->isTranslatable ? $languageCode : $contentCreateStruct->mainLanguageCode; |
||
| 540 | $isLanguageMain = $languageCode === $contentCreateStruct->mainLanguageCode; |
||
| 541 | if (isset($fields[$fieldDefinition->identifier][$valueLanguageCode])) { |
||
| 542 | $fieldValue = $fields[$fieldDefinition->identifier][$valueLanguageCode]->value; |
||
| 543 | } else { |
||
| 544 | $fieldValue = $fieldDefinition->defaultValue; |
||
| 545 | } |
||
| 546 | |||
| 547 | $fieldValue = $fieldType->acceptValue($fieldValue); |
||
| 548 | |||
| 549 | View Code Duplication | if ($fieldType->isEmptyValue($fieldValue)) { |
|
| 550 | $isEmptyValue = true; |
||
| 551 | if ($fieldDefinition->isRequired) { |
||
| 552 | $allFieldErrors[$fieldDefinition->id][$languageCode] = new ValidationError( |
||
| 553 | "Value for required field definition '%identifier%' with language '%languageCode%' is empty", |
||
| 554 | null, |
||
| 555 | ['%identifier%' => $fieldDefinition->identifier, '%languageCode%' => $languageCode], |
||
| 556 | 'empty' |
||
| 557 | ); |
||
| 558 | } |
||
| 559 | } else { |
||
| 560 | $fieldErrors = $fieldType->validate( |
||
| 561 | $fieldDefinition, |
||
| 562 | $fieldValue |
||
| 563 | ); |
||
| 564 | if (!empty($fieldErrors)) { |
||
| 565 | $allFieldErrors[$fieldDefinition->id][$languageCode] = $fieldErrors; |
||
| 566 | } |
||
| 567 | } |
||
| 568 | |||
| 569 | if (!empty($allFieldErrors)) { |
||
| 570 | continue; |
||
| 571 | } |
||
| 572 | |||
| 573 | $this->relationProcessor->appendFieldRelations( |
||
| 574 | $inputRelations, |
||
| 575 | $locationIdToContentIdMapping, |
||
| 576 | $fieldType, |
||
| 577 | $fieldValue, |
||
| 578 | $fieldDefinition->id |
||
| 579 | ); |
||
| 580 | $fieldValues[$fieldDefinition->identifier][$languageCode] = $fieldValue; |
||
| 581 | |||
| 582 | // Only non-empty value for: translatable field or in main language |
||
| 583 | if ( |
||
| 584 | (!$isEmptyValue && $fieldDefinition->isTranslatable) || |
||
| 585 | (!$isEmptyValue && $isLanguageMain) |
||
| 586 | ) { |
||
| 587 | $spiFields[] = new SPIField( |
||
| 588 | array( |
||
| 589 | 'id' => null, |
||
| 590 | 'fieldDefinitionId' => $fieldDefinition->id, |
||
| 591 | 'type' => $fieldDefinition->fieldTypeIdentifier, |
||
| 592 | 'value' => $fieldType->toPersistenceValue($fieldValue), |
||
| 593 | 'languageCode' => $languageCode, |
||
| 594 | 'versionNo' => null, |
||
| 595 | ) |
||
| 596 | ); |
||
| 597 | } |
||
| 598 | } |
||
| 599 | } |
||
| 600 | |||
| 601 | if (!empty($allFieldErrors)) { |
||
| 602 | throw new ContentFieldValidationException($allFieldErrors); |
||
| 603 | } |
||
| 604 | |||
| 605 | $spiContentCreateStruct = new SPIContentCreateStruct( |
||
| 606 | array( |
||
| 607 | 'name' => $this->nameSchemaService->resolve( |
||
| 608 | $contentCreateStruct->contentType->nameSchema, |
||
| 609 | $contentCreateStruct->contentType, |
||
| 610 | $fieldValues, |
||
| 611 | $languageCodes |
||
| 612 | ), |
||
| 613 | 'typeId' => $contentCreateStruct->contentType->id, |
||
| 614 | 'sectionId' => $contentCreateStruct->sectionId, |
||
| 615 | 'ownerId' => $contentCreateStruct->ownerId, |
||
| 616 | 'locations' => $spiLocationCreateStructs, |
||
| 617 | 'fields' => $spiFields, |
||
| 618 | 'alwaysAvailable' => $contentCreateStruct->alwaysAvailable, |
||
| 619 | 'remoteId' => $contentCreateStruct->remoteId, |
||
| 620 | 'modified' => isset($contentCreateStruct->modificationDate) ? $contentCreateStruct->modificationDate->getTimestamp() : time(), |
||
| 621 | 'initialLanguageId' => $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode( |
||
| 622 | $contentCreateStruct->mainLanguageCode |
||
| 623 | )->id, |
||
| 624 | ) |
||
| 625 | ); |
||
| 626 | |||
| 627 | $defaultObjectStates = $this->getDefaultObjectStates(); |
||
| 628 | |||
| 629 | $this->repository->beginTransaction(); |
||
| 630 | try { |
||
| 631 | $spiContent = $this->persistenceHandler->contentHandler()->create($spiContentCreateStruct); |
||
| 632 | $this->relationProcessor->processFieldRelations( |
||
| 633 | $inputRelations, |
||
| 634 | $spiContent->versionInfo->contentInfo->id, |
||
| 635 | $spiContent->versionInfo->versionNo, |
||
| 636 | $contentCreateStruct->contentType |
||
| 637 | ); |
||
| 638 | |||
| 639 | foreach ($defaultObjectStates as $objectStateGroupId => $objectState) { |
||
| 640 | $this->persistenceHandler->objectStateHandler()->setContentState( |
||
| 641 | $spiContent->versionInfo->contentInfo->id, |
||
| 642 | $objectStateGroupId, |
||
| 643 | $objectState->id |
||
| 644 | ); |
||
| 645 | } |
||
| 646 | |||
| 647 | $this->repository->commit(); |
||
| 648 | } catch (Exception $e) { |
||
| 649 | $this->repository->rollback(); |
||
| 650 | throw $e; |
||
| 651 | } |
||
| 652 | |||
| 653 | return $this->domainMapper->buildContentDomainObject($spiContent); |
||
| 654 | } |
||
| 655 | |||
| 656 | /** |
||
| 657 | * Returns an array of default content states with content state group id as key. |
||
| 658 | * |
||
| 659 | * @return \eZ\Publish\SPI\Persistence\Content\ObjectState[] |
||
| 660 | */ |
||
| 661 | protected function getDefaultObjectStates() |
||
| 662 | { |
||
| 663 | $defaultObjectStatesMap = array(); |
||
| 664 | $objectStateHandler = $this->persistenceHandler->objectStateHandler(); |
||
| 665 | |||
| 666 | foreach ($objectStateHandler->loadAllGroups() as $objectStateGroup) { |
||
| 667 | foreach ($objectStateHandler->loadObjectStates($objectStateGroup->id) as $objectState) { |
||
| 668 | // Only register the first object state which is the default one. |
||
| 669 | $defaultObjectStatesMap[$objectStateGroup->id] = $objectState; |
||
| 670 | break; |
||
| 671 | } |
||
| 672 | } |
||
| 673 | |||
| 674 | return $defaultObjectStatesMap; |
||
| 675 | } |
||
| 676 | |||
| 677 | /** |
||
| 678 | * Returns all language codes used in given $fields. |
||
| 679 | * |
||
| 680 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value is set in main language |
||
| 681 | * |
||
| 682 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 683 | * |
||
| 684 | * @return string[] |
||
| 685 | */ |
||
| 686 | protected function getLanguageCodesForCreate(APIContentCreateStruct $contentCreateStruct) |
||
| 687 | { |
||
| 688 | $languageCodes = array(); |
||
| 689 | |||
| 690 | View Code Duplication | foreach ($contentCreateStruct->fields as $field) { |
|
| 691 | if ($field->languageCode === null || isset($languageCodes[$field->languageCode])) { |
||
| 692 | continue; |
||
| 693 | } |
||
| 694 | |||
| 695 | $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode( |
||
| 696 | $field->languageCode |
||
| 697 | ); |
||
| 698 | $languageCodes[$field->languageCode] = true; |
||
| 699 | } |
||
| 700 | |||
| 701 | if (!isset($languageCodes[$contentCreateStruct->mainLanguageCode])) { |
||
| 702 | $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode( |
||
| 703 | $contentCreateStruct->mainLanguageCode |
||
| 704 | ); |
||
| 705 | $languageCodes[$contentCreateStruct->mainLanguageCode] = true; |
||
| 706 | } |
||
| 707 | |||
| 708 | return array_keys($languageCodes); |
||
| 709 | } |
||
| 710 | |||
| 711 | /** |
||
| 712 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
| 713 | * |
||
| 714 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
| 715 | * or value is set for non-translatable field in language |
||
| 716 | * other than main |
||
| 717 | * |
||
| 718 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 719 | * |
||
| 720 | * @return array |
||
| 721 | */ |
||
| 722 | protected function mapFieldsForCreate(APIContentCreateStruct $contentCreateStruct) |
||
| 723 | { |
||
| 724 | $fields = array(); |
||
| 725 | |||
| 726 | foreach ($contentCreateStruct->fields as $field) { |
||
| 727 | $fieldDefinition = $contentCreateStruct->contentType->getFieldDefinition($field->fieldDefIdentifier); |
||
| 728 | |||
| 729 | if ($fieldDefinition === null) { |
||
| 730 | throw new ContentValidationException( |
||
| 731 | "Field definition '%identifier%' does not exist in given ContentType", |
||
| 732 | ['%identifier%' => $field->fieldDefIdentifier] |
||
| 733 | ); |
||
| 734 | } |
||
| 735 | |||
| 736 | if ($field->languageCode === null) { |
||
| 737 | $field = $this->cloneField( |
||
| 738 | $field, |
||
| 739 | array('languageCode' => $contentCreateStruct->mainLanguageCode) |
||
| 740 | ); |
||
| 741 | } |
||
| 742 | |||
| 743 | View Code Duplication | if (!$fieldDefinition->isTranslatable && ($field->languageCode != $contentCreateStruct->mainLanguageCode)) { |
|
| 744 | throw new ContentValidationException( |
||
| 745 | "A value is set for non translatable field definition '%identifier%' with language '%languageCode%'", |
||
| 746 | ['%identifier%' => $field->fieldDefIdentifier, '%languageCode%' => $field->languageCode] |
||
| 747 | ); |
||
| 748 | } |
||
| 749 | |||
| 750 | $fields[$field->fieldDefIdentifier][$field->languageCode] = $field; |
||
| 751 | } |
||
| 752 | |||
| 753 | return $fields; |
||
| 754 | } |
||
| 755 | |||
| 756 | /** |
||
| 757 | * Clones $field with overriding specific properties from given $overrides array. |
||
| 758 | * |
||
| 759 | * @param Field $field |
||
| 760 | * @param array $overrides |
||
| 761 | * |
||
| 762 | * @return Field |
||
| 763 | */ |
||
| 764 | private function cloneField(Field $field, array $overrides = []) |
||
| 765 | { |
||
| 766 | $fieldData = array_merge( |
||
| 767 | [ |
||
| 768 | 'id' => $field->id, |
||
| 769 | 'value' => $field->value, |
||
| 770 | 'languageCode' => $field->languageCode, |
||
| 771 | 'fieldDefIdentifier' => $field->fieldDefIdentifier, |
||
| 772 | 'fieldTypeIdentifier' => $field->fieldTypeIdentifier, |
||
| 773 | ], |
||
| 774 | $overrides |
||
| 775 | ); |
||
| 776 | |||
| 777 | return new Field($fieldData); |
||
| 778 | } |
||
| 779 | |||
| 780 | /** |
||
| 781 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 782 | * |
||
| 783 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs |
||
| 784 | * |
||
| 785 | * @return \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct[] |
||
| 786 | */ |
||
| 787 | protected function buildSPILocationCreateStructs(array $locationCreateStructs) |
||
| 821 | |||
| 822 | /** |
||
| 823 | * Updates the metadata. |
||
| 824 | * |
||
| 825 | * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent |
||
| 826 | * |
||
| 827 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data |
||
| 828 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists |
||
| 829 | * |
||
| 830 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 831 | * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct |
||
| 832 | * |
||
| 833 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes |
||
| 834 | */ |
||
| 835 | public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct) |
||
| 921 | |||
| 922 | /** |
||
| 923 | * Publishes URL aliases for all locations of a given content. |
||
| 924 | * |
||
| 925 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 926 | * @param bool $updatePathIdentificationString this parameter is legacy storage specific for updating |
||
| 927 | * ezcontentobject_tree.path_identification_string, it is ignored by other storage engines |
||
| 928 | */ |
||
| 929 | protected function publishUrlAliasesForContent(APIContent $content, $updatePathIdentificationString = true) |
||
| 954 | |||
| 955 | /** |
||
| 956 | * Deletes a content object including all its versions and locations including their subtrees. |
||
| 957 | * |
||
| 958 | * @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) |
||
| 959 | * |
||
| 960 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 961 | * |
||
| 962 | * @return mixed[] Affected Location Id's |
||
| 963 | */ |
||
| 964 | public function deleteContent(ContentInfo $contentInfo) |
||
| 990 | |||
| 991 | /** |
||
| 992 | * Creates a draft from a published or archived version. |
||
| 993 | * |
||
| 994 | * If no version is given, the current published version is used. |
||
| 995 | * 4.x: The draft is created with the initialLanguage code of the source version or if not present with the main language. |
||
| 996 | * It can be changed on updating the version. |
||
| 997 | * |
||
| 998 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to create the draft |
||
| 999 | * |
||
| 1000 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1001 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1002 | * @param \eZ\Publish\API\Repository\Values\User\User $creator if set given user is used to create the draft - otherwise the current-user is used |
||
| 1003 | * |
||
| 1004 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 1005 | */ |
||
| 1006 | public function createContentDraft(ContentInfo $contentInfo, APIVersionInfo $versionInfo = null, User $creator = null) |
||
| 1068 | |||
| 1069 | /** |
||
| 1070 | * Loads drafts for a user. |
||
| 1071 | * |
||
| 1072 | * If no user is given the drafts for the authenticated user a returned |
||
| 1073 | * |
||
| 1074 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to load the draft list |
||
| 1075 | * |
||
| 1076 | * @param \eZ\Publish\API\Repository\Values\User\UserReference $user |
||
| 1077 | * |
||
| 1078 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo the drafts ({@link VersionInfo}) owned by the given user |
||
| 1079 | */ |
||
| 1080 | public function loadContentDrafts(User $user = null) |
||
| 1104 | |||
| 1105 | /** |
||
| 1106 | * Updates the fields of a draft. |
||
| 1107 | * |
||
| 1108 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version |
||
| 1109 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1110 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a property on the struct is invalid. |
||
| 1111 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid, |
||
| 1112 | * or if a required field is missing / set to an empty value. |
||
| 1113 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType, |
||
| 1114 | * or value is set for non-translatable field in language |
||
| 1115 | * other than main. |
||
| 1116 | * |
||
| 1117 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1118 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1119 | * |
||
| 1120 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields |
||
| 1121 | */ |
||
| 1122 | public function updateContent(APIVersionInfo $versionInfo, APIContentUpdateStruct $contentUpdateStruct) |
||
| 1286 | |||
| 1287 | /** |
||
| 1288 | * Returns all language codes used in given $fields. |
||
| 1289 | * |
||
| 1290 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value exists in initial language |
||
| 1291 | * |
||
| 1292 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1293 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 1294 | * |
||
| 1295 | * @return array |
||
| 1296 | */ |
||
| 1297 | protected function getLanguageCodesForUpdate(APIContentUpdateStruct $contentUpdateStruct, APIContent $content) |
||
| 1323 | |||
| 1324 | /** |
||
| 1325 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
| 1326 | * |
||
| 1327 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
| 1328 | * or value is set for non-translatable field in language |
||
| 1329 | * other than main |
||
| 1330 | * |
||
| 1331 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1332 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 1333 | * @param string $mainLanguageCode |
||
| 1334 | * |
||
| 1335 | * @return array |
||
| 1336 | */ |
||
| 1337 | protected function mapFieldsForUpdate( |
||
| 1375 | |||
| 1376 | /** |
||
| 1377 | * Publishes a content version. |
||
| 1378 | * |
||
| 1379 | * Publishes a content version and deletes archive versions if they overflow max archive versions. |
||
| 1380 | * Max archive versions are currently a configuration, but might be moved to be a param of ContentType in the future. |
||
| 1381 | * |
||
| 1382 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version |
||
| 1383 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1384 | * |
||
| 1385 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1386 | * |
||
| 1387 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1388 | */ |
||
| 1389 | public function publishVersion(APIVersionInfo $versionInfo) |
||
| 1412 | |||
| 1413 | /** |
||
| 1414 | * Publishes a content version. |
||
| 1415 | * |
||
| 1416 | * Publishes a content version and deletes archive versions if they overflow max archive versions. |
||
| 1417 | * Max archive versions are currently a configuration, but might be moved to be a param of ContentType in the future. |
||
| 1418 | * |
||
| 1419 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1420 | * |
||
| 1421 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1422 | * @param int|null $publicationDate If null existing date is kept if there is one, otherwise current time is used. |
||
| 1423 | * |
||
| 1424 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1425 | */ |
||
| 1426 | protected function internalPublishVersion(APIVersionInfo $versionInfo, $publicationDate = null) |
||
| 1471 | |||
| 1472 | /** |
||
| 1473 | * Removes the given version. |
||
| 1474 | * |
||
| 1475 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in |
||
| 1476 | * published state or is the last version of the Content |
||
| 1477 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version |
||
| 1478 | * |
||
| 1479 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1480 | */ |
||
| 1481 | public function deleteVersion(APIVersionInfo $versionInfo) |
||
| 1523 | |||
| 1524 | /** |
||
| 1525 | * Loads all versions for the given content. |
||
| 1526 | * |
||
| 1527 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions |
||
| 1528 | * |
||
| 1529 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1530 | * |
||
| 1531 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date |
||
| 1532 | */ |
||
| 1533 | public function loadVersions(ContentInfo $contentInfo) |
||
| 1553 | |||
| 1554 | /** |
||
| 1555 | * Copies the content to a new location. If no version is given, |
||
| 1556 | * all versions are copied, otherwise only the given version. |
||
| 1557 | * |
||
| 1558 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location |
||
| 1559 | * |
||
| 1560 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1561 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to |
||
| 1562 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1563 | * |
||
| 1564 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1565 | */ |
||
| 1566 | public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, APIVersionInfo $versionInfo = null) |
||
| 1616 | |||
| 1617 | /** |
||
| 1618 | * Loads all outgoing relations for the given version. |
||
| 1619 | * |
||
| 1620 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 1621 | * |
||
| 1622 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1623 | * |
||
| 1624 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 1625 | */ |
||
| 1626 | public function loadRelations(APIVersionInfo $versionInfo) |
||
| 1661 | |||
| 1662 | /** |
||
| 1663 | * Loads all incoming relations for a content object. |
||
| 1664 | * |
||
| 1665 | * The relations come only from published versions of the source content objects |
||
| 1666 | * |
||
| 1667 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 1668 | * |
||
| 1669 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1670 | * |
||
| 1671 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 1672 | */ |
||
| 1673 | public function loadReverseRelations(ContentInfo $contentInfo) |
||
| 1699 | |||
| 1700 | /** |
||
| 1701 | * Adds a relation of type common. |
||
| 1702 | * |
||
| 1703 | * The source of the relation is the content and version |
||
| 1704 | * referenced by $versionInfo. |
||
| 1705 | * |
||
| 1706 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version |
||
| 1707 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1708 | * |
||
| 1709 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 1710 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation |
||
| 1711 | * |
||
| 1712 | * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation |
||
| 1713 | */ |
||
| 1714 | public function addRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 1755 | |||
| 1756 | /** |
||
| 1757 | * Removes a relation of type COMMON from a draft. |
||
| 1758 | * |
||
| 1759 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version |
||
| 1760 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1761 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination |
||
| 1762 | * |
||
| 1763 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 1764 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent |
||
| 1765 | */ |
||
| 1766 | public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 1816 | |||
| 1817 | /** |
||
| 1818 | * {@inheritdoc} |
||
| 1819 | */ |
||
| 1820 | public function removeTranslation(ContentInfo $contentInfo, $languageCode) |
||
| 1828 | |||
| 1829 | /** |
||
| 1830 | * Delete Content item Translation from all Versions (including archived ones) of a Content Object. |
||
| 1831 | * |
||
| 1832 | * NOTE: this operation is risky and permanent, so user interface should provide a warning before performing it. |
||
| 1833 | * |
||
| 1834 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation |
||
| 1835 | * is the Main Translation of a Content Item. |
||
| 1836 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed |
||
| 1837 | * to delete the content (in one of the locations of the given Content Item). |
||
| 1838 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument |
||
| 1839 | * is invalid for the given content. |
||
| 1840 | * |
||
| 1841 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1842 | * @param string $languageCode |
||
| 1843 | * |
||
| 1844 | * @since 6.13 |
||
| 1845 | */ |
||
| 1846 | public function deleteTranslation(ContentInfo $contentInfo, $languageCode) |
||
| 1923 | |||
| 1924 | /** |
||
| 1925 | * Delete specified Translation from a Content Draft. |
||
| 1926 | * |
||
| 1927 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation |
||
| 1928 | * is the only one the Content Draft has or it is the main Translation of a Content Object. |
||
| 1929 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed |
||
| 1930 | * to edit the Content (in one of the locations of the given Content Object). |
||
| 1931 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument |
||
| 1932 | * is invalid for the given Draft. |
||
| 1933 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if specified Version was not found |
||
| 1934 | * |
||
| 1935 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo Content Version Draft |
||
| 1936 | * @param string $languageCode Language code of the Translation to be removed |
||
| 1937 | * |
||
| 1938 | * @return \eZ\Publish\API\Repository\Values\Content\Content Content Draft w/o the specified Translation |
||
| 1939 | * |
||
| 1940 | * @since 6.12 |
||
| 1941 | */ |
||
| 1942 | public function deleteTranslationFromDraft(APIVersionInfo $versionInfo, $languageCode) |
||
| 2003 | |||
| 2004 | /** |
||
| 2005 | * Instantiates a new content create struct object. |
||
| 2006 | * |
||
| 2007 | * alwaysAvailable is set to the ContentType's defaultAlwaysAvailable |
||
| 2008 | * |
||
| 2009 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 2010 | * @param string $mainLanguageCode |
||
| 2011 | * |
||
| 2012 | * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct |
||
| 2013 | */ |
||
| 2014 | public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode) |
||
| 2024 | |||
| 2025 | /** |
||
| 2026 | * Instantiates a new content meta data update struct. |
||
| 2027 | * |
||
| 2028 | * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct |
||
| 2029 | */ |
||
| 2030 | public function newContentMetadataUpdateStruct() |
||
| 2034 | |||
| 2035 | /** |
||
| 2036 | * Instantiates a new content update struct. |
||
| 2037 | * |
||
| 2038 | * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct |
||
| 2039 | */ |
||
| 2040 | public function newContentUpdateStruct() |
||
| 2044 | } |
||
| 2045 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.