Publication time: Monday, March 14, 2016 (8 years ago)

Created by: Семенов Александр Сергеевич

Category: Other

Current version:
Jan 1, 1970, 3:00:00 AM (54 years ago)

Packagist: yii-dream-team/yii2-lockable-activerecord

: https://github.com/yii-dream-team/yii2-lockable-activerecord

:

Type of:

Pessimistic locking behavior for Yii2 ActiveRecord

This package allows you to use pessimistic locking (select for update) when you work with ActiveRecord models.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yii-dream-team/yii2-lockable-activerecord "*"

or add

"yii-dream-team/yii2-lockable-activerecord": "*"

to the require section of your composer.json.

Usage

Attach the behavior to your controller class.

public function behaviors()
{
    return [
        '\yiidreamteam\behaviors\LockableActiveRecord',
    ];
}

Add @mixin phpdoc to you class definition.

/**
 * Class Sample
 * @package common\models
 *
 * @mixin \yiidreamteam\behaviors\LockableActiveRecord
 */
class Sample extends ActiveRecord { ... }

Use model locks in transaction.

$dbTransaction = $model->getDb()->beginTransaction(\yii\db\Transaction::SERIALIZABLE);
try {
    $model->lock();
    $model->doSomethingWhileLocked();
    $dbTransaction->commit();
} catch(\Exception $e) {
    $dbTransaction->rollBack();
    throw $e;
}

Licence

MIT

Links


All Comments (0)
No Comments

dev-master — Jan 1, 1970, 3:00:00 AM (54 years ago)

1.0.5 — Jan 1, 1970, 3:00:00 AM (54 years ago)

1.0.4 — Jan 1, 1970, 3:00:00 AM (54 years ago)

1.0.3 — Jan 1, 1970, 3:00:00 AM (54 years ago)

1.0.2 — Jan 1, 1970, 3:00:00 AM (54 years ago)

1.0.1 — Jan 1, 1970, 3:00:00 AM (54 years ago)

1.0.0 — Jan 1, 1970, 3:00:00 AM (54 years ago)

Стандартная установка:

  1. Установка файлов

    # Download latest version of composer
    curl -sS https://getcomposer.org/installer | COMPOSER_HOME=.composer php
    # Installing the base project SkeekS CMS
    COMPOSER_HOME=.composer php composer.phar create-project --no-install --prefer-dist yii-dream-team/yii2-lockable-activerecord demo.ru
    # Going into the project folder
    cd demo.ru
    # Download latest version of composer in project
    curl -sS https://getcomposer.org/installer | COMPOSER_HOME=.composer php
    # Extra plug-ins
    COMPOSER_HOME=.composer php composer.phar global require fxp/composer-asset-plugin --no-plugins
    # Download dependency
    COMPOSER_HOME=.composer php composer.phar install -o
    # Run the command to initialize the project, the installer executable file and the necessary rights to the directory
    php yii cms/init
  2. Конфигурирование базы данных

    Отредактируйте файл доступа к базе данных, он находится по адресу common/config/db.php

  3. Установка миграций

    php yii dbDumper/mysql/restore

Подробнее про установку написано тут