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\Repository\Helper\FieldTypeRegistry */  | 
            ||
| 81 | protected $fieldTypeRegistry;  | 
            ||
| 82 | |||
| 83 | /**  | 
            ||
| 84 | * Setups service with reference to repository object that created it & corresponding handler.  | 
            ||
| 85 | *  | 
            ||
| 86 | * @param \eZ\Publish\API\Repository\Repository $repository  | 
            ||
| 87 | * @param \eZ\Publish\SPI\Persistence\Handler $handler  | 
            ||
| 88 | * @param \eZ\Publish\Core\Repository\Helper\DomainMapper $domainMapper  | 
            ||
| 89 | * @param \eZ\Publish\Core\Repository\Helper\RelationProcessor $relationProcessor  | 
            ||
| 90 | * @param \eZ\Publish\Core\Repository\Helper\NameSchemaService $nameSchemaService  | 
            ||
| 91 | * @param \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry $fieldTypeRegistry,  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 92 | * @param array $settings  | 
            ||
| 93 | */  | 
            ||
| 94 | public function __construct(  | 
            ||
| 95 | RepositoryInterface $repository,  | 
            ||
| 96 | Handler $handler,  | 
            ||
| 97 | Helper\DomainMapper $domainMapper,  | 
            ||
| 98 | Helper\RelationProcessor $relationProcessor,  | 
            ||
| 99 | Helper\NameSchemaService $nameSchemaService,  | 
            ||
| 100 | Helper\FieldTypeRegistry $fieldTypeRegistry,  | 
            ||
| 101 | array $settings = []  | 
            ||
| 102 |     ) { | 
            ||
| 103 | $this->repository = $repository;  | 
            ||
| 104 | $this->persistenceHandler = $handler;  | 
            ||
| 105 | $this->domainMapper = $domainMapper;  | 
            ||
| 106 | $this->relationProcessor = $relationProcessor;  | 
            ||
| 107 | $this->nameSchemaService = $nameSchemaService;  | 
            ||
| 108 | $this->fieldTypeRegistry = $fieldTypeRegistry;  | 
            ||
| 109 | // Union makes sure default settings are ignored if provided in argument  | 
            ||
| 110 | $this->settings = $settings + [  | 
            ||
| 111 | // Version archive limit (0-50), only enforced on publish, not on un-publish.  | 
            ||
| 112 | 'default_version_archive_limit' => 5,  | 
            ||
| 113 | ];  | 
            ||
| 114 | }  | 
            ||
| 115 | |||
| 116 | /**  | 
            ||
| 117 | * Loads a content info object.  | 
            ||
| 118 | *  | 
            ||
| 119 | * To load fields use loadContent  | 
            ||
| 120 | *  | 
            ||
| 121 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content  | 
            ||
| 122 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist  | 
            ||
| 123 | *  | 
            ||
| 124 | * @param int $contentId  | 
            ||
| 125 | *  | 
            ||
| 126 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo  | 
            ||
| 127 | */  | 
            ||
| 128 | public function loadContentInfo($contentId)  | 
            ||
| 129 |     { | 
            ||
| 130 | $contentInfo = $this->internalLoadContentInfo($contentId);  | 
            ||
| 131 |         if (!$this->repository->canUser('content', 'read', $contentInfo)) { | 
            ||
| 132 |             throw new UnauthorizedException('content', 'read', ['contentId' => $contentId]); | 
            ||
| 133 | }  | 
            ||
| 134 | |||
| 135 | return $contentInfo;  | 
            ||
| 136 | }  | 
            ||
| 137 | |||
| 138 | /**  | 
            ||
| 139 |      * {@inheritdoc} | 
            ||
| 140 | */  | 
            ||
| 141 | public function loadContentInfoList(array $contentIds): iterable  | 
            ||
| 142 |     { | 
            ||
| 143 | $contentInfoList = [];  | 
            ||
| 144 | $spiInfoList = $this->persistenceHandler->contentHandler()->loadContentInfoList($contentIds);  | 
            ||
| 145 |         foreach ($spiInfoList as $id => $spiInfo) { | 
            ||
| 146 | $contentInfo = $this->domainMapper->buildContentInfoDomainObject($spiInfo);  | 
            ||
| 147 |             if ($this->repository->canUser('content', 'read', $contentInfo)) { | 
            ||
| 148 | $contentInfoList[$id] = $contentInfo;  | 
            ||
| 149 | }  | 
            ||
| 150 | }  | 
            ||
| 151 | |||
| 152 | return $contentInfoList;  | 
            ||
| 153 | }  | 
            ||
| 154 | |||
| 155 | /**  | 
            ||
| 156 | * Loads a content info object.  | 
            ||
| 157 | *  | 
            ||
| 158 | * To load fields use loadContent  | 
            ||
| 159 | *  | 
            ||
| 160 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist  | 
            ||
| 161 | *  | 
            ||
| 162 | * @param mixed $id  | 
            ||
| 163 | * @param bool $isRemoteId  | 
            ||
| 164 | *  | 
            ||
| 165 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo  | 
            ||
| 166 | */  | 
            ||
| 167 | public function internalLoadContentInfo($id, $isRemoteId = false)  | 
            ||
| 168 |     { | 
            ||
| 169 |         try { | 
            ||
| 170 | $method = $isRemoteId ? 'loadContentInfoByRemoteId' : 'loadContentInfo';  | 
            ||
| 171 | |||
| 172 | return $this->domainMapper->buildContentInfoDomainObject(  | 
            ||
| 173 | $this->persistenceHandler->contentHandler()->$method($id)  | 
            ||
| 174 | );  | 
            ||
| 175 |         } catch (APINotFoundException $e) { | 
            ||
| 176 | throw new NotFoundException(  | 
            ||
| 177 | 'Content',  | 
            ||
| 178 | $id,  | 
            ||
| 179 | $e  | 
            ||
| 180 | );  | 
            ||
| 181 | }  | 
            ||
| 182 | }  | 
            ||
| 183 | |||
| 184 | /**  | 
            ||
| 185 | * Loads a content info object for the given remoteId.  | 
            ||
| 186 | *  | 
            ||
| 187 | * To load fields use loadContent  | 
            ||
| 188 | *  | 
            ||
| 189 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content  | 
            ||
| 190 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given remote id does not exist  | 
            ||
| 191 | *  | 
            ||
| 192 | * @param string $remoteId  | 
            ||
| 193 | *  | 
            ||
| 194 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo  | 
            ||
| 195 | */  | 
            ||
| 196 | public function loadContentInfoByRemoteId($remoteId)  | 
            ||
| 197 |     { | 
            ||
| 198 | $contentInfo = $this->internalLoadContentInfo($remoteId, true);  | 
            ||
| 199 | |||
| 200 |         if (!$this->repository->canUser('content', 'read', $contentInfo)) { | 
            ||
| 201 |             throw new UnauthorizedException('content', 'read', ['remoteId' => $remoteId]); | 
            ||
| 202 | }  | 
            ||
| 203 | |||
| 204 | return $contentInfo;  | 
            ||
| 205 | }  | 
            ||
| 206 | |||
| 207 | /**  | 
            ||
| 208 | * Loads a version info of the given content object.  | 
            ||
| 209 | *  | 
            ||
| 210 | * If no version number is given, the method returns the current version  | 
            ||
| 211 | *  | 
            ||
| 212 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist  | 
            ||
| 213 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version  | 
            ||
| 214 | *  | 
            ||
| 215 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo  | 
            ||
| 216 | * @param int $versionNo the version number. If not given the current version is returned.  | 
            ||
| 217 | *  | 
            ||
| 218 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo  | 
            ||
| 219 | */  | 
            ||
| 220 | public function loadVersionInfo(ContentInfo $contentInfo, $versionNo = null)  | 
            ||
| 221 |     { | 
            ||
| 222 | return $this->loadVersionInfoById($contentInfo->id, $versionNo);  | 
            ||
| 223 | }  | 
            ||
| 224 | |||
| 225 | /**  | 
            ||
| 226 | * Loads a version info of the given content object id.  | 
            ||
| 227 | *  | 
            ||
| 228 | * If no version number is given, the method returns the current version  | 
            ||
| 229 | *  | 
            ||
| 230 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist  | 
            ||
| 231 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version  | 
            ||
| 232 | *  | 
            ||
| 233 | * @param mixed $contentId  | 
            ||
| 234 | * @param int $versionNo the version number. If not given the current version is returned.  | 
            ||
| 235 | *  | 
            ||
| 236 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo  | 
            ||
| 237 | */  | 
            ||
| 238 | public function loadVersionInfoById($contentId, $versionNo = null)  | 
            ||
| 239 |     { | 
            ||
| 240 |         try { | 
            ||
| 241 | $spiVersionInfo = $this->persistenceHandler->contentHandler()->loadVersionInfo(  | 
            ||
| 242 | $contentId,  | 
            ||
| 243 | $versionNo  | 
            ||
| 244 | );  | 
            ||
| 245 |         } catch (APINotFoundException $e) { | 
            ||
| 246 | throw new NotFoundException(  | 
            ||
| 247 | 'VersionInfo',  | 
            ||
| 248 | [  | 
            ||
| 249 | 'contentId' => $contentId,  | 
            ||
| 250 | 'versionNo' => $versionNo,  | 
            ||
| 251 | ],  | 
            ||
| 252 | $e  | 
            ||
| 253 | );  | 
            ||
| 254 | }  | 
            ||
| 255 | |||
| 256 | $versionInfo = $this->domainMapper->buildVersionInfoDomainObject($spiVersionInfo);  | 
            ||
| 257 | |||
| 258 |         if ($versionInfo->isPublished()) { | 
            ||
| 259 | $function = 'read';  | 
            ||
| 260 |         } else { | 
            ||
| 261 | $function = 'versionread';  | 
            ||
| 262 | }  | 
            ||
| 263 | |||
| 264 |         if (!$this->repository->canUser('content', $function, $versionInfo)) { | 
            ||
| 265 |             throw new UnauthorizedException('content', $function, ['contentId' => $contentId]); | 
            ||
| 266 | }  | 
            ||
| 267 | |||
| 268 | return $versionInfo;  | 
            ||
| 269 | }  | 
            ||
| 270 | |||
| 271 | /**  | 
            ||
| 272 |      * {@inheritdoc} | 
            ||
| 273 | */  | 
            ||
| 274 | public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true)  | 
            ||
| 275 |     { | 
            ||
| 276 | // Change $useAlwaysAvailable to false to avoid contentInfo lookup if we know alwaysAvailable is disabled  | 
            ||
| 277 |         if ($useAlwaysAvailable && !$contentInfo->alwaysAvailable) { | 
            ||
| 278 | $useAlwaysAvailable = false;  | 
            ||
| 279 | }  | 
            ||
| 280 | |||
| 281 | return $this->loadContent(  | 
            ||
| 282 | $contentInfo->id,  | 
            ||
| 283 | $languages,  | 
            ||
| 284 | $versionNo,// On purpose pass as-is and not use $contentInfo, to make sure to return actual current version on null  | 
            ||
| 285 | $useAlwaysAvailable  | 
            ||
| 286 | );  | 
            ||
| 287 | }  | 
            ||
| 288 | |||
| 289 | /**  | 
            ||
| 290 |      * {@inheritdoc} | 
            ||
| 291 | */  | 
            ||
| 292 | public function loadContentByVersionInfo(APIVersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true)  | 
            ||
| 306 | |||
| 307 | /**  | 
            ||
| 308 |      * {@inheritdoc} | 
            ||
| 309 | */  | 
            ||
| 310 | public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true)  | 
            ||
| 326 | |||
| 327 | /**  | 
            ||
| 328 | * Loads content in a version of the given content object.  | 
            ||
| 329 | *  | 
            ||
| 330 | * If no version number is given, the method returns the current version  | 
            ||
| 331 | *  | 
            ||
| 332 | * @internal  | 
            ||
| 333 | *  | 
            ||
| 334 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content or version with the given id and languages does not exist  | 
            ||
| 335 | *  | 
            ||
| 336 | * @param mixed $id  | 
            ||
| 337 | * @param array|null $languages A language priority, filters returned fields and is used as prioritized language code on  | 
            ||
| 338 | * returned value object. If not given all languages are returned.  | 
            ||
| 339 | * @param int|null $versionNo the version number. If not given the current version is returned  | 
            ||
| 340 | * @param bool $isRemoteId  | 
            ||
| 341 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true  | 
            ||
| 342 | *  | 
            ||
| 343 | * @return \eZ\Publish\API\Repository\Values\Content\Content  | 
            ||
| 344 | */  | 
            ||
| 345 | public function internalLoadContent($id, array $languages = null, $versionNo = null, $isRemoteId = false, $useAlwaysAvailable = true)  | 
            ||
| 346 |     { | 
            ||
| 347 |         try { | 
            ||
| 348 | // Get Content ID if lookup by remote ID  | 
            ||
| 349 |             if ($isRemoteId) { | 
            ||
| 350 | $spiContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfoByRemoteId($id);  | 
            ||
| 351 | $id = $spiContentInfo->id;  | 
            ||
| 352 | // Set $isRemoteId to false as the next loads will be for content id now that we have it (for exception use now)  | 
            ||
| 353 | $isRemoteId = false;  | 
            ||
| 354 | }  | 
            ||
| 355 | |||
| 356 | $loadLanguages = $languages;  | 
            ||
| 357 | $alwaysAvailableLanguageCode = null;  | 
            ||
| 358 | // Set main language on $languages filter if not empty (all) and $useAlwaysAvailable being true  | 
            ||
| 359 | // @todo Move use always available logic to SPI load methods, like done in location handler in 7.x  | 
            ||
| 360 |             if (!empty($loadLanguages) && $useAlwaysAvailable) { | 
            ||
| 361 |                 if (!isset($spiContentInfo)) { | 
            ||
| 362 | $spiContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo($id);  | 
            ||
| 363 | }  | 
            ||
| 364 | |||
| 365 |                 if ($spiContentInfo->alwaysAvailable) { | 
            ||
| 366 | $loadLanguages[] = $alwaysAvailableLanguageCode = $spiContentInfo->mainLanguageCode;  | 
            ||
| 367 | $loadLanguages = array_unique($loadLanguages);  | 
            ||
| 368 | }  | 
            ||
| 369 | }  | 
            ||
| 370 | |||
| 371 | $spiContent = $this->persistenceHandler->contentHandler()->load(  | 
            ||
| 372 | $id,  | 
            ||
| 373 | $versionNo,  | 
            ||
| 374 | $loadLanguages  | 
            ||
| 375 | );  | 
            ||
| 376 |         } catch (APINotFoundException $e) { | 
            ||
| 377 | throw new NotFoundException(  | 
            ||
| 378 | 'Content',  | 
            ||
| 379 | [  | 
            ||
| 380 | $isRemoteId ? 'remoteId' : 'id' => $id,  | 
            ||
| 381 | 'languages' => $languages,  | 
            ||
| 382 | 'versionNo' => $versionNo,  | 
            ||
| 383 | ],  | 
            ||
| 384 | $e  | 
            ||
| 385 | );  | 
            ||
| 386 | }  | 
            ||
| 387 | |||
| 388 |         if ($languages === null) { | 
            ||
| 389 | $languages = [];  | 
            ||
| 390 | }  | 
            ||
| 391 | |||
| 392 | return $this->domainMapper->buildContentDomainObject(  | 
            ||
| 393 | $spiContent,  | 
            ||
| 394 | $this->repository->getContentTypeService()->loadContentType(  | 
            ||
| 395 | $spiContent->versionInfo->contentInfo->contentTypeId,  | 
            ||
| 396 | $languages  | 
            ||
| 397 | ),  | 
            ||
| 398 | $languages,  | 
            ||
| 399 | $alwaysAvailableLanguageCode  | 
            ||
| 400 | );  | 
            ||
| 401 | }  | 
            ||
| 402 | |||
| 403 | /**  | 
            ||
| 404 | * Loads content in a version for the content object reference by the given remote id.  | 
            ||
| 405 | *  | 
            ||
| 406 | * If no version is given, the method returns the current version  | 
            ||
| 407 | *  | 
            ||
| 408 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given remote id does not exist  | 
            ||
| 409 | * @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  | 
            ||
| 410 | *  | 
            ||
| 411 | * @param string $remoteId  | 
            ||
| 412 | * @param array $languages A language filter for fields. If not given all languages are returned  | 
            ||
| 413 | * @param int $versionNo the version number. If not given the current version is returned  | 
            ||
| 414 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true  | 
            ||
| 415 | *  | 
            ||
| 416 | * @return \eZ\Publish\API\Repository\Values\Content\Content  | 
            ||
| 417 | */  | 
            ||
| 418 | public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true)  | 
            ||
| 419 |     { | 
            ||
| 420 | $content = $this->internalLoadContent($remoteId, $languages, $versionNo, true, $useAlwaysAvailable);  | 
            ||
| 421 | |||
| 422 |         if (!$this->repository->canUser('content', 'read', $content)) { | 
            ||
| 423 |             throw new UnauthorizedException('content', 'read', ['remoteId' => $remoteId]); | 
            ||
| 424 | }  | 
            ||
| 425 | |||
| 426 | if (  | 
            ||
| 427 | !$content->getVersionInfo()->isPublished()  | 
            ||
| 428 |             && !$this->repository->canUser('content', 'versionread', $content) | 
            ||
| 429 |         ) { | 
            ||
| 430 |             throw new UnauthorizedException('content', 'versionread', ['remoteId' => $remoteId, 'versionNo' => $versionNo]); | 
            ||
| 431 | }  | 
            ||
| 432 | |||
| 433 | return $content;  | 
            ||
| 434 | }  | 
            ||
| 435 | |||
| 436 | /**  | 
            ||
| 437 | * Bulk-load Content items by the list of ContentInfo Value Objects.  | 
            ||
| 438 | *  | 
            ||
| 439 | * Note: it does not throw exceptions on load, just ignores erroneous Content item.  | 
            ||
| 440 | * Moreover, since the method works on pre-loaded ContentInfo list, it is assumed that user is  | 
            ||
| 441 | * allowed to access every Content on the list.  | 
            ||
| 442 | *  | 
            ||
| 443 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo[] $contentInfoList  | 
            ||
| 444 | * @param string[] $languages A language priority, filters returned fields and is used as prioritized language code on  | 
            ||
| 445 | * returned value object. If not given all languages are returned.  | 
            ||
| 446 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true,  | 
            ||
| 447 | * unless all languages have been asked for.  | 
            ||
| 448 | *  | 
            ||
| 449 | * @return \eZ\Publish\API\Repository\Values\Content\Content[] list of Content items with Content Ids as keys  | 
            ||
| 450 | */  | 
            ||
| 451 | public function loadContentListByContentInfo(  | 
            ||
| 452 | array $contentInfoList,  | 
            ||
| 453 | array $languages = [],  | 
            ||
| 454 | $useAlwaysAvailable = true  | 
            ||
| 455 |     ) { | 
            ||
| 456 | $loadAllLanguages = $languages === Language::ALL;  | 
            ||
| 457 | $contentIds = [];  | 
            ||
| 458 | $contentTypeIds = [];  | 
            ||
| 459 | $translations = $languages;  | 
            ||
| 460 |         foreach ($contentInfoList as $contentInfo) { | 
            ||
| 461 | $contentIds[] = $contentInfo->id;  | 
            ||
| 462 | $contentTypeIds[] = $contentInfo->contentTypeId;  | 
            ||
| 463 | // Unless we are told to load all languages, we add main language to translations so they are loaded too  | 
            ||
| 464 | // Might in some case load more languages then intended, but prioritised handling will pick right one  | 
            ||
| 465 |             if (!$loadAllLanguages && $useAlwaysAvailable && $contentInfo->alwaysAvailable) { | 
            ||
| 466 | $translations[] = $contentInfo->mainLanguageCode;  | 
            ||
| 467 | }  | 
            ||
| 468 | }  | 
            ||
| 469 | |||
| 470 | $contentList = [];  | 
            ||
| 471 | $translations = array_unique($translations);  | 
            ||
| 472 | $spiContentList = $this->persistenceHandler->contentHandler()->loadContentList(  | 
            ||
| 473 | $contentIds,  | 
            ||
| 474 | $translations  | 
            ||
| 475 | );  | 
            ||
| 476 | $contentTypeList = $this->repository->getContentTypeService()->loadContentTypeList(  | 
            ||
| 477 | array_unique($contentTypeIds),  | 
            ||
| 478 | $languages  | 
            ||
| 479 | );  | 
            ||
| 480 |         foreach ($spiContentList as $contentId => $spiContent) { | 
            ||
| 481 | $contentInfo = $spiContent->versionInfo->contentInfo;  | 
            ||
| 482 | $contentList[$contentId] = $this->domainMapper->buildContentDomainObject(  | 
            ||
| 483 | $spiContent,  | 
            ||
| 484 | $contentTypeList[$contentInfo->contentTypeId],  | 
            ||
| 485 | $languages,  | 
            ||
| 486 | $contentInfo->alwaysAvailable ? $contentInfo->mainLanguageCode : null  | 
            ||
| 487 | );  | 
            ||
| 488 | }  | 
            ||
| 489 | |||
| 490 | return $contentList;  | 
            ||
| 491 | }  | 
            ||
| 492 | |||
| 493 | /**  | 
            ||
| 494 | * Creates a new content draft assigned to the authenticated user.  | 
            ||
| 495 | *  | 
            ||
| 496 | * If a different userId is given in $contentCreateStruct it is assigned to the given user  | 
            ||
| 497 | * but this required special rights for the authenticated user  | 
            ||
| 498 | * (this is useful for content staging where the transfer process does not  | 
            ||
| 499 | * have to authenticate with the user which created the content object in the source server).  | 
            ||
| 500 | * The user has to publish the draft if it should be visible.  | 
            ||
| 501 | * In 4.x at least one location has to be provided in the location creation array.  | 
            ||
| 502 | *  | 
            ||
| 503 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location  | 
            ||
| 504 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the provided remoteId exists in the system, required properties on  | 
            ||
| 505 | * struct are missing or invalid, or if multiple locations are under the  | 
            ||
| 506 | * same parent.  | 
            ||
| 507 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid,  | 
            ||
| 508 | * or if a required field is missing / set to an empty value.  | 
            ||
| 509 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType,  | 
            ||
| 510 | * or value is set for non-translatable field in language  | 
            ||
| 511 | * other than main.  | 
            ||
| 512 | *  | 
            ||
| 513 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct  | 
            ||
| 514 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content  | 
            ||
| 515 | *  | 
            ||
| 516 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft  | 
            ||
| 517 | */  | 
            ||
| 518 | public function createContent(APIContentCreateStruct $contentCreateStruct, array $locationCreateStructs = [])  | 
            ||
| 519 |     { | 
            ||
| 520 |         if ($contentCreateStruct->mainLanguageCode === null) { | 
            ||
| 521 |             throw new InvalidArgumentException('$contentCreateStruct', "'mainLanguageCode' property must be set"); | 
            ||
| 522 | }  | 
            ||
| 523 | |||
| 524 |         if ($contentCreateStruct->contentType === null) { | 
            ||
| 525 |             throw new InvalidArgumentException('$contentCreateStruct', "'contentType' property must be set"); | 
            ||
| 526 | }  | 
            ||
| 527 | |||
| 528 | $contentCreateStruct = clone $contentCreateStruct;  | 
            ||
| 529 | |||
| 530 |         if ($contentCreateStruct->ownerId === null) { | 
            ||
| 531 | $contentCreateStruct->ownerId = $this->repository->getCurrentUserReference()->getUserId();  | 
            ||
| 532 | }  | 
            ||
| 533 | |||
| 534 |         if ($contentCreateStruct->alwaysAvailable === null) { | 
            ||
| 535 | $contentCreateStruct->alwaysAvailable = $contentCreateStruct->contentType->defaultAlwaysAvailable ?: false;  | 
            ||
| 536 | }  | 
            ||
| 537 | |||
| 538 | $contentCreateStruct->contentType = $this->repository->getContentTypeService()->loadContentType(  | 
            ||
| 539 | $contentCreateStruct->contentType->id  | 
            ||
| 540 | );  | 
            ||
| 541 | |||
| 542 |         if (empty($contentCreateStruct->sectionId)) { | 
            ||
| 543 |             if (isset($locationCreateStructs[0])) { | 
            ||
| 544 | $location = $this->repository->getLocationService()->loadLocation(  | 
            ||
| 545 | $locationCreateStructs[0]->parentLocationId  | 
            ||
| 546 | );  | 
            ||
| 547 | $contentCreateStruct->sectionId = $location->contentInfo->sectionId;  | 
            ||
| 548 |             } else { | 
            ||
| 549 | $contentCreateStruct->sectionId = 1;  | 
            ||
| 550 | }  | 
            ||
| 551 | }  | 
            ||
| 552 | |||
| 553 |         if (!$this->repository->canUser('content', 'create', $contentCreateStruct, $locationCreateStructs)) { | 
            ||
| 554 | throw new UnauthorizedException(  | 
            ||
| 555 | 'content',  | 
            ||
| 556 | 'create',  | 
            ||
| 557 | [  | 
            ||
| 558 | 'parentLocationId' => isset($locationCreateStructs[0]) ?  | 
            ||
| 559 | $locationCreateStructs[0]->parentLocationId :  | 
            ||
| 560 | null,  | 
            ||
| 561 | 'sectionId' => $contentCreateStruct->sectionId,  | 
            ||
| 562 | ]  | 
            ||
| 563 | );  | 
            ||
| 564 | }  | 
            ||
| 565 | |||
| 566 |         if (!empty($contentCreateStruct->remoteId)) { | 
            ||
| 567 |             try { | 
            ||
| 568 | $this->loadContentByRemoteId($contentCreateStruct->remoteId);  | 
            ||
| 569 | |||
| 570 | throw new InvalidArgumentException(  | 
            ||
| 571 | '$contentCreateStruct',  | 
            ||
| 572 |                     "Another content with remoteId '{$contentCreateStruct->remoteId}' exists" | 
            ||
| 573 | );  | 
            ||
| 574 |             } catch (APINotFoundException $e) { | 
            ||
| 575 | // Do nothing  | 
            ||
| 576 | }  | 
            ||
| 577 |         } else { | 
            ||
| 578 | $contentCreateStruct->remoteId = $this->domainMapper->getUniqueHash($contentCreateStruct);  | 
            ||
| 579 | }  | 
            ||
| 580 | |||
| 581 | $spiLocationCreateStructs = $this->buildSPILocationCreateStructs($locationCreateStructs);  | 
            ||
| 582 | |||
| 583 | $languageCodes = $this->getLanguageCodesForCreate($contentCreateStruct);  | 
            ||
| 584 | $fields = $this->mapFieldsForCreate($contentCreateStruct);  | 
            ||
| 585 | |||
| 586 | $fieldValues = [];  | 
            ||
| 587 | $spiFields = [];  | 
            ||
| 588 | $allFieldErrors = [];  | 
            ||
| 589 | $inputRelations = [];  | 
            ||
| 590 | $locationIdToContentIdMapping = [];  | 
            ||
| 591 | |||
| 592 |         foreach ($contentCreateStruct->contentType->getFieldDefinitions() as $fieldDefinition) { | 
            ||
| 593 | /** @var $fieldType \eZ\Publish\Core\FieldType\FieldType */  | 
            ||
| 594 | $fieldType = $this->fieldTypeRegistry->getFieldType(  | 
            ||
| 595 | $fieldDefinition->fieldTypeIdentifier  | 
            ||
| 596 | );  | 
            ||
| 597 | |||
| 598 |             foreach ($languageCodes as $languageCode) { | 
            ||
| 599 | $isEmptyValue = false;  | 
            ||
| 600 | $valueLanguageCode = $fieldDefinition->isTranslatable ? $languageCode : $contentCreateStruct->mainLanguageCode;  | 
            ||
| 601 | $isLanguageMain = $languageCode === $contentCreateStruct->mainLanguageCode;  | 
            ||
| 602 |                 if (isset($fields[$fieldDefinition->identifier][$valueLanguageCode])) { | 
            ||
| 603 | $fieldValue = $fields[$fieldDefinition->identifier][$valueLanguageCode]->value;  | 
            ||
| 604 |                 } else { | 
            ||
| 605 | $fieldValue = $fieldDefinition->defaultValue;  | 
            ||
| 606 | }  | 
            ||
| 607 | |||
| 608 | $fieldValue = $fieldType->acceptValue($fieldValue);  | 
            ||
| 609 | |||
| 610 |                 if ($fieldType->isEmptyValue($fieldValue)) { | 
            ||
| 611 | $isEmptyValue = true;  | 
            ||
| 612 |                     if ($fieldDefinition->isRequired) { | 
            ||
| 613 | $allFieldErrors[$fieldDefinition->id][$languageCode] = new ValidationError(  | 
            ||
| 614 | "Value for required field definition '%identifier%' with language '%languageCode%' is empty",  | 
            ||
| 615 | null,  | 
            ||
| 616 | ['%identifier%' => $fieldDefinition->identifier, '%languageCode%' => $languageCode],  | 
            ||
| 617 | 'empty'  | 
            ||
| 618 | );  | 
            ||
| 619 | }  | 
            ||
| 620 |                 } else { | 
            ||
| 621 | $fieldErrors = $fieldType->validate(  | 
            ||
| 622 | $fieldDefinition,  | 
            ||
| 623 | $fieldValue  | 
            ||
| 624 | );  | 
            ||
| 625 |                     if (!empty($fieldErrors)) { | 
            ||
| 626 | $allFieldErrors[$fieldDefinition->id][$languageCode] = $fieldErrors;  | 
            ||
| 627 | }  | 
            ||
| 628 | }  | 
            ||
| 629 | |||
| 630 |                 if (!empty($allFieldErrors)) { | 
            ||
| 631 | continue;  | 
            ||
| 632 | }  | 
            ||
| 633 | |||
| 634 | $this->relationProcessor->appendFieldRelations(  | 
            ||
| 635 | $inputRelations,  | 
            ||
| 636 | $locationIdToContentIdMapping,  | 
            ||
| 637 | $fieldType,  | 
            ||
| 638 | $fieldValue,  | 
            ||
| 639 | $fieldDefinition->id  | 
            ||
| 640 | );  | 
            ||
| 641 | $fieldValues[$fieldDefinition->identifier][$languageCode] = $fieldValue;  | 
            ||
| 642 | |||
| 643 | // Only non-empty value for: translatable field or in main language  | 
            ||
| 644 | if (  | 
            ||
| 645 | (!$isEmptyValue && $fieldDefinition->isTranslatable) ||  | 
            ||
| 646 | (!$isEmptyValue && $isLanguageMain)  | 
            ||
| 647 |                 ) { | 
            ||
| 648 | $spiFields[] = new SPIField(  | 
            ||
| 649 | [  | 
            ||
| 650 | 'id' => null,  | 
            ||
| 651 | 'fieldDefinitionId' => $fieldDefinition->id,  | 
            ||
| 652 | 'type' => $fieldDefinition->fieldTypeIdentifier,  | 
            ||
| 653 | 'value' => $fieldType->toPersistenceValue($fieldValue),  | 
            ||
| 654 | 'languageCode' => $languageCode,  | 
            ||
| 655 | 'versionNo' => null,  | 
            ||
| 656 | ]  | 
            ||
| 657 | );  | 
            ||
| 658 | }  | 
            ||
| 659 | }  | 
            ||
| 660 | }  | 
            ||
| 661 | |||
| 662 |         if (!empty($allFieldErrors)) { | 
            ||
| 663 | throw new ContentFieldValidationException($allFieldErrors);  | 
            ||
| 664 | }  | 
            ||
| 665 | |||
| 666 | $spiContentCreateStruct = new SPIContentCreateStruct(  | 
            ||
| 667 | [  | 
            ||
| 668 | 'name' => $this->nameSchemaService->resolve(  | 
            ||
| 669 | $contentCreateStruct->contentType->nameSchema,  | 
            ||
| 670 | $contentCreateStruct->contentType,  | 
            ||
| 671 | $fieldValues,  | 
            ||
| 672 | $languageCodes  | 
            ||
| 673 | ),  | 
            ||
| 674 | 'typeId' => $contentCreateStruct->contentType->id,  | 
            ||
| 675 | 'sectionId' => $contentCreateStruct->sectionId,  | 
            ||
| 676 | 'ownerId' => $contentCreateStruct->ownerId,  | 
            ||
| 677 | 'locations' => $spiLocationCreateStructs,  | 
            ||
| 678 | 'fields' => $spiFields,  | 
            ||
| 679 | 'alwaysAvailable' => $contentCreateStruct->alwaysAvailable,  | 
            ||
| 680 | 'remoteId' => $contentCreateStruct->remoteId,  | 
            ||
| 681 | 'modified' => isset($contentCreateStruct->modificationDate) ? $contentCreateStruct->modificationDate->getTimestamp() : time(),  | 
            ||
| 682 | 'initialLanguageId' => $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode(  | 
            ||
| 683 | $contentCreateStruct->mainLanguageCode  | 
            ||
| 684 | )->id,  | 
            ||
| 685 | ]  | 
            ||
| 686 | );  | 
            ||
| 687 | |||
| 688 | $defaultObjectStates = $this->getDefaultObjectStates();  | 
            ||
| 689 | |||
| 690 | $this->repository->beginTransaction();  | 
            ||
| 691 |         try { | 
            ||
| 692 | $spiContent = $this->persistenceHandler->contentHandler()->create($spiContentCreateStruct);  | 
            ||
| 693 | $this->relationProcessor->processFieldRelations(  | 
            ||
| 694 | $inputRelations,  | 
            ||
| 695 | $spiContent->versionInfo->contentInfo->id,  | 
            ||
| 696 | $spiContent->versionInfo->versionNo,  | 
            ||
| 697 | $contentCreateStruct->contentType  | 
            ||
| 698 | );  | 
            ||
| 699 | |||
| 700 | $objectStateHandler = $this->persistenceHandler->objectStateHandler();  | 
            ||
| 701 |             foreach ($defaultObjectStates as $objectStateGroupId => $objectState) { | 
            ||
| 702 | $objectStateHandler->setContentState(  | 
            ||
| 703 | $spiContent->versionInfo->contentInfo->id,  | 
            ||
| 704 | $objectStateGroupId,  | 
            ||
| 705 | $objectState->id  | 
            ||
| 706 | );  | 
            ||
| 707 | }  | 
            ||
| 708 | |||
| 709 | $this->repository->commit();  | 
            ||
| 710 |         } catch (Exception $e) { | 
            ||
| 711 | $this->repository->rollback();  | 
            ||
| 712 | throw $e;  | 
            ||
| 713 | }  | 
            ||
| 714 | |||
| 715 | return $this->domainMapper->buildContentDomainObject(  | 
            ||
| 716 | $spiContent,  | 
            ||
| 717 | $contentCreateStruct->contentType  | 
            ||
| 718 | );  | 
            ||
| 719 | }  | 
            ||
| 720 | |||
| 721 | /**  | 
            ||
| 722 | * Returns an array of default content states with content state group id as key.  | 
            ||
| 723 | *  | 
            ||
| 724 | * @return \eZ\Publish\SPI\Persistence\Content\ObjectState[]  | 
            ||
| 725 | */  | 
            ||
| 726 | protected function getDefaultObjectStates()  | 
            ||
| 727 |     { | 
            ||
| 728 | $defaultObjectStatesMap = [];  | 
            ||
| 729 | $objectStateHandler = $this->persistenceHandler->objectStateHandler();  | 
            ||
| 730 | |||
| 731 |         foreach ($objectStateHandler->loadAllGroups() as $objectStateGroup) { | 
            ||
| 732 |             foreach ($objectStateHandler->loadObjectStates($objectStateGroup->id) as $objectState) { | 
            ||
| 733 | // Only register the first object state which is the default one.  | 
            ||
| 734 | $defaultObjectStatesMap[$objectStateGroup->id] = $objectState;  | 
            ||
| 735 | break;  | 
            ||
| 736 | }  | 
            ||
| 737 | }  | 
            ||
| 738 | |||
| 739 | return $defaultObjectStatesMap;  | 
            ||
| 740 | }  | 
            ||
| 741 | |||
| 742 | /**  | 
            ||
| 743 | * Returns all language codes used in given $fields.  | 
            ||
| 744 | *  | 
            ||
| 745 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value is set in main language  | 
            ||
| 746 | *  | 
            ||
| 747 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct  | 
            ||
| 748 | *  | 
            ||
| 749 | * @return string[]  | 
            ||
| 750 | */  | 
            ||
| 751 | protected function getLanguageCodesForCreate(APIContentCreateStruct $contentCreateStruct)  | 
            ||
| 752 |     { | 
            ||
| 753 | $languageCodes = [];  | 
            ||
| 754 | |||
| 755 |         foreach ($contentCreateStruct->fields as $field) { | 
            ||
| 756 |             if ($field->languageCode === null || isset($languageCodes[$field->languageCode])) { | 
            ||
| 757 | continue;  | 
            ||
| 758 | }  | 
            ||
| 759 | |||
| 760 | $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode(  | 
            ||
| 761 | $field->languageCode  | 
            ||
| 762 | );  | 
            ||
| 763 | $languageCodes[$field->languageCode] = true;  | 
            ||
| 764 | }  | 
            ||
| 765 | |||
| 766 |         if (!isset($languageCodes[$contentCreateStruct->mainLanguageCode])) { | 
            ||
| 767 | $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode(  | 
            ||
| 768 | $contentCreateStruct->mainLanguageCode  | 
            ||
| 769 | );  | 
            ||
| 770 | $languageCodes[$contentCreateStruct->mainLanguageCode] = true;  | 
            ||
| 771 | }  | 
            ||
| 772 | |||
| 773 | return array_keys($languageCodes);  | 
            ||
| 774 | }  | 
            ||
| 775 | |||
| 776 | /**  | 
            ||
| 777 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode].  | 
            ||
| 778 | *  | 
            ||
| 779 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType  | 
            ||
| 780 | * or value is set for non-translatable field in language  | 
            ||
| 781 | * other than main  | 
            ||
| 782 | *  | 
            ||
| 783 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct  | 
            ||
| 784 | *  | 
            ||
| 785 | * @return array  | 
            ||
| 786 | */  | 
            ||
| 787 | protected function mapFieldsForCreate(APIContentCreateStruct $contentCreateStruct)  | 
            ||
| 788 |     { | 
            ||
| 789 | $fields = [];  | 
            ||
| 790 | |||
| 791 |         foreach ($contentCreateStruct->fields as $field) { | 
            ||
| 792 | $fieldDefinition = $contentCreateStruct->contentType->getFieldDefinition($field->fieldDefIdentifier);  | 
            ||
| 793 | |||
| 794 |             if ($fieldDefinition === null) { | 
            ||
| 795 | throw new ContentValidationException(  | 
            ||
| 796 | "Field definition '%identifier%' does not exist in given ContentType",  | 
            ||
| 797 | ['%identifier%' => $field->fieldDefIdentifier]  | 
            ||
| 798 | );  | 
            ||
| 799 | }  | 
            ||
| 800 | |||
| 801 |             if ($field->languageCode === null) { | 
            ||
| 802 | $field = $this->cloneField(  | 
            ||
| 803 | $field,  | 
            ||
| 804 | ['languageCode' => $contentCreateStruct->mainLanguageCode]  | 
            ||
| 805 | );  | 
            ||
| 806 | }  | 
            ||
| 807 | |||
| 808 |             if (!$fieldDefinition->isTranslatable && ($field->languageCode != $contentCreateStruct->mainLanguageCode)) { | 
            ||
| 809 | throw new ContentValidationException(  | 
            ||
| 810 | "A value is set for non translatable field definition '%identifier%' with language '%languageCode%'",  | 
            ||
| 811 | ['%identifier%' => $field->fieldDefIdentifier, '%languageCode%' => $field->languageCode]  | 
            ||
| 812 | );  | 
            ||
| 813 | }  | 
            ||
| 814 | |||
| 815 | $fields[$field->fieldDefIdentifier][$field->languageCode] = $field;  | 
            ||
| 816 | }  | 
            ||
| 817 | |||
| 818 | return $fields;  | 
            ||
| 819 | }  | 
            ||
| 820 | |||
| 821 | /**  | 
            ||
| 822 | * Clones $field with overriding specific properties from given $overrides array.  | 
            ||
| 823 | *  | 
            ||
| 824 | * @param Field $field  | 
            ||
| 825 | * @param array $overrides  | 
            ||
| 826 | *  | 
            ||
| 827 | * @return Field  | 
            ||
| 828 | */  | 
            ||
| 829 | private function cloneField(Field $field, array $overrides = [])  | 
            ||
| 830 |     { | 
            ||
| 831 | $fieldData = array_merge(  | 
            ||
| 832 | [  | 
            ||
| 833 | 'id' => $field->id,  | 
            ||
| 834 | 'value' => $field->value,  | 
            ||
| 835 | 'languageCode' => $field->languageCode,  | 
            ||
| 836 | 'fieldDefIdentifier' => $field->fieldDefIdentifier,  | 
            ||
| 837 | 'fieldTypeIdentifier' => $field->fieldTypeIdentifier,  | 
            ||
| 838 | ],  | 
            ||
| 839 | $overrides  | 
            ||
| 840 | );  | 
            ||
| 841 | |||
| 842 | return new Field($fieldData);  | 
            ||
| 843 | }  | 
            ||
| 844 | |||
| 845 | /**  | 
            ||
| 846 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException  | 
            ||
| 847 | *  | 
            ||
| 848 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs  | 
            ||
| 849 | *  | 
            ||
| 850 | * @return \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct[]  | 
            ||
| 851 | */  | 
            ||
| 852 | protected function buildSPILocationCreateStructs(array $locationCreateStructs)  | 
            ||
| 853 |     { | 
            ||
| 854 | $spiLocationCreateStructs = [];  | 
            ||
| 855 | $parentLocationIdSet = [];  | 
            ||
| 856 | $mainLocation = true;  | 
            ||
| 857 | |||
| 858 |         foreach ($locationCreateStructs as $locationCreateStruct) { | 
            ||
| 859 |             if (isset($parentLocationIdSet[$locationCreateStruct->parentLocationId])) { | 
            ||
| 860 | throw new InvalidArgumentException(  | 
            ||
| 861 | '$locationCreateStructs',  | 
            ||
| 862 |                     "Multiple LocationCreateStructs with the same parent Location '{$locationCreateStruct->parentLocationId}' are given" | 
            ||
| 863 | );  | 
            ||
| 864 | }  | 
            ||
| 865 | |||
| 866 |             if (!array_key_exists($locationCreateStruct->sortField, Location::SORT_FIELD_MAP)) { | 
            ||
| 867 | $locationCreateStruct->sortField = Location::SORT_FIELD_NAME;  | 
            ||
| 868 | }  | 
            ||
| 869 | |||
| 870 |             if (!array_key_exists($locationCreateStruct->sortOrder, Location::SORT_ORDER_MAP)) { | 
            ||
| 871 | $locationCreateStruct->sortOrder = Location::SORT_ORDER_ASC;  | 
            ||
| 872 | }  | 
            ||
| 873 | |||
| 874 | $parentLocationIdSet[$locationCreateStruct->parentLocationId] = true;  | 
            ||
| 875 | $parentLocation = $this->repository->getLocationService()->loadLocation(  | 
            ||
| 876 | $locationCreateStruct->parentLocationId  | 
            ||
| 877 | );  | 
            ||
| 878 | |||
| 879 | $spiLocationCreateStructs[] = $this->domainMapper->buildSPILocationCreateStruct(  | 
            ||
| 880 | $locationCreateStruct,  | 
            ||
| 881 | $parentLocation,  | 
            ||
| 882 | $mainLocation,  | 
            ||
| 883 | // For Content draft contentId and contentVersionNo are set in ContentHandler upon draft creation  | 
            ||
| 884 | null,  | 
            ||
| 885 | null  | 
            ||
| 886 | );  | 
            ||
| 887 | |||
| 888 | // First Location in the list will be created as main Location  | 
            ||
| 889 | $mainLocation = false;  | 
            ||
| 890 | }  | 
            ||
| 891 | |||
| 892 | return $spiLocationCreateStructs;  | 
            ||
| 893 | }  | 
            ||
| 894 | |||
| 895 | /**  | 
            ||
| 896 | * Updates the metadata.  | 
            ||
| 897 | *  | 
            ||
| 898 |      * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent | 
            ||
| 899 | *  | 
            ||
| 900 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data  | 
            ||
| 901 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists  | 
            ||
| 902 | *  | 
            ||
| 903 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo  | 
            ||
| 904 | * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct  | 
            ||
| 905 | *  | 
            ||
| 906 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes  | 
            ||
| 907 | */  | 
            ||
| 908 | public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct)  | 
            ||
| 909 |     { | 
            ||
| 910 | $propertyCount = 0;  | 
            ||
| 911 |         foreach ($contentMetadataUpdateStruct as $propertyName => $propertyValue) { | 
            ||
| 912 |             if (isset($contentMetadataUpdateStruct->$propertyName)) { | 
            ||
| 913 | ++$propertyCount;  | 
            ||
| 914 | }  | 
            ||
| 915 | }  | 
            ||
| 916 |         if ($propertyCount === 0) { | 
            ||
| 917 | throw new InvalidArgumentException(  | 
            ||
| 918 | '$contentMetadataUpdateStruct',  | 
            ||
| 919 | 'At least one property must be set'  | 
            ||
| 920 | );  | 
            ||
| 921 | }  | 
            ||
| 922 | |||
| 923 | $loadedContentInfo = $this->loadContentInfo($contentInfo->id);  | 
            ||
| 924 | |||
| 925 |         if (!$this->repository->canUser('content', 'edit', $loadedContentInfo)) { | 
            ||
| 926 |             throw new UnauthorizedException('content', 'edit', ['contentId' => $loadedContentInfo->id]); | 
            ||
| 927 | }  | 
            ||
| 928 | |||
| 929 |         if (isset($contentMetadataUpdateStruct->remoteId)) { | 
            ||
| 930 |             try { | 
            ||
| 931 | $existingContentInfo = $this->loadContentInfoByRemoteId($contentMetadataUpdateStruct->remoteId);  | 
            ||
| 932 | |||
| 933 |                 if ($existingContentInfo->id !== $loadedContentInfo->id) { | 
            ||
| 934 | throw new InvalidArgumentException(  | 
            ||
| 935 | '$contentMetadataUpdateStruct',  | 
            ||
| 936 |                         "Another content with remoteId '{$contentMetadataUpdateStruct->remoteId}' exists" | 
            ||
| 937 | );  | 
            ||
| 938 | }  | 
            ||
| 939 |             } catch (APINotFoundException $e) { | 
            ||
| 940 | // Do nothing  | 
            ||
| 941 | }  | 
            ||
| 942 | }  | 
            ||
| 943 | |||
| 944 | $this->repository->beginTransaction();  | 
            ||
| 945 |         try { | 
            ||
| 946 |             if ($propertyCount > 1 || !isset($contentMetadataUpdateStruct->mainLocationId)) { | 
            ||
| 947 | $this->persistenceHandler->contentHandler()->updateMetadata(  | 
            ||
| 948 | $loadedContentInfo->id,  | 
            ||
| 949 | new SPIMetadataUpdateStruct(  | 
            ||
| 950 | [  | 
            ||
| 951 | 'ownerId' => $contentMetadataUpdateStruct->ownerId,  | 
            ||
| 952 | 'publicationDate' => isset($contentMetadataUpdateStruct->publishedDate) ?  | 
            ||
| 953 | $contentMetadataUpdateStruct->publishedDate->getTimestamp() :  | 
            ||
| 954 | null,  | 
            ||
| 955 | 'modificationDate' => isset($contentMetadataUpdateStruct->modificationDate) ?  | 
            ||
| 956 | $contentMetadataUpdateStruct->modificationDate->getTimestamp() :  | 
            ||
| 957 | null,  | 
            ||
| 958 | 'mainLanguageId' => isset($contentMetadataUpdateStruct->mainLanguageCode) ?  | 
            ||
| 959 | $this->repository->getContentLanguageService()->loadLanguage(  | 
            ||
| 960 | $contentMetadataUpdateStruct->mainLanguageCode  | 
            ||
| 961 | )->id :  | 
            ||
| 962 | null,  | 
            ||
| 963 | 'alwaysAvailable' => $contentMetadataUpdateStruct->alwaysAvailable,  | 
            ||
| 964 | 'remoteId' => $contentMetadataUpdateStruct->remoteId,  | 
            ||
| 965 | 'name' => $contentMetadataUpdateStruct->name,  | 
            ||
| 966 | ]  | 
            ||
| 967 | )  | 
            ||
| 968 | );  | 
            ||
| 969 | }  | 
            ||
| 970 | |||
| 971 | // Change main location  | 
            ||
| 972 | if (isset($contentMetadataUpdateStruct->mainLocationId)  | 
            ||
| 973 |                 && $loadedContentInfo->mainLocationId !== $contentMetadataUpdateStruct->mainLocationId) { | 
            ||
| 974 | $this->persistenceHandler->locationHandler()->changeMainLocation(  | 
            ||
| 975 | $loadedContentInfo->id,  | 
            ||
| 976 | $contentMetadataUpdateStruct->mainLocationId  | 
            ||
| 977 | );  | 
            ||
| 978 | }  | 
            ||
| 979 | |||
| 980 | // Republish URL aliases to update always-available flag  | 
            ||
| 981 | if (isset($contentMetadataUpdateStruct->alwaysAvailable)  | 
            ||
| 982 |                 && $loadedContentInfo->alwaysAvailable !== $contentMetadataUpdateStruct->alwaysAvailable) { | 
            ||
| 983 | $content = $this->loadContent($loadedContentInfo->id);  | 
            ||
| 984 | $this->publishUrlAliasesForContent($content, false);  | 
            ||
| 985 | }  | 
            ||
| 986 | |||
| 987 | $this->repository->commit();  | 
            ||
| 988 |         } catch (Exception $e) { | 
            ||
| 989 | $this->repository->rollback();  | 
            ||
| 990 | throw $e;  | 
            ||
| 991 | }  | 
            ||
| 992 | |||
| 993 | return isset($content) ? $content : $this->loadContent($loadedContentInfo->id);  | 
            ||
| 994 | }  | 
            ||
| 995 | |||
| 996 | /**  | 
            ||
| 997 | * Publishes URL aliases for all locations of a given content.  | 
            ||
| 998 | *  | 
            ||
| 999 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content  | 
            ||
| 1000 | * @param bool $updatePathIdentificationString this parameter is legacy storage specific for updating  | 
            ||
| 1001 | * ezcontentobject_tree.path_identification_string, it is ignored by other storage engines  | 
            ||
| 1002 | */  | 
            ||
| 1003 | protected function publishUrlAliasesForContent(APIContent $content, $updatePathIdentificationString = true)  | 
            ||
| 1004 |     { | 
            ||
| 1005 | $urlAliasNames = $this->nameSchemaService->resolveUrlAliasSchema($content);  | 
            ||
| 1006 | $locations = $this->repository->getLocationService()->loadLocations(  | 
            ||
| 1007 | $content->getVersionInfo()->getContentInfo()  | 
            ||
| 1008 | );  | 
            ||
| 1009 | $urlAliasHandler = $this->persistenceHandler->urlAliasHandler();  | 
            ||
| 1010 |         foreach ($locations as $location) { | 
            ||
| 1011 |             foreach ($urlAliasNames as $languageCode => $name) { | 
            ||
| 1012 | $urlAliasHandler->publishUrlAliasForLocation(  | 
            ||
| 1013 | $location->id,  | 
            ||
| 1014 | $location->parentLocationId,  | 
            ||
| 1015 | $name,  | 
            ||
| 1016 | $languageCode,  | 
            ||
| 1017 | $content->contentInfo->alwaysAvailable,  | 
            ||
| 1018 | $updatePathIdentificationString ? $languageCode === $content->contentInfo->mainLanguageCode : false  | 
            ||
| 1019 | );  | 
            ||
| 1020 | }  | 
            ||
| 1021 | // archive URL aliases of Translations that got deleted  | 
            ||
| 1022 | $urlAliasHandler->archiveUrlAliasesForDeletedTranslations(  | 
            ||
| 1023 | $location->id,  | 
            ||
| 1024 | $location->parentLocationId,  | 
            ||
| 1025 | $content->versionInfo->languageCodes  | 
            ||
| 1026 | );  | 
            ||
| 1027 | }  | 
            ||
| 1028 | }  | 
            ||
| 1029 | |||
| 1030 | /**  | 
            ||
| 1031 | * Deletes a content object including all its versions and locations including their subtrees.  | 
            ||
| 1032 | *  | 
            ||
| 1033 | * @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)  | 
            ||
| 1034 | *  | 
            ||
| 1035 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo  | 
            ||
| 1036 | *  | 
            ||
| 1037 | * @return mixed[] Affected Location Id's  | 
            ||
| 1038 | */  | 
            ||
| 1039 | public function deleteContent(ContentInfo $contentInfo)  | 
            ||
| 1040 |     { | 
            ||
| 1041 | $contentInfo = $this->internalLoadContentInfo($contentInfo->id);  | 
            ||
| 1042 | |||
| 1043 |         if (!$this->repository->canUser('content', 'remove', $contentInfo)) { | 
            ||
| 1044 |             throw new UnauthorizedException('content', 'remove', ['contentId' => $contentInfo->id]); | 
            ||
| 1045 | }  | 
            ||
| 1046 | |||
| 1047 | $affectedLocations = [];  | 
            ||
| 1048 | $this->repository->beginTransaction();  | 
            ||
| 1049 |         try { | 
            ||
| 1050 | // Load Locations first as deleting Content also deletes belonging Locations  | 
            ||
| 1051 | $spiLocations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentInfo->id);  | 
            ||
| 1052 | $this->persistenceHandler->contentHandler()->deleteContent($contentInfo->id);  | 
            ||
| 1053 | $urlAliasHandler = $this->persistenceHandler->urlAliasHandler();  | 
            ||
| 1054 |             foreach ($spiLocations as $spiLocation) { | 
            ||
| 1055 | $urlAliasHandler->locationDeleted($spiLocation->id);  | 
            ||
| 1056 | $affectedLocations[] = $spiLocation->id;  | 
            ||
| 1057 | }  | 
            ||
| 1058 | $this->repository->commit();  | 
            ||
| 1059 |         } catch (Exception $e) { | 
            ||
| 1060 | $this->repository->rollback();  | 
            ||
| 1061 | throw $e;  | 
            ||
| 1062 | }  | 
            ||
| 1063 | |||
| 1064 | return $affectedLocations;  | 
            ||
| 1065 | }  | 
            ||
| 1066 | |||
| 1067 | /**  | 
            ||
| 1068 | * Creates a draft from a published or archived version.  | 
            ||
| 1069 | *  | 
            ||
| 1070 | * If no version is given, the current published version is used.  | 
            ||
| 1071 | *  | 
            ||
| 1072 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo  | 
            ||
| 1073 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo  | 
            ||
| 1074 | * @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  | 
            ||
| 1075 | * @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.  | 
            ||
| 1076 | *  | 
            ||
| 1077 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft  | 
            ||
| 1078 | *  | 
            ||
| 1079 | * @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException  | 
            ||
| 1080 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the current-user is not allowed to create the draft  | 
            ||
| 1081 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to create the draft  | 
            ||
| 1082 | */  | 
            ||
| 1083 | public function createContentDraft(  | 
            ||
| 1084 | ContentInfo $contentInfo,  | 
            ||
| 1085 | APIVersionInfo $versionInfo = null,  | 
            ||
| 1086 | User $creator = null,  | 
            ||
| 1087 | ?Language $language = null  | 
            ||
| 1088 |     ) { | 
            ||
| 1089 | $contentInfo = $this->loadContentInfo($contentInfo->id);  | 
            ||
| 1090 | |||
| 1091 |         if ($versionInfo !== null) { | 
            ||
| 1092 | // Check that given $contentInfo and $versionInfo belong to the same content  | 
            ||
| 1093 |             if ($versionInfo->getContentInfo()->id != $contentInfo->id) { | 
            ||
| 1094 | throw new InvalidArgumentException(  | 
            ||
| 1095 | '$versionInfo',  | 
            ||
| 1096 | 'VersionInfo does not belong to the same content as given ContentInfo'  | 
            ||
| 1097 | );  | 
            ||
| 1098 | }  | 
            ||
| 1099 | |||
| 1100 | $versionInfo = $this->loadVersionInfoById($contentInfo->id, $versionInfo->versionNo);  | 
            ||
| 1101 | |||
| 1102 |             switch ($versionInfo->status) { | 
            ||
| 1103 | case VersionInfo::STATUS_PUBLISHED:  | 
            ||
| 1104 | case VersionInfo::STATUS_ARCHIVED:  | 
            ||
| 1105 | break;  | 
            ||
| 1106 | |||
| 1107 | default:  | 
            ||
| 1108 | // @todo: throw an exception here, to be defined  | 
            ||
| 1109 | throw new BadStateException(  | 
            ||
| 1110 | '$versionInfo',  | 
            ||
| 1111 | 'Draft can not be created from a draft version'  | 
            ||
| 1112 | );  | 
            ||
| 1113 | }  | 
            ||
| 1114 | |||
| 1115 | $versionNo = $versionInfo->versionNo;  | 
            ||
| 1116 |         } elseif ($contentInfo->published) { | 
            ||
| 1117 | $versionNo = $contentInfo->currentVersionNo;  | 
            ||
| 1118 |         } else { | 
            ||
| 1119 | // @todo: throw an exception here, to be defined  | 
            ||
| 1120 | throw new BadStateException(  | 
            ||
| 1121 | '$contentInfo',  | 
            ||
| 1122 | 'Content is not published, draft can be created only from published or archived version'  | 
            ||
| 1123 | );  | 
            ||
| 1124 | }  | 
            ||
| 1125 | |||
| 1126 |         if ($creator === null) { | 
            ||
| 1127 | $creator = $this->repository->getCurrentUserReference();  | 
            ||
| 1128 | }  | 
            ||
| 1129 | |||
| 1130 | $fallbackLanguageCode = $versionInfo->initialLanguageCode ?? $contentInfo->mainLanguageCode;  | 
            ||
| 1131 | $languageCode = $language->languageCode ?? $fallbackLanguageCode;  | 
            ||
| 1132 | |||
| 1133 | if (!$this->repository->getPermissionResolver()->canUser(  | 
            ||
| 1134 | 'content',  | 
            ||
| 1135 | 'edit',  | 
            ||
| 1136 | $contentInfo,  | 
            ||
| 1137 | [  | 
            ||
| 1138 | (new Target\Builder\VersionBuilder())  | 
            ||
| 1139 | ->changeStatusTo(APIVersionInfo::STATUS_DRAFT)  | 
            ||
| 1140 | ->build(),  | 
            ||
| 1141 | ]  | 
            ||
| 1142 |         )) { | 
            ||
| 1143 | throw new UnauthorizedException(  | 
            ||
| 1144 | 'content',  | 
            ||
| 1145 | 'edit',  | 
            ||
| 1146 | ['contentId' => $contentInfo->id]  | 
            ||
| 1147 | );  | 
            ||
| 1148 | }  | 
            ||
| 1149 | |||
| 1150 | $this->repository->beginTransaction();  | 
            ||
| 1151 |         try { | 
            ||
| 1152 | $spiContent = $this->persistenceHandler->contentHandler()->createDraftFromVersion(  | 
            ||
| 1153 | $contentInfo->id,  | 
            ||
| 1154 | $versionNo,  | 
            ||
| 1155 | $creator->getUserId(),  | 
            ||
| 1156 | $languageCode  | 
            ||
| 1157 | );  | 
            ||
| 1158 | $this->repository->commit();  | 
            ||
| 1159 |         } catch (Exception $e) { | 
            ||
| 1160 | $this->repository->rollback();  | 
            ||
| 1161 | throw $e;  | 
            ||
| 1162 | }  | 
            ||
| 1163 | |||
| 1164 | return $this->domainMapper->buildContentDomainObject(  | 
            ||
| 1165 | $spiContent,  | 
            ||
| 1166 | $this->repository->getContentTypeService()->loadContentType(  | 
            ||
| 1167 | $spiContent->versionInfo->contentInfo->contentTypeId  | 
            ||
| 1168 | )  | 
            ||
| 1169 | );  | 
            ||
| 1170 | }  | 
            ||
| 1171 | |||
| 1172 | /**  | 
            ||
| 1173 |      * {@inheritdoc} | 
            ||
| 1174 | */  | 
            ||
| 1175 | public function countContentDrafts(?User $user = null): int  | 
            ||
| 1176 |     { | 
            ||
| 1177 |         if ($this->repository->hasAccess('content', 'versionread') === false) { | 
            ||
| 1178 | return 0;  | 
            ||
| 1179 | }  | 
            ||
| 1180 | |||
| 1181 | return $this->persistenceHandler->contentHandler()->countDraftsForUser(  | 
            ||
| 1182 | $this->resolveUser($user)->getUserId()  | 
            ||
| 1183 | );  | 
            ||
| 1184 | }  | 
            ||
| 1185 | |||
| 1186 | /**  | 
            ||
| 1187 | * Loads drafts for a user.  | 
            ||
| 1188 | *  | 
            ||
| 1189 | * If no user is given the drafts for the authenticated user are returned  | 
            ||
| 1190 | *  | 
            ||
| 1191 | * @param \eZ\Publish\API\Repository\Values\User\User|null $user  | 
            ||
| 1192 | *  | 
            ||
| 1193 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Drafts owned by the given user  | 
            ||
| 1194 | *  | 
            ||
| 1195 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException  | 
            ||
| 1196 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException  | 
            ||
| 1197 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException  | 
            ||
| 1198 | */  | 
            ||
| 1199 | public function loadContentDrafts(User $user = null)  | 
            ||
| 1200 |     { | 
            ||
| 1201 | // throw early if user has absolutely no access to versionread  | 
            ||
| 1202 |         if ($this->repository->hasAccess('content', 'versionread') === false) { | 
            ||
| 1203 |             throw new UnauthorizedException('content', 'versionread'); | 
            ||
| 1204 | }  | 
            ||
| 1205 | |||
| 1206 | $spiVersionInfoList = $this->persistenceHandler->contentHandler()->loadDraftsForUser(  | 
            ||
| 1207 | $this->resolveUser($user)->getUserId()  | 
            ||
| 1208 | );  | 
            ||
| 1209 | $versionInfoList = [];  | 
            ||
| 1210 |         foreach ($spiVersionInfoList as $spiVersionInfo) { | 
            ||
| 1211 | $versionInfo = $this->domainMapper->buildVersionInfoDomainObject($spiVersionInfo);  | 
            ||
| 1212 | // @todo: Change this to filter returned drafts by permissions instead of throwing  | 
            ||
| 1213 |             if (!$this->repository->canUser('content', 'versionread', $versionInfo)) { | 
            ||
| 1214 |                 throw new UnauthorizedException('content', 'versionread', ['contentId' => $versionInfo->contentInfo->id]); | 
            ||
| 1215 | }  | 
            ||
| 1216 | |||
| 1217 | $versionInfoList[] = $versionInfo;  | 
            ||
| 1218 | }  | 
            ||
| 1219 | |||
| 1220 | return $versionInfoList;  | 
            ||
| 1221 | }  | 
            ||
| 1222 | |||
| 1223 | /**  | 
            ||
| 1224 |      * {@inheritdoc} | 
            ||
| 1225 | */  | 
            ||
| 1226 | public function loadContentDraftList(?User $user = null, int $offset = 0, int $limit = -1): ContentDraftList  | 
            ||
| 1227 |     { | 
            ||
| 1228 | $list = new ContentDraftList();  | 
            ||
| 1229 |         if ($this->repository->hasAccess('content', 'versionread') === false) { | 
            ||
| 1230 | return $list;  | 
            ||
| 1231 | }  | 
            ||
| 1232 | |||
| 1233 | $list->totalCount = $this->persistenceHandler->contentHandler()->countDraftsForUser(  | 
            ||
| 1234 | $this->resolveUser($user)->getUserId()  | 
            ||
| 1235 | );  | 
            ||
| 1236 |         if ($list->totalCount > 0) { | 
            ||
| 1237 | $spiVersionInfoList = $this->persistenceHandler->contentHandler()->loadDraftListForUser(  | 
            ||
| 1238 | $this->resolveUser($user)->getUserId(),  | 
            ||
| 1239 | $offset,  | 
            ||
| 1240 | $limit  | 
            ||
| 1241 | );  | 
            ||
| 1242 |             foreach ($spiVersionInfoList as $spiVersionInfo) { | 
            ||
| 1243 | $versionInfo = $this->domainMapper->buildVersionInfoDomainObject($spiVersionInfo);  | 
            ||
| 1244 |                 if ($this->repository->canUser('content', 'versionread', $versionInfo)) { | 
            ||
| 1245 | $list->items[] = new ContentDraftListItem($versionInfo);  | 
            ||
| 1246 |                 } else { | 
            ||
| 1247 | $list->items[] = new UnauthorizedContentDraftListItem(  | 
            ||
| 1248 | 'content',  | 
            ||
| 1249 | 'versionread',  | 
            ||
| 1250 | ['contentId' => $versionInfo->contentInfo->id]  | 
            ||
| 1251 | );  | 
            ||
| 1252 | }  | 
            ||
| 1253 | }  | 
            ||
| 1254 | }  | 
            ||
| 1255 | |||
| 1256 | return $list;  | 
            ||
| 1257 | }  | 
            ||
| 1258 | |||
| 1259 | /**  | 
            ||
| 1260 | * Updates the fields of a draft.  | 
            ||
| 1261 | *  | 
            ||
| 1262 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo  | 
            ||
| 1263 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct  | 
            ||
| 1264 | *  | 
            ||
| 1265 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields  | 
            ||
| 1266 | *  | 
            ||
| 1267 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid,  | 
            ||
| 1268 | * or if a required field is missing / set to an empty value.  | 
            ||
| 1269 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType,  | 
            ||
| 1270 | * or value is set for non-translatable field in language  | 
            ||
| 1271 | * other than main.  | 
            ||
| 1272 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version  | 
            ||
| 1273 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft  | 
            ||
| 1274 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a property on the struct is invalid.  | 
            ||
| 1275 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException  | 
            ||
| 1276 | */  | 
            ||
| 1277 | public function updateContent(APIVersionInfo $versionInfo, APIContentUpdateStruct $contentUpdateStruct)  | 
            ||
| 1278 |     { | 
            ||
| 1279 | /** @var $content \eZ\Publish\Core\Repository\Values\Content\Content */  | 
            ||
| 1280 | $content = $this->loadContent(  | 
            ||
| 1281 | $versionInfo->getContentInfo()->id,  | 
            ||
| 1282 | null,  | 
            ||
| 1283 | $versionInfo->versionNo  | 
            ||
| 1284 | );  | 
            ||
| 1285 | |||
| 1286 | if (!$this->repository->getPermissionResolver()->canUser(  | 
            ||
| 1287 | 'content',  | 
            ||
| 1288 | 'edit',  | 
            ||
| 1289 | $content,  | 
            ||
| 1290 | [  | 
            ||
| 1291 | (new Target\Builder\VersionBuilder())  | 
            ||
| 1292 | ->updateFieldsTo(  | 
            ||
| 1293 | $contentUpdateStruct->initialLanguageCode,  | 
            ||
| 1294 | $contentUpdateStruct->fields  | 
            ||
| 1295 | )  | 
            ||
| 1296 | ->build(),  | 
            ||
| 1297 | ]  | 
            ||
| 1298 |         )) { | 
            ||
| 1299 |             throw new UnauthorizedException('content', 'edit', ['contentId' => $content->id]); | 
            ||
| 1300 | }  | 
            ||
| 1301 | |||
| 1302 | return $this->internalUpdateContent($versionInfo, $contentUpdateStruct);  | 
            ||
| 1303 | }  | 
            ||
| 1304 | |||
| 1305 | /**  | 
            ||
| 1306 | * Updates the fields of a draft without checking the permissions.  | 
            ||
| 1307 | *  | 
            ||
| 1308 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid,  | 
            ||
| 1309 | * or if a required field is missing / set to an empty value.  | 
            ||
| 1310 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType,  | 
            ||
| 1311 | * or value is set for non-translatable field in language  | 
            ||
| 1312 | * other than main.  | 
            ||
| 1313 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft  | 
            ||
| 1314 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a property on the struct is invalid.  | 
            ||
| 1315 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException  | 
            ||
| 1316 | */  | 
            ||
| 1317 | protected function internalUpdateContent(APIVersionInfo $versionInfo, APIContentUpdateStruct $contentUpdateStruct): Content  | 
            ||
| 1488 | |||
| 1489 | /**  | 
            ||
| 1490 | * Returns only updated language codes.  | 
            ||
| 1491 | *  | 
            ||
| 1492 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct  | 
            ||
| 1493 | *  | 
            ||
| 1494 | * @return array  | 
            ||
| 1495 | */  | 
            ||
| 1496 | private function getUpdatedLanguageCodes(APIContentUpdateStruct $contentUpdateStruct)  | 
            ||
| 1512 | |||
| 1513 | /**  | 
            ||
| 1514 | * Returns all language codes used in given $fields.  | 
            ||
| 1515 | *  | 
            ||
| 1516 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value exists in initial language  | 
            ||
| 1517 | *  | 
            ||
| 1518 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct  | 
            ||
| 1519 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content  | 
            ||
| 1520 | *  | 
            ||
| 1521 | * @return array  | 
            ||
| 1522 | */  | 
            ||
| 1523 | protected function getLanguageCodesForUpdate(APIContentUpdateStruct $contentUpdateStruct, APIContent $content)  | 
            ||
| 1535 | |||
| 1536 | /**  | 
            ||
| 1537 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode].  | 
            ||
| 1538 | *  | 
            ||
| 1539 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType  | 
            ||
| 1540 | * or value is set for non-translatable field in language  | 
            ||
| 1541 | * other than main  | 
            ||
| 1542 | *  | 
            ||
| 1543 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct  | 
            ||
| 1544 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType  | 
            ||
| 1545 | * @param string $mainLanguageCode  | 
            ||
| 1546 | *  | 
            ||
| 1547 | * @return array  | 
            ||
| 1548 | */  | 
            ||
| 1549 | protected function mapFieldsForUpdate(  | 
            ||
| 1587 | |||
| 1588 | /**  | 
            ||
| 1589 | * Publishes a content version.  | 
            ||
| 1590 | *  | 
            ||
| 1591 | * Publishes a content version and deletes archive versions if they overflow max archive versions.  | 
            ||
| 1592 | * Max archive versions are currently a configuration, but might be moved to be a param of ContentType in the future.  | 
            ||
| 1593 | *  | 
            ||
| 1594 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo  | 
            ||
| 1595 | * @param string[] $translations  | 
            ||
| 1596 | *  | 
            ||
| 1597 | * @return \eZ\Publish\API\Repository\Values\Content\Content  | 
            ||
| 1598 | *  | 
            ||
| 1599 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft  | 
            ||
| 1600 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException  | 
            ||
| 1601 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException  | 
            ||
| 1602 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException  | 
            ||
| 1603 | */  | 
            ||
| 1604 | public function publishVersion(APIVersionInfo $versionInfo, array $translations = Language::ALL)  | 
            ||
| 1642 | |||
| 1643 | /**  | 
            ||
| 1644 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo  | 
            ||
| 1645 | * @param array $translations  | 
            ||
| 1646 | *  | 
            ||
| 1647 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException  | 
            ||
| 1648 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException  | 
            ||
| 1649 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException  | 
            ||
| 1650 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException  | 
            ||
| 1651 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException  | 
            ||
| 1652 | */  | 
            ||
| 1653 | protected function copyTranslationsFromPublishedVersion(APIVersionInfo $versionInfo, array $translations = []): void  | 
            ||
| 1654 |     { | 
            ||
| 1655 | $contendId = $versionInfo->contentInfo->id;  | 
            ||
| 1656 | |||
| 1657 | $currentContent = $this->internalLoadContent($contendId);  | 
            ||
| 1658 | $currentVersionInfo = $currentContent->versionInfo;  | 
            ||
| 1659 | |||
| 1660 | // Copying occurs only if:  | 
            ||
| 1661 | // - There is published Version  | 
            ||
| 1662 | // - Published version is older than the currently published one unless specific translations are provided.  | 
            ||
| 1663 | if (!$currentVersionInfo->isPublished() ||  | 
            ||
| 1664 |             ($versionInfo->versionNo >= $currentVersionInfo->versionNo && empty($translations))) { | 
            ||
| 1665 | return;  | 
            ||
| 1666 | }  | 
            ||
| 1748 | |||
| 1749 | protected function fieldValuesAreEqual(FieldType $fieldType, Value $value1, Value $value2): bool  | 
            ||
| 1768 | |||
| 1769 | /**  | 
            ||
| 1770 | * Publishes a content version.  | 
            ||
| 1771 | *  | 
            ||
| 1772 | * Publishes a content version and deletes archive versions if they overflow max archive versions.  | 
            ||
| 1773 | * Max archive versions are currently a configuration, but might be moved to be a param of ContentType in the future.  | 
            ||
| 1774 | *  | 
            ||
| 1775 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft  | 
            ||
| 1776 | *  | 
            ||
| 1777 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo  | 
            ||
| 1778 | * @param int|null $publicationDate If null existing date is kept if there is one, otherwise current time is used.  | 
            ||
| 1779 | *  | 
            ||
| 1780 | * @return \eZ\Publish\API\Repository\Values\Content\Content  | 
            ||
| 1781 | */  | 
            ||
| 1782 | protected function internalPublishVersion(APIVersionInfo $versionInfo, $publicationDate = null)  | 
            ||
| 1834 | |||
| 1835 | /**  | 
            ||
| 1836 | * @return int  | 
            ||
| 1837 | */  | 
            ||
| 1838 | protected function getUnixTimestamp()  | 
            ||
| 1842 | |||
| 1843 | /**  | 
            ||
| 1844 | * Removes the given version.  | 
            ||
| 1845 | *  | 
            ||
| 1846 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in  | 
            ||
| 1847 | * published state or is a last version of Content in non draft state  | 
            ||
| 1848 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version  | 
            ||
| 1849 | *  | 
            ||
| 1850 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo  | 
            ||
| 1851 | */  | 
            ||
| 1852 | public function deleteVersion(APIVersionInfo $versionInfo)  | 
            ||
| 1894 | |||
| 1895 | /**  | 
            ||
| 1896 | * Loads all versions for the given content.  | 
            ||
| 1897 | *  | 
            ||
| 1898 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions  | 
            ||
| 1899 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the given status is invalid  | 
            ||
| 1900 | *  | 
            ||
| 1901 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo  | 
            ||
| 1902 | * @param int|null $status  | 
            ||
| 1903 | *  | 
            ||
| 1904 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date  | 
            ||
| 1905 | */  | 
            ||
| 1906 | public function loadVersions(ContentInfo $contentInfo, ?int $status = null)  | 
            ||
| 1935 | |||
| 1936 | /**  | 
            ||
| 1937 | * Copies the content to a new location. If no version is given,  | 
            ||
| 1938 | * all versions are copied, otherwise only the given version.  | 
            ||
| 1939 | *  | 
            ||
| 1940 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location  | 
            ||
| 1941 | *  | 
            ||
| 1942 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo  | 
            ||
| 1943 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to  | 
            ||
| 1944 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo  | 
            ||
| 1945 | *  | 
            ||
| 1946 | * @return \eZ\Publish\API\Repository\Values\Content\Content  | 
            ||
| 1947 | */  | 
            ||
| 1948 | public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, APIVersionInfo $versionInfo = null)  | 
            ||
| 2003 | |||
| 2004 | /**  | 
            ||
| 2005 | * Loads all outgoing relations for the given version.  | 
            ||
| 2006 | *  | 
            ||
| 2007 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version  | 
            ||
| 2008 | *  | 
            ||
| 2009 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo  | 
            ||
| 2010 | *  | 
            ||
| 2011 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[]  | 
            ||
| 2012 | */  | 
            ||
| 2013 | public function loadRelations(APIVersionInfo $versionInfo)  | 
            ||
| 2027 | |||
| 2028 | /**  | 
            ||
| 2029 | * Loads all outgoing relations for the given version without checking the permissions.  | 
            ||
| 2030 | *  | 
            ||
| 2031 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException  | 
            ||
| 2032 | *  | 
            ||
| 2033 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[]  | 
            ||
| 2034 | */  | 
            ||
| 2035 | protected function internalLoadRelations(APIVersionInfo $versionInfo): array  | 
            ||
| 2060 | |||
| 2061 | /**  | 
            ||
| 2062 |      * {@inheritdoc} | 
            ||
| 2063 | */  | 
            ||
| 2064 | public function countReverseRelations(ContentInfo $contentInfo): int  | 
            ||
| 2074 | |||
| 2075 | /**  | 
            ||
| 2076 | * Loads all incoming relations for a content object.  | 
            ||
| 2077 | *  | 
            ||
| 2078 | * The relations come only from published versions of the source content objects  | 
            ||
| 2079 | *  | 
            ||
| 2080 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version  | 
            ||
| 2081 | *  | 
            ||
| 2082 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo  | 
            ||
| 2083 | *  | 
            ||
| 2084 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[]  | 
            ||
| 2085 | */  | 
            ||
| 2086 | public function loadReverseRelations(ContentInfo $contentInfo)  | 
            ||
| 2112 | |||
| 2113 | /**  | 
            ||
| 2114 |      * {@inheritdoc} | 
            ||
| 2115 | */  | 
            ||
| 2116 | public function loadReverseRelationList(ContentInfo $contentInfo, int $offset = 0, int $limit = -1): RelationList  | 
            ||
| 2153 | |||
| 2154 | /**  | 
            ||
| 2155 | * Adds a relation of type common.  | 
            ||
| 2156 | *  | 
            ||
| 2157 | * The source of the relation is the content and version  | 
            ||
| 2158 | * referenced by $versionInfo.  | 
            ||
| 2159 | *  | 
            ||
| 2160 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version  | 
            ||
| 2161 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft  | 
            ||
| 2162 | *  | 
            ||
| 2163 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion  | 
            ||
| 2164 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation  | 
            ||
| 2165 | *  | 
            ||
| 2166 | * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation  | 
            ||
| 2167 | */  | 
            ||
| 2168 | public function addRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent)  | 
            ||
| 2209 | |||
| 2210 | /**  | 
            ||
| 2211 | * Removes a relation of type COMMON from a draft.  | 
            ||
| 2212 | *  | 
            ||
| 2213 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version  | 
            ||
| 2214 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft  | 
            ||
| 2215 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination  | 
            ||
| 2216 | *  | 
            ||
| 2217 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion  | 
            ||
| 2218 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent  | 
            ||
| 2219 | */  | 
            ||
| 2220 | public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent)  | 
            ||
| 2270 | |||
| 2271 | /**  | 
            ||
| 2272 |      * {@inheritdoc} | 
            ||
| 2273 | */  | 
            ||
| 2274 | public function removeTranslation(ContentInfo $contentInfo, $languageCode)  | 
            ||
| 2282 | |||
| 2283 | /**  | 
            ||
| 2284 | * Delete Content item Translation from all Versions (including archived ones) of a Content Object.  | 
            ||
| 2285 | *  | 
            ||
| 2286 | * NOTE: this operation is risky and permanent, so user interface should provide a warning before performing it.  | 
            ||
| 2287 | *  | 
            ||
| 2288 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation  | 
            ||
| 2289 | * is the Main Translation of a Content Item.  | 
            ||
| 2290 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed  | 
            ||
| 2291 | * to delete the content (in one of the locations of the given Content Item).  | 
            ||
| 2292 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument  | 
            ||
| 2293 | * is invalid for the given content.  | 
            ||
| 2294 | *  | 
            ||
| 2295 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo  | 
            ||
| 2296 | * @param string $languageCode  | 
            ||
| 2297 | *  | 
            ||
| 2298 | * @since 6.13  | 
            ||
| 2299 | */  | 
            ||
| 2300 | public function deleteTranslation(ContentInfo $contentInfo, $languageCode)  | 
            ||
| 2379 | |||
| 2380 | /**  | 
            ||
| 2381 | * Delete specified Translation from a Content Draft.  | 
            ||
| 2382 | *  | 
            ||
| 2383 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation  | 
            ||
| 2384 | * is the only one the Content Draft has or it is the main Translation of a Content Object.  | 
            ||
| 2385 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed  | 
            ||
| 2386 | * to edit the Content (in one of the locations of the given Content Object).  | 
            ||
| 2387 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument  | 
            ||
| 2388 | * is invalid for the given Draft.  | 
            ||
| 2389 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if specified Version was not found  | 
            ||
| 2390 | *  | 
            ||
| 2391 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo Content Version Draft  | 
            ||
| 2392 | * @param string $languageCode Language code of the Translation to be removed  | 
            ||
| 2393 | *  | 
            ||
| 2394 | * @return \eZ\Publish\API\Repository\Values\Content\Content Content Draft w/o the specified Translation  | 
            ||
| 2395 | *  | 
            ||
| 2396 | * @since 6.12  | 
            ||
| 2397 | */  | 
            ||
| 2398 | public function deleteTranslationFromDraft(APIVersionInfo $versionInfo, $languageCode)  | 
            ||
| 2464 | |||
| 2465 | /**  | 
            ||
| 2466 | * Hides Content by making all the Locations appear hidden.  | 
            ||
| 2467 | * It does not persist hidden state on Location object itself.  | 
            ||
| 2468 | *  | 
            ||
| 2469 | * Content hidden by this API can be revealed by revealContent API.  | 
            ||
| 2470 | *  | 
            ||
| 2471 | * @see revealContent  | 
            ||
| 2472 | *  | 
            ||
| 2473 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo  | 
            ||
| 2474 | */  | 
            ||
| 2475 | public function hideContent(ContentInfo $contentInfo): void  | 
            ||
| 2500 | |||
| 2501 | /**  | 
            ||
| 2502 | * Reveals Content hidden by hideContent API.  | 
            ||
| 2503 | * Locations which were hidden before hiding Content will remain hidden.  | 
            ||
| 2504 | *  | 
            ||
| 2505 | * @see hideContent  | 
            ||
| 2506 | *  | 
            ||
| 2507 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo  | 
            ||
| 2508 | */  | 
            ||
| 2509 | public function revealContent(ContentInfo $contentInfo): void  | 
            ||
| 2534 | |||
| 2535 | /**  | 
            ||
| 2536 | * Instantiates a new content create struct object.  | 
            ||
| 2537 | *  | 
            ||
| 2538 | * alwaysAvailable is set to the ContentType's defaultAlwaysAvailable  | 
            ||
| 2539 | *  | 
            ||
| 2540 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType  | 
            ||
| 2541 | * @param string $mainLanguageCode  | 
            ||
| 2542 | *  | 
            ||
| 2543 | * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct  | 
            ||
| 2544 | */  | 
            ||
| 2545 | public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode)  | 
            ||
| 2555 | |||
| 2556 | /**  | 
            ||
| 2557 | * Instantiates a new content meta data update struct.  | 
            ||
| 2558 | *  | 
            ||
| 2559 | * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct  | 
            ||
| 2560 | */  | 
            ||
| 2561 | public function newContentMetadataUpdateStruct()  | 
            ||
| 2565 | |||
| 2566 | /**  | 
            ||
| 2567 | * Instantiates a new content update struct.  | 
            ||
| 2568 | *  | 
            ||
| 2569 | * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct  | 
            ||
| 2570 | */  | 
            ||
| 2571 | public function newContentUpdateStruct()  | 
            ||
| 2575 | |||
| 2576 | /**  | 
            ||
| 2577 | * @param \eZ\Publish\API\Repository\Values\User\User|null $user  | 
            ||
| 2578 | *  | 
            ||
| 2579 | * @return \eZ\Publish\API\Repository\Values\User\UserReference  | 
            ||
| 2580 | */  | 
            ||
| 2581 | private function resolveUser(?User $user): UserReference  | 
            ||
| 2589 | }  | 
            ||
| 2590 | 
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.