private function internalUpdate()
    {
        if ($this->triggerEvent(self::EVENT_NAME_BEFORE_UPDATE)->isCancelled()) {
            return;
        }

        // locking
        $query = array('_id' => $this->getId());
        if ($this->getOption('lock') === Definition::LOCK_OPTIMISTIC) {
            $query['__version__'] = $this->get('__version__');
            $this->getOperator()->increment('__version__');
        }

        // update
        try {
            $status = $this
                ->collection
                ->getMongoCollection()
                ->update(
                    $query,
                    $this->getOperator()->toArray()
                );
        } catch (\Exception $e) {
            throw new WriteException(
                $e->getMessage(),
                $e->getCode(),
                $e
            );
        }

        // check update status
        if ($status['ok'] != 1) {
            throw new WriteException(
                sprintf(
                    'Update error: %s: %s',
                    $status['err'],
                    $status['errmsg']
                )
            );
        }

        // check if document modified due to specified lock
        if ($this->getOption('lock') === Definition::LOCK_OPTIMISTIC) {
            if ($status['n'] === 0) {
                throw new OptimisticLockFailureException;
            }
        }

        if ($this->getOperator()->isReloadRequired()) {
            $this->refresh();
        } else {
            $this->getOperator()->reset();
        }

        $this->triggerEvent(self::EVENT_NAME_AFTER_UPDATE);
    }
private function internalUpdate()
    {
        if ($this->triggerEvent(self::EVENT_NAME_BEFORE_UPDATE)->isCancelled()) {
            return;
        }

        // locking
        $query = array('_id' => $this->getId());
        if ($this->getOption('lock') === Definition::LOCK_OPTIMISTIC) {
            $query['__version__'] = $this->get('__version__');
            $this->getOperator()->increment('__version__');
        }

        // update
        try {
            $status = $this
                ->collection
                ->getMongoCollection()
                ->update(
                    $query,
                    $this->getOperator()->toArray()
                );
        } catch (\Exception $e) {
            throw new WriteException(
                $e->getMessage(),
                $e->getCode(),
                $e
            );
        }

        // check update status
        if ($status['ok'] != 1) {
            throw new WriteException(
                sprintf(
                    'Update error: %s: %s',
                    $status['err'],
                    $status['errmsg']
                )
            );
        }

        // check if document modified due to specified lock
        if ($this->getOption('lock') === Definition::LOCK_OPTIMISTIC) {
            if ($status['n'] === 0) {
                throw new OptimisticLockFailureException;
            }
        }

        if ($this->getOperator()->isReloadRequired()) {
            $this->refresh();
        } else {
            $this->getOperator()->reset();
        }

        $this->triggerEvent(self::EVENT_NAME_AFTER_UPDATE);
    }
private function internalUpdate ( ) { if ( $ this -> triggerEvent ( self :: EVENT_NAME_BEFORE_UPDATE ) -> isCancelled ( ) ) { return ; } // locking $ query = array ( '_id' => $ this -> getId ( ) ) ; if ( $ this -> getOption ( 'lock' ) === Definition :: LOCK_OPTIMISTIC ) { $ query [ '__version__' ] = $ this -> get ( '__version__' ) ; $ this -> getOperator ( ) -> increment ( '__version__' ) ; } // update try { $ status = $ this -> collection -> getMongoCollection ( ) -> update ( $ query , $ this -> getOperator ( ) -> toArray ( ) ) ; } catch ( \ Exception $ e ) { throw new WriteException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } // check update status if ( $ status [ 'ok' ] != 1 ) { throw new WriteException ( sprintf ( 'Update error: %s: %s' , $ status [ 'err' ] , $ status [ 'errmsg' ] ) ) ; } // check if document modified due to specified lock if ( $ this -> getOption ( 'lock' ) === Definition :: LOCK_OPTIMISTIC ) { if ( $ status [ 'n' ] === 0 ) { throw new OptimisticLockFailureException ; } } if ( $ this -> getOperator ( ) -> isReloadRequired ( ) ) { $ this -> refresh ( ) ; } else { $ this -> getOperator ( ) -> reset ( ) ; } $ this -> triggerEvent ( self :: EVENT_NAME_AFTER_UPDATE ) ; }
Internal method to update document

@throws WriteException
@throws OptimisticLockFailureException
Internal method to update document