2020
2121namespace Fusio \Impl \Backend \Action \Action ;
2222
23+ use Doctrine \DBAL \Connection ;
2324use Fusio \Engine \ActionInterface ;
2425use Fusio \Engine \ContextInterface ;
2526use Fusio \Engine \ParametersInterface ;
3132use PSX \Http \Environment \HttpResponseInterface ;
3233use PSX \Http \Response ;
3334use PSX \Http \Writer \WriterInterface ;
35+ use stdClass ;
36+ use Throwable ;
3437
3538/**
3639 * Execute
3942 * @license http://www.apache.org/licenses/LICENSE-2.0
4043 * @link https://www.fusio-project.org
4144 */
42- class Execute implements ActionInterface
45+ readonly class Execute implements ActionInterface
4346{
44- private Action \Executor $ actionExecutorService ;
4547 private Converter $ exceptionConverter ;
4648
47- public function __construct (Action \Executor $ actionExecutorService )
49+ public function __construct (private Action \Executor $ actionExecutorService, private Connection $ connection )
4850 {
49- $ this ->actionExecutorService = $ actionExecutorService ;
5051 $ this ->exceptionConverter = new Converter (true );
5152 }
5253
@@ -56,6 +57,8 @@ public function handle(RequestInterface $request, ParametersInterface $configura
5657
5758 assert ($ body instanceof ActionExecuteRequest);
5859
60+ $ this ->connection ->beginTransaction ();
61+
5962 try {
6063 $ response = $ this ->actionExecutorService ->execute (
6164 $ request ->get ('action_id ' ),
@@ -74,30 +77,34 @@ public function handle(RequestInterface $request, ParametersInterface $configura
7477 $ body = (string ) $ tempResponse ->getBody ();
7578 }
7679
77- return [
80+ $ return = [
7881 'statusCode ' => $ response ->getStatusCode (),
7982 'headers ' => $ headers ,
8083 'body ' => $ body ,
8184 ];
8285 } else {
83- return [
86+ $ return = [
8487 'statusCode ' => 200 ,
85- 'headers ' => new \ stdClass (),
88+ 'headers ' => new stdClass (),
8689 'body ' => $ response ,
8790 ];
8891 }
89- } catch (\ Throwable $ e ) {
92+ } catch (Throwable $ e ) {
9093 if ($ e instanceof MessageException) {
9194 $ body = $ e ->getPayload ();
9295 } else {
9396 $ body = $ this ->exceptionConverter ->convert ($ e );
9497 }
9598
96- return [
99+ $ return = [
97100 'statusCode ' => 500 ,
98- 'headers ' => new \ stdClass (),
101+ 'headers ' => new stdClass (),
99102 'body ' => $ body ,
100103 ];
101104 }
105+
106+ $ this ->connection ->rollBack ();
107+
108+ return $ return ;
102109 }
103110}
0 commit comments