@@ -108,13 +108,20 @@ public function updateWithUserKey(
108108 );
109109
110110 $ this ->userApi ->mergeUsers ($ apiAwareResource , $ userByEmailFromForm ['id ' ], [$ userFoundByKey ['id ' ]]);
111- $ this ->changeCookieWithEvent ($ user , $ apiAwareResource , $ eventName , $ payload );
111+ if (is_array ($ user ) && isset ($ user ['email ' ]) && is_string ($ user ['email ' ])) {
112+ $ this ->sendEvent ($ apiAwareResource , $ user ['email ' ], $ eventName , $ payload );
113+ }
114+ $ this ->changeCookie ($ user );
112115
113116 return $ user ;
114117 }
115118
116119 $ user = $ this ->userApi ->createUser ($ apiAwareResource , $ payload );
117- $ this ->changeCookieWithEvent ($ user , $ apiAwareResource , $ eventName , $ payload );
120+
121+ if (is_array ($ user ) && isset ($ user ['email ' ]) && is_string ($ user ['email ' ])) {
122+ $ this ->sendEvent ($ apiAwareResource , $ user ['email ' ], $ eventName , $ payload );
123+ }
124+ $ this ->changeCookie ($ user );
118125
119126 return $ user ;
120127 }
@@ -154,16 +161,16 @@ private function updateForUserWithoutEmail(
154161 $ this ->userApi ->mergeUsers ($ apiAwareResource , $ customerFoundByEmail ['id ' ], [$ userFromUserKey ['id ' ]]);
155162 }
156163
157- $ this ->sendEvent ($ apiAwareResource , $ email , $ eventName , $ payload );
164+ if (is_array ($ user ) && isset ($ user ['email ' ]) && is_string ($ user ['email ' ])) {
165+ $ this ->sendEvent ($ apiAwareResource , $ user ['email ' ], $ eventName , $ payload );
166+ }
167+ $ this ->changeCookie ($ user );
158168
159169 return $ user ;
160170 }
161171
162- public function changeCookieWithEvent (
172+ public function changeCookie (
163173 ?array $ user ,
164- UserComApiAwareInterface $ apiAwareResource ,
165- string $ eventName ,
166- ?array $ payload = null ,
167174 ): void {
168175 if (false === is_array ($ user ) ||
169176 false === array_key_exists ('id ' , $ user ) ||
@@ -173,6 +180,5 @@ public function changeCookieWithEvent(
173180 }
174181
175182 $ this ->cookieManager ->setUserComCookie ($ user ['user_key ' ]);
176- $ this ->sendEvent ($ apiAwareResource , $ user ['email ' ], $ eventName , $ payload );
177183 }
178184}
0 commit comments