@@ -998,28 +998,34 @@ public function transferPackageAction(Request $req, #[MapEntity] Package $packag
998998 $ form = $ this ->createTransferPackageForm ($ package );
999999 $ form ->handleRequest ($ req );
10001000
1001- if ($ form ->isSubmitted () && $ form ->isValid ()) {
1002- try {
1003- $ newMaintainers = $ form ->getData ()->getMaintainers ()->toArray ();
1004- $ result = $ this ->packageManager ->transferPackage ($ package , $ newMaintainers );
1005- $ this ->getEM ()->flush ();
1006-
1007- if ($ result ) {
1008- $ usernames = array_map (fn (User $ user ) => $ user ->getUsername (), $ newMaintainers );
1009- $ this ->addFlash ('success ' , sprintf ('Package has been transferred to %s ' , implode (', ' , $ usernames )));
1010- } else {
1011- $ this ->addFlash ('warning ' , 'Package maintainers are identical and have not been changed ' );
1012- }
1001+ if (!$ form ->isSubmitted ()) {
1002+ return $ this ->redirectToRoute ('view_package ' , ['name ' => $ package ->getName ()]);
1003+ }
10131004
1014- return $ this ->redirectToRoute ('view_package ' , ['name ' => $ package ->getName ()]);
1015- } catch (\Exception $ e ) {
1016- $ logger ->critical ($ e ->getMessage (), ['exception ' , $ e ]);
1017- $ this ->addFlash ('error ' , 'The package could not be transferred. ' );
1018- }
1019- } elseif (!$ form ->isValid ()) {
1005+ if (!$ form ->isValid ()) {
10201006 foreach ($ form ->getErrors (true , true ) as $ error ) {
10211007 $ this ->addFlash ('error ' , $ error ->getMessage ());
10221008 }
1009+
1010+ return $ this ->redirectToRoute ('view_package ' , ['name ' => $ package ->getName ()]);
1011+ }
1012+
1013+ try {
1014+ $ newMaintainers = $ form ->getData ()->getMaintainers ()->toArray ();
1015+ $ result = $ this ->packageManager ->transferPackage ($ package , $ newMaintainers );
1016+ $ this ->getEM ()->flush ();
1017+
1018+ if ($ result ) {
1019+ $ usernames = array_map (fn (User $ user ) => $ user ->getUsername (), $ newMaintainers );
1020+ $ this ->addFlash ('success ' , sprintf ('Package has been transferred to %s ' , implode (', ' , $ usernames )));
1021+ } else {
1022+ $ this ->addFlash ('warning ' , 'Package maintainers are identical and have not been changed ' );
1023+ }
1024+
1025+ return $ this ->redirectToRoute ('view_package ' , ['name ' => $ package ->getName ()]);
1026+ } catch (\Exception $ e ) {
1027+ $ logger ->critical ($ e ->getMessage (), ['exception ' , $ e ]);
1028+ $ this ->addFlash ('error ' , 'The package could not be transferred. ' );
10231029 }
10241030
10251031 return $ this ->redirectToRoute ('view_package ' , ['name ' => $ package ->getName ()]);
0 commit comments