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

5.0: Use RelationListIterator #2548

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft

Conversation

adriendupuis
Copy link
Contributor

@adriendupuis adriendupuis commented Nov 20, 2024

Question Answer
JIRA Ticket N/A
Versions 5.0
Edition All

To get all relations, use RelationListIteratorAdapter + BatchIterator instead of ContentService::countRelations() + ContentService::loadRelationList()

Follows #2544 and in particular this comment.

Previews:

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 added the Wait with merge PRs that shouldn't be merged instantly label Nov 21, 2024
# Conflicts:
#	code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php
#	code_samples/front/embed_content/src/Controller/RelationController.php
#	docs/content_management/content_api/browsing_content.md
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will be removed from this PR when PHP API Ref will be generated with first 5.0.0 stable release.

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) =]]

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@32:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 18, 19) =]]
docs/content_management/content_api/browsing_content.md@33:// ...
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@34:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 52, 54) =]][[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 60, 61) =]]
docs/content_management/content_api/browsing_content.md@35:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 62, 68) =]]
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@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@52:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 70, 74) =]]
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@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@69:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 70, 73) =]][[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 74, 77) =]]
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@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@78:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 79, 81) =]]
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@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@87:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 83, 90) =]]
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@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@94:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 90, 91) =]]
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@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, 107) =]]
docs/content_management/content_api/browsing_content.md@111:```
docs/content_management/content_api/browsing_content.md@110:``` php
docs/content_management/content_api/browsing_content.md@111:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 102, 113) =]]
docs/content_management/content_api/browsing_content.md@112:```

001⫶ $versionInfo = $this->contentService->loadVersionInfo($contentInfo);

001⫶ $versionInfo = $this->contentService->loadVersionInfo($contentInfo);
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:```
002⫶        $relationListIterator = new BatchIterator(
003⫶ new RelationListIteratorAdapter(
004⫶ $this->contentService,
005⫶ $versionInfo
006⫶ )
007⫶ );
008⫶ foreach ($relationListIterator as $relationListItem) {
009⫶ $name = $relationListItem->hasRelation() ? $relationListItem->getRelation()->destinationContentInfo->name : '(Unauthorized)';
010⫶ $output->writeln("Relation to content '$name'");
011⫶ }

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

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


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

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:```
docs/content_management/content_api/browsing_content.md@143:``` php
docs/content_management/content_api/browsing_content.md@144:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 118, 119) =]]
docs/content_management/content_api/browsing_content.md@145:```

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


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

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:```
docs/content_management/content_api/browsing_content.md@159:``` php
docs/content_management/content_api/browsing_content.md@160:[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 121, 126) =]]
docs/content_management/content_api/browsing_content.md@161:```

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⫶ }


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⫶ }

Download colorized diff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Wait with merge PRs that shouldn't be merged instantly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant