1111use Icinga \Authentication \User \UserBackend ;
1212use Icinga \Data \Selectable ;
1313use Icinga \Module \Notifications \Common \Database ;
14+ use Icinga \Module \Notifications \Repository \ContactRepository ;
1415use Icinga \Module \Notifications \Web \Form \ContactForm ;
1516use Icinga \Repository \Repository ;
1617use Icinga \Web \Notification ;
1718use ipl \Html \Contract \Form ;
19+ use ipl \Sql \Connection ;
1820use ipl \Web \Compat \CompatController ;
1921use ipl \Web \FormElement \SearchSuggestions ;
2022
@@ -27,29 +29,35 @@ public function init(): void
2729
2830 public function indexAction (): void
2931 {
30- $ contactId = $ this ->params ->getRequired ('id ' );
31-
32- $ form = (new ContactForm (Database::get ()))
33- ->loadContact ($ contactId )
32+ $ contact = (new ContactRepository (Database::get ()))
33+ ->find ((int ) $ this ->params ->getRequired ('id ' ));
34+ if ($ contact === null ) {
35+ $ this ->httpNotFound ($ this ->translate ('Contact not found ' ));
36+ }
37+
38+ $ form = (new ContactForm ())
39+ ->setContact ($ contact )
3440 ->on (Form::ON_SUBMIT , function (ContactForm $ form ) {
35- $ form ->editContact ();
41+ $ contact = $ form ->getContact ();
42+ Database::get ()->transaction (fn (Connection $ db ) => (new ContactRepository ($ db ))->update ($ contact ));
3643 Notification::success (sprintf (
37- t ('Contact "%s" has successfully been saved ' ),
38- $ form -> getContactName ()
44+ $ this -> translate ('Contact "%s" has successfully been saved ' ),
45+ $ contact -> full_name
3946 ));
4047
4148 $ this ->redirectNow ('__CLOSE__ ' );
4249 })->on (ContactForm::ON_REMOVE , function (ContactForm $ form ) {
43- $ form ->removeContact ();
50+ $ contact = $ form ->getContact ();
51+ Database::get ()->transaction (fn (Connection $ db ) => (new ContactRepository ($ db ))->delete ($ contact ));
4452 Notification::success (sprintf (
45- t ('Deleted contact "%s" successfully ' ),
46- $ form -> getContactName ()
53+ $ this -> translate ('Deleted contact "%s" successfully ' ),
54+ $ contact -> full_name
4755 ));
4856
4957 $ this ->redirectNow ('__CLOSE__ ' );
5058 })->handleRequest ($ this ->getServerRequest ());
5159
52- $ this ->addTitleTab (sprintf (t ('Contact: %s ' ), $ form -> getContactName () ));
60+ $ this ->addTitleTab (sprintf ($ this -> translate ('Contact: %s ' ), $ contact -> full_name ));
5361
5462 $ this ->addContent ($ form );
5563 }
0 commit comments