Skip to content

Error applying draft #67

@mikeymeister

Description

@mikeymeister

We are getting the following error when trying to apply a draft on a craft 5.7.6 site with typesense 5.7.2.1:

percipiolondon\typesense\controllers\DocumentsController::handleSave(): Argument #1 ($entry) must be of type craft\elements\Entry, null given, called in /var/www/html/vendor/craftpulse/craft-typesense/src/controllers/DocumentsController.php on line 66

It looks like the entry query isn't finding the draft. I'm not sure if it should or shouldn't find an entry that is a draft, but perhaps an addition that doesn't call the handleSave function unless there is an entry returned? Changing this:

if ($event->name === Elements::EVENT_AFTER_RESTORE_ELEMENT || $event->name === Structures::EVENT_AFTER_MOVE_ELEMENT) {
    foreach($element->getSupportedSites() as $site) {
        if ($site['siteId'] ?? null) {
            $entry = Entry::find()->id($element->id)->siteId($site['siteId'])->one();
            $this->handleSave($entry);
        }
    }
}

to

if ($event->name === Elements::EVENT_AFTER_RESTORE_ELEMENT || $event->name === Structures::EVENT_AFTER_MOVE_ELEMENT) {
    foreach($element->getSupportedSites() as $site) {
        if ($site['siteId'] ?? null) {
            $entry = Entry::find()->id($element->id)->siteId($site['siteId'])->one();
            if ($entry) {
                $this->handleSave($entry);
            }
        }
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions