Skip to content

Commit 2ac8667

Browse files
committed
fix: $user->getEmailIdentity() returns null after saving new user
Now UserModel does not alter the passed User object state when saving, but if it is insertion, add the user id to it.
1 parent c82ef36 commit 2ac8667

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Models/UserModel.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,18 @@ public function activate(User $user): void
225225
*/
226226
public function insert($data = null, bool $returnID = true)
227227
{
228-
$this->tempUser = $data instanceof User ? $data : null;
228+
// Clone User object for not changing the passed object.
229+
$this->tempUser = $data instanceof User ? clone $data : null;
229230

230231
$result = parent::insert($data, $returnID);
231232

232233
$this->checkQueryReturn($result);
233234

235+
// Set user id to the passed User object.
236+
if ($data instanceof User) {
237+
$data->id = $this->insertID;
238+
}
239+
234240
return $returnID ? $this->insertID : $result;
235241
}
236242

@@ -245,7 +251,8 @@ public function insert($data = null, bool $returnID = true)
245251
*/
246252
public function update($id = null, $data = null): bool
247253
{
248-
$this->tempUser = $data instanceof User ? $data : null;
254+
// Clone User object for not changing the passed object.
255+
$this->tempUser = $data instanceof User ? clone $data : null;
249256

250257
try {
251258
/** @throws DataException */

0 commit comments

Comments
 (0)