ActiveRecord.php 18.6 KB
Newer Older
w  
Qiang Xue committed
1 2 3 4
<?php
/**
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @link http://www.yiiframework.com/
Qiang Xue committed
5
 * @copyright Copyright (c) 2008 Yii Software LLC
w  
Qiang Xue committed
6 7 8
 * @license http://www.yiiframework.com/license/
 */

Qiang Xue committed
9
namespace yii\db;
w  
Qiang Xue committed
10

Qiang Xue committed
11
use yii\base\InvalidConfigException;
12
use yii\helpers\Inflector;
13
use yii\helpers\StringHelper;
w  
Qiang Xue committed
14

w  
Qiang Xue committed
15
/**
Qiang Xue committed
16
 * ActiveRecord is the base class for classes representing relational data in terms of objects.
w  
Qiang Xue committed
17
 *
Qiang Xue committed
18
 * @include @yii/db/ActiveRecord.md
w  
Qiang Xue committed
19
 *
Qiang Xue committed
20
 * @author Qiang Xue <qiang.xue@gmail.com>
21
 * @author Carsten Brandt <mail@cebe.cc>
Qiang Xue committed
22
 * @since 2.0
w  
Qiang Xue committed
23
 */
24
class ActiveRecord extends BaseActiveRecord
w  
Qiang Xue committed
25
{
26
	/**
27
	 * The insert operation. This is mainly used when overriding [[transactions()]] to specify which operations are transactional.
28
	 */
29
	const OP_INSERT = 0x01;
30
	/**
31
	 * The update operation. This is mainly used when overriding [[transactions()]] to specify which operations are transactional.
32
	 */
33
	const OP_UPDATE = 0x02;
34
	/**
35
	 * The delete operation. This is mainly used when overriding [[transactions()]] to specify which operations are transactional.
36
	 */
37 38 39 40 41 42
	const OP_DELETE = 0x04;
	/**
	 * All three operations: insert, update, delete.
	 * This is a shortcut of the expression: OP_INSERT | OP_UPDATE | OP_DELETE.
	 */
	const OP_ALL = 0x07;
43

Qiang Xue committed
44 45 46 47 48 49
	/**
	 * Returns the database connection used by this AR class.
	 * By default, the "db" application component is used as the database connection.
	 * You may override this method if you want to use a different database connection.
	 * @return Connection the database connection used by this AR class.
	 */
Qiang Xue committed
50
	public static function getDb()
Qiang Xue committed
51
	{
Qiang Xue committed
52
		return \Yii::$app->getDb();
Qiang Xue committed
53 54
	}

Qiang Xue committed
55
	/**
Qiang Xue committed
56 57 58 59 60 61 62 63 64 65 66 67 68
	 * Creates an [[ActiveQuery]] instance with a given SQL statement.
	 *
	 * Note that because the SQL statement is already specified, calling additional
	 * query modification methods (such as `where()`, `order()`) on the created [[ActiveQuery]]
	 * instance will have no effect. However, calling `with()`, `asArray()` or `indexBy()` is
	 * still fine.
	 *
	 * Below is an example:
	 *
	 * ~~~
	 * $customers = Customer::findBySql('SELECT * FROM tbl_customer')->all();
	 * ~~~
	 *
Qiang Xue committed
69 70
	 * @param string $sql the SQL statement to be executed
	 * @param array $params parameters to be bound to the SQL statement during execution.
Qiang Xue committed
71
	 * @return ActiveQuery the newly created [[ActiveQuery]] instance
Qiang Xue committed
72
	 */
Alexander Makarov committed
73
	public static function findBySql($sql, $params = [])
w  
Qiang Xue committed
74
	{
Qiang Xue committed
75
		$query = static::createQuery();
Qiang Xue committed
76 77 78 79 80 81
		$query->sql = $sql;
		return $query->params($params);
	}

	/**
	 * Updates the whole table using the provided attribute values and conditions.
Qiang Xue committed
82 83 84
	 * For example, to change the status to be 1 for all customers whose status is 2:
	 *
	 * ~~~
Alexander Makarov committed
85
	 * Customer::updateAll(['status' => 1], 'status = 2');
Qiang Xue committed
86 87 88 89
	 * ~~~
	 *
	 * @param array $attributes attribute values (name-value pairs) to be saved into the table
	 * @param string|array $condition the conditions that will be put in the WHERE part of the UPDATE SQL.
Qiang Xue committed
90
	 * Please refer to [[Query::where()]] on how to specify this parameter.
resurtm committed
91
	 * @param array $params the parameters (name => value) to be bound to the query.
Qiang Xue committed
92 93
	 * @return integer the number of rows updated
	 */
Alexander Makarov committed
94
	public static function updateAll($attributes, $condition = '', $params = [])
w  
Qiang Xue committed
95
	{
Qiang Xue committed
96
		$command = static::getDb()->createCommand();
Qiang Xue committed
97 98
		$command->update(static::tableName(), $attributes, $condition, $params);
		return $command->execute();
w  
Qiang Xue committed
99 100
	}

Qiang Xue committed
101
	/**
Qiang Xue committed
102 103 104 105
	 * Updates the whole table using the provided counter changes and conditions.
	 * For example, to increment all customers' age by 1,
	 *
	 * ~~~
Alexander Makarov committed
106
	 * Customer::updateAllCounters(['age' => 1]);
Qiang Xue committed
107 108
	 * ~~~
	 *
Qiang Xue committed
109
	 * @param array $counters the counters to be updated (attribute name => increment value).
Qiang Xue committed
110 111
	 * Use negative values if you want to decrement the counters.
	 * @param string|array $condition the conditions that will be put in the WHERE part of the UPDATE SQL.
Qiang Xue committed
112
	 * Please refer to [[Query::where()]] on how to specify this parameter.
resurtm committed
113
	 * @param array $params the parameters (name => value) to be bound to the query.
Qiang Xue committed
114
	 * Do not name the parameters as `:bp0`, `:bp1`, etc., because they are used internally by this method.
Qiang Xue committed
115 116
	 * @return integer the number of rows updated
	 */
Alexander Makarov committed
117
	public static function updateAllCounters($counters, $condition = '', $params = [])
w  
Qiang Xue committed
118
	{
Qiang Xue committed
119
		$n = 0;
Qiang Xue committed
120
		foreach ($counters as $name => $value) {
Alexander Makarov committed
121
			$counters[$name] = new Expression("[[$name]]+:bp{$n}", [":bp{$n}" => $value]);
Qiang Xue committed
122
			$n++;
Qiang Xue committed
123
		}
124
		$command = static::getDb()->createCommand();
Qiang Xue committed
125 126
		$command->update(static::tableName(), $counters, $condition, $params);
		return $command->execute();
w  
Qiang Xue committed
127 128
	}

Qiang Xue committed
129 130
	/**
	 * Deletes rows in the table using the provided conditions.
Qiang Xue committed
131 132 133 134 135 136 137 138 139
	 * WARNING: If you do not specify any condition, this method will delete ALL rows in the table.
	 *
	 * For example, to delete all customers whose status is 3:
	 *
	 * ~~~
	 * Customer::deleteAll('status = 3');
	 * ~~~
	 *
	 * @param string|array $condition the conditions that will be put in the WHERE part of the DELETE SQL.
Qiang Xue committed
140
	 * Please refer to [[Query::where()]] on how to specify this parameter.
resurtm committed
141
	 * @param array $params the parameters (name => value) to be bound to the query.
Qiang Xue committed
142
	 * @return integer the number of rows deleted
Qiang Xue committed
143
	 */
Alexander Makarov committed
144
	public static function deleteAll($condition = '', $params = [])
w  
Qiang Xue committed
145
	{
Qiang Xue committed
146
		$command = static::getDb()->createCommand();
Qiang Xue committed
147 148
		$command->delete(static::tableName(), $condition, $params);
		return $command->execute();
w  
Qiang Xue committed
149 150
	}

.  
Qiang Xue committed
151
	/**
Qiang Xue committed
152
	 * Creates an [[ActiveQuery]] instance.
153
	 *
154
	 * This method is called by [[find()]], [[findBySql()]] to start a SELECT query.
Qiang Xue committed
155 156
	 * You may override this method to return a customized query (e.g. `CustomerQuery` specified
	 * written for querying `Customer` purpose.)
157 158 159 160 161 162 163 164 165 166 167 168 169
	 *
	 * You may also define default conditions that should apply to all queries unless overridden:
	 *
	 * ```php
	 * public static function createQuery()
	 * {
	 *     return parent::createQuery()->where(['deleted' => false]);
	 * }
	 * ```
	 *
	 * Note that all queries should use [[Query::andWhere()]] and [[Query::orWhere()]] to keep the
	 * default condition. Using [[Query::where()]] will override the default condition.
	 *
Qiang Xue committed
170
	 * @return ActiveQuery the newly created [[ActiveQuery]] instance.
.  
Qiang Xue committed
171
	 */
Qiang Xue committed
172
	public static function createQuery()
w  
Qiang Xue committed
173
	{
Alexander Makarov committed
174
		return new ActiveQuery(['modelClass' => get_called_class()]);
w  
Qiang Xue committed
175 176 177
	}

	/**
Qiang Xue committed
178
	 * Declares the name of the database table associated with this AR class.
179
	 * By default this method returns the class name as the table name by calling [[Inflector::camel2id()]]
Qiang Xue committed
180 181
	 * with prefix 'tbl_'. For example, 'Customer' becomes 'tbl_customer', and 'OrderItem' becomes
	 * 'tbl_order_item'. You may override this method if the table is not named after this convention.
w  
Qiang Xue committed
182 183
	 * @return string the table name
	 */
Qiang Xue committed
184
	public static function tableName()
w  
Qiang Xue committed
185
	{
186
		return 'tbl_' . Inflector::camel2id(StringHelper::basename(get_called_class()), '_');
w  
Qiang Xue committed
187 188 189
	}

	/**
Qiang Xue committed
190 191
	 * Returns the schema information of the DB table associated with this AR class.
	 * @return TableSchema the schema information of the DB table associated with this AR class.
192
	 * @throws InvalidConfigException if the table for the AR class does not exist.
w  
Qiang Xue committed
193
	 */
Qiang Xue committed
194
	public static function getTableSchema()
w  
Qiang Xue committed
195
	{
196 197 198 199 200 201
		$schema = static::getDb()->getTableSchema(static::tableName());
		if ($schema !== null) {
			return $schema;
		} else {
			throw new InvalidConfigException("The table does not exist: " . static::tableName());
		}
w  
Qiang Xue committed
202 203 204
	}

	/**
Qiang Xue committed
205 206
	 * Returns the primary key name(s) for this AR class.
	 * The default implementation will return the primary key(s) as declared
Qiang Xue committed
207
	 * in the DB table that is associated with this AR class.
Qiang Xue committed
208
	 *
Qiang Xue committed
209 210 211
	 * If the DB table does not declare any primary key, you should override
	 * this method to return the attributes that you want to use as primary keys
	 * for this AR class.
Qiang Xue committed
212 213 214
	 *
	 * Note that an array should be returned even for a table with single primary key.
	 *
Qiang Xue committed
215
	 * @return string[] the primary keys of the associated database table.
w  
Qiang Xue committed
216
	 */
Qiang Xue committed
217
	public static function primaryKey()
w  
Qiang Xue committed
218
	{
Qiang Xue committed
219
		return static::getTableSchema()->primaryKey;
w  
Qiang Xue committed
220 221
	}

222
	/**
223 224 225
	 * Returns the list of all attribute names of the model.
	 * The default implementation will return all column names of the table associated with this AR class.
	 * @return array list of attribute names.
226
	 */
227
	public function attributes()
228
	{
229
		return array_keys(static::getTableSchema()->columns);
230 231
	}

232 233 234 235 236 237 238 239 240 241 242
	/**
	 * Declares which DB operations should be performed within a transaction in different scenarios.
	 * The supported DB operations are: [[OP_INSERT]], [[OP_UPDATE]] and [[OP_DELETE]],
	 * which correspond to the [[insert()]], [[update()]] and [[delete()]] methods, respectively.
	 * By default, these methods are NOT enclosed in a DB transaction.
	 *
	 * In some scenarios, to ensure data consistency, you may want to enclose some or all of them
	 * in transactions. You can do so by overriding this method and returning the operations
	 * that need to be transactional. For example,
	 *
	 * ~~~
Alexander Makarov committed
243
	 * return [
244 245 246 247 248
	 *     'admin' => self::OP_INSERT,
	 *     'api' => self::OP_INSERT | self::OP_UPDATE | self::OP_DELETE,
	 *     // the above is equivalent to the following:
	 *     // 'api' => self::OP_ALL,
	 *
Alexander Makarov committed
249
	 * ];
250 251 252 253 254 255 256 257 258 259 260
	 * ~~~
	 *
	 * The above declaration specifies that in the "admin" scenario, the insert operation ([[insert()]])
	 * should be done in a transaction; and in the "api" scenario, all the operations should be done
	 * in a transaction.
	 *
	 * @return array the declarations of transactional operations. The array keys are scenarios names,
	 * and the array values are the corresponding transaction operations.
	 */
	public function transactions()
	{
Alexander Makarov committed
261
		return [];
262 263
	}

264 265 266 267 268 269 270
	/**
	 * Creates an [[ActiveRelation]] instance.
	 * This method is called by [[hasOne()]] and [[hasMany()]] to create a relation instance.
	 * You may override this method to return a customized relation.
	 * @param array $config the configuration passed to the ActiveRelation class.
	 * @return ActiveRelation the newly created [[ActiveRelation]] instance.
	 */
271
	public static function createActiveRelation($config = [])
272 273
	{
		return new ActiveRelation($config);
Qiang Xue committed
274 275
	}

Qiang Xue committed
276
	/**
Qiang Xue committed
277 278 279 280 281 282
	 * Inserts a row into the associated database table using the attribute values of this record.
	 *
	 * This method performs the following steps in order:
	 *
	 * 1. call [[beforeValidate()]] when `$runValidation` is true. If validation
	 *    fails, it will skip the rest of the steps;
283 284
	 * 2. call [[afterValidate()]] when `$runValidation` is true.
	 * 3. call [[beforeSave()]]. If the method returns false, it will skip the
Qiang Xue committed
285
	 *    rest of the steps;
286 287
	 * 4. insert the record into database. If this fails, it will skip the rest of the steps;
	 * 5. call [[afterSave()]];
Qiang Xue committed
288
	 *
289
	 * In the above step 1, 2, 3 and 5, events [[EVENT_BEFORE_VALIDATE]],
Qiang Xue committed
290 291
	 * [[EVENT_BEFORE_INSERT]], [[EVENT_AFTER_INSERT]] and [[EVENT_AFTER_VALIDATE]]
	 * will be raised by the corresponding methods.
Qiang Xue committed
292
	 *
293
	 * Only the [[dirtyAttributes|changed attribute values]] will be inserted into database.
Qiang Xue committed
294 295
	 *
	 * If the table's primary key is auto-incremental and is null during insertion,
Qiang Xue committed
296
	 * it will be populated with the actual value after insertion.
Qiang Xue committed
297 298 299 300 301 302 303 304 305 306 307 308
	 *
	 * For example, to insert a customer record:
	 *
	 * ~~~
	 * $customer = new Customer;
	 * $customer->name = $name;
	 * $customer->email = $email;
	 * $customer->insert();
	 * ~~~
	 *
	 * @param boolean $runValidation whether to perform validation before saving the record.
	 * If the validation fails, the record will not be inserted into the database.
Qiang Xue committed
309 310 311
	 * @param array $attributes list of attributes that need to be saved. Defaults to null,
	 * meaning all attributes that are loaded from DB will be saved.
	 * @return boolean whether the attributes are valid and the record is inserted successfully.
312
	 * @throws \Exception in case insert failed.
Qiang Xue committed
313
	 */
Qiang Xue committed
314
	public function insert($runValidation = true, $attributes = null)
Qiang Xue committed
315
	{
316 317 318 319
		if ($runValidation && !$this->validate($attributes)) {
			return false;
		}
		$db = static::getDb();
Qiang Xue committed
320 321 322 323
		if ($this->isTransactional(self::OP_INSERT) && $db->getTransaction() === null) {
			$transaction = $db->beginTransaction();
			try {
				$result = $this->insertInternal($attributes);
resurtm committed
324
				if ($result === false) {
325 326 327 328
					$transaction->rollback();
				} else {
					$transaction->commit();
				}
Qiang Xue committed
329
			} catch (\Exception $e) {
330
				$transaction->rollback();
Qiang Xue committed
331
				throw $e;
332
			}
Qiang Xue committed
333 334
		} else {
			$result = $this->insertInternal($attributes);
335 336 337 338 339 340 341
		}
		return $result;
	}

	/**
	 * @see ActiveRecord::insert()
	 */
resurtm committed
342
	private function insertInternal($attributes = null)
343 344
	{
		if (!$this->beforeSave(true)) {
Qiang Xue committed
345 346
			return false;
		}
347 348
		$values = $this->getDirtyAttributes($attributes);
		if (empty($values)) {
349 350
			foreach ($this->getPrimaryKey(true) as $key => $value) {
				$values[$key] = $value;
Qiang Xue committed
351
			}
352 353 354
		}
		$db = static::getDb();
		$command = $db->createCommand()->insert($this->tableName(), $values);
355 356 357 358 359 360
		if (!$command->execute()) {
			return false;
		}
		$table = $this->getTableSchema();
		if ($table->sequenceName !== null) {
			foreach ($table->primaryKey as $name) {
361 362 363 364
				if ($this->getAttribute($name) === null) {
					$id = $db->getLastInsertID($table->sequenceName);
					$this->setAttribute($name, $id);
					$this->setOldAttribute($name, $id);
365
					break;
Qiang Xue committed
366 367 368
				}
			}
		}
369
		foreach ($values as $name => $value) {
370
			$this->setOldAttribute($name, $value);
371 372 373
		}
		$this->afterSave(true);
		return true;
Qiang Xue committed
374 375 376
	}

	/**
Qiang Xue committed
377 378 379 380 381 382
	 * Saves the changes to this active record into the associated database table.
	 *
	 * This method performs the following steps in order:
	 *
	 * 1. call [[beforeValidate()]] when `$runValidation` is true. If validation
	 *    fails, it will skip the rest of the steps;
383 384
	 * 2. call [[afterValidate()]] when `$runValidation` is true.
	 * 3. call [[beforeSave()]]. If the method returns false, it will skip the
Qiang Xue committed
385
	 *    rest of the steps;
386 387
	 * 4. save the record into database. If this fails, it will skip the rest of the steps;
	 * 5. call [[afterSave()]];
Qiang Xue committed
388
	 *
389
	 * In the above step 1, 2, 3 and 5, events [[EVENT_BEFORE_VALIDATE]],
Qiang Xue committed
390 391
	 * [[EVENT_BEFORE_UPDATE]], [[EVENT_AFTER_UPDATE]] and [[EVENT_AFTER_VALIDATE]]
	 * will be raised by the corresponding methods.
Qiang Xue committed
392 393 394 395 396 397 398 399 400 401 402 403
	 *
	 * Only the [[changedAttributes|changed attribute values]] will be saved into database.
	 *
	 * For example, to update a customer record:
	 *
	 * ~~~
	 * $customer = Customer::find($id);
	 * $customer->name = $name;
	 * $customer->email = $email;
	 * $customer->update();
	 * ~~~
	 *
404 405 406 407 408 409 410 411 412 413 414 415
	 * Note that it is possible the update does not affect any row in the table.
	 * In this case, this method will return 0. For this reason, you should use the following
	 * code to check if update() is successful or not:
	 *
	 * ~~~
	 * if ($this->update() !== false) {
	 *     // update successful
	 * } else {
	 *     // update failed
	 * }
	 * ~~~
	 *
Qiang Xue committed
416 417
	 * @param boolean $runValidation whether to perform validation before saving the record.
	 * If the validation fails, the record will not be inserted into the database.
Qiang Xue committed
418 419
	 * @param array $attributes list of attributes that need to be saved. Defaults to null,
	 * meaning all attributes that are loaded from DB will be saved.
420 421
	 * @return integer|boolean the number of rows affected, or false if validation fails
	 * or [[beforeSave()]] stops the updating process.
422
	 * @throws StaleObjectException if [[optimisticLock|optimistic locking]] is enabled and the data
423
	 * being updated is outdated.
424
	 * @throws \Exception in case update failed.
Qiang Xue committed
425
	 */
Qiang Xue committed
426
	public function update($runValidation = true, $attributes = null)
Qiang Xue committed
427
	{
428
		if ($runValidation && !$this->validate($attributes)) {
Qiang Xue committed
429 430
			return false;
		}
431
		$db = static::getDb();
Qiang Xue committed
432 433 434 435
		if ($this->isTransactional(self::OP_UPDATE) && $db->getTransaction() === null) {
			$transaction = $db->beginTransaction();
			try {
				$result = $this->updateInternal($attributes);
resurtm committed
436
				if ($result === false) {
437 438 439
					$transaction->rollback();
				} else {
					$transaction->commit();
440
				}
Qiang Xue committed
441
			} catch (\Exception $e) {
442
				$transaction->rollback();
Qiang Xue committed
443
				throw $e;
444
			}
Qiang Xue committed
445 446
		} else {
			$result = $this->updateInternal($attributes);
447 448 449
		}
		return $result;
	}
450

Qiang Xue committed
451
	/**
Qiang Xue committed
452 453 454 455 456 457 458 459 460
	 * Deletes the table row corresponding to this active record.
	 *
	 * This method performs the following steps in order:
	 *
	 * 1. call [[beforeDelete()]]. If the method returns false, it will skip the
	 *    rest of the steps;
	 * 2. delete the record from the database;
	 * 3. call [[afterDelete()]].
	 *
Qiang Xue committed
461
	 * In the above step 1 and 3, events named [[EVENT_BEFORE_DELETE]] and [[EVENT_AFTER_DELETE]]
Qiang Xue committed
462 463
	 * will be raised by the corresponding methods.
	 *
464 465
	 * @return integer|boolean the number of rows deleted, or false if the deletion is unsuccessful for some reason.
	 * Note that it is possible the number of rows deleted is 0, even though the deletion execution is successful.
466
	 * @throws StaleObjectException if [[optimisticLock|optimistic locking]] is enabled and the data
467
	 * being deleted is outdated.
468
	 * @throws \Exception in case delete failed.
Qiang Xue committed
469 470 471
	 */
	public function delete()
	{
472
		$db = static::getDb();
473
		$transaction = $this->isTransactional(self::OP_DELETE) && $db->getTransaction() === null ? $db->beginTransaction() : null;
474 475 476 477 478 479 480
		try {
			$result = false;
			if ($this->beforeDelete()) {
				// we do not check the return value of deleteAll() because it's possible
				// the record is already deleted in the database and thus the method will return 0
				$condition = $this->getOldPrimaryKey(true);
				$lock = $this->optimisticLock();
resurtm committed
481
				if ($lock !== null) {
482 483 484
					$condition[$lock] = $this->$lock;
				}
				$result = $this->deleteAll($condition);
resurtm committed
485
				if ($lock !== null && !$result) {
486 487
					throw new StaleObjectException('The object being deleted is outdated.');
				}
488
				$this->setOldAttributes(null);
489
				$this->afterDelete();
490
			}
resurtm committed
491 492
			if ($transaction !== null) {
				if ($result === false) {
493 494 495 496
					$transaction->rollback();
				} else {
					$transaction->commit();
				}
497
			}
498
		} catch (\Exception $e) {
resurtm committed
499
			if ($transaction !== null) {
500 501 502
				$transaction->rollback();
			}
			throw $e;
Qiang Xue committed
503
		}
504
		return $result;
w  
Qiang Xue committed
505 506 507
	}

	/**
Qiang Xue committed
508 509
	 * Returns a value indicating whether the given active record is the same as the current one.
	 * The comparison is made by comparing the table names and the primary key values of the two active records.
510
	 * If one of the records [[isNewRecord|is new]] they are also considered not equal.
Qiang Xue committed
511
	 * @param ActiveRecord $record record to compare to
Qiang Xue committed
512
	 * @return boolean whether the two active records refer to the same row in the same database table.
w  
Qiang Xue committed
513
	 */
Qiang Xue committed
514
	public function equals($record)
w  
Qiang Xue committed
515
	{
516 517 518
		if ($this->isNewRecord || $record->isNewRecord) {
			return false;
		}
Qiang Xue committed
519
		return $this->tableName() === $record->tableName() && $this->getPrimaryKey() === $record->getPrimaryKey();
w  
Qiang Xue committed
520 521
	}

522
	/**
523 524 525
	 * Returns a value indicating whether the specified operation is transactional in the current [[scenario]].
	 * @param integer $operation the operation to check. Possible values are [[OP_INSERT]], [[OP_UPDATE]] and [[OP_DELETE]].
	 * @return boolean whether the specified operation is transactional in the current [[scenario]].
526
	 */
527
	public function isTransactional($operation)
528 529
	{
		$scenario = $this->getScenario();
530 531
		$transactions = $this->transactions();
		return isset($transactions[$scenario]) && ($transactions[$scenario] & $operation);
532
	}
w  
Qiang Xue committed
533
}