yii\elasticsearch\ActiveRecord::updateInternal PHP 메소드

updateInternal() 보호된 메소드

또한 보기: update()
protected updateInternal ( array $attributes = null, array $options = [] ) : integer | false
$attributes array attributes to update
$options array options given in this parameter are passed to elasticsearch as request URI parameters. See [[update()]] for details.
리턴 integer | false the number of rows affected, or false if [[beforeSave()]] stops the updating process.
    protected function updateInternal($attributes = null, $options = [])
    {
        if (!$this->beforeSave(false)) {
            return false;
        }
        $values = $this->getDirtyAttributes($attributes);
        if (empty($values)) {
            $this->afterSave(false, $values);
            return 0;
        }
        if (isset($options['optimistic_locking']) && $options['optimistic_locking']) {
            if ($this->_version === null) {
                throw new InvalidParamException('Unable to use optimistic locking on a record that has no version set. Refer to the docs of ActiveRecord::update() for details.');
            }
            $options['version'] = $this->_version;
            unset($options['optimistic_locking']);
        }
        try {
            $result = static::getDb()->createCommand()->update(static::index(), static::type(), $this->getOldPrimaryKey(false), $values, $options);
        } catch (Exception $e) {
            // HTTP 409 is the response in case of failed optimistic locking
            // http://www.elastic.co/guide/en/elasticsearch/guide/current/optimistic-concurrency-control.html
            if (isset($e->errorInfo['responseCode']) && $e->errorInfo['responseCode'] == 409) {
                throw new StaleObjectException('The object being updated is outdated.', $e->errorInfo, $e->getCode(), $e);
            }
            throw $e;
        }
        if (is_array($result) && isset($result['_version'])) {
            $this->_version = $result['_version'];
        }
        $changedAttributes = [];
        foreach ($values as $name => $value) {
            $changedAttributes[$name] = $this->getOldAttribute($name);
            $this->setOldAttribute($name, $value);
        }
        $this->afterSave(false, $changedAttributes);
        if ($result === false) {
            return 0;
        } else {
            return 1;
        }
    }