Heure de publication: lundi 14 mars 2016 (il y a 3 ans)

Créé par: Семенов Александр Сергеевич

Catégorie: Autre

Version actuelle: 1.0.5
3 août 2017 12:15:38 (il y a 2 ans)

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

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

: 14963 (Par mois: 1602)

Type:

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


Tous les commentaires (0)
Sans commentaires

dev-master — 3 août 2017 12:15:38 (il y a 2 ans)

1.0.5 — 3 août 2017 12:15:38 (il y a 2 ans)

1.0.4 — 29 sept. 2015 07:48:44 (il y a 3 ans)

1.0.2 — 16 juil. 2015 12:19:19 (il y a 4 ans)

1.0.3 — 16 juil. 2015 12:19:19 (il y a 4 ans)

1.0.1 — 16 juil. 2015 11:32:55 (il y a 4 ans)

1.0.0 — 23 mars 2015 13:58:07 (il y a 4 ans)

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

  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

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