Skip to content

listener beforeRules method defined in Behaviour class doesn't support primary key with multiple column #2

@cjeraldop

Description

@cjeraldop

Dear kaihiro,

I finded a problem in listener event on the Behaviour Class. In this method doesn't considered a primary key with multiple column (unlike the trait, if it supports it):

Problem source
I've tracked the problem to this part of:

Lines 32 and 33 of file:
https://github.com/kaihiro/optimistic-lock/blob/master/src/Model/Behavior/OptimisticLockBehavior.php

/**
     * versionが一致しているかをチェックします.
     *
     * DBの最新レコードのversionとフォームのversionが一致しない場合、OptimisticLockExceptionをスローします.
     *
     * @param Event           $event
     * @param EntityInterface $entity
     * @param $options
     * @param $operation
     */
    public function beforeRules(Event $event, EntityInterface $entity, $options, $operation)
    {
        if (isset($entity->{$this->_table->primaryKey()})) {
            $latestEntity = $this->_table->get($entity->{$this->_table->primaryKey()});
            if (!empty($latestEntity)) {
                $postVersion = $entity->get('version');
                $this->postVersion = $postVersion;
                $latestVersion = $latestEntity->get('version');
                if ($postVersion != $latestVersion) {
                    $event->stopPropagation();
                    throw new OptimisticLockException();
                }
            }
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions