Skip to content

Commit

Permalink
PR review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkingmedia committed Nov 19, 2016
1 parent 078f675 commit 163716b
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/ORM/Table.php
Expand Up @@ -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();
}

/**
Expand All @@ -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));
}
Expand Down Expand Up @@ -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']);
}

/**
Expand Down Expand Up @@ -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']) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 163716b

Please sign in to comment.