55use App \Entity \AddressBook ;
66use App \Entity \Principal ;
77use App \Form \AddressBookType ;
8+ use App \Services \BirthdayService ;
89use Doctrine \Persistence \ManagerRegistry ;
910use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
1011use Symfony \Component \HttpFoundation \Request ;
@@ -30,7 +31,7 @@ public function addressBooks(ManagerRegistry $doctrine, string $username): Respo
3031
3132 #[Route('/{username}/new ' , name: 'create ' )]
3233 #[Route('/{username}/edit/{id} ' , name: 'edit ' , requirements: ['id ' => "\d+ " ])]
33- public function addressbookCreate (ManagerRegistry $ doctrine , Request $ request , string $ username , ?int $ id , TranslatorInterface $ trans ): Response
34+ public function addressbookCreate (ManagerRegistry $ doctrine , Request $ request , string $ username , ?int $ id , TranslatorInterface $ trans, BirthdayService $ birthdayService ): Response
3435 {
3536 $ principal = $ doctrine ->getRepository (Principal::class)->findOneByUri (Principal::PREFIX .$ username );
3637
@@ -61,6 +62,9 @@ public function addressbookCreate(ManagerRegistry $doctrine, Request $request, s
6162
6263 $ this ->addFlash ('success ' , $ trans ->trans ('addressbooks.saved ' ));
6364
65+ // Let's sync the user birthday calendar if needed
66+ $ birthdayService ->syncUser ($ username );
67+
6468 return $ this ->redirectToRoute ('addressbook_index ' , ['username ' => $ username ]);
6569 }
6670
@@ -73,7 +77,7 @@ public function addressbookCreate(ManagerRegistry $doctrine, Request $request, s
7377 }
7478
7579 #[Route('/{username}/delete/{id} ' , name: 'delete ' , requirements: ['id ' => "\d+ " ])]
76- public function addressbookDelete (ManagerRegistry $ doctrine , string $ username , string $ id , TranslatorInterface $ trans ): Response
80+ public function addressbookDelete (ManagerRegistry $ doctrine , string $ username , string $ id , TranslatorInterface $ trans, BirthdayService $ birthdayService ): Response
7781 {
7882 $ addressbook = $ doctrine ->getRepository (AddressBook::class)->findOneById ($ id );
7983 if (!$ addressbook ) {
@@ -93,6 +97,9 @@ public function addressbookDelete(ManagerRegistry $doctrine, string $username, s
9397 $ entityManager ->flush ();
9498 $ this ->addFlash ('success ' , $ trans ->trans ('addressbooks.deleted ' ));
9599
100+ // Let's sync the user birthday calendar if needed
101+ $ birthdayService ->syncUser ($ username );
102+
96103 return $ this ->redirectToRoute ('addressbook_index ' , ['username ' => $ username ]);
97104 }
98105}
0 commit comments