Commands now use db transactions. Fixes #1745

This commit is contained in:
James Brooks 2016-05-05 16:47:41 +01:00
parent 3feb93c074
commit bfd0ccd652
2 changed files with 48 additions and 0 deletions

View 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);
});
}
}

View File

@ -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);
});