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 |
||
| 60 | class ContentService implements ContentServiceInterface |
||
| 61 | { |
||
| 62 | /** @var \eZ\Publish\Core\Repository\Repository */ |
||
| 63 | protected $repository; |
||
| 64 | |||
| 65 | /** @var \eZ\Publish\SPI\Persistence\Handler */ |
||
| 66 | protected $persistenceHandler; |
||
| 67 | |||
| 68 | /** @var array */ |
||
| 69 | protected $settings; |
||
| 70 | |||
| 71 | /** @var \eZ\Publish\Core\Repository\Helper\DomainMapper */ |
||
| 72 | protected $domainMapper; |
||
| 73 | |||
| 74 | /** @var \eZ\Publish\Core\Repository\Helper\RelationProcessor */ |
||
| 75 | protected $relationProcessor; |
||
| 76 | |||
| 77 | /** @var \eZ\Publish\Core\Repository\Helper\NameSchemaService */ |
||
| 78 | protected $nameSchemaService; |
||
| 79 | |||
| 80 | /** @var \eZ\Publish\Core\FieldType\FieldTypeRegistry */ |
||
| 81 | protected $fieldTypeRegistry; |
||
| 82 | |||
| 83 | /** @var \eZ\Publish\API\Repository\PermissionResolver */ |
||
| 84 | private $permissionResolver; |
||
| 85 | |||
| 86 | public function __construct( |
||
| 87 | RepositoryInterface $repository, |
||
| 88 | Handler $handler, |
||
| 89 | Helper\DomainMapper $domainMapper, |
||
| 90 | Helper\RelationProcessor $relationProcessor, |
||
| 91 | Helper\NameSchemaService $nameSchemaService, |
||
| 92 | FieldTypeRegistry $fieldTypeRegistry, |
||
| 93 | PermissionResolver $permissionResolver, |
||
| 94 | array $settings = [] |
||
| 95 | ) { |
||
| 96 | $this->repository = $repository; |
||
|
|
|||
| 97 | $this->persistenceHandler = $handler; |
||
| 98 | $this->domainMapper = $domainMapper; |
||
| 99 | $this->relationProcessor = $relationProcessor; |
||
| 100 | $this->nameSchemaService = $nameSchemaService; |
||
| 101 | $this->fieldTypeRegistry = $fieldTypeRegistry; |
||
| 102 | // Union makes sure default settings are ignored if provided in argument |
||
| 103 | $this->settings = $settings + [ |
||
| 104 | // Version archive limit (0-50), only enforced on publish, not on un-publish. |
||
| 105 | 'default_version_archive_limit' => 5, |
||
| 106 | ]; |
||
| 107 | $this->permissionResolver = $permissionResolver; |
||
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Loads a content info object. |
||
| 112 | * |
||
| 113 | * To load fields use loadContent |
||
| 114 | * |
||
| 115 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
| 116 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
| 117 | * |
||
| 118 | * @param int $contentId |
||
| 119 | * |
||
| 120 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 121 | */ |
||
| 122 | public function loadContentInfo($contentId) |
||
| 123 | { |
||
| 124 | $contentInfo = $this->internalLoadContentInfo($contentId); |
||
| 125 | if (!$this->permissionResolver->canUser('content', 'read', $contentInfo)) { |
||
| 126 | throw new UnauthorizedException('content', 'read', ['contentId' => $contentId]); |
||
| 127 | } |
||
| 128 | |||
| 129 | return $contentInfo; |
||
| 130 | } |
||
| 131 | |||
| 132 | /** |
||
| 133 | * {@inheritdoc} |
||
| 134 | */ |
||
| 135 | public function loadContentInfoList(array $contentIds): iterable |
||
| 136 | { |
||
| 137 | $contentInfoList = []; |
||
| 138 | $spiInfoList = $this->persistenceHandler->contentHandler()->loadContentInfoList($contentIds); |
||
| 139 | foreach ($spiInfoList as $id => $spiInfo) { |
||
| 140 | $contentInfo = $this->domainMapper->buildContentInfoDomainObject($spiInfo); |
||
| 141 | if ($this->permissionResolver->canUser('content', 'read', $contentInfo)) { |
||
| 142 | $contentInfoList[$id] = $contentInfo; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 146 | return $contentInfoList; |
||
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Loads a content info object. |
||
| 151 | * |
||
| 152 | * To load fields use loadContent |
||
| 153 | * |
||
| 154 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
| 155 | * |
||
| 156 | * @param mixed $id |
||
| 157 | * @param bool $isRemoteId |
||
| 158 | * |
||
| 159 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 160 | */ |
||
| 161 | public function internalLoadContentInfo($id, $isRemoteId = false) |
||
| 162 | { |
||
| 163 | try { |
||
| 164 | $method = $isRemoteId ? 'loadContentInfoByRemoteId' : 'loadContentInfo'; |
||
| 165 | |||
| 166 | return $this->domainMapper->buildContentInfoDomainObject( |
||
| 167 | $this->persistenceHandler->contentHandler()->$method($id) |
||
| 168 | ); |
||
| 169 | } catch (APINotFoundException $e) { |
||
| 170 | throw new NotFoundException( |
||
| 171 | 'Content', |
||
| 172 | $id, |
||
| 173 | $e |
||
| 174 | ); |
||
| 175 | } |
||
| 176 | } |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Loads a content info object for the given remoteId. |
||
| 180 | * |
||
| 181 | * To load fields use loadContent |
||
| 182 | * |
||
| 183 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
| 184 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given remote id does not exist |
||
| 185 | * |
||
| 186 | * @param string $remoteId |
||
| 187 | * |
||
| 188 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 189 | */ |
||
| 190 | public function loadContentInfoByRemoteId($remoteId) |
||
| 191 | { |
||
| 192 | $contentInfo = $this->internalLoadContentInfo($remoteId, true); |
||
| 193 | |||
| 194 | if (!$this->permissionResolver->canUser('content', 'read', $contentInfo)) { |
||
| 195 | throw new UnauthorizedException('content', 'read', ['remoteId' => $remoteId]); |
||
| 196 | } |
||
| 197 | |||
| 198 | return $contentInfo; |
||
| 199 | } |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Loads a version info of the given content object. |
||
| 203 | * |
||
| 204 | * If no version number is given, the method returns the current version |
||
| 205 | * |
||
| 206 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 207 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 208 | * |
||
| 209 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 210 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 211 | * |
||
| 212 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 213 | */ |
||
| 214 | public function loadVersionInfo(ContentInfo $contentInfo, $versionNo = null) |
||
| 215 | { |
||
| 216 | return $this->loadVersionInfoById($contentInfo->id, $versionNo); |
||
| 217 | } |
||
| 218 | |||
| 219 | /** |
||
| 220 | * Loads a version info of the given content object id. |
||
| 221 | * |
||
| 222 | * If no version number is given, the method returns the current version |
||
| 223 | * |
||
| 224 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 225 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 226 | * |
||
| 227 | * @param mixed $contentId |
||
| 228 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 229 | * |
||
| 230 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 231 | */ |
||
| 232 | public function loadVersionInfoById($contentId, $versionNo = null) |
||
| 233 | { |
||
| 234 | try { |
||
| 235 | $spiVersionInfo = $this->persistenceHandler->contentHandler()->loadVersionInfo( |
||
| 236 | $contentId, |
||
| 237 | $versionNo |
||
| 238 | ); |
||
| 239 | } catch (APINotFoundException $e) { |
||
| 240 | throw new NotFoundException( |
||
| 241 | 'VersionInfo', |
||
| 242 | [ |
||
| 243 | 'contentId' => $contentId, |
||
| 244 | 'versionNo' => $versionNo, |
||
| 245 | ], |
||
| 246 | $e |
||
| 247 | ); |
||
| 248 | } |
||
| 249 | |||
| 250 | $versionInfo = $this->domainMapper->buildVersionInfoDomainObject($spiVersionInfo); |
||
| 251 | |||
| 252 | if ($versionInfo->isPublished()) { |
||
| 253 | $function = 'read'; |
||
| 254 | } else { |
||
| 255 | $function = 'versionread'; |
||
| 256 | } |
||
| 257 | |||
| 258 | if (!$this->permissionResolver->canUser('content', $function, $versionInfo)) { |
||
| 259 | throw new UnauthorizedException('content', $function, ['contentId' => $contentId]); |
||
| 260 | } |
||
| 261 | |||
| 262 | return $versionInfo; |
||
| 263 | } |
||
| 264 | |||
| 265 | /** |
||
| 266 | * {@inheritdoc} |
||
| 267 | */ |
||
| 268 | public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 269 | { |
||
| 270 | // Change $useAlwaysAvailable to false to avoid contentInfo lookup if we know alwaysAvailable is disabled |
||
| 271 | if ($useAlwaysAvailable && !$contentInfo->alwaysAvailable) { |
||
| 272 | $useAlwaysAvailable = false; |
||
| 273 | } |
||
| 274 | |||
| 275 | return $this->loadContent( |
||
| 276 | $contentInfo->id, |
||
| 277 | $languages, |
||
| 278 | $versionNo,// On purpose pass as-is and not use $contentInfo, to make sure to return actual current version on null |
||
| 279 | $useAlwaysAvailable |
||
| 280 | ); |
||
| 281 | } |
||
| 282 | |||
| 283 | /** |
||
| 284 | * {@inheritdoc} |
||
| 285 | */ |
||
| 286 | public function loadContentByVersionInfo(APIVersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true) |
||
| 287 | { |
||
| 288 | // Change $useAlwaysAvailable to false to avoid contentInfo lookup if we know alwaysAvailable is disabled |
||
| 289 | if ($useAlwaysAvailable && !$versionInfo->getContentInfo()->alwaysAvailable) { |
||
| 290 | $useAlwaysAvailable = false; |
||
| 291 | } |
||
| 292 | |||
| 293 | return $this->loadContent( |
||
| 294 | $versionInfo->getContentInfo()->id, |
||
| 295 | $languages, |
||
| 296 | $versionInfo->versionNo, |
||
| 297 | $useAlwaysAvailable |
||
| 298 | ); |
||
| 299 | } |
||
| 300 | |||
| 301 | /** |
||
| 302 | * {@inheritdoc} |
||
| 303 | */ |
||
| 304 | public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 305 | { |
||
| 306 | $content = $this->internalLoadContent($contentId, $languages, $versionNo, false, $useAlwaysAvailable); |
||
| 307 | |||
| 308 | if (!$this->permissionResolver->canUser('content', 'read', $content)) { |
||
| 309 | throw new UnauthorizedException('content', 'read', ['contentId' => $contentId]); |
||
| 310 | } |
||
| 311 | if ( |
||
| 312 | !$content->getVersionInfo()->isPublished() |
||
| 313 | && !$this->permissionResolver->canUser('content', 'versionread', $content) |
||
| 314 | ) { |
||
| 315 | throw new UnauthorizedException('content', 'versionread', ['contentId' => $contentId, 'versionNo' => $versionNo]); |
||
| 316 | } |
||
| 317 | |||
| 318 | return $content; |
||
| 319 | } |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Loads content in a version of the given content object. |
||
| 323 | * |
||
| 324 | * If no version number is given, the method returns the current version |
||
| 325 | * |
||
| 326 | * @internal |
||
| 327 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content or version with the given id and languages does not exist |
||
| 328 | * |
||
| 329 | * @param mixed $id |
||
| 330 | * @param array|null $languages A language priority, filters returned fields and is used as prioritized language code on |
||
| 331 | * returned value object. If not given all languages are returned. |
||
| 332 | * @param int|null $versionNo the version number. If not given the current version is returned |
||
| 333 | * @param bool $isRemoteId |
||
| 334 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 335 | * |
||
| 336 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 337 | */ |
||
| 338 | public function internalLoadContent($id, array $languages = null, $versionNo = null, $isRemoteId = false, $useAlwaysAvailable = true) |
||
| 339 | { |
||
| 340 | try { |
||
| 341 | // Get Content ID if lookup by remote ID |
||
| 342 | if ($isRemoteId) { |
||
| 343 | $spiContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfoByRemoteId($id); |
||
| 344 | $id = $spiContentInfo->id; |
||
| 345 | // Set $isRemoteId to false as the next loads will be for content id now that we have it (for exception use now) |
||
| 346 | $isRemoteId = false; |
||
| 347 | } |
||
| 348 | |||
| 349 | $loadLanguages = $languages; |
||
| 350 | $alwaysAvailableLanguageCode = null; |
||
| 351 | // Set main language on $languages filter if not empty (all) and $useAlwaysAvailable being true |
||
| 352 | // @todo Move use always available logic to SPI load methods, like done in location handler in 7.x |
||
| 353 | if (!empty($loadLanguages) && $useAlwaysAvailable) { |
||
| 354 | if (!isset($spiContentInfo)) { |
||
| 355 | $spiContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo($id); |
||
| 356 | } |
||
| 357 | |||
| 358 | if ($spiContentInfo->alwaysAvailable) { |
||
| 359 | $loadLanguages[] = $alwaysAvailableLanguageCode = $spiContentInfo->mainLanguageCode; |
||
| 360 | $loadLanguages = array_unique($loadLanguages); |
||
| 361 | } |
||
| 362 | } |
||
| 363 | |||
| 364 | $spiContent = $this->persistenceHandler->contentHandler()->load( |
||
| 365 | $id, |
||
| 366 | $versionNo, |
||
| 367 | $loadLanguages |
||
| 368 | ); |
||
| 369 | } catch (APINotFoundException $e) { |
||
| 370 | throw new NotFoundException( |
||
| 371 | 'Content', |
||
| 372 | [ |
||
| 373 | $isRemoteId ? 'remoteId' : 'id' => $id, |
||
| 374 | 'languages' => $languages, |
||
| 375 | 'versionNo' => $versionNo, |
||
| 376 | ], |
||
| 377 | $e |
||
| 378 | ); |
||
| 379 | } |
||
| 380 | |||
| 381 | if ($languages === null) { |
||
| 382 | $languages = []; |
||
| 383 | } |
||
| 384 | |||
| 385 | return $this->domainMapper->buildContentDomainObject( |
||
| 386 | $spiContent, |
||
| 387 | $this->repository->getContentTypeService()->loadContentType( |
||
| 388 | $spiContent->versionInfo->contentInfo->contentTypeId, |
||
| 389 | $languages |
||
| 390 | ), |
||
| 391 | $languages, |
||
| 392 | $alwaysAvailableLanguageCode |
||
| 393 | ); |
||
| 394 | } |
||
| 395 | |||
| 396 | /** |
||
| 397 | * Loads content in a version for the content object reference by the given remote id. |
||
| 398 | * |
||
| 399 | * If no version is given, the method returns the current version |
||
| 400 | * |
||
| 401 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given remote id does not exist |
||
| 402 | * @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 |
||
| 403 | * |
||
| 404 | * @param string $remoteId |
||
| 405 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 406 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 407 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 408 | * |
||
| 409 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 410 | */ |
||
| 411 | public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 412 | { |
||
| 413 | $content = $this->internalLoadContent($remoteId, $languages, $versionNo, true, $useAlwaysAvailable); |
||
| 414 | |||
| 415 | if (!$this->permissionResolver->canUser('content', 'read', $content)) { |
||
| 416 | throw new UnauthorizedException('content', 'read', ['remoteId' => $remoteId]); |
||
| 417 | } |
||
| 418 | |||
| 419 | if ( |
||
| 420 | !$content->getVersionInfo()->isPublished() |
||
| 421 | && !$this->permissionResolver->canUser('content', 'versionread', $content) |
||
| 422 | ) { |
||
| 423 | throw new UnauthorizedException('content', 'versionread', ['remoteId' => $remoteId, 'versionNo' => $versionNo]); |
||
| 424 | } |
||
| 425 | |||
| 426 | return $content; |
||
| 427 | } |
||
| 428 | |||
| 429 | /** |
||
| 430 | * Bulk-load Content items by the list of ContentInfo Value Objects. |
||
| 431 | * |
||
| 432 | * Note: it does not throw exceptions on load, just ignores erroneous Content item. |
||
| 433 | * Moreover, since the method works on pre-loaded ContentInfo list, it is assumed that user is |
||
| 434 | * allowed to access every Content on the list. |
||
| 435 | * |
||
| 436 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo[] $contentInfoList |
||
| 437 | * @param string[] $languages A language priority, filters returned fields and is used as prioritized language code on |
||
| 438 | * returned value object. If not given all languages are returned. |
||
| 439 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true, |
||
| 440 | * unless all languages have been asked for. |
||
| 441 | * |
||
| 442 | * @return \eZ\Publish\API\Repository\Values\Content\Content[] list of Content items with Content Ids as keys |
||
| 443 | */ |
||
| 444 | public function loadContentListByContentInfo( |
||
| 445 | array $contentInfoList, |
||
| 446 | array $languages = [], |
||
| 447 | $useAlwaysAvailable = true |
||
| 448 | ) { |
||
| 449 | $loadAllLanguages = $languages === Language::ALL; |
||
| 450 | $contentIds = []; |
||
| 451 | $contentTypeIds = []; |
||
| 452 | $translations = $languages; |
||
| 453 | foreach ($contentInfoList as $contentInfo) { |
||
| 454 | $contentIds[] = $contentInfo->id; |
||
| 455 | $contentTypeIds[] = $contentInfo->contentTypeId; |
||
| 456 | // Unless we are told to load all languages, we add main language to translations so they are loaded too |
||
| 457 | // Might in some case load more languages then intended, but prioritised handling will pick right one |
||
| 458 | if (!$loadAllLanguages && $useAlwaysAvailable && $contentInfo->alwaysAvailable) { |
||
| 459 | $translations[] = $contentInfo->mainLanguageCode; |
||
| 460 | } |
||
| 461 | } |
||
| 462 | |||
| 463 | $contentList = []; |
||
| 464 | $translations = array_unique($translations); |
||
| 465 | $spiContentList = $this->persistenceHandler->contentHandler()->loadContentList( |
||
| 466 | $contentIds, |
||
| 467 | $translations |
||
| 468 | ); |
||
| 469 | $contentTypeList = $this->repository->getContentTypeService()->loadContentTypeList( |
||
| 470 | array_unique($contentTypeIds), |
||
| 471 | $languages |
||
| 472 | ); |
||
| 473 | foreach ($spiContentList as $contentId => $spiContent) { |
||
| 474 | $contentInfo = $spiContent->versionInfo->contentInfo; |
||
| 475 | $contentList[$contentId] = $this->domainMapper->buildContentDomainObject( |
||
| 476 | $spiContent, |
||
| 477 | $contentTypeList[$contentInfo->contentTypeId], |
||
| 478 | $languages, |
||
| 479 | $contentInfo->alwaysAvailable ? $contentInfo->mainLanguageCode : null |
||
| 480 | ); |
||
| 481 | } |
||
| 482 | |||
| 483 | return $contentList; |
||
| 484 | } |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Creates a new content draft assigned to the authenticated user. |
||
| 488 | * |
||
| 489 | * If a different userId is given in $contentCreateStruct it is assigned to the given user |
||
| 490 | * but this required special rights for the authenticated user |
||
| 491 | * (this is useful for content staging where the transfer process does not |
||
| 492 | * have to authenticate with the user which created the content object in the source server). |
||
| 493 | * The user has to publish the draft if it should be visible. |
||
| 494 | * In 4.x at least one location has to be provided in the location creation array. |
||
| 495 | * |
||
| 496 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location |
||
| 497 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the provided remoteId exists in the system, required properties on |
||
| 498 | * struct are missing or invalid, or if multiple locations are under the |
||
| 499 | * same parent. |
||
| 500 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid, |
||
| 501 | * or if a required field is missing / set to an empty value. |
||
| 502 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType, |
||
| 503 | * or value is set for non-translatable field in language |
||
| 504 | * other than main. |
||
| 505 | * |
||
| 506 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 507 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content |
||
| 508 | * |
||
| 509 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 510 | */ |
||
| 511 | public function createContent(APIContentCreateStruct $contentCreateStruct, array $locationCreateStructs = []) |
||
| 512 | { |
||
| 513 | if ($contentCreateStruct->mainLanguageCode === null) { |
||
| 514 | throw new InvalidArgumentException('$contentCreateStruct', "'mainLanguageCode' property must be set"); |
||
| 515 | } |
||
| 516 | |||
| 517 | if ($contentCreateStruct->contentType === null) { |
||
| 518 | throw new InvalidArgumentException('$contentCreateStruct', "'contentType' property must be set"); |
||
| 519 | } |
||
| 520 | |||
| 521 | $contentCreateStruct = clone $contentCreateStruct; |
||
| 522 | |||
| 523 | if ($contentCreateStruct->ownerId === null) { |
||
| 524 | $contentCreateStruct->ownerId = $this->permissionResolver->getCurrentUserReference()->getUserId(); |
||
| 525 | } |
||
| 526 | |||
| 527 | if ($contentCreateStruct->alwaysAvailable === null) { |
||
| 528 | $contentCreateStruct->alwaysAvailable = $contentCreateStruct->contentType->defaultAlwaysAvailable ?: false; |
||
| 529 | } |
||
| 530 | |||
| 531 | $contentCreateStruct->contentType = $this->repository->getContentTypeService()->loadContentType( |
||
| 532 | $contentCreateStruct->contentType->id |
||
| 533 | ); |
||
| 534 | |||
| 535 | if (empty($contentCreateStruct->sectionId)) { |
||
| 536 | if (isset($locationCreateStructs[0])) { |
||
| 537 | $location = $this->repository->getLocationService()->loadLocation( |
||
| 538 | $locationCreateStructs[0]->parentLocationId |
||
| 539 | ); |
||
| 540 | $contentCreateStruct->sectionId = $location->contentInfo->sectionId; |
||
| 541 | } else { |
||
| 542 | $contentCreateStruct->sectionId = 1; |
||
| 543 | } |
||
| 544 | } |
||
| 545 | |||
| 546 | if (!$this->permissionResolver->canUser('content', 'create', $contentCreateStruct, $locationCreateStructs)) { |
||
| 547 | throw new UnauthorizedException( |
||
| 548 | 'content', |
||
| 549 | 'create', |
||
| 550 | [ |
||
| 551 | 'parentLocationId' => isset($locationCreateStructs[0]) ? |
||
| 552 | $locationCreateStructs[0]->parentLocationId : |
||
| 553 | null, |
||
| 554 | 'sectionId' => $contentCreateStruct->sectionId, |
||
| 555 | ] |
||
| 556 | ); |
||
| 557 | } |
||
| 558 | |||
| 559 | if (!empty($contentCreateStruct->remoteId)) { |
||
| 560 | try { |
||
| 561 | $this->loadContentByRemoteId($contentCreateStruct->remoteId); |
||
| 562 | |||
| 563 | throw new InvalidArgumentException( |
||
| 564 | '$contentCreateStruct', |
||
| 565 | "Another content with remoteId '{$contentCreateStruct->remoteId}' exists" |
||
| 566 | ); |
||
| 567 | } catch (APINotFoundException $e) { |
||
| 568 | // Do nothing |
||
| 569 | } |
||
| 570 | } else { |
||
| 571 | $contentCreateStruct->remoteId = $this->domainMapper->getUniqueHash($contentCreateStruct); |
||
| 572 | } |
||
| 573 | |||
| 574 | $spiLocationCreateStructs = $this->buildSPILocationCreateStructs($locationCreateStructs); |
||
| 575 | |||
| 576 | $languageCodes = $this->getLanguageCodesForCreate($contentCreateStruct); |
||
| 577 | $fields = $this->mapFieldsForCreate($contentCreateStruct); |
||
| 578 | |||
| 579 | $fieldValues = []; |
||
| 580 | $spiFields = []; |
||
| 581 | $allFieldErrors = []; |
||
| 582 | $inputRelations = []; |
||
| 583 | $locationIdToContentIdMapping = []; |
||
| 584 | |||
| 585 | foreach ($contentCreateStruct->contentType->getFieldDefinitions() as $fieldDefinition) { |
||
| 586 | /** @var $fieldType \eZ\Publish\Core\FieldType\FieldType */ |
||
| 587 | $fieldType = $this->fieldTypeRegistry->getFieldType( |
||
| 588 | $fieldDefinition->fieldTypeIdentifier |
||
| 589 | ); |
||
| 590 | |||
| 591 | foreach ($languageCodes as $languageCode) { |
||
| 592 | $isEmptyValue = false; |
||
| 593 | $valueLanguageCode = $fieldDefinition->isTranslatable ? $languageCode : $contentCreateStruct->mainLanguageCode; |
||
| 594 | $isLanguageMain = $languageCode === $contentCreateStruct->mainLanguageCode; |
||
| 595 | if (isset($fields[$fieldDefinition->identifier][$valueLanguageCode])) { |
||
| 596 | $fieldValue = $fields[$fieldDefinition->identifier][$valueLanguageCode]->value; |
||
| 597 | } else { |
||
| 598 | $fieldValue = $fieldDefinition->defaultValue; |
||
| 599 | } |
||
| 600 | |||
| 601 | $fieldValue = $fieldType->acceptValue($fieldValue); |
||
| 602 | |||
| 603 | if ($fieldType->isEmptyValue($fieldValue)) { |
||
| 604 | $isEmptyValue = true; |
||
| 605 | if ($fieldDefinition->isRequired) { |
||
| 606 | $allFieldErrors[$fieldDefinition->id][$languageCode] = new ValidationError( |
||
| 607 | "Value for required field definition '%identifier%' with language '%languageCode%' is empty", |
||
| 608 | null, |
||
| 609 | ['%identifier%' => $fieldDefinition->identifier, '%languageCode%' => $languageCode], |
||
| 610 | 'empty' |
||
| 611 | ); |
||
| 612 | } |
||
| 613 | } else { |
||
| 614 | $fieldErrors = $fieldType->validate( |
||
| 615 | $fieldDefinition, |
||
| 616 | $fieldValue |
||
| 617 | ); |
||
| 618 | if (!empty($fieldErrors)) { |
||
| 619 | $allFieldErrors[$fieldDefinition->id][$languageCode] = $fieldErrors; |
||
| 620 | } |
||
| 621 | } |
||
| 622 | |||
| 623 | if (!empty($allFieldErrors)) { |
||
| 624 | continue; |
||
| 625 | } |
||
| 626 | |||
| 627 | $this->relationProcessor->appendFieldRelations( |
||
| 628 | $inputRelations, |
||
| 629 | $locationIdToContentIdMapping, |
||
| 630 | $fieldType, |
||
| 631 | $fieldValue, |
||
| 632 | $fieldDefinition->id |
||
| 633 | ); |
||
| 634 | $fieldValues[$fieldDefinition->identifier][$languageCode] = $fieldValue; |
||
| 635 | |||
| 636 | // Only non-empty value for: translatable field or in main language |
||
| 637 | if ( |
||
| 638 | (!$isEmptyValue && $fieldDefinition->isTranslatable) || |
||
| 639 | (!$isEmptyValue && $isLanguageMain) |
||
| 640 | ) { |
||
| 641 | $spiFields[] = new SPIField( |
||
| 642 | [ |
||
| 643 | 'id' => null, |
||
| 644 | 'fieldDefinitionId' => $fieldDefinition->id, |
||
| 645 | 'type' => $fieldDefinition->fieldTypeIdentifier, |
||
| 646 | 'value' => $fieldType->toPersistenceValue($fieldValue), |
||
| 647 | 'languageCode' => $languageCode, |
||
| 648 | 'versionNo' => null, |
||
| 649 | ] |
||
| 650 | ); |
||
| 651 | } |
||
| 652 | } |
||
| 653 | } |
||
| 654 | |||
| 655 | if (!empty($allFieldErrors)) { |
||
| 656 | throw new ContentFieldValidationException($allFieldErrors); |
||
| 657 | } |
||
| 658 | |||
| 659 | $spiContentCreateStruct = new SPIContentCreateStruct( |
||
| 660 | [ |
||
| 661 | 'name' => $this->nameSchemaService->resolve( |
||
| 662 | $contentCreateStruct->contentType->nameSchema, |
||
| 663 | $contentCreateStruct->contentType, |
||
| 664 | $fieldValues, |
||
| 665 | $languageCodes |
||
| 666 | ), |
||
| 667 | 'typeId' => $contentCreateStruct->contentType->id, |
||
| 668 | 'sectionId' => $contentCreateStruct->sectionId, |
||
| 669 | 'ownerId' => $contentCreateStruct->ownerId, |
||
| 670 | 'locations' => $spiLocationCreateStructs, |
||
| 671 | 'fields' => $spiFields, |
||
| 672 | 'alwaysAvailable' => $contentCreateStruct->alwaysAvailable, |
||
| 673 | 'remoteId' => $contentCreateStruct->remoteId, |
||
| 674 | 'modified' => isset($contentCreateStruct->modificationDate) ? $contentCreateStruct->modificationDate->getTimestamp() : time(), |
||
| 675 | 'initialLanguageId' => $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode( |
||
| 676 | $contentCreateStruct->mainLanguageCode |
||
| 677 | )->id, |
||
| 678 | ] |
||
| 679 | ); |
||
| 680 | |||
| 681 | $defaultObjectStates = $this->getDefaultObjectStates(); |
||
| 682 | |||
| 683 | $this->repository->beginTransaction(); |
||
| 684 | try { |
||
| 685 | $spiContent = $this->persistenceHandler->contentHandler()->create($spiContentCreateStruct); |
||
| 686 | $this->relationProcessor->processFieldRelations( |
||
| 687 | $inputRelations, |
||
| 688 | $spiContent->versionInfo->contentInfo->id, |
||
| 689 | $spiContent->versionInfo->versionNo, |
||
| 690 | $contentCreateStruct->contentType |
||
| 691 | ); |
||
| 692 | |||
| 693 | $objectStateHandler = $this->persistenceHandler->objectStateHandler(); |
||
| 694 | foreach ($defaultObjectStates as $objectStateGroupId => $objectState) { |
||
| 695 | $objectStateHandler->setContentState( |
||
| 696 | $spiContent->versionInfo->contentInfo->id, |
||
| 697 | $objectStateGroupId, |
||
| 698 | $objectState->id |
||
| 699 | ); |
||
| 700 | } |
||
| 701 | |||
| 702 | $this->repository->commit(); |
||
| 703 | } catch (Exception $e) { |
||
| 704 | $this->repository->rollback(); |
||
| 705 | throw $e; |
||
| 706 | } |
||
| 707 | |||
| 708 | return $this->domainMapper->buildContentDomainObject( |
||
| 709 | $spiContent, |
||
| 710 | $contentCreateStruct->contentType |
||
| 711 | ); |
||
| 712 | } |
||
| 713 | |||
| 714 | /** |
||
| 715 | * Returns an array of default content states with content state group id as key. |
||
| 716 | * |
||
| 717 | * @return \eZ\Publish\SPI\Persistence\Content\ObjectState[] |
||
| 718 | */ |
||
| 719 | protected function getDefaultObjectStates() |
||
| 720 | { |
||
| 721 | $defaultObjectStatesMap = []; |
||
| 722 | $objectStateHandler = $this->persistenceHandler->objectStateHandler(); |
||
| 723 | |||
| 724 | foreach ($objectStateHandler->loadAllGroups() as $objectStateGroup) { |
||
| 725 | foreach ($objectStateHandler->loadObjectStates($objectStateGroup->id) as $objectState) { |
||
| 726 | // Only register the first object state which is the default one. |
||
| 727 | $defaultObjectStatesMap[$objectStateGroup->id] = $objectState; |
||
| 728 | break; |
||
| 729 | } |
||
| 730 | } |
||
| 731 | |||
| 732 | return $defaultObjectStatesMap; |
||
| 733 | } |
||
| 734 | |||
| 735 | /** |
||
| 736 | * Returns all language codes used in given $fields. |
||
| 737 | * |
||
| 738 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value is set in main language |
||
| 739 | * |
||
| 740 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 741 | * |
||
| 742 | * @return string[] |
||
| 743 | */ |
||
| 744 | protected function getLanguageCodesForCreate(APIContentCreateStruct $contentCreateStruct) |
||
| 745 | { |
||
| 746 | $languageCodes = []; |
||
| 747 | |||
| 748 | foreach ($contentCreateStruct->fields as $field) { |
||
| 749 | if ($field->languageCode === null || isset($languageCodes[$field->languageCode])) { |
||
| 750 | continue; |
||
| 751 | } |
||
| 752 | |||
| 753 | $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode( |
||
| 754 | $field->languageCode |
||
| 755 | ); |
||
| 756 | $languageCodes[$field->languageCode] = true; |
||
| 757 | } |
||
| 758 | |||
| 759 | if (!isset($languageCodes[$contentCreateStruct->mainLanguageCode])) { |
||
| 760 | $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode( |
||
| 761 | $contentCreateStruct->mainLanguageCode |
||
| 762 | ); |
||
| 763 | $languageCodes[$contentCreateStruct->mainLanguageCode] = true; |
||
| 764 | } |
||
| 765 | |||
| 766 | return array_keys($languageCodes); |
||
| 767 | } |
||
| 768 | |||
| 769 | /** |
||
| 770 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
| 771 | * |
||
| 772 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
| 773 | * or value is set for non-translatable field in language |
||
| 774 | * other than main |
||
| 775 | * |
||
| 776 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 777 | * |
||
| 778 | * @return array |
||
| 779 | */ |
||
| 780 | protected function mapFieldsForCreate(APIContentCreateStruct $contentCreateStruct) |
||
| 781 | { |
||
| 782 | $fields = []; |
||
| 783 | |||
| 784 | foreach ($contentCreateStruct->fields as $field) { |
||
| 785 | $fieldDefinition = $contentCreateStruct->contentType->getFieldDefinition($field->fieldDefIdentifier); |
||
| 786 | |||
| 787 | if ($fieldDefinition === null) { |
||
| 788 | throw new ContentValidationException( |
||
| 789 | "Field definition '%identifier%' does not exist in given ContentType", |
||
| 790 | ['%identifier%' => $field->fieldDefIdentifier] |
||
| 791 | ); |
||
| 792 | } |
||
| 793 | |||
| 794 | if ($field->languageCode === null) { |
||
| 795 | $field = $this->cloneField( |
||
| 796 | $field, |
||
| 797 | ['languageCode' => $contentCreateStruct->mainLanguageCode] |
||
| 798 | ); |
||
| 799 | } |
||
| 800 | |||
| 801 | if (!$fieldDefinition->isTranslatable && ($field->languageCode != $contentCreateStruct->mainLanguageCode)) { |
||
| 802 | throw new ContentValidationException( |
||
| 803 | "A value is set for non translatable field definition '%identifier%' with language '%languageCode%'", |
||
| 804 | ['%identifier%' => $field->fieldDefIdentifier, '%languageCode%' => $field->languageCode] |
||
| 805 | ); |
||
| 806 | } |
||
| 807 | |||
| 808 | $fields[$field->fieldDefIdentifier][$field->languageCode] = $field; |
||
| 809 | } |
||
| 810 | |||
| 811 | return $fields; |
||
| 812 | } |
||
| 813 | |||
| 814 | /** |
||
| 815 | * Clones $field with overriding specific properties from given $overrides array. |
||
| 816 | * |
||
| 817 | * @param Field $field |
||
| 818 | * @param array $overrides |
||
| 819 | * |
||
| 820 | * @return Field |
||
| 821 | */ |
||
| 822 | private function cloneField(Field $field, array $overrides = []) |
||
| 823 | { |
||
| 824 | $fieldData = array_merge( |
||
| 825 | [ |
||
| 826 | 'id' => $field->id, |
||
| 827 | 'value' => $field->value, |
||
| 828 | 'languageCode' => $field->languageCode, |
||
| 829 | 'fieldDefIdentifier' => $field->fieldDefIdentifier, |
||
| 830 | 'fieldTypeIdentifier' => $field->fieldTypeIdentifier, |
||
| 831 | ], |
||
| 832 | $overrides |
||
| 833 | ); |
||
| 834 | |||
| 835 | return new Field($fieldData); |
||
| 836 | } |
||
| 837 | |||
| 838 | /** |
||
| 839 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 840 | * |
||
| 841 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs |
||
| 842 | * |
||
| 843 | * @return \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct[] |
||
| 844 | */ |
||
| 845 | protected function buildSPILocationCreateStructs(array $locationCreateStructs) |
||
| 846 | { |
||
| 847 | $spiLocationCreateStructs = []; |
||
| 848 | $parentLocationIdSet = []; |
||
| 849 | $mainLocation = true; |
||
| 850 | |||
| 851 | foreach ($locationCreateStructs as $locationCreateStruct) { |
||
| 852 | if (isset($parentLocationIdSet[$locationCreateStruct->parentLocationId])) { |
||
| 853 | throw new InvalidArgumentException( |
||
| 854 | '$locationCreateStructs', |
||
| 855 | "Multiple LocationCreateStructs with the same parent Location '{$locationCreateStruct->parentLocationId}' are given" |
||
| 856 | ); |
||
| 857 | } |
||
| 858 | |||
| 859 | if (!array_key_exists($locationCreateStruct->sortField, Location::SORT_FIELD_MAP)) { |
||
| 860 | $locationCreateStruct->sortField = Location::SORT_FIELD_NAME; |
||
| 861 | } |
||
| 862 | |||
| 863 | if (!array_key_exists($locationCreateStruct->sortOrder, Location::SORT_ORDER_MAP)) { |
||
| 864 | $locationCreateStruct->sortOrder = Location::SORT_ORDER_ASC; |
||
| 865 | } |
||
| 866 | |||
| 867 | $parentLocationIdSet[$locationCreateStruct->parentLocationId] = true; |
||
| 868 | $parentLocation = $this->repository->getLocationService()->loadLocation( |
||
| 869 | $locationCreateStruct->parentLocationId |
||
| 870 | ); |
||
| 871 | |||
| 872 | $spiLocationCreateStructs[] = $this->domainMapper->buildSPILocationCreateStruct( |
||
| 873 | $locationCreateStruct, |
||
| 874 | $parentLocation, |
||
| 875 | $mainLocation, |
||
| 876 | // For Content draft contentId and contentVersionNo are set in ContentHandler upon draft creation |
||
| 877 | null, |
||
| 878 | null |
||
| 879 | ); |
||
| 880 | |||
| 881 | // First Location in the list will be created as main Location |
||
| 882 | $mainLocation = false; |
||
| 883 | } |
||
| 884 | |||
| 885 | return $spiLocationCreateStructs; |
||
| 886 | } |
||
| 887 | |||
| 888 | /** |
||
| 889 | * Updates the metadata. |
||
| 890 | * |
||
| 891 | * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent |
||
| 892 | * |
||
| 893 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data |
||
| 894 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists |
||
| 895 | * |
||
| 896 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 897 | * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct |
||
| 898 | * |
||
| 899 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes |
||
| 900 | */ |
||
| 901 | public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct) |
||
| 902 | { |
||
| 903 | $propertyCount = 0; |
||
| 904 | foreach ($contentMetadataUpdateStruct as $propertyName => $propertyValue) { |
||
| 905 | if (isset($contentMetadataUpdateStruct->$propertyName)) { |
||
| 906 | $propertyCount += 1; |
||
| 907 | } |
||
| 908 | } |
||
| 909 | if ($propertyCount === 0) { |
||
| 910 | throw new InvalidArgumentException( |
||
| 911 | '$contentMetadataUpdateStruct', |
||
| 912 | 'At least one property must be set' |
||
| 913 | ); |
||
| 914 | } |
||
| 915 | |||
| 916 | $loadedContentInfo = $this->loadContentInfo($contentInfo->id); |
||
| 917 | |||
| 918 | if (!$this->permissionResolver->canUser('content', 'edit', $loadedContentInfo)) { |
||
| 919 | throw new UnauthorizedException('content', 'edit', ['contentId' => $loadedContentInfo->id]); |
||
| 920 | } |
||
| 921 | |||
| 922 | if (isset($contentMetadataUpdateStruct->remoteId)) { |
||
| 923 | try { |
||
| 924 | $existingContentInfo = $this->loadContentInfoByRemoteId($contentMetadataUpdateStruct->remoteId); |
||
| 925 | |||
| 926 | if ($existingContentInfo->id !== $loadedContentInfo->id) { |
||
| 927 | throw new InvalidArgumentException( |
||
| 928 | '$contentMetadataUpdateStruct', |
||
| 929 | "Another content with remoteId '{$contentMetadataUpdateStruct->remoteId}' exists" |
||
| 930 | ); |
||
| 931 | } |
||
| 932 | } catch (APINotFoundException $e) { |
||
| 933 | // Do nothing |
||
| 934 | } |
||
| 935 | } |
||
| 936 | |||
| 937 | $this->repository->beginTransaction(); |
||
| 938 | try { |
||
| 939 | if ($propertyCount > 1 || !isset($contentMetadataUpdateStruct->mainLocationId)) { |
||
| 940 | $this->persistenceHandler->contentHandler()->updateMetadata( |
||
| 941 | $loadedContentInfo->id, |
||
| 942 | new SPIMetadataUpdateStruct( |
||
| 943 | [ |
||
| 944 | 'ownerId' => $contentMetadataUpdateStruct->ownerId, |
||
| 945 | 'publicationDate' => isset($contentMetadataUpdateStruct->publishedDate) ? |
||
| 946 | $contentMetadataUpdateStruct->publishedDate->getTimestamp() : |
||
| 947 | null, |
||
| 948 | 'modificationDate' => isset($contentMetadataUpdateStruct->modificationDate) ? |
||
| 949 | $contentMetadataUpdateStruct->modificationDate->getTimestamp() : |
||
| 950 | null, |
||
| 951 | 'mainLanguageId' => isset($contentMetadataUpdateStruct->mainLanguageCode) ? |
||
| 952 | $this->repository->getContentLanguageService()->loadLanguage( |
||
| 953 | $contentMetadataUpdateStruct->mainLanguageCode |
||
| 954 | )->id : |
||
| 955 | null, |
||
| 956 | 'alwaysAvailable' => $contentMetadataUpdateStruct->alwaysAvailable, |
||
| 957 | 'remoteId' => $contentMetadataUpdateStruct->remoteId, |
||
| 958 | 'name' => $contentMetadataUpdateStruct->name, |
||
| 959 | ] |
||
| 960 | ) |
||
| 961 | ); |
||
| 962 | } |
||
| 963 | |||
| 964 | // Change main location |
||
| 965 | if (isset($contentMetadataUpdateStruct->mainLocationId) |
||
| 966 | && $loadedContentInfo->mainLocationId !== $contentMetadataUpdateStruct->mainLocationId) { |
||
| 967 | $this->persistenceHandler->locationHandler()->changeMainLocation( |
||
| 968 | $loadedContentInfo->id, |
||
| 969 | $contentMetadataUpdateStruct->mainLocationId |
||
| 970 | ); |
||
| 971 | } |
||
| 972 | |||
| 973 | // Republish URL aliases to update always-available flag |
||
| 974 | if (isset($contentMetadataUpdateStruct->alwaysAvailable) |
||
| 975 | && $loadedContentInfo->alwaysAvailable !== $contentMetadataUpdateStruct->alwaysAvailable) { |
||
| 976 | $content = $this->loadContent($loadedContentInfo->id); |
||
| 977 | $this->publishUrlAliasesForContent($content, false); |
||
| 978 | } |
||
| 979 | |||
| 980 | $this->repository->commit(); |
||
| 981 | } catch (Exception $e) { |
||
| 982 | $this->repository->rollback(); |
||
| 983 | throw $e; |
||
| 984 | } |
||
| 985 | |||
| 986 | return isset($content) ? $content : $this->loadContent($loadedContentInfo->id); |
||
| 987 | } |
||
| 988 | |||
| 989 | /** |
||
| 990 | * Publishes URL aliases for all locations of a given content. |
||
| 991 | * |
||
| 992 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 993 | * @param bool $updatePathIdentificationString this parameter is legacy storage specific for updating |
||
| 994 | * ezcontentobject_tree.path_identification_string, it is ignored by other storage engines |
||
| 995 | */ |
||
| 996 | protected function publishUrlAliasesForContent(APIContent $content, $updatePathIdentificationString = true) |
||
| 997 | { |
||
| 998 | $urlAliasNames = $this->nameSchemaService->resolveUrlAliasSchema($content); |
||
| 999 | $locations = $this->repository->getLocationService()->loadLocations( |
||
| 1000 | $content->getVersionInfo()->getContentInfo() |
||
| 1001 | ); |
||
| 1002 | $urlAliasHandler = $this->persistenceHandler->urlAliasHandler(); |
||
| 1003 | foreach ($locations as $location) { |
||
| 1004 | foreach ($urlAliasNames as $languageCode => $name) { |
||
| 1005 | $urlAliasHandler->publishUrlAliasForLocation( |
||
| 1006 | $location->id, |
||
| 1007 | $location->parentLocationId, |
||
| 1008 | $name, |
||
| 1009 | $languageCode, |
||
| 1010 | $content->contentInfo->alwaysAvailable, |
||
| 1011 | $updatePathIdentificationString ? $languageCode === $content->contentInfo->mainLanguageCode : false |
||
| 1012 | ); |
||
| 1013 | } |
||
| 1014 | // archive URL aliases of Translations that got deleted |
||
| 1015 | $urlAliasHandler->archiveUrlAliasesForDeletedTranslations( |
||
| 1016 | $location->id, |
||
| 1017 | $location->parentLocationId, |
||
| 1018 | $content->versionInfo->languageCodes |
||
| 1019 | ); |
||
| 1020 | } |
||
| 1021 | } |
||
| 1022 | |||
| 1023 | /** |
||
| 1024 | * Deletes a content object including all its versions and locations including their subtrees. |
||
| 1025 | * |
||
| 1026 | * @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) |
||
| 1027 | * |
||
| 1028 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1029 | * |
||
| 1030 | * @return mixed[] Affected Location Id's |
||
| 1031 | */ |
||
| 1032 | public function deleteContent(ContentInfo $contentInfo) |
||
| 1033 | { |
||
| 1034 | $contentInfo = $this->internalLoadContentInfo($contentInfo->id); |
||
| 1035 | |||
| 1036 | if (!$this->permissionResolver->canUser('content', 'remove', $contentInfo)) { |
||
| 1037 | throw new UnauthorizedException('content', 'remove', ['contentId' => $contentInfo->id]); |
||
| 1038 | } |
||
| 1039 | |||
| 1040 | $affectedLocations = []; |
||
| 1041 | $this->repository->beginTransaction(); |
||
| 1042 | try { |
||
| 1043 | // Load Locations first as deleting Content also deletes belonging Locations |
||
| 1044 | $spiLocations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentInfo->id); |
||
| 1045 | $this->persistenceHandler->contentHandler()->deleteContent($contentInfo->id); |
||
| 1046 | $urlAliasHandler = $this->persistenceHandler->urlAliasHandler(); |
||
| 1047 | foreach ($spiLocations as $spiLocation) { |
||
| 1048 | $urlAliasHandler->locationDeleted($spiLocation->id); |
||
| 1049 | $affectedLocations[] = $spiLocation->id; |
||
| 1050 | } |
||
| 1051 | $this->repository->commit(); |
||
| 1052 | } catch (Exception $e) { |
||
| 1053 | $this->repository->rollback(); |
||
| 1054 | throw $e; |
||
| 1055 | } |
||
| 1056 | |||
| 1057 | return $affectedLocations; |
||
| 1058 | } |
||
| 1059 | |||
| 1060 | /** |
||
| 1061 | * Creates a draft from a published or archived version. |
||
| 1062 | * |
||
| 1063 | * If no version is given, the current published version is used. |
||
| 1064 | * |
||
| 1065 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1066 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1067 | * @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 |
||
| 1068 | * @param \eZ\Publish\API\Repository\Values\Content\Language|null if not set the draft is created with the initialLanguage code of the source version or if not present with the main language. |
||
| 1069 | * |
||
| 1070 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 1071 | * |
||
| 1072 | * @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException |
||
| 1073 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the current-user is not allowed to create the draft |
||
| 1074 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to create the draft |
||
| 1075 | */ |
||
| 1076 | public function createContentDraft( |
||
| 1077 | ContentInfo $contentInfo, |
||
| 1078 | APIVersionInfo $versionInfo = null, |
||
| 1079 | User $creator = null, |
||
| 1080 | ?Language $language = null |
||
| 1081 | ) { |
||
| 1082 | $contentInfo = $this->loadContentInfo($contentInfo->id); |
||
| 1083 | |||
| 1084 | if ($versionInfo !== null) { |
||
| 1085 | // Check that given $contentInfo and $versionInfo belong to the same content |
||
| 1086 | if ($versionInfo->getContentInfo()->id != $contentInfo->id) { |
||
| 1087 | throw new InvalidArgumentException( |
||
| 1088 | '$versionInfo', |
||
| 1089 | 'VersionInfo does not belong to the same content as given ContentInfo' |
||
| 1090 | ); |
||
| 1091 | } |
||
| 1092 | |||
| 1093 | $versionInfo = $this->loadVersionInfoById($contentInfo->id, $versionInfo->versionNo); |
||
| 1094 | |||
| 1095 | switch ($versionInfo->status) { |
||
| 1096 | case VersionInfo::STATUS_PUBLISHED: |
||
| 1097 | case VersionInfo::STATUS_ARCHIVED: |
||
| 1098 | break; |
||
| 1099 | |||
| 1100 | default: |
||
| 1101 | // @todo: throw an exception here, to be defined |
||
| 1102 | throw new BadStateException( |
||
| 1103 | '$versionInfo', |
||
| 1104 | 'Draft can not be created from a draft version' |
||
| 1105 | ); |
||
| 1106 | } |
||
| 1107 | |||
| 1108 | $versionNo = $versionInfo->versionNo; |
||
| 1109 | } elseif ($contentInfo->published) { |
||
| 1110 | $versionNo = $contentInfo->currentVersionNo; |
||
| 1111 | } else { |
||
| 1112 | // @todo: throw an exception here, to be defined |
||
| 1113 | throw new BadStateException( |
||
| 1114 | '$contentInfo', |
||
| 1115 | 'Content is not published, draft can be created only from published or archived version' |
||
| 1116 | ); |
||
| 1117 | } |
||
| 1118 | |||
| 1119 | if ($creator === null) { |
||
| 1120 | $creator = $this->permissionResolver->getCurrentUserReference(); |
||
| 1121 | } |
||
| 1122 | |||
| 1123 | $fallbackLanguageCode = $versionInfo->initialLanguageCode ?? $contentInfo->mainLanguageCode; |
||
| 1124 | $languageCode = $language->languageCode ?? $fallbackLanguageCode; |
||
| 1125 | |||
| 1126 | if (!$this->permissionResolver->canUser( |
||
| 1127 | 'content', |
||
| 1128 | 'edit', |
||
| 1129 | $contentInfo, |
||
| 1130 | [ |
||
| 1131 | (new Target\Builder\VersionBuilder()) |
||
| 1132 | ->changeStatusTo(APIVersionInfo::STATUS_DRAFT) |
||
| 1133 | ->build(), |
||
| 1134 | ] |
||
| 1135 | )) { |
||
| 1136 | throw new UnauthorizedException( |
||
| 1137 | 'content', |
||
| 1138 | 'edit', |
||
| 1139 | ['contentId' => $contentInfo->id] |
||
| 1140 | ); |
||
| 1141 | } |
||
| 1142 | |||
| 1143 | $this->repository->beginTransaction(); |
||
| 1144 | try { |
||
| 1145 | $spiContent = $this->persistenceHandler->contentHandler()->createDraftFromVersion( |
||
| 1146 | $contentInfo->id, |
||
| 1147 | $versionNo, |
||
| 1148 | $creator->getUserId(), |
||
| 1149 | $languageCode |
||
| 1150 | ); |
||
| 1151 | $this->repository->commit(); |
||
| 1152 | } catch (Exception $e) { |
||
| 1153 | $this->repository->rollback(); |
||
| 1154 | throw $e; |
||
| 1155 | } |
||
| 1156 | |||
| 1157 | return $this->domainMapper->buildContentDomainObject( |
||
| 1158 | $spiContent, |
||
| 1159 | $this->repository->getContentTypeService()->loadContentType( |
||
| 1160 | $spiContent->versionInfo->contentInfo->contentTypeId |
||
| 1161 | ) |
||
| 1162 | ); |
||
| 1163 | } |
||
| 1164 | |||
| 1165 | public function countContentDrafts(?User $user = null): int |
||
| 1166 | { |
||
| 1167 | if ($this->permissionResolver->hasAccess('content', 'versionread') === false) { |
||
| 1168 | return 0; |
||
| 1169 | } |
||
| 1170 | |||
| 1171 | return $this->persistenceHandler->contentHandler()->countDraftsForUser( |
||
| 1172 | $this->resolveUser($user)->getUserId() |
||
| 1173 | ); |
||
| 1174 | } |
||
| 1175 | |||
| 1176 | /** |
||
| 1177 | * Loads drafts for a user. |
||
| 1178 | * |
||
| 1179 | * If no user is given the drafts for the authenticated user are returned |
||
| 1180 | * |
||
| 1181 | * @param \eZ\Publish\API\Repository\Values\User\User|null $user |
||
| 1182 | * |
||
| 1183 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Drafts owned by the given user |
||
| 1184 | * |
||
| 1185 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 1186 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 1187 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 1188 | */ |
||
| 1189 | public function loadContentDrafts(User $user = null) |
||
| 1190 | { |
||
| 1191 | // throw early if user has absolutely no access to versionread |
||
| 1192 | if ($this->permissionResolver->hasAccess('content', 'versionread') === false) { |
||
| 1193 | throw new UnauthorizedException('content', 'versionread'); |
||
| 1194 | } |
||
| 1195 | |||
| 1196 | $spiVersionInfoList = $this->persistenceHandler->contentHandler()->loadDraftsForUser( |
||
| 1197 | $this->resolveUser($user)->getUserId() |
||
| 1198 | ); |
||
| 1199 | $versionInfoList = []; |
||
| 1200 | foreach ($spiVersionInfoList as $spiVersionInfo) { |
||
| 1201 | $versionInfo = $this->domainMapper->buildVersionInfoDomainObject($spiVersionInfo); |
||
| 1202 | // @todo: Change this to filter returned drafts by permissions instead of throwing |
||
| 1203 | if (!$this->permissionResolver->canUser('content', 'versionread', $versionInfo)) { |
||
| 1204 | throw new UnauthorizedException('content', 'versionread', ['contentId' => $versionInfo->contentInfo->id]); |
||
| 1205 | } |
||
| 1206 | |||
| 1207 | $versionInfoList[] = $versionInfo; |
||
| 1208 | } |
||
| 1209 | |||
| 1210 | return $versionInfoList; |
||
| 1211 | } |
||
| 1212 | |||
| 1213 | public function loadContentDraftList(?User $user = null, int $offset = 0, int $limit = -1): ContentDraftList |
||
| 1245 | |||
| 1246 | /** |
||
| 1247 | * Updates the fields of a draft. |
||
| 1248 | * |
||
| 1249 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1250 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1251 | * |
||
| 1252 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields |
||
| 1253 | * |
||
| 1254 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid, |
||
| 1255 | * or if a required field is missing / set to an empty value. |
||
| 1256 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType, |
||
| 1257 | * or value is set for non-translatable field in language |
||
| 1258 | * other than main. |
||
| 1259 | * |
||
| 1260 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version |
||
| 1261 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1262 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a property on the struct is invalid. |
||
| 1263 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 1264 | */ |
||
| 1265 | public function updateContent(APIVersionInfo $versionInfo, APIContentUpdateStruct $contentUpdateStruct) |
||
| 1452 | |||
| 1453 | /** |
||
| 1454 | * Returns only updated language codes. |
||
| 1455 | * |
||
| 1456 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1457 | * |
||
| 1458 | * @return array |
||
| 1459 | */ |
||
| 1460 | private function getUpdatedLanguageCodes(APIContentUpdateStruct $contentUpdateStruct) |
||
| 1476 | |||
| 1477 | /** |
||
| 1478 | * Returns all language codes used in given $fields. |
||
| 1479 | * |
||
| 1480 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value exists in initial language |
||
| 1481 | * |
||
| 1482 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1483 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 1484 | * |
||
| 1485 | * @return array |
||
| 1486 | */ |
||
| 1487 | protected function getLanguageCodesForUpdate(APIContentUpdateStruct $contentUpdateStruct, APIContent $content) |
||
| 1499 | |||
| 1500 | /** |
||
| 1501 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
| 1502 | * |
||
| 1503 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
| 1504 | * or value is set for non-translatable field in language |
||
| 1505 | * other than main |
||
| 1506 | * |
||
| 1507 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1508 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 1509 | * @param string $mainLanguageCode |
||
| 1510 | * |
||
| 1511 | * @return array |
||
| 1512 | */ |
||
| 1513 | protected function mapFieldsForUpdate( |
||
| 1551 | |||
| 1552 | /** |
||
| 1553 | * Publishes a content version. |
||
| 1554 | * |
||
| 1555 | * Publishes a content version and deletes archive versions if they overflow max archive versions. |
||
| 1556 | * Max archive versions are currently a configuration, but might be moved to be a param of ContentType in the future. |
||
| 1557 | * |
||
| 1558 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1559 | * @param string[] $translations |
||
| 1560 | * |
||
| 1561 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1562 | * |
||
| 1563 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1564 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 1565 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 1566 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 1567 | */ |
||
| 1568 | public function publishVersion(APIVersionInfo $versionInfo, array $translations = Language::ALL) |
||
| 1611 | |||
| 1612 | /** |
||
| 1613 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1614 | * @param array $translations |
||
| 1615 | * |
||
| 1616 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 1617 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
||
| 1618 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException |
||
| 1619 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 1620 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 1621 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 1622 | */ |
||
| 1623 | protected function copyTranslationsFromPublishedVersion(APIVersionInfo $versionInfo, array $translations = []): void |
||
| 1624 | { |
||
| 1625 | $contendId = $versionInfo->contentInfo->id; |
||
| 1626 | |||
| 1627 | $currentContent = $this->internalLoadContent($contendId); |
||
| 1628 | $currentVersionInfo = $currentContent->versionInfo; |
||
| 1629 | |||
| 1630 | // Copying occurs only if: |
||
| 1631 | // - There is published Version |
||
| 1632 | // - Published version is older than the currently published one unless specific translations are provided. |
||
| 1633 | if (!$currentVersionInfo->isPublished() || |
||
| 1634 | ($versionInfo->versionNo >= $currentVersionInfo->versionNo && empty($translations))) { |
||
| 1635 | return; |
||
| 1636 | } |
||
| 1717 | |||
| 1718 | /** |
||
| 1719 | * Publishes a content version. |
||
| 1720 | * |
||
| 1721 | * Publishes a content version and deletes archive versions if they overflow max archive versions. |
||
| 1722 | * Max archive versions are currently a configuration, but might be moved to be a param of ContentType in the future. |
||
| 1723 | * |
||
| 1724 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1725 | * |
||
| 1726 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1727 | * @param int|null $publicationDate If null existing date is kept if there is one, otherwise current time is used. |
||
| 1728 | * |
||
| 1729 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1730 | */ |
||
| 1731 | protected function internalPublishVersion(APIVersionInfo $versionInfo, $publicationDate = null) |
||
| 1783 | |||
| 1784 | /** |
||
| 1785 | * @return int |
||
| 1786 | */ |
||
| 1787 | protected function getUnixTimestamp() |
||
| 1791 | |||
| 1792 | /** |
||
| 1793 | * Removes the given version. |
||
| 1794 | * |
||
| 1795 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in |
||
| 1796 | * published state or is a last version of Content in non draft state |
||
| 1797 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version |
||
| 1798 | * |
||
| 1799 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1800 | */ |
||
| 1801 | public function deleteVersion(APIVersionInfo $versionInfo) |
||
| 1843 | |||
| 1844 | /** |
||
| 1845 | * Loads all versions for the given content. |
||
| 1846 | * |
||
| 1847 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions |
||
| 1848 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the given status is invalid |
||
| 1849 | * |
||
| 1850 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1851 | * @param int|null $status |
||
| 1852 | * |
||
| 1853 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date |
||
| 1854 | */ |
||
| 1855 | public function loadVersions(ContentInfo $contentInfo, ?int $status = null) |
||
| 1884 | |||
| 1885 | /** |
||
| 1886 | * Copies the content to a new location. If no version is given, |
||
| 1887 | * all versions are copied, otherwise only the given version. |
||
| 1888 | * |
||
| 1889 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location |
||
| 1890 | * |
||
| 1891 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1892 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to |
||
| 1893 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1894 | * |
||
| 1895 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1896 | */ |
||
| 1897 | public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, APIVersionInfo $versionInfo = null) |
||
| 1952 | |||
| 1953 | /** |
||
| 1954 | * Loads all outgoing relations for the given version. |
||
| 1955 | * |
||
| 1956 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 1957 | * |
||
| 1958 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1959 | * |
||
| 1960 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 1961 | */ |
||
| 1962 | public function loadRelations(APIVersionInfo $versionInfo) |
||
| 1997 | |||
| 1998 | /** |
||
| 1999 | * {@inheritdoc} |
||
| 2000 | */ |
||
| 2001 | public function countReverseRelations(ContentInfo $contentInfo): int |
||
| 2011 | |||
| 2012 | /** |
||
| 2013 | * Loads all incoming relations for a content object. |
||
| 2014 | * |
||
| 2015 | * The relations come only from published versions of the source content objects |
||
| 2016 | * |
||
| 2017 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 2018 | * |
||
| 2019 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 2020 | * |
||
| 2021 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 2022 | */ |
||
| 2023 | public function loadReverseRelations(ContentInfo $contentInfo) |
||
| 2049 | |||
| 2050 | /** |
||
| 2051 | * {@inheritdoc} |
||
| 2052 | */ |
||
| 2053 | public function loadReverseRelationList(ContentInfo $contentInfo, int $offset = 0, int $limit = -1): RelationList |
||
| 2090 | |||
| 2091 | /** |
||
| 2092 | * Adds a relation of type common. |
||
| 2093 | * |
||
| 2094 | * The source of the relation is the content and version |
||
| 2095 | * referenced by $versionInfo. |
||
| 2096 | * |
||
| 2097 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version |
||
| 2098 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 2099 | * |
||
| 2100 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 2101 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation |
||
| 2102 | * |
||
| 2103 | * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation |
||
| 2104 | */ |
||
| 2105 | public function addRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 2146 | |||
| 2147 | /** |
||
| 2148 | * Removes a relation of type COMMON from a draft. |
||
| 2149 | * |
||
| 2150 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version |
||
| 2151 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 2152 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination |
||
| 2153 | * |
||
| 2154 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 2155 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent |
||
| 2156 | */ |
||
| 2157 | public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 2207 | |||
| 2208 | /** |
||
| 2209 | * {@inheritdoc} |
||
| 2210 | */ |
||
| 2211 | public function removeTranslation(ContentInfo $contentInfo, $languageCode) |
||
| 2219 | |||
| 2220 | /** |
||
| 2221 | * Delete Content item Translation from all Versions (including archived ones) of a Content Object. |
||
| 2222 | * |
||
| 2223 | * NOTE: this operation is risky and permanent, so user interface should provide a warning before performing it. |
||
| 2224 | * |
||
| 2225 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation |
||
| 2226 | * is the Main Translation of a Content Item. |
||
| 2227 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed |
||
| 2228 | * to delete the content (in one of the locations of the given Content Item). |
||
| 2229 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument |
||
| 2230 | * is invalid for the given content. |
||
| 2231 | * |
||
| 2232 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 2233 | * @param string $languageCode |
||
| 2234 | * |
||
| 2235 | * @since 6.13 |
||
| 2236 | */ |
||
| 2237 | public function deleteTranslation(ContentInfo $contentInfo, $languageCode) |
||
| 2314 | |||
| 2315 | /** |
||
| 2316 | * Delete specified Translation from a Content Draft. |
||
| 2317 | * |
||
| 2318 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation |
||
| 2319 | * is the only one the Content Draft has or it is the main Translation of a Content Object. |
||
| 2320 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed |
||
| 2321 | * to edit the Content (in one of the locations of the given Content Object). |
||
| 2322 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument |
||
| 2323 | * is invalid for the given Draft. |
||
| 2324 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if specified Version was not found |
||
| 2325 | * |
||
| 2326 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo Content Version Draft |
||
| 2327 | * @param string $languageCode Language code of the Translation to be removed |
||
| 2328 | * |
||
| 2329 | * @return \eZ\Publish\API\Repository\Values\Content\Content Content Draft w/o the specified Translation |
||
| 2330 | * |
||
| 2331 | * @since 6.12 |
||
| 2332 | */ |
||
| 2333 | public function deleteTranslationFromDraft(APIVersionInfo $versionInfo, $languageCode) |
||
| 2399 | |||
| 2400 | /** |
||
| 2401 | * Hides Content by making all the Locations appear hidden. |
||
| 2402 | * It does not persist hidden state on Location object itself. |
||
| 2403 | * |
||
| 2404 | * Content hidden by this API can be revealed by revealContent API. |
||
| 2405 | * |
||
| 2406 | * @see revealContent |
||
| 2407 | * |
||
| 2408 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 2409 | */ |
||
| 2410 | public function hideContent(ContentInfo $contentInfo): void |
||
| 2435 | |||
| 2436 | /** |
||
| 2437 | * Reveals Content hidden by hideContent API. |
||
| 2438 | * Locations which were hidden before hiding Content will remain hidden. |
||
| 2439 | * |
||
| 2440 | * @see hideContent |
||
| 2441 | * |
||
| 2442 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 2443 | */ |
||
| 2444 | public function revealContent(ContentInfo $contentInfo): void |
||
| 2469 | |||
| 2470 | /** |
||
| 2471 | * Instantiates a new content create struct object. |
||
| 2472 | * |
||
| 2473 | * alwaysAvailable is set to the ContentType's defaultAlwaysAvailable |
||
| 2474 | * |
||
| 2475 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 2476 | * @param string $mainLanguageCode |
||
| 2477 | * |
||
| 2478 | * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct |
||
| 2479 | */ |
||
| 2480 | public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode) |
||
| 2490 | |||
| 2491 | /** |
||
| 2492 | * Instantiates a new content meta data update struct. |
||
| 2493 | * |
||
| 2494 | * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct |
||
| 2495 | */ |
||
| 2496 | public function newContentMetadataUpdateStruct() |
||
| 2500 | |||
| 2501 | /** |
||
| 2502 | * Instantiates a new content update struct. |
||
| 2503 | * |
||
| 2504 | * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct |
||
| 2505 | */ |
||
| 2506 | public function newContentUpdateStruct() |
||
| 2510 | |||
| 2511 | /** |
||
| 2512 | * @param \eZ\Publish\API\Repository\Values\User\User|null $user |
||
| 2513 | * |
||
| 2514 | * @return \eZ\Publish\API\Repository\Values\User\UserReference |
||
| 2515 | */ |
||
| 2516 | private function resolveUser(?User $user): UserReference |
||
| 2524 | } |
||
| 2525 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..