Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like ContentService often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ContentService, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 52 | class ContentService implements ContentServiceInterface |
||
| 53 | { |
||
| 54 | /** |
||
| 55 | * @var \eZ\Publish\Core\Repository\Repository |
||
| 56 | */ |
||
| 57 | protected $repository; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var \eZ\Publish\SPI\Persistence\Handler |
||
| 61 | */ |
||
| 62 | protected $persistenceHandler; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var array |
||
| 66 | */ |
||
| 67 | protected $settings; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var \eZ\Publish\Core\Repository\Helper\DomainMapper |
||
| 71 | */ |
||
| 72 | protected $domainMapper; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var \eZ\Publish\Core\Repository\Helper\RelationProcessor |
||
| 76 | */ |
||
| 77 | protected $relationProcessor; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var \eZ\Publish\Core\Repository\Helper\NameSchemaService |
||
| 81 | */ |
||
| 82 | protected $nameSchemaService; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry |
||
| 86 | */ |
||
| 87 | protected $fieldTypeRegistry; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Setups service with reference to repository object that created it & corresponding handler. |
||
| 91 | * |
||
| 92 | * @param \eZ\Publish\API\Repository\Repository $repository |
||
| 93 | * @param \eZ\Publish\SPI\Persistence\Handler $handler |
||
| 94 | * @param \eZ\Publish\Core\Repository\Helper\DomainMapper $domainMapper |
||
| 95 | * @param \eZ\Publish\Core\Repository\Helper\RelationProcessor $relationProcessor |
||
| 96 | * @param \eZ\Publish\Core\Repository\Helper\NameSchemaService $nameSchemaService |
||
| 97 | * @param \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry $fieldTypeRegistry, |
||
|
|
|||
| 98 | * @param array $settings |
||
| 99 | */ |
||
| 100 | View Code Duplication | public function __construct( |
|
| 101 | RepositoryInterface $repository, |
||
| 102 | Handler $handler, |
||
| 103 | Helper\DomainMapper $domainMapper, |
||
| 104 | Helper\RelationProcessor $relationProcessor, |
||
| 105 | Helper\NameSchemaService $nameSchemaService, |
||
| 106 | Helper\FieldTypeRegistry $fieldTypeRegistry, |
||
| 107 | array $settings = array() |
||
| 108 | ) { |
||
| 109 | $this->repository = $repository; |
||
| 110 | $this->persistenceHandler = $handler; |
||
| 111 | $this->domainMapper = $domainMapper; |
||
| 112 | $this->relationProcessor = $relationProcessor; |
||
| 113 | $this->nameSchemaService = $nameSchemaService; |
||
| 114 | $this->fieldTypeRegistry = $fieldTypeRegistry; |
||
| 115 | // Union makes sure default settings are ignored if provided in argument |
||
| 116 | $this->settings = $settings + array( |
||
| 117 | //'defaultSetting' => array(), |
||
| 118 | ); |
||
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Loads a content info object. |
||
| 123 | * |
||
| 124 | * To load fields use loadContent |
||
| 125 | * |
||
| 126 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
| 127 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
| 128 | * |
||
| 129 | * @param int $contentId |
||
| 130 | * |
||
| 131 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 132 | */ |
||
| 133 | View Code Duplication | public function loadContentInfo($contentId) |
|
| 134 | { |
||
| 135 | $contentInfo = $this->internalLoadContentInfo($contentId); |
||
| 136 | if (!$this->repository->canUser('content', 'read', $contentInfo)) { |
||
| 137 | throw new UnauthorizedException('content', 'read', array('contentId' => $contentId)); |
||
| 138 | } |
||
| 139 | |||
| 140 | return $contentInfo; |
||
| 141 | } |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Loads a content info object. |
||
| 145 | * |
||
| 146 | * To load fields use loadContent |
||
| 147 | * |
||
| 148 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
| 149 | * |
||
| 150 | * @param mixed $id |
||
| 151 | * @param bool $isRemoteId |
||
| 152 | * |
||
| 153 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 154 | */ |
||
| 155 | public function internalLoadContentInfo($id, $isRemoteId = false) |
||
| 156 | { |
||
| 157 | try { |
||
| 158 | $method = $isRemoteId ? 'loadContentInfoByRemoteId' : 'loadContentInfo'; |
||
| 159 | |||
| 160 | return $this->domainMapper->buildContentInfoDomainObject( |
||
| 161 | $this->persistenceHandler->contentHandler()->$method($id) |
||
| 162 | ); |
||
| 163 | } catch (APINotFoundException $e) { |
||
| 164 | throw new NotFoundException( |
||
| 165 | 'Content', |
||
| 166 | $id, |
||
| 167 | $e |
||
| 168 | ); |
||
| 169 | } |
||
| 170 | } |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Loads a content info object for the given remoteId. |
||
| 174 | * |
||
| 175 | * To load fields use loadContent |
||
| 176 | * |
||
| 177 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
| 178 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given remote id does not exist |
||
| 179 | * |
||
| 180 | * @param string $remoteId |
||
| 181 | * |
||
| 182 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 183 | */ |
||
| 184 | View Code Duplication | public function loadContentInfoByRemoteId($remoteId) |
|
| 185 | { |
||
| 186 | $contentInfo = $this->internalLoadContentInfo($remoteId, true); |
||
| 187 | |||
| 188 | if (!$this->repository->canUser('content', 'read', $contentInfo)) { |
||
| 189 | throw new UnauthorizedException('content', 'read', array('remoteId' => $remoteId)); |
||
| 190 | } |
||
| 191 | |||
| 192 | return $contentInfo; |
||
| 193 | } |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Loads a version info of the given content object. |
||
| 197 | * |
||
| 198 | * If no version number is given, the method returns the current version |
||
| 199 | * |
||
| 200 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 201 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 202 | * |
||
| 203 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 204 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 205 | * |
||
| 206 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 207 | */ |
||
| 208 | public function loadVersionInfo(ContentInfo $contentInfo, $versionNo = null) |
||
| 209 | { |
||
| 210 | return $this->loadVersionInfoById($contentInfo->id, $versionNo); |
||
| 211 | } |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Loads a version info of the given content object id. |
||
| 215 | * |
||
| 216 | * If no version number is given, the method returns the current version |
||
| 217 | * |
||
| 218 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 219 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 220 | * |
||
| 221 | * @param mixed $contentId |
||
| 222 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 223 | * |
||
| 224 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 225 | */ |
||
| 226 | public function loadVersionInfoById($contentId, $versionNo = null) |
||
| 227 | { |
||
| 228 | if ($versionNo === null) { |
||
| 229 | $versionNo = $this->loadContentInfo($contentId)->currentVersionNo; |
||
| 230 | } |
||
| 231 | |||
| 232 | try { |
||
| 233 | $spiVersionInfo = $this->persistenceHandler->contentHandler()->loadVersionInfo( |
||
| 234 | $contentId, |
||
| 235 | $versionNo |
||
| 236 | ); |
||
| 237 | } catch (APINotFoundException $e) { |
||
| 238 | throw new NotFoundException( |
||
| 239 | 'VersionInfo', |
||
| 240 | array( |
||
| 241 | 'contentId' => $contentId, |
||
| 242 | 'versionNo' => $versionNo, |
||
| 243 | ), |
||
| 244 | $e |
||
| 245 | ); |
||
| 246 | } |
||
| 247 | |||
| 248 | $versionInfo = $this->domainMapper->buildVersionInfoDomainObject($spiVersionInfo); |
||
| 249 | |||
| 250 | if ($versionInfo->status === APIVersionInfo::STATUS_PUBLISHED) { |
||
| 251 | $function = 'read'; |
||
| 252 | } else { |
||
| 253 | $function = 'versionread'; |
||
| 254 | } |
||
| 255 | |||
| 256 | if (!$this->repository->canUser('content', $function, $versionInfo)) { |
||
| 257 | throw new UnauthorizedException('content', $function, array('contentId' => $contentId)); |
||
| 258 | } |
||
| 259 | |||
| 260 | return $versionInfo; |
||
| 261 | } |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Loads content in a version for the given content info object. |
||
| 265 | * |
||
| 266 | * If no version number is given, the method returns the current version |
||
| 267 | * |
||
| 268 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if version with the given number does not exist |
||
| 269 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 270 | * |
||
| 271 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 272 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 273 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 274 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 275 | * |
||
| 276 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 277 | */ |
||
| 278 | public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 279 | { |
||
| 280 | // Change $useAlwaysAvailable to false to avoid contentInfo lookup if we know alwaysAvailable is disabled |
||
| 281 | if ($useAlwaysAvailable && !$contentInfo->alwaysAvailable) { |
||
| 282 | $useAlwaysAvailable = false; |
||
| 283 | } |
||
| 284 | |||
| 285 | return $this->loadContent( |
||
| 286 | $contentInfo->id, |
||
| 287 | $languages, |
||
| 288 | $versionNo, |
||
| 289 | $useAlwaysAvailable |
||
| 290 | ); |
||
| 291 | } |
||
| 292 | |||
| 293 | /** |
||
| 294 | * Loads content in the version given by version info. |
||
| 295 | * |
||
| 296 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 297 | * |
||
| 298 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 299 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 300 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 301 | * |
||
| 302 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 303 | */ |
||
| 304 | public function loadContentByVersionInfo(APIVersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true) |
||
| 305 | { |
||
| 306 | // Change $useAlwaysAvailable to false to avoid contentInfo lookup if we know alwaysAvailable is disabled |
||
| 307 | if ($useAlwaysAvailable && !$versionInfo->getContentInfo()->alwaysAvailable) { |
||
| 308 | $useAlwaysAvailable = false; |
||
| 309 | } |
||
| 310 | |||
| 311 | return $this->loadContent( |
||
| 312 | $versionInfo->getContentInfo()->id, |
||
| 313 | $languages, |
||
| 314 | $versionInfo->versionNo, |
||
| 315 | $useAlwaysAvailable |
||
| 316 | ); |
||
| 317 | } |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Loads content in a version of the given content object. |
||
| 321 | * |
||
| 322 | * If no version number is given, the method returns the current version |
||
| 323 | * |
||
| 324 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content or version with the given id and languages does not exist |
||
| 325 | * @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 |
||
| 326 | * |
||
| 327 | * @param int $contentId |
||
| 328 | * @param array|null $languages A language filter for fields. If not given all languages are returned |
||
| 329 | * @param int|null $versionNo the version number. If not given the current version is returned |
||
| 330 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 331 | * |
||
| 332 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 333 | */ |
||
| 334 | View Code Duplication | public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
|
| 335 | { |
||
| 336 | $content = $this->internalLoadContent($contentId, $languages, $versionNo, false, $useAlwaysAvailable); |
||
| 337 | |||
| 338 | if (!$this->repository->canUser('content', 'read', $content)) { |
||
| 339 | throw new UnauthorizedException('content', 'read', array('contentId' => $contentId)); |
||
| 340 | } |
||
| 341 | |||
| 342 | if ( |
||
| 343 | $content->getVersionInfo()->status !== APIVersionInfo::STATUS_PUBLISHED |
||
| 344 | && !$this->repository->canUser('content', 'versionread', $content) |
||
| 345 | ) { |
||
| 346 | throw new UnauthorizedException('content', 'versionread', array('contentId' => $contentId, 'versionNo' => $versionNo)); |
||
| 347 | } |
||
| 348 | |||
| 349 | return $content; |
||
| 350 | } |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Loads content in a version of the given content object. |
||
| 354 | * |
||
| 355 | * If no version number is given, the method returns the current version |
||
| 356 | * |
||
| 357 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content or version with the given id and languages does not exist |
||
| 358 | * |
||
| 359 | * @param mixed $id |
||
| 360 | * @param array|null $languages A language filter for fields. If not given all languages are returned |
||
| 361 | * @param int|null $versionNo the version number. If not given the current version is returned |
||
| 362 | * @param bool $isRemoteId |
||
| 363 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 364 | * |
||
| 365 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 366 | */ |
||
| 367 | public function internalLoadContent($id, array $languages = null, $versionNo = null, $isRemoteId = false, $useAlwaysAvailable = true) |
||
| 368 | { |
||
| 369 | try { |
||
| 370 | // Get Content ID if lookup by remote ID |
||
| 371 | if ($isRemoteId) { |
||
| 372 | $spiContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfoByRemoteId($id); |
||
| 373 | $id = $spiContentInfo->id; |
||
| 374 | } |
||
| 375 | |||
| 376 | // Get current version if $versionNo is not defined |
||
| 377 | if ($versionNo === null) { |
||
| 378 | if (!isset($spiContentInfo)) { |
||
| 379 | $spiContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo($id); |
||
| 380 | } |
||
| 381 | |||
| 382 | $versionNo = $spiContentInfo->currentVersionNo; |
||
| 383 | } |
||
| 384 | |||
| 385 | $loadLanguages = $languages; |
||
| 386 | $alwaysAvailableLanguageCode = null; |
||
| 387 | // Set main language on $languages filter if not empty (all) and $useAlwaysAvailable being true |
||
| 388 | if (!empty($loadLanguages) && $useAlwaysAvailable) { |
||
| 389 | if (!isset($spiContentInfo)) { |
||
| 390 | $spiContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo($id); |
||
| 391 | } |
||
| 392 | |||
| 393 | if ($spiContentInfo->alwaysAvailable) { |
||
| 394 | $loadLanguages[] = $alwaysAvailableLanguageCode = $spiContentInfo->mainLanguageCode; |
||
| 395 | $loadLanguages = array_unique($loadLanguages); |
||
| 396 | } |
||
| 397 | } |
||
| 398 | |||
| 399 | $spiContent = $this->persistenceHandler->contentHandler()->load( |
||
| 400 | $id, |
||
| 401 | $versionNo, |
||
| 402 | $loadLanguages |
||
| 403 | ); |
||
| 404 | } catch (APINotFoundException $e) { |
||
| 405 | throw new NotFoundException( |
||
| 406 | 'Content', |
||
| 407 | array( |
||
| 408 | $isRemoteId ? 'remoteId' : 'id' => $id, |
||
| 409 | 'languages' => $languages, |
||
| 410 | 'versionNo' => $versionNo, |
||
| 411 | ), |
||
| 412 | $e |
||
| 413 | ); |
||
| 414 | } |
||
| 415 | |||
| 416 | return $this->domainMapper->buildContentDomainObject( |
||
| 417 | $spiContent, |
||
| 418 | null, |
||
| 419 | empty($languages) ? null : $languages, |
||
| 420 | $alwaysAvailableLanguageCode |
||
| 421 | ); |
||
| 422 | } |
||
| 423 | |||
| 424 | /** |
||
| 425 | * Loads content in a version for the content object reference by the given remote id. |
||
| 426 | * |
||
| 427 | * If no version is given, the method returns the current version |
||
| 428 | * |
||
| 429 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given remote id does not exist |
||
| 430 | * @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 |
||
| 431 | * |
||
| 432 | * @param string $remoteId |
||
| 433 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 434 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 435 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 436 | * |
||
| 437 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 438 | */ |
||
| 439 | View Code Duplication | public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
|
| 440 | { |
||
| 441 | $content = $this->internalLoadContent($remoteId, $languages, $versionNo, true, $useAlwaysAvailable); |
||
| 442 | |||
| 443 | if (!$this->repository->canUser('content', 'read', $content)) { |
||
| 444 | throw new UnauthorizedException('content', 'read', array('remoteId' => $remoteId)); |
||
| 445 | } |
||
| 446 | |||
| 447 | if ( |
||
| 448 | $content->getVersionInfo()->status !== APIVersionInfo::STATUS_PUBLISHED |
||
| 449 | && !$this->repository->canUser('content', 'versionread', $content) |
||
| 450 | ) { |
||
| 451 | throw new UnauthorizedException('content', 'versionread', array('remoteId' => $remoteId, 'versionNo' => $versionNo)); |
||
| 452 | } |
||
| 453 | |||
| 454 | return $content; |
||
| 455 | } |
||
| 456 | |||
| 457 | /** |
||
| 458 | * Creates a new content draft assigned to the authenticated user. |
||
| 459 | * |
||
| 460 | * If a different userId is given in $contentCreateStruct it is assigned to the given user |
||
| 461 | * but this required special rights for the authenticated user |
||
| 462 | * (this is useful for content staging where the transfer process does not |
||
| 463 | * have to authenticate with the user which created the content object in the source server). |
||
| 464 | * The user has to publish the draft if it should be visible. |
||
| 465 | * In 4.x at least one location has to be provided in the location creation array. |
||
| 466 | * |
||
| 467 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location |
||
| 468 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the provided remoteId exists in the system, required properties on |
||
| 469 | * struct are missing or invalid, or if multiple locations are under the |
||
| 470 | * same parent. |
||
| 471 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid, |
||
| 472 | * or if a required field is missing / set to an empty value. |
||
| 473 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType, |
||
| 474 | * or value is set for non-translatable field in language |
||
| 475 | * other than main. |
||
| 476 | * |
||
| 477 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 478 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content |
||
| 479 | * |
||
| 480 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 481 | */ |
||
| 482 | public function createContent(APIContentCreateStruct $contentCreateStruct, array $locationCreateStructs = array()) |
||
| 483 | { |
||
| 484 | if ($contentCreateStruct->mainLanguageCode === null) { |
||
| 485 | throw new InvalidArgumentException('$contentCreateStruct', "'mainLanguageCode' property must be set"); |
||
| 486 | } |
||
| 487 | |||
| 488 | if ($contentCreateStruct->contentType === null) { |
||
| 489 | throw new InvalidArgumentException('$contentCreateStruct', "'contentType' property must be set"); |
||
| 490 | } |
||
| 491 | |||
| 492 | $contentCreateStruct = clone $contentCreateStruct; |
||
| 493 | |||
| 494 | if ($contentCreateStruct->ownerId === null) { |
||
| 495 | $contentCreateStruct->ownerId = $this->repository->getCurrentUserReference()->getUserId(); |
||
| 496 | } |
||
| 497 | |||
| 498 | if ($contentCreateStruct->alwaysAvailable === null) { |
||
| 499 | $contentCreateStruct->alwaysAvailable = false; |
||
| 500 | } |
||
| 501 | |||
| 502 | $contentCreateStruct->contentType = $this->repository->getContentTypeService()->loadContentType( |
||
| 503 | $contentCreateStruct->contentType->id |
||
| 504 | ); |
||
| 505 | |||
| 506 | if (empty($contentCreateStruct->sectionId)) { |
||
| 507 | if (isset($locationCreateStructs[0])) { |
||
| 508 | $location = $this->repository->getLocationService()->loadLocation( |
||
| 509 | $locationCreateStructs[0]->parentLocationId |
||
| 510 | ); |
||
| 511 | $contentCreateStruct->sectionId = $location->contentInfo->sectionId; |
||
| 512 | } else { |
||
| 513 | $contentCreateStruct->sectionId = 1; |
||
| 514 | } |
||
| 515 | } |
||
| 516 | |||
| 517 | if (!$this->repository->canUser('content', 'create', $contentCreateStruct, $locationCreateStructs)) { |
||
| 518 | throw new UnauthorizedException( |
||
| 519 | 'content', |
||
| 520 | 'create', |
||
| 521 | array( |
||
| 522 | 'parentLocationId' => isset($locationCreateStructs[0]) ? |
||
| 523 | $locationCreateStructs[0]->parentLocationId : |
||
| 524 | null, |
||
| 525 | 'sectionId' => $contentCreateStruct->sectionId, |
||
| 526 | ) |
||
| 527 | ); |
||
| 528 | } |
||
| 529 | |||
| 530 | if (!empty($contentCreateStruct->remoteId)) { |
||
| 531 | try { |
||
| 532 | $this->loadContentByRemoteId($contentCreateStruct->remoteId); |
||
| 533 | |||
| 534 | throw new InvalidArgumentException( |
||
| 535 | '$contentCreateStruct', |
||
| 536 | "Another content with remoteId '{$contentCreateStruct->remoteId}' exists" |
||
| 537 | ); |
||
| 538 | } catch (APINotFoundException $e) { |
||
| 539 | // Do nothing |
||
| 540 | } |
||
| 541 | } else { |
||
| 542 | $contentCreateStruct->remoteId = $this->domainMapper->getUniqueHash($contentCreateStruct); |
||
| 543 | } |
||
| 544 | |||
| 545 | $spiLocationCreateStructs = $this->buildSPILocationCreateStructs($locationCreateStructs); |
||
| 546 | |||
| 547 | $languageCodes = $this->getLanguageCodesForCreate($contentCreateStruct); |
||
| 548 | $fields = $this->mapFieldsForCreate($contentCreateStruct); |
||
| 549 | |||
| 550 | $fieldValues = array(); |
||
| 551 | $spiFields = array(); |
||
| 552 | $allFieldErrors = array(); |
||
| 553 | $inputRelations = array(); |
||
| 554 | $locationIdToContentIdMapping = array(); |
||
| 555 | |||
| 556 | foreach ($contentCreateStruct->contentType->getFieldDefinitions() as $fieldDefinition) { |
||
| 557 | /** @var $fieldType \eZ\Publish\Core\FieldType\FieldType */ |
||
| 558 | $fieldType = $this->fieldTypeRegistry->getFieldType( |
||
| 559 | $fieldDefinition->fieldTypeIdentifier |
||
| 560 | ); |
||
| 561 | |||
| 562 | foreach ($languageCodes as $languageCode) { |
||
| 563 | $isEmptyValue = false; |
||
| 564 | $valueLanguageCode = $fieldDefinition->isTranslatable ? $languageCode : $contentCreateStruct->mainLanguageCode; |
||
| 565 | $isLanguageMain = $languageCode === $contentCreateStruct->mainLanguageCode; |
||
| 566 | if (isset($fields[$fieldDefinition->identifier][$valueLanguageCode])) { |
||
| 567 | $fieldValue = $fields[$fieldDefinition->identifier][$valueLanguageCode]->value; |
||
| 568 | } else { |
||
| 569 | $fieldValue = $fieldDefinition->defaultValue; |
||
| 570 | } |
||
| 571 | |||
| 572 | $fieldValue = $fieldType->acceptValue($fieldValue); |
||
| 573 | |||
| 574 | View Code Duplication | if ($fieldType->isEmptyValue($fieldValue)) { |
|
| 575 | $isEmptyValue = true; |
||
| 576 | if ($fieldDefinition->isRequired) { |
||
| 577 | $allFieldErrors[$fieldDefinition->id][$languageCode] = new ValidationError( |
||
| 578 | "Value for required field definition '%identifier%' with language '%languageCode%' is empty", |
||
| 579 | null, |
||
| 580 | ['%identifier%' => $fieldDefinition->identifier, '%languageCode%' => $languageCode], |
||
| 581 | 'empty' |
||
| 582 | ); |
||
| 583 | } |
||
| 584 | } else { |
||
| 585 | $fieldErrors = $fieldType->validate( |
||
| 586 | $fieldDefinition, |
||
| 587 | $fieldValue |
||
| 588 | ); |
||
| 589 | if (!empty($fieldErrors)) { |
||
| 590 | $allFieldErrors[$fieldDefinition->id][$languageCode] = $fieldErrors; |
||
| 591 | } |
||
| 592 | } |
||
| 593 | |||
| 594 | if (!empty($allFieldErrors)) { |
||
| 595 | continue; |
||
| 596 | } |
||
| 597 | |||
| 598 | $this->relationProcessor->appendFieldRelations( |
||
| 599 | $inputRelations, |
||
| 600 | $locationIdToContentIdMapping, |
||
| 601 | $fieldType, |
||
| 602 | $fieldValue, |
||
| 603 | $fieldDefinition->id |
||
| 604 | ); |
||
| 605 | $fieldValues[$fieldDefinition->identifier][$languageCode] = $fieldValue; |
||
| 606 | |||
| 607 | // Only non-empty value for: translatable field or in main language |
||
| 608 | if ( |
||
| 609 | (!$isEmptyValue && $fieldDefinition->isTranslatable) || |
||
| 610 | (!$isEmptyValue && $isLanguageMain) |
||
| 611 | ) { |
||
| 612 | $spiFields[] = new SPIField( |
||
| 613 | array( |
||
| 614 | 'id' => null, |
||
| 615 | 'fieldDefinitionId' => $fieldDefinition->id, |
||
| 616 | 'type' => $fieldDefinition->fieldTypeIdentifier, |
||
| 617 | 'value' => $fieldType->toPersistenceValue($fieldValue), |
||
| 618 | 'languageCode' => $languageCode, |
||
| 619 | 'versionNo' => null, |
||
| 620 | ) |
||
| 621 | ); |
||
| 622 | } |
||
| 623 | } |
||
| 624 | } |
||
| 625 | |||
| 626 | if (!empty($allFieldErrors)) { |
||
| 627 | throw new ContentFieldValidationException($allFieldErrors); |
||
| 628 | } |
||
| 629 | |||
| 630 | $spiContentCreateStruct = new SPIContentCreateStruct( |
||
| 631 | array( |
||
| 632 | 'name' => $this->nameSchemaService->resolve( |
||
| 633 | $contentCreateStruct->contentType->nameSchema, |
||
| 634 | $contentCreateStruct->contentType, |
||
| 635 | $fieldValues, |
||
| 636 | $languageCodes |
||
| 637 | ), |
||
| 638 | 'typeId' => $contentCreateStruct->contentType->id, |
||
| 639 | 'sectionId' => $contentCreateStruct->sectionId, |
||
| 640 | 'ownerId' => $contentCreateStruct->ownerId, |
||
| 641 | 'locations' => $spiLocationCreateStructs, |
||
| 642 | 'fields' => $spiFields, |
||
| 643 | 'alwaysAvailable' => $contentCreateStruct->alwaysAvailable, |
||
| 644 | 'remoteId' => $contentCreateStruct->remoteId, |
||
| 645 | 'modified' => isset($contentCreateStruct->modificationDate) ? $contentCreateStruct->modificationDate->getTimestamp() : time(), |
||
| 646 | 'initialLanguageId' => $this->persistenceHandler->contentLanguageHandler()->loadByLanguageCode( |
||
| 647 | $contentCreateStruct->mainLanguageCode |
||
| 648 | )->id, |
||
| 649 | ) |
||
| 650 | ); |
||
| 651 | |||
| 652 | $defaultObjectStates = $this->getDefaultObjectStates(); |
||
| 653 | |||
| 654 | $this->repository->beginTransaction(); |
||
| 655 | try { |
||
| 656 | $spiContent = $this->persistenceHandler->contentHandler()->create($spiContentCreateStruct); |
||
| 657 | $this->relationProcessor->processFieldRelations( |
||
| 658 | $inputRelations, |
||
| 659 | $spiContent->versionInfo->contentInfo->id, |
||
| 660 | $spiContent->versionInfo->versionNo, |
||
| 661 | $contentCreateStruct->contentType |
||
| 662 | ); |
||
| 663 | |||
| 664 | foreach ($defaultObjectStates as $objectStateGroupId => $objectState) { |
||
| 665 | $this->persistenceHandler->objectStateHandler()->setContentState( |
||
| 666 | $spiContent->versionInfo->contentInfo->id, |
||
| 667 | $objectStateGroupId, |
||
| 668 | $objectState->id |
||
| 669 | ); |
||
| 670 | } |
||
| 671 | |||
| 672 | $this->repository->commit(); |
||
| 673 | } catch (Exception $e) { |
||
| 674 | $this->repository->rollback(); |
||
| 675 | throw $e; |
||
| 676 | } |
||
| 677 | |||
| 678 | return $this->domainMapper->buildContentDomainObject($spiContent); |
||
| 679 | } |
||
| 680 | |||
| 681 | /** |
||
| 682 | * Returns an array of default content states with content state group id as key. |
||
| 683 | * |
||
| 684 | * @return \eZ\Publish\SPI\Persistence\Content\ObjectState[] |
||
| 685 | */ |
||
| 686 | protected function getDefaultObjectStates() |
||
| 701 | |||
| 702 | /** |
||
| 703 | * Returns all language codes used in given $fields. |
||
| 704 | * |
||
| 705 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value is set in main language |
||
| 706 | * |
||
| 707 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 708 | * |
||
| 709 | * @return string[] |
||
| 710 | */ |
||
| 711 | protected function getLanguageCodesForCreate(APIContentCreateStruct $contentCreateStruct) |
||
| 735 | |||
| 736 | /** |
||
| 737 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
| 738 | * |
||
| 739 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
| 740 | * or value is set for non-translatable field in language |
||
| 741 | * other than main |
||
| 742 | * |
||
| 743 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 744 | * |
||
| 745 | * @return array |
||
| 746 | */ |
||
| 747 | protected function mapFieldsForCreate(APIContentCreateStruct $contentCreateStruct) |
||
| 780 | |||
| 781 | /** |
||
| 782 | * Clones $field with overriding specific properties from given $overrides array. |
||
| 783 | * |
||
| 784 | * @param Field $field |
||
| 785 | * @param array $overrides |
||
| 786 | * |
||
| 787 | * @return Field |
||
| 788 | */ |
||
| 789 | private function cloneField(Field $field, array $overrides = array()) |
||
| 803 | |||
| 804 | /** |
||
| 805 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 806 | * |
||
| 807 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs |
||
| 808 | * |
||
| 809 | * @return \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct[] |
||
| 810 | */ |
||
| 811 | protected function buildSPILocationCreateStructs(array $locationCreateStructs) |
||
| 845 | |||
| 846 | /** |
||
| 847 | * Updates the metadata. |
||
| 848 | * |
||
| 849 | * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent |
||
| 850 | * |
||
| 851 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data |
||
| 852 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists |
||
| 853 | * |
||
| 854 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 855 | * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct |
||
| 856 | * |
||
| 857 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes |
||
| 858 | */ |
||
| 859 | public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct) |
||
| 945 | |||
| 946 | /** |
||
| 947 | * Publishes URL aliases for all locations of a given content. |
||
| 948 | * |
||
| 949 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 950 | * @param bool $updatePathIdentificationString this parameter is legacy storage specific for updating |
||
| 951 | * ezcontentobject_tree.path_identification_string, it is ignored by other storage engines |
||
| 952 | */ |
||
| 953 | protected function publishUrlAliasesForContent(APIContent $content, $updatePathIdentificationString = true) |
||
| 972 | |||
| 973 | /** |
||
| 974 | * Deletes a content object including all its versions and locations including their subtrees. |
||
| 975 | * |
||
| 976 | * @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) |
||
| 977 | * |
||
| 978 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 979 | * |
||
| 980 | * @return mixed[] Affected Location Id's |
||
| 981 | */ |
||
| 982 | public function deleteContent(ContentInfo $contentInfo) |
||
| 983 | { |
||
| 984 | $contentInfo = $this->internalLoadContentInfo($contentInfo->id); |
||
| 1008 | |||
| 1009 | /** |
||
| 1010 | * Creates a draft from a published or archived version. |
||
| 1011 | * |
||
| 1012 | * If no version is given, the current published version is used. |
||
| 1013 | * 4.x: The draft is created with the initialLanguage code of the source version or if not present with the main language. |
||
| 1014 | * It can be changed on updating the version. |
||
| 1015 | * |
||
| 1016 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to create the draft |
||
| 1017 | * |
||
| 1018 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1019 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1020 | * @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 |
||
| 1021 | * |
||
| 1022 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 1023 | */ |
||
| 1024 | public function createContentDraft(ContentInfo $contentInfo, APIVersionInfo $versionInfo = null, User $creator = null) |
||
| 1086 | |||
| 1087 | /** |
||
| 1088 | * Loads drafts for a user. |
||
| 1089 | * |
||
| 1090 | * If no user is given the drafts for the authenticated user a returned |
||
| 1091 | * |
||
| 1092 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to load the draft list |
||
| 1093 | * |
||
| 1094 | * @param \eZ\Publish\API\Repository\Values\User\UserReference $user |
||
| 1095 | * |
||
| 1096 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo the drafts ({@link VersionInfo}) owned by the given user |
||
| 1097 | */ |
||
| 1098 | public function loadContentDrafts(User $user = null) |
||
| 1122 | |||
| 1123 | /** |
||
| 1124 | * Translate a version. |
||
| 1125 | * |
||
| 1126 | * updates the destination version given in $translationInfo with the provided translated fields in $translationValues |
||
| 1127 | * |
||
| 1128 | * @example Examples/translation_5x.php |
||
| 1129 | * |
||
| 1130 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the current-user is not allowed to update this version |
||
| 1131 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the given destination version is not a draft |
||
| 1132 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $translationValues is not valid, or if a required field is missing or is set to an empty value. |
||
| 1133 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
| 1134 | * or value is set for non-translatable field in language |
||
| 1135 | * other than main. |
||
| 1136 | * |
||
| 1137 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo |
||
| 1138 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationValues $translationValues |
||
| 1139 | * @param \eZ\Publish\API\Repository\Values\User\User $modifier If set, this user is taken as modifier of the version |
||
| 1140 | * |
||
| 1141 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the translated fields |
||
| 1142 | * |
||
| 1143 | * @since 5.0 |
||
| 1144 | */ |
||
| 1145 | public function translateVersion(TranslationInfo $translationInfo, APITranslationValues $translationValues, User $modifier = null) |
||
| 1149 | |||
| 1150 | /** |
||
| 1151 | * Updates the fields of a draft. |
||
| 1152 | * |
||
| 1153 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version |
||
| 1154 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1155 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a property on the struct is invalid. |
||
| 1156 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid, |
||
| 1157 | * or if a required field is missing / set to an empty value. |
||
| 1158 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType, |
||
| 1159 | * or value is set for non-translatable field in language |
||
| 1160 | * other than main. |
||
| 1161 | * |
||
| 1162 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1163 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1164 | * |
||
| 1165 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields |
||
| 1166 | */ |
||
| 1167 | public function updateContent(APIVersionInfo $versionInfo, APIContentUpdateStruct $contentUpdateStruct) |
||
| 1331 | |||
| 1332 | /** |
||
| 1333 | * Returns all language codes used in given $fields. |
||
| 1334 | * |
||
| 1335 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if no field value exists in initial language |
||
| 1336 | * |
||
| 1337 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1338 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 1339 | * |
||
| 1340 | * @return array |
||
| 1341 | */ |
||
| 1342 | protected function getLanguageCodesForUpdate(APIContentUpdateStruct $contentUpdateStruct, APIContent $content) |
||
| 1368 | |||
| 1369 | /** |
||
| 1370 | * Returns an array of fields like $fields[$field->fieldDefIdentifier][$field->languageCode]. |
||
| 1371 | * |
||
| 1372 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException If field definition does not exist in the ContentType |
||
| 1373 | * or value is set for non-translatable field in language |
||
| 1374 | * other than main |
||
| 1375 | * |
||
| 1376 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 1377 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 1378 | * @param string $mainLanguageCode |
||
| 1379 | * |
||
| 1380 | * @return array |
||
| 1381 | */ |
||
| 1382 | protected function mapFieldsForUpdate( |
||
| 1420 | |||
| 1421 | /** |
||
| 1422 | * Publishes a content version. |
||
| 1423 | * |
||
| 1424 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version |
||
| 1425 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1426 | * |
||
| 1427 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1428 | * |
||
| 1429 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1430 | */ |
||
| 1431 | public function publishVersion(APIVersionInfo $versionInfo) |
||
| 1458 | |||
| 1459 | /** |
||
| 1460 | * Publishes a content version. |
||
| 1461 | * |
||
| 1462 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1463 | * |
||
| 1464 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1465 | * @param int|null $publicationDate If null existing date is kept if there is one, otherwise current time is used. |
||
| 1466 | * |
||
| 1467 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1468 | */ |
||
| 1469 | protected function internalPublishVersion(APIVersionInfo $versionInfo, $publicationDate = null) |
||
| 1495 | |||
| 1496 | /** |
||
| 1497 | * Removes the given version. |
||
| 1498 | * |
||
| 1499 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in |
||
| 1500 | * published state or is the last version of the Content |
||
| 1501 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version |
||
| 1502 | * |
||
| 1503 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1504 | */ |
||
| 1505 | public function deleteVersion(APIVersionInfo $versionInfo) |
||
| 1545 | |||
| 1546 | /** |
||
| 1547 | * Loads all versions for the given content. |
||
| 1548 | * |
||
| 1549 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions |
||
| 1550 | * |
||
| 1551 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1552 | * |
||
| 1553 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date |
||
| 1554 | */ |
||
| 1555 | public function loadVersions(ContentInfo $contentInfo) |
||
| 1575 | |||
| 1576 | /** |
||
| 1577 | * Copies the content to a new location. If no version is given, |
||
| 1578 | * all versions are copied, otherwise only the given version. |
||
| 1579 | * |
||
| 1580 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location |
||
| 1581 | * |
||
| 1582 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1583 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to |
||
| 1584 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1585 | * |
||
| 1586 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1587 | */ |
||
| 1588 | public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, APIVersionInfo $versionInfo = null) |
||
| 1635 | |||
| 1636 | /** |
||
| 1637 | * Loads all outgoing relations for the given version. |
||
| 1638 | * |
||
| 1639 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 1640 | * |
||
| 1641 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 1642 | * |
||
| 1643 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 1644 | */ |
||
| 1645 | public function loadRelations(APIVersionInfo $versionInfo) |
||
| 1680 | |||
| 1681 | /** |
||
| 1682 | * Loads all incoming relations for a content object. |
||
| 1683 | * |
||
| 1684 | * The relations come only from published versions of the source content objects |
||
| 1685 | * |
||
| 1686 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 1687 | * |
||
| 1688 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1689 | * |
||
| 1690 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 1691 | */ |
||
| 1692 | public function loadReverseRelations(ContentInfo $contentInfo) |
||
| 1718 | |||
| 1719 | /** |
||
| 1720 | * Adds a relation of type common. |
||
| 1721 | * |
||
| 1722 | * The source of the relation is the content and version |
||
| 1723 | * referenced by $versionInfo. |
||
| 1724 | * |
||
| 1725 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version |
||
| 1726 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1727 | * |
||
| 1728 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 1729 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation |
||
| 1730 | * |
||
| 1731 | * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation |
||
| 1732 | */ |
||
| 1733 | public function addRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 1774 | |||
| 1775 | /** |
||
| 1776 | * Removes a relation of type COMMON from a draft. |
||
| 1777 | * |
||
| 1778 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version |
||
| 1779 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 1780 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination |
||
| 1781 | * |
||
| 1782 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 1783 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent |
||
| 1784 | */ |
||
| 1785 | public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 1835 | |||
| 1836 | /** |
||
| 1837 | * Adds translation information to the content object. |
||
| 1838 | * |
||
| 1839 | * @example Examples/translation_5x.php |
||
| 1840 | * |
||
| 1841 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed add a translation info |
||
| 1842 | * |
||
| 1843 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo |
||
| 1844 | * |
||
| 1845 | * @since 5.0 |
||
| 1846 | */ |
||
| 1847 | public function addTranslationInfo(TranslationInfo $translationInfo) |
||
| 1851 | |||
| 1852 | /** |
||
| 1853 | * lists the translations done on this content object. |
||
| 1854 | * |
||
| 1855 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed read translation infos |
||
| 1856 | * |
||
| 1857 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 1858 | * @param array $filter |
||
| 1859 | * |
||
| 1860 | * @todo TBD - filter by source version destination version and languages |
||
| 1861 | * |
||
| 1862 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo[] |
||
| 1863 | * |
||
| 1864 | * @since 5.0 |
||
| 1865 | */ |
||
| 1866 | public function loadTranslationInfos(ContentInfo $contentInfo, array $filter = array()) |
||
| 1870 | |||
| 1871 | /** |
||
| 1872 | * Instantiates a new content create struct object. |
||
| 1873 | * |
||
| 1874 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 1875 | * @param string $mainLanguageCode |
||
| 1876 | * |
||
| 1877 | * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct |
||
| 1878 | */ |
||
| 1879 | public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode) |
||
| 1888 | |||
| 1889 | /** |
||
| 1890 | * Instantiates a new content meta data update struct. |
||
| 1891 | * |
||
| 1892 | * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct |
||
| 1893 | */ |
||
| 1894 | public function newContentMetadataUpdateStruct() |
||
| 1898 | |||
| 1899 | /** |
||
| 1900 | * Instantiates a new content update struct. |
||
| 1901 | * |
||
| 1902 | * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct |
||
| 1903 | */ |
||
| 1904 | public function newContentUpdateStruct() |
||
| 1908 | |||
| 1909 | /** |
||
| 1910 | * Instantiates a new TranslationInfo object. |
||
| 1911 | * |
||
| 1912 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo |
||
| 1913 | */ |
||
| 1914 | public function newTranslationInfo() |
||
| 1918 | |||
| 1919 | /** |
||
| 1920 | * Instantiates a Translation object. |
||
| 1921 | * |
||
| 1922 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationValues |
||
| 1923 | */ |
||
| 1924 | public function newTranslationValues() |
||
| 1928 | } |
||
| 1929 |
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.