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

Fix indexing of assets #25

Closed
wants to merge 2 commits into from
Closed

Fix indexing of assets #25

wants to merge 2 commits into from

Conversation

danrot
Copy link
Contributor

@danrot danrot commented Mar 30, 2023

There was already a TYPE_ASSETS constants availabe on the DocumentInterface, but when using it errors were thrown. With these changes it should be possible to index assets as well.

@limenet
Copy link
Member

limenet commented Apr 3, 2023

Assets have a similar listing behavior as documents, hence a few more changes are necessary to get this working:

  • \Valantic\ElasticaBridgeBundle\DocumentType\AbstractDocument::getDocumentType needs to be extended for assets, see below for a sample implementation
  • \Valantic\ElasticaBridgeBundle\DocumentType\Index\ListingTrait::getListingInstance:54 also include assets for changing the listing conditions (just like for documents)

\Valantic\ElasticaBridgeBundle\DocumentType\AbstractDocument::getDocumentType

use Pimcore\Model\Asset as PimcoreAsset;
use Pimcore\Model\Asset\Listing as AssetListing;

    public function getDocumentType(): ?string
    {
        if (!in_array($this->getType(), [DocumentInterface::TYPE_DOCUMENT, DocumentInterface::TYPE_ASSET], true)) {
            return null;
        }

        $candidate = null;

        if ($this->getType() === DocumentInterface::TYPE_DOCUMENT) {
            $candidate = [
                PimcoreDocument\Folder::class => 'folder',
                PimcoreDocument\Page::class => 'page',
                PimcoreDocument\Snippet::class => 'snippet',
                PimcoreDocument\Link::class => 'link',
                PimcoreDocument\Hardlink::class => 'hardlink',
                PimcoreDocument\Email::class => 'email',
                PimcoreDocument\Newsletter::class => 'newsletter',
                PimcoreDocument\Printpage::class => 'printpage',
                PimcoreDocument\Printcontainer::class => 'printcontainer',
            ][$this->getSubType()] ?? null;

            if (!in_array($candidate, PimcoreDocument::getTypes(), true)) {
                throw new UnknownPimcoreElementType($candidate);
            }
        }

        if ($this->getType() === DocumentInterface::TYPE_ASSET) {
            $candidate = [
                PimcoreAsset\Archive::class => 'archive',
                PimcoreAsset\Audio::class => 'audio',
                PimcoreAsset\Document::class => 'document',
                PimcoreAsset\Folder::class => 'folder',
                PimcoreAsset\Image::class => 'image',
                PimcoreAsset\Text::class => 'text',
                PimcoreAsset\Unknown::class => 'unknown',
                PimcoreAsset\Video::class => 'video',
            ][$this->getSubType()] ?? null;

            if (!in_array($candidate, PimcoreAsset::getTypes(), true)) {
                throw new UnknownPimcoreElementType($candidate);
            }
        }

        if ($candidate === null) {
            throw new UnknownPimcoreElementType($candidate);
        }

        return $candidate;
    }

src/DocumentType/AbstractDocument.php Outdated Show resolved Hide resolved
@limenet
Copy link
Member

limenet commented Apr 7, 2023

FYI this is also being worked on in #40

@danrot
Copy link
Contributor Author

danrot commented Apr 11, 2023

@limenet Does it already work there? Does it make sense for me to continue work on that in this PR?

@limenet
Copy link
Member

limenet commented Apr 11, 2023

@danrot yes, it's looking good over there. #40 also includes #26 and #28. Does this work for your needs or do you need PHP 8.0 compatibility? If so, we can backport the changes manually to this MR and tag a 1.x release.

@danrot
Copy link
Contributor Author

danrot commented Apr 11, 2023

That does not work for me, I need PHP 8.0 compatibility. Can you backport it and make a release?

@limenet
Copy link
Member

limenet commented Apr 24, 2023

@danrot does a merge with the current changes work for your use case?

#42 is now pretty much implemented for v2 but a backport for v1 isn't (easily) possible, unfortunately.

@danrot
Copy link
Contributor Author

danrot commented May 2, 2023

@limenet It seems to work, although it is quite tedious and error-prone. But it is good enough and I am happy that there is a proper solution in v2.

@limenet limenet changed the base branch from main to 1.x June 14, 2023 08:48
@limenet
Copy link
Member

limenet commented Sep 18, 2023

This feature has been implemented in the meantime.

@limenet limenet closed this Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants