mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-01-17 13:38:20 +01:00
Commands now use db transactions. Fixes #1745
This commit is contained in:
parent
3feb93c074
commit
bfd0ccd652
38
app/Bus/Middleware/UseDatabaseTransactions.php
Normal file
38
app/Bus/Middleware/UseDatabaseTransactions.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Bus\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* This is the use database transactions bus middleware class.
|
||||
*
|
||||
* @author James Brooks <james@alt-three.com>
|
||||
*/
|
||||
class UseDatabaseTransactions
|
||||
{
|
||||
/**
|
||||
* Handle the current command in the pipeline.
|
||||
*
|
||||
* @param mixed $command
|
||||
* @param \Closure $next
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function handle($command, Closure $next)
|
||||
{
|
||||
return DB::transaction(function () use ($command, $next) {
|
||||
return $next($command);
|
||||
});
|
||||
}
|
||||
}
|
@ -12,10 +12,18 @@
|
||||
namespace CachetHQ\Cachet\Foundation\Providers;
|
||||
|
||||
use AltThree\Bus\Dispatcher;
|
||||
use CachetHQ\Cachet\Bus\Middleware\UseDatabaseTransactions;
|
||||
use CachetHQ\Cachet\Dates\DateFactory;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* This is the app service provider.
|
||||
*
|
||||
* @author James Brooks <james@alt-three.com>
|
||||
* @author Joe Cohen <joe@alt-three.com>
|
||||
* @author Graham Campbell <graham@alt-three.com>
|
||||
*/
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
@ -29,6 +37,8 @@ class AppServiceProvider extends ServiceProvider
|
||||
return Dispatcher::simpleMapping($command, 'CachetHQ\Cachet\Bus', 'CachetHQ\Cachet\Bus\Handlers');
|
||||
});
|
||||
|
||||
$dispatcher->pipeThrough([UseDatabaseTransactions::class]);
|
||||
|
||||
Str::macro('canonicalize', function ($url) {
|
||||
return preg_replace('/([^\/])$/', '$1/', $url);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user