Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContentService::loadRelations → ContentService::loadRelationList #2544

Merged
merged 8 commits into from
Nov 27, 2024

Conversation

adriendupuis
Copy link
Contributor

@adriendupuis adriendupuis commented Nov 15, 2024

Question Answer
JIRA Ticket IBX-8534
Versions 4.6, master
Edition All

ContentService::loadRelations is deprecated in 4.6 and won't exist in 5.0 (removal in ibexa/core#435)

Previews:

Note: its deprecation is reported in the hidden https://doc.ibexa.co/en/latest/api/php_api/php_api_reference/reports/deprecated.html#vendor/ibexa/core/src/contracts/Repository/ContentService.php
I have checked other elements from this report. ("Not documented" means that the element is nowhere in the documentation text and nowhere in the code examples used by the documentation.)

Element  Status
ContentService::loadContentDrafts() Not documented
SearchResult::$spellSuggestion Not documented
AbstractCriterionQuery Not documented
CriterionMapperInterface Not documented
FieldValueSortClause Not documented
SortDirection Not documented
SegmentationServiceInterface::loadSegment() Deprecation is documented, element is not used 
SegmentationServiceInterface::loadSegmentGroup() Deprecation is documented, element is not used 
TaxonomyTreeServiceInterface::getPath() Not documented

Checklist

  • Text renders correctly
  • Text has been checked with vale
  • Description metadata is up to date
  • Redirects cover removed/moved pages
  • Code samples are working
  • PHP code samples have been fixed with PHP CS fixer
  • Added link to this PR in relevant JIRA ticket or code PR

Fix "Argument #1 ($contentId) must be of type int, string given"
loadRelations is deprecated in 4.5, and removed in 5.0

Fix "Call to an undefined method Ibexa\Contracts\Core\Repository\ContentService::loadRelations()." on PHPStan + 5.0
loadRelations is deprecated in 4.5, and removed in 5.0

Fix "Call to an undefined method Ibexa\Contracts\Core\Repository\ContentService::loadRelations()." on PHPStan + 5.0
@adriendupuis adriendupuis marked this pull request as ready for review November 18, 2024 11:23
@adamwojs adamwojs requested a review from ViniTou November 18, 2024 11:55
@adriendupuis adriendupuis requested a review from a team November 19, 2024 10:41
Copy link
Contributor

@mnocon mnocon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking care of this!

One question aboout the hasRelation usage - and one suggestion for the pagination remark.

@adriendupuis adriendupuis requested a review from mnocon November 26, 2024 14:26
Copy link

code_samples/ change report

Before (on target branch)After (in current PR)

code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php

docs/content_management/content_api/browsing_content.md@29:``` php hl_lines="9"
docs/content_management/content_api/browsing_content.md@30:// ...
docs/content_management/content_api/browsing_content.md@31:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 4, 5) =]]
docs/content_management/content_api/browsing_content.md@32:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 16, 17) =]]
docs/content_management/content_api/browsing_content.md@33:// ...
docs/content_management/content_api/browsing_content.md@34:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 50, 52) =]][[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 58, 59) =]]
docs/content_management/content_api/browsing_content.md@35:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 60, 66) =]]
docs/content_management/content_api/browsing_content.md@36:```

001⫶// ...
002⫶use Ibexa\Contracts\Core\Repository\ContentService;
003⫶
004⫶class ViewContentMetaDataCommand extends Command
005⫶
006⫶// ...
007⫶ protected function execute(InputInterface $input, OutputInterface $output): int
008⫶ {
009⫸ $contentInfo = $this->contentService->loadContentInfo($contentId);
010⫶
011⫶ $output->writeln("Name: $contentInfo->name");
012⫶ $output->writeln('Last modified: ' . $contentInfo->modificationDate->format('Y-m-d'));
013⫶ $output->writeln('Published: ' . $contentInfo->publishedDate->format('Y-m-d'));
014⫶ $output->writeln("RemoteId: $contentInfo->remoteId");
015⫶ $output->writeln("Main Language: $contentInfo->mainLanguageCode");
016⫶ $output->writeln('Always available: ' . ($contentInfo->alwaysAvailable ? 'Yes' : 'No'));

docs/content_management/content_api/browsing_content.md@51:``` php
docs/content_management/content_api/browsing_content.md@52:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 68, 72) =]]
docs/content_management/content_api/browsing_content.md@53:```

001⫶ $locations = $this->locationService->loadLocations($contentInfo);
002⫶
003⫶ foreach ($locations as $location) {
004⫶ $output->writeln('Location: ' . $location->pathString);

docs/content_management/content_api/browsing_content.md@68:``` php
docs/content_management/content_api/browsing_content.md@69:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 68, 71) =]][[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 72, 75) =]]
docs/content_management/content_api/browsing_content.md@70:```

001⫶ $locations = $this->locationService->loadLocations($contentInfo);
002⫶
003⫶ foreach ($locations as $location) {
004⫶ $urlAlias = $this->urlAliasService->reverseLookup($location);
005⫶ $output->writeln('URL alias: ' . $urlAlias->path);
006⫶ }

docs/content_management/content_api/browsing_content.md@77:``` php
docs/content_management/content_api/browsing_content.md@78:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 77, 79) =]]
docs/content_management/content_api/browsing_content.md@79:```

001⫶ $content = $this->contentService->loadContent($contentId);
002⫶ $output->writeln('Content type: ' . $content->getContentType()->getName());

docs/content_management/content_api/browsing_content.md@86:``` php
docs/content_management/content_api/browsing_content.md@87:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 81, 87) =]]
docs/content_management/content_api/browsing_content.md@88:```

001⫶ $versionInfos = $this->contentService->loadVersions($contentInfo);
002⫶ foreach ($versionInfos as $versionInfo) {
003⫶ $output->write("Version $versionInfo->versionNo");
004⫶ $output->write(' by ' . $versionInfo->getCreator()->getName());
005⫶ $output->writeln(' in ' . $versionInfo->getInitialLanguage()->name);
006⫶ }

docs/content_management/content_api/browsing_content.md@93:``` php
docs/content_management/content_api/browsing_content.md@94:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 88, 89) =]]
docs/content_management/content_api/browsing_content.md@95:```

001⫶ $versionInfoArray = iterator_to_array($this->contentService->loadVersions($contentInfo, VersionInfo::STATUS_ARCHIVED));

docs/content_management/content_api/browsing_content.md@109:``` php

code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php

docs/content_management/content_api/browsing_content.md@29:``` php hl_lines="9"
docs/content_management/content_api/browsing_content.md@30:// ...
docs/content_management/content_api/browsing_content.md@31:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 4, 5) =]]
docs/content_management/content_api/browsing_content.md@32:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 16, 17) =]]
docs/content_management/content_api/browsing_content.md@33:// ...
docs/content_management/content_api/browsing_content.md@34:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 50, 52) =]][[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 58, 59) =]]
docs/content_management/content_api/browsing_content.md@35:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 60, 66) =]]
docs/content_management/content_api/browsing_content.md@36:```

001⫶// ...
002⫶use Ibexa\Contracts\Core\Repository\ContentService;
003⫶
004⫶class ViewContentMetaDataCommand extends Command
005⫶
006⫶// ...
007⫶ protected function execute(InputInterface $input, OutputInterface $output): int
008⫶ {
009⫸ $contentInfo = $this->contentService->loadContentInfo($contentId);
010⫶
011⫶ $output->writeln("Name: $contentInfo->name");
012⫶ $output->writeln('Last modified: ' . $contentInfo->modificationDate->format('Y-m-d'));
013⫶ $output->writeln('Published: ' . $contentInfo->publishedDate->format('Y-m-d'));
014⫶ $output->writeln("RemoteId: $contentInfo->remoteId");
015⫶ $output->writeln("Main Language: $contentInfo->mainLanguageCode");
016⫶ $output->writeln('Always available: ' . ($contentInfo->alwaysAvailable ? 'Yes' : 'No'));

docs/content_management/content_api/browsing_content.md@51:``` php
docs/content_management/content_api/browsing_content.md@52:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 68, 72) =]]
docs/content_management/content_api/browsing_content.md@53:```

001⫶ $locations = $this->locationService->loadLocations($contentInfo);
002⫶
003⫶ foreach ($locations as $location) {
004⫶ $output->writeln('Location: ' . $location->pathString);

docs/content_management/content_api/browsing_content.md@68:``` php
docs/content_management/content_api/browsing_content.md@69:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 68, 71) =]][[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 72, 75) =]]
docs/content_management/content_api/browsing_content.md@70:```

001⫶ $locations = $this->locationService->loadLocations($contentInfo);
002⫶
003⫶ foreach ($locations as $location) {
004⫶ $urlAlias = $this->urlAliasService->reverseLookup($location);
005⫶ $output->writeln('URL alias: ' . $urlAlias->path);
006⫶ }

docs/content_management/content_api/browsing_content.md@77:``` php
docs/content_management/content_api/browsing_content.md@78:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 77, 79) =]]
docs/content_management/content_api/browsing_content.md@79:```

001⫶ $content = $this->contentService->loadContent($contentId);
002⫶ $output->writeln('Content type: ' . $content->getContentType()->getName());

docs/content_management/content_api/browsing_content.md@86:``` php
docs/content_management/content_api/browsing_content.md@87:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 81, 87) =]]
docs/content_management/content_api/browsing_content.md@88:```

001⫶ $versionInfos = $this->contentService->loadVersions($contentInfo);
002⫶ foreach ($versionInfos as $versionInfo) {
003⫶ $output->write("Version $versionInfo->versionNo");
004⫶ $output->write(' by ' . $versionInfo->getCreator()->getName());
005⫶ $output->writeln(' in ' . $versionInfo->getInitialLanguage()->name);
006⫶ }

docs/content_management/content_api/browsing_content.md@93:``` php
docs/content_management/content_api/browsing_content.md@94:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 88, 89) =]]
docs/content_management/content_api/browsing_content.md@95:```

001⫶ $versionInfoArray = iterator_to_array($this->contentService->loadVersions($contentInfo, VersionInfo::STATUS_ARCHIVED));

docs/content_management/content_api/browsing_content.md@109:``` php
docs/content_management/content_api/browsing_content.md@110:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 100, 106) =]]
docs/content_management/content_api/browsing_content.md@110:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 100, 107) =]]
docs/content_management/content_api/browsing_content.md@111:```

001⫶ $versionInfo = $this->contentService->loadVersionInfo($contentInfo);
docs/content_management/content_api/browsing_content.md@111:```

001⫶ $versionInfo = $this->contentService->loadVersionInfo($contentInfo);
002⫶        $relations = $this->contentService->loadRelations($versionInfo);
003⫶ foreach ($relations as $relation) {
004⫶ $name = $relation->destinationContentInfo->name;
005⫶ $output->writeln('Relation to content ' . $name);
006⫶ }

docs/content_management/content_api/browsing_content.md@128:``` php
docs/content_management/content_api/browsing_content.md@129:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 108, 109) =]]
docs/content_management/content_api/browsing_content.md@130:```
002⫶        $relationCount = $this->contentService->countRelations($versionInfo);
003⫶ $relationList = $this->contentService->loadRelationList($versionInfo, 0, $relationCount);
004⫶ foreach ($relationList as $relationListItem) {
005⫶ $name = $relationListItem->hasRelation() ? $relationListItem->getRelation()->destinationContentInfo->name : '(Unauthorized)';
006⫶ $output->writeln("Relation to content '$name'");
007⫶ }

docs/content_management/content_api/browsing_content.md@129:``` php
docs/content_management/content_api/browsing_content.md@130:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 109, 110) =]]
docs/content_management/content_api/browsing_content.md@131:```

001⫶ $output->writeln('Owner: ' . $contentInfo->getOwner()->getName());


001⫶ $output->writeln('Owner: ' . $contentInfo->getOwner()->getName());

docs/content_management/content_api/browsing_content.md@141:``` php
docs/content_management/content_api/browsing_content.md@142:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 111, 112) =]]
docs/content_management/content_api/browsing_content.md@143:```
docs/content_management/content_api/browsing_content.md@142:``` php
docs/content_management/content_api/browsing_content.md@143:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 112, 113) =]]
docs/content_management/content_api/browsing_content.md@144:```

001⫶ $output->writeln('Section: ' . $contentInfo->getSection()->name);


001⫶ $output->writeln('Section: ' . $contentInfo->getSection()->name);

docs/content_management/content_api/browsing_content.md@157:``` php
docs/content_management/content_api/browsing_content.md@158:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 114, 119) =]]
docs/content_management/content_api/browsing_content.md@159:```
docs/content_management/content_api/browsing_content.md@158:``` php
docs/content_management/content_api/browsing_content.md@159:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 115, 120) =]]
docs/content_management/content_api/browsing_content.md@160:```

001⫶ $stateGroups = $this->objectStateService->loadObjectStateGroups();
002⫶ foreach ($stateGroups as $stateGroup) {
003⫶ $state = $this->objectStateService->getContentState($contentInfo, $stateGroup);
004⫶ $output->writeln("Object state: $state->identifier");
005⫶ }


code_samples/front/embed_content/src/Controller/RelationController.php

docs/templating/embed_and_list_content/embed_content.md@39:``` php hl_lines="23 27 28"
docs/templating/embed_and_list_content/embed_content.md@40:[[= include_file('code_samples/front/embed_content/src/Controller/RelationController.php') =]]
docs/templating/embed_and_list_content/embed_content.md@41:```

001⫶<?php declare(strict_types=1);
002⫶
003⫶namespace App\Controller;
004⫶
005⫶use Ibexa\Contracts\Core\Repository\ContentService;
006⫶use Ibexa\Contracts\Core\Repository\LocationService;
007⫶use Ibexa\Core\MVC\Symfony\View\View;
008⫶
009⫶class RelationController
010⫶{
011⫶ private ContentService $contentService;
012⫶
013⫶ private LocationService $locationService;
014⫶
015⫶ public function __construct(ContentService $contentService, LocationService $locationService)
016⫶ {
017⫶ $this->contentService = $contentService;
018⫶ $this->locationService = $locationService;
019⫶ }
020⫶
021⫶ public function showContentAction(View $view, $locationId): View
022⫶ {
023⫸ $acceptedContentTypes = $view->getParameter('accepted_content_types');
024⫶
025⫶ $location = $this->locationService->loadLocation($locationId);
026⫶ $contentInfo = $location->getContentInfo();
027⫸ $versionInfo = $this->contentService->loadVersionInfo($contentInfo);

001⫶ $stateGroups = $this->objectStateService->loadObjectStateGroups();
002⫶ foreach ($stateGroups as $stateGroup) {
003⫶ $state = $this->objectStateService->getContentState($contentInfo, $stateGroup);
004⫶ $output->writeln("Object state: $state->identifier");
005⫶ }


code_samples/front/embed_content/src/Controller/RelationController.php

docs/templating/embed_and_list_content/embed_content.md@39:``` php hl_lines="23 27 28"
docs/templating/embed_and_list_content/embed_content.md@40:[[= include_file('code_samples/front/embed_content/src/Controller/RelationController.php') =]]
docs/templating/embed_and_list_content/embed_content.md@41:```

001⫶<?php declare(strict_types=1);
002⫶
003⫶namespace App\Controller;
004⫶
005⫶use Ibexa\Contracts\Core\Repository\ContentService;
006⫶use Ibexa\Contracts\Core\Repository\LocationService;
007⫶use Ibexa\Core\MVC\Symfony\View\View;
008⫶
009⫶class RelationController
010⫶{
011⫶ private ContentService $contentService;
012⫶
013⫶ private LocationService $locationService;
014⫶
015⫶ public function __construct(ContentService $contentService, LocationService $locationService)
016⫶ {
017⫶ $this->contentService = $contentService;
018⫶ $this->locationService = $locationService;
019⫶ }
020⫶
021⫶ public function showContentAction(View $view, $locationId): View
022⫶ {
023⫸ $acceptedContentTypes = $view->getParameter('accepted_content_types');
024⫶
025⫶ $location = $this->locationService->loadLocation($locationId);
026⫶ $contentInfo = $location->getContentInfo();
027⫸ $versionInfo = $this->contentService->loadVersionInfo($contentInfo);
028⫸        $relations = $this->contentService->loadRelations($versionInfo);
028⫸        $relationList = $this->contentService->loadRelationList($versionInfo);
029⫶
030⫶ $items = [];
031⫶
029⫶
030⫶ $items = [];
031⫶
032⫶        foreach ($relations as $relation) {
033⫶ if (in_array($relation->getDestinationContentInfo()->getContentType()->identifier, $acceptedContentTypes)) {
034⫶ $items[] = $this->contentService->loadContentByContentInfo($relation->getDestinationContentInfo());
032⫶        foreach ($relationList as $relationListItem) {
033⫶ if ($relationListItem->hasRelation() && in_array($relationListItem->getRelation()->getDestinationContentInfo()->getContentType()->identifier, $acceptedContentTypes)) {
034⫶ $items[] = $this->contentService->loadContentByContentInfo($relationListItem->getRelation()->getDestinationContentInfo());
035⫶            }
036⫶ }
037⫶
038⫶ $view->addParameters([
039⫶ 'items' => $items,
040⫶ ]);
041⫶
042⫶ return $view;
043⫶ }
044⫶}

docs/templating/queries_and_controllers/controllers.md@15:``` php
docs/templating/queries_and_controllers/controllers.md@16:[[= include_file('code_samples/front/embed_content/src/Controller/RelationController.php', 2, 9) =]]
docs/templating/queries_and_controllers/controllers.md@17:```

001⫶namespace App\Controller;
002⫶
003⫶use Ibexa\Contracts\Core\Repository\ContentService;
004⫶use Ibexa\Contracts\Core\Repository\LocationService;
005⫶use Ibexa\Core\MVC\Symfony\View\View;
006⫶
007⫶class RelationController

035⫶            }
036⫶ }
037⫶
038⫶ $view->addParameters([
039⫶ 'items' => $items,
040⫶ ]);
041⫶
042⫶ return $view;
043⫶ }
044⫶}

docs/templating/queries_and_controllers/controllers.md@15:``` php
docs/templating/queries_and_controllers/controllers.md@16:[[= include_file('code_samples/front/embed_content/src/Controller/RelationController.php', 2, 9) =]]
docs/templating/queries_and_controllers/controllers.md@17:```

001⫶namespace App\Controller;
002⫶
003⫶use Ibexa\Contracts\Core\Repository\ContentService;
004⫶use Ibexa\Contracts\Core\Repository\LocationService;
005⫶use Ibexa\Core\MVC\Symfony\View\View;
006⫶
007⫶class RelationController

Download colorized diff

Copy link
Contributor

@mnocon mnocon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@adriendupuis adriendupuis merged commit e68a80c into master Nov 27, 2024
6 checks passed
@adriendupuis adriendupuis deleted the update-deprecated branch November 27, 2024 09:17
adriendupuis added a commit that referenced this pull request Nov 27, 2024
loadRelations is deprecated in 4.5, and removed in 5.0

---------

Co-authored-by: Marek Nocoń <[email protected]>
(cherry picked from commit e68a80c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants