Skip to content
Permalink
Browse files

PR review changes

  • Loading branch information...
thinkingmedia
thinkingmedia committed Nov 19, 2016
1 parent 078f675 commit 163716b8abf466c9e51682291289322aac7d1a25
Showing with 13 additions and 13 deletions.
  1. +13 −13 src/ORM/Table.php
@@ -1437,19 +1437,19 @@ public function get($primaryKey, $options = [])
/**
* Handles the logic executing of a worker inside a transaction.
*
* @param bool $atomic Whether to execute the worker inside a database transaction.
* @param callable $worker The worker that will run inside the transaction.
* @param bool $atomic Whether to execute the worker inside a database transaction.
* @return mixed
*/
protected function _executeTransaction($atomic, callable $worker)
protected function _executeTransaction(callable $worker, $atomic = true)
{
if ($atomic) {
return $this->connection()->transactional(function () use ($worker) {
return call_user_func($worker);
return $worker();
});
}
return call_user_func($worker);
return $worker();
}
/**
@@ -1459,7 +1459,7 @@ protected function _executeTransaction($atomic, callable $worker)
* @param bool $primary True if a primary was used.
* @return bool Returns true if a transaction was committed.
*/
protected function _getCommitUsed($atomic, $primary)
protected function _transactionCommitted($atomic, $primary)
{
return !$this->connection()->inTransaction() && ($atomic || (!$atomic && $primary));
}
@@ -1504,9 +1504,9 @@ public function findOrCreate($search, callable $callback = null, $options = [])
'defaults' => true
];
return $this->_executeTransaction($options['atomic'], function () use ($search, $callback, $options) {
return $this->_executeTransaction(function () use ($search, $callback, $options) {
return $this->_processFindOrCreate($search, $callback, $options);
});
}, $options['atomic']);
}
/**
@@ -1721,12 +1721,12 @@ public function save(EntityInterface $entity, $options = [])
return $entity;
}
$success = $this->_executeTransaction($options['atomic'], function () use ($entity, $options) {
$success = $this->_executeTransaction(function () use ($entity, $options) {
return $this->_processSave($entity, $options);
});
}, $options['atomic']);
if ($success) {
if ($this->_getCommitUsed($options['atomic'], $options['_primary'])) {
if ($this->_transactionCommitted($options['atomic'], $options['_primary'])) {
$this->dispatchEvent('Model.afterSaveCommit', compact('entity', 'options'));
}
if ($options['atomic'] || $options['_primary']) {
@@ -2051,11 +2051,11 @@ public function delete(EntityInterface $entity, $options = [])
'_primary' => true,
]);
$success = $this->_executeTransaction($options['atomic'], function () use ($entity, $options) {
$success = $this->_executeTransaction(function () use ($entity, $options) {
return $this->_processDelete($entity, $options);
});
}, $options['atomic']);
if ($success && $this->_getCommitUsed($options['atomic'], $options['_primary'])) {
if ($success && $this->_transactionCommitted($options['atomic'], $options['_primary'])) {
$this->dispatchEvent('Model.afterDeleteCommit', [
'entity' => $entity,
'options' => $options

0 comments on commit 163716b

Please sign in to comment.
You can’t perform that action at this time.