Increment votes for given model
@param ActiveRecord $model
@param string $type of vote, up or down
@return ActiveRecord
540308
public static function process(ActiveRecord $model, $type)
    {
        $value = self::value($type);

        if (isset($model['votes'])) {
            $model['votes'] += $value;

            $vote = new self([
                'entity_id' => $model['id'],
                'vote' => $value,
                'entity' => self::modelEntityType($model)
            ]);

            if ($vote->save() && $model->save()) {
                return $model;
            }
        }

        return false;
    }
574713
public function next($model, $category_id = null, array $with = [], $all = false)
    {
        return $this->adjacent(1, $model, $category_id, $with, $all);
    }
192383
public function vote($item, $type = 'up_vote')
    {
        $items = array_fill_keys((array) $this->checkVoteItem($item), ['type' => $type]);

        return $this->votedItems()->sync($items, false);
    }
1362982
public static function findRelatedElement(Model $model, $type=null)
	{
		if($model->bootstrap_parentId == '' && $model->getType() != $model::TYPE_START) {
			return null;
		}

		$options = array(
			'order' => 'sorting'
		);

		if($type === null) {
			$column   = 'bootstrap_parentId';
			$values[] = $model->id;
		}
		else {
			$column   = array('bootstrap_parentId=? ', 'type=?');
			$values[] = $model->id;
			$values[] = $model->getTypeName($type);

		}

		return \ContentModel::findOneBy($column, $values, $options);
	}
911515
public function set($models)
    {
        if ($models instanceof ActiveRecord) {
            $models = [$models];
        }

        $first = reset($models);
        if ($first === false) {
            return $this;
        }
        $this->first = $first;

        $this->formName = $first->formName();
        $this->model    = $this->setModel($first);
        $this->models   = $models;

        if ($this->checkConsistency && !$this->isConsistent()) {
            throw new InvalidValueException('Models are not objects of same class or not follow same operation');
        }

        return $this;
    }
700689
public function setBelongsToData(Model $model) {
        $typeAhead = array();

        foreach ($model->belongsTo as $alias => $assoc) {
            $object = Admin::introspectModel($assoc['className']);
            $count = $this->getRecordCount($object);

            // Add to type ahead if too many records
            if (!$count || $count > $object->admin['associationLimit']) {
                $class = $assoc['className'];

                if (mb_strpos($class, '.') === false) {
                    $class = Configure::read('Admin.coreName') . '.' . $class;
                }

                // Get the foreign key from the child -> parent
                $foreignKey = null;

                foreach ($object->belongsTo as $childAssoc) {
                    if ($childAssoc['className'] === $model->name) {
                        $foreignKey = $childAssoc['foreignKey'];
                        break;
                    }
                }

                $typeAhead[$assoc['foreignKey']] = array(
                    'alias' => $alias,
                    'model' => $class,
                    'foreignKey' => $foreignKey
                );

            } else {
                $variable = Inflector::variable(Inflector::pluralize(preg_replace('/(?:_id)$/', '', $assoc['foreignKey'])));

                $this->Controller->set($variable, $this->getRecordList($object));
            }
        }

        $this->Controller->set('typeAhead', $typeAhead);
    }
131333
public function update(Record $model)
    {
        $query = $this->updateQuery($model);

        if ($query) {
            return $query->execute();
        }

        return false;
    }
1141763
public function save(Record $model)
    {
        $pk = $this->getPrimaryKey();

        if (isset($model->{$pk})) {
            $model->update();

            return $model->{$pk};
        } else {
            /** @var Record $previous */
            $previous = $model->exists();

            if ($previous) {
                $data = $model->toArray();

                if ($data) {
                    $previous->writeData($model->toArray());
                }
                $previous->update();

                $model->writeData($previous->toArray());

                return $model->getPrimaryKey();
            }
        }

        $model->insert();

        return $model->getPrimaryKey();
    }
766059
protected function getCacheKey(Model $model, $type, $allowed = true)
    {
        return implode('-', [
            $this->tag(),
            $type,
            $model->getMorphClass(),
            $model->getKey(),
            $allowed ? 'a' : 'f',
        ]);
    }
1180007
private function update($model)
    {
        $attrs = $this->getMutableAttributes($model);
        $values = array_values($attrs);
        $values[] = $model->{$this->key};
        $this->db
            ->connect()
            ->update($this->table, array_keys($attrs))
            ->where($this->key . ' = ?')
            ->execute($values);
    }
78485
public function associate($model)
    {
        $this->parent->setAttribute($this->foreignKey, $model->getKey());

        $this->parent->setAttribute($this->morphType, $model->getMorphClass());

        return $this->parent->setRelation($this->relation, $model);
    }
835174
public function sortAction($field, $type)
    {
        $this->setOrder('measureunit', $field, $type);

        return $this->redirect($this->generateUrl('admin_shop_measure_unit'));
    }
119946
public function count($model)
    {
        $method = 'search_count';

        $condition = $this->condition ?: [[]];

        $result = $this->call($model, $method, $condition);

        //Reset params for future queries.
        $this->resetParams('condition');

        return $this->makeResponse($result, 0);

    }
961206
public function register(ActiveRecord $model)
    {
        /* @var $seo Seo */
        $seo = $model->seo;
        if ($seo->title) {
            Yii::$app->seo->setTitle($seo->title);
        }
        if ($seo->h1) {
            Yii::$app->seo->setH1($seo->h1);
        }
        if ($seo->description) {
            Yii::$app->seo->setDescription($seo->description);
        }
        if ($seo->keywords) {
            Yii::$app->seo->setKeywords($seo->keywords);
        }
        if ($seo->text) {
            Yii::$app->seo->setText($seo->text);
        }
        if ($seo->og_image) {
            Yii::$app->seo->setOgImage($seo->og_image);
        }
        if (Yii::$app->has('openGraph')) {
            Yii::$app->openGraph->title = Yii::$app->seo->getTitle();
            if (Yii::$app->seo->getDescription()) {
                Yii::$app->openGraph->description = Yii::$app->seo->getDescription();
            }
            if (Yii::$app->seo->getOgImage()) {
                $image = Module::twigCompile($seo->og_image, [
                    'model' => $model
                ]);
                Yii::$app->openGraph->image = Url::to($image, true);
            }
        }
    }
1265567
protected function insertModelAsFirstRoot(Model &$model)
    {
        /** @var \T4\Orm\Model $class */
        $class = get_class($model);
        $tableName = $class::getTableName();
        /** @var \T4\Dbal\Connection $connection */
        $connection = $class::getDbConnection();

        $query = (new Query())
            ->select('MIN(__lft)')->from($tableName);
        $minLft = (int)$connection->query($query)->fetchScalar();

        $width = $model->getTreeWidth();
        $this->expandTreeBeforeLft($connection, $tableName, $minLft, $width);

        if (!$model->isNew()) {
            $model->refreshTreeColumns();
            $query = (new Query("
                UPDATE `" . $tableName . "`
                SET
                    `__lft` = `__lft` - :lft + :min,
                    `__rgt` = `__rgt` - :lft + :min,
                    `__lvl` = `__lvl` - :lvl
                WHERE `__lft` >= :lft AND `__rgt` <= :rgt
                "))
                ->params([':min' => $minLft, ':width'=> $width, ':lft' => $model->__lft, ':rgt' => $model->__rgt, ':lvl' => $model->__lvl]);
            $connection->execute($query);
            $this->removeFromTreeByElement($model);
        }

        $model->__lft = $minLft;
        $model->__rgt = $model->__lft + $width;
        $model->__lvl = 0;
        $model->__prt = 0;
    }
1348908
protected static function decrementNextNodes(ActiveRecordInterface $row)
    {
        $old = $row::findByPK($row->getRoleValue('id'));
        if ($next = static::findNextNeighbour($old)) {
            $sortIndex = $row->getRoleField('sort-index');
            $skew = $next->getRoleValue('sort-index') - $old->getRoleValue('sort-index');
            $row::query()->update([
                $sortIndex => QueryExpression::math(['@' . $sortIndex, '-', $skew])
            ], QueryCriteria::createAND(static::getNeighbourCondition($old, '>')))
            ->execute();
        }
    }
47729
function increment(type, version) {
  debug(`incrementing ${version} by ${type}`);

  let [major, minor, patch] = version
    .replace('v', '')
    .split('.')
    .map((v) => parseInt(v, 10));

  if (major === 0) {
    switch (type) {
      case 'major':
        minor += 1;
        patch = 0;
        break;
      case 'minor':
        patch += 1;
        break;
      case 'patch':
        patch += 1;
        break;
      default:
        throw new Error('unrecognized change type');
    }
  }
  else {
    switch (type) {
      case 'major':
        major += 1;
        minor = 0;
        patch = 0;
        break;
      case 'minor':
        minor += 1;
        patch = 0;
        break;
      case 'patch':
        patch += 1;
        break;
      default:
        throw new Error('unrecognized change type');
    }
  }

  return `${major}.${minor}.${patch}`;
}