Skip to content

Commit

Permalink
Add missing event listeners for database transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
sebdesign committed Feb 18, 2017
1 parent ac6adfe commit 506c1eb
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/LaravelDebugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,37 @@ function ($query, $bindings = null, $time = null, $connectionName = null) use ($
)
);
}

try {
$db->getEventDispatcher()->listen([
\Illuminate\Database\Events\TransactionBeginning::class,
'connection.*.beganTransaction',
], function ($transaction) use ($queryCollector) {
$queryCollector->collectTransactionEvent('Begin Transaction', $transaction->connection);
});

$db->getEventDispatcher()->listen([
\Illuminate\Database\Events\TransactionCommitted::class,
'connection.*.committed',
], function ($transaction) use ($queryCollector) {
$queryCollector->collectTransactionEvent('Commit Transaction', $transaction->connection);
});

$db->getEventDispatcher()->listen([
\Illuminate\Database\Events\TransactionRolledBack::class,
'connection.*.rollingBack',
], function ($transaction) use ($queryCollector) {
$queryCollector->collectTransactionEvent('Rollback Transaction', $transaction->connection);
});
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add listen transactions to Queries for Laravel Debugbar: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}

if ($this->shouldCollect('mail', true) && class_exists('Illuminate\Mail\MailServiceProvider')) {
Expand Down

0 comments on commit 506c1eb

Please sign in to comment.