Merge pull request #1756 from CachetHQ/command-bus-db-transactions
Command bus DB transactions
This commit is contained in:
@@ -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;
|
namespace CachetHQ\Cachet\Foundation\Providers;
|
||||||
|
|
||||||
use AltThree\Bus\Dispatcher;
|
use AltThree\Bus\Dispatcher;
|
||||||
|
use CachetHQ\Cachet\Bus\Middleware\UseDatabaseTransactions;
|
||||||
use CachetHQ\Cachet\Dates\DateFactory;
|
use CachetHQ\Cachet\Dates\DateFactory;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Illuminate\Support\Str;
|
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
|
class AppServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -29,6 +37,8 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
return Dispatcher::simpleMapping($command, 'CachetHQ\Cachet\Bus', 'CachetHQ\Cachet\Bus\Handlers');
|
return Dispatcher::simpleMapping($command, 'CachetHQ\Cachet\Bus', 'CachetHQ\Cachet\Bus\Handlers');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$dispatcher->pipeThrough([UseDatabaseTransactions::class]);
|
||||||
|
|
||||||
Str::macro('canonicalize', function ($url) {
|
Str::macro('canonicalize', function ($url) {
|
||||||
return preg_replace('/([^\/])$/', '$1/', $url);
|
return preg_replace('/([^\/])$/', '$1/', $url);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -120,8 +120,6 @@ class IncidentController extends Controller
|
|||||||
null
|
null
|
||||||
));
|
));
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
dd($e->getMessageBag());
|
|
||||||
|
|
||||||
return Redirect::route('dashboard.incidents.add')
|
return Redirect::route('dashboard.incidents.add')
|
||||||
->withInput(Binput::all())
|
->withInput(Binput::all())
|
||||||
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.add.failure')))
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.add.failure')))
|
||||||
|
|||||||
Reference in New Issue
Block a user