Skip to content

[Elastica] Error The message data misses id when remove in PostFlush #913

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

Closed
aumel opened this issue Jul 11, 2019 · 3 comments · Fixed by php-enqueue/enqueue-elastica-bundle#22
Labels

Comments

@aumel
Copy link

aumel commented Jul 11, 2019

The problem is related to my last accepted PR php-enqueue/enqueue-elastica-bundle#21

The sendUpdateIndexMessage is now invoked in PostFlush. Unfortunately, the $object = $args->getObject(); has an ID null in PostFlush in a remove context.

IMO, a good solution would be to handle only ID in method sendUpdateIndexMessage and implement new method extractId.

I am working on new PR to fix this.

...
public function preRemove(LifecycleEventArgs $args)
    {
        if ($args->getObject() instanceof $this->modelClass) {
            $this->scheduledForUpdateIndex[] = [
                'action' => SyncProcessor::REMOVE_ACTION,
                'id' => $this->extractId($args->getObject())
            ];
        }
    }
...
    /**
     * @param string $action
     * @param $id
     */
    private function sendUpdateIndexMessage($action, $id)
    {
        $queue = $this->context->createQueue(Commands::SYNC_INDEX_WITH_OBJECT_CHANGE);

        $message = $this->context->createMessage(JSON::encode([
            'action' => $action,
            'model_class' => $this->modelClass,
            'model_id' => $this->config['model_id'],
            'id' => $id,
            'index_name' => $this->config['index_name'],
            'type_name' => $this->config['type_name'],
            'repository_method' => $this->config['repository_method'],
        ]));

        $this->context->createProducer()->send($queue, $message);
    }

    /**
     * @param $object
     * @return mixed
     */
    private function extractId($object)
    {
        $rp = new \ReflectionProperty($object, $this->config['model_id']);
        $rp->setAccessible(true);
        $id = $rp->getValue($object);
        $rp->setAccessible(false);

        return $id;
    }
@stale
Copy link

stale bot commented Aug 11, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Aug 11, 2019
@aumel
Copy link
Author

aumel commented Aug 12, 2019

Hi stale bot :), The problem still exists on the master of enqueue-elastica-bundle.
Problem fixed in pending pull-request php-enqueue/enqueue-elastica-bundle#22

@stale stale bot removed the wontfix label Aug 12, 2019
@stale
Copy link

stale bot commented Sep 11, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Sep 11, 2019
@stale stale bot closed this as completed Sep 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant