From c922fb3ea002f97d01f6680e3874ebcd0814feea Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Wed, 16 Oct 2024 15:05:23 +0200 Subject: [PATCH 1/3] fix: update default user profile is not attribute --- inc/userinjection.class.php | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/inc/userinjection.class.php b/inc/userinjection.class.php index cbb0dad..ca459d9 100644 --- a/inc/userinjection.class.php +++ b/inc/userinjection.class.php @@ -185,6 +185,45 @@ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) /** @phpstan-ignore-next-line */ $DB->query($query); // phpcs:ignore } + + if (isset($values['User']['profiles_id'])) { + $profile_user = new Profile_User(); + $profile_users = $profile_user->find([ + 'users_id' => $values['User']['id'], + 'entities_id' => $values['User']['entities_id'], + ]); + $is_new_profile_user = true; + foreach ($profile_users as $profile) { + if ( + in_array('users_id', $profile) + && in_array('profiles_id', $profile) + && in_array('entities_id', $profile) + ) { + $is_new_profile_user = false; + $profile_user->update([ + 'id' => $profile['id'], + 'is_default_profile' => 1 + ]); + } + $profile_user->update([ + 'id' => $profile['id'], + 'is_default_profile' => 0 + ]); + } + if ($is_new_profile_user) { + $profile_user->add([ + 'users_id' => $values['User']['id'], + 'profiles_id' => $values['User']['profiles_id'], + 'entities_id' => $values['User']['entities_id'], + 'is_default_profile' => 1, + ]); + } + $user = new User(); + $user->update([ + 'id' => $values['User']['id'], + 'profiles_id' => $values['User']['profiles_id'], + ]); + } } From a98d9d66ecae65a2bf0c98f54f0976c7068a7752 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 17 Oct 2024 14:56:50 +0200 Subject: [PATCH 2/3] Update verif profiles_id --- inc/userinjection.class.php | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/inc/userinjection.class.php b/inc/userinjection.class.php index ca459d9..5587e37 100644 --- a/inc/userinjection.class.php +++ b/inc/userinjection.class.php @@ -187,37 +187,6 @@ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) } if (isset($values['User']['profiles_id'])) { - $profile_user = new Profile_User(); - $profile_users = $profile_user->find([ - 'users_id' => $values['User']['id'], - 'entities_id' => $values['User']['entities_id'], - ]); - $is_new_profile_user = true; - foreach ($profile_users as $profile) { - if ( - in_array('users_id', $profile) - && in_array('profiles_id', $profile) - && in_array('entities_id', $profile) - ) { - $is_new_profile_user = false; - $profile_user->update([ - 'id' => $profile['id'], - 'is_default_profile' => 1 - ]); - } - $profile_user->update([ - 'id' => $profile['id'], - 'is_default_profile' => 0 - ]); - } - if ($is_new_profile_user) { - $profile_user->add([ - 'users_id' => $values['User']['id'], - 'profiles_id' => $values['User']['profiles_id'], - 'entities_id' => $values['User']['entities_id'], - 'is_default_profile' => 1, - ]); - } $user = new User(); $user->update([ 'id' => $values['User']['id'], From f8ca2043e529a7a7964d9107e100b519f231d11c Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 17 Oct 2024 15:36:16 +0200 Subject: [PATCH 3/3] Update verif profiles_id --- inc/userinjection.class.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/inc/userinjection.class.php b/inc/userinjection.class.php index 5587e37..acc4654 100644 --- a/inc/userinjection.class.php +++ b/inc/userinjection.class.php @@ -187,6 +187,25 @@ public function processAfterInsertOrUpdate($values, $add = true, $rights = []) } if (isset($values['User']['profiles_id'])) { + $profile_user = new Profile_User(); + $profile_user->getFromDBByCrit([ + 'users_id' => $values['User']['id'], + 'entities_id' => $values['User']['entities_id'], + ]); + if (!in_array('id', $profile_user->fields)) { + $profile_user->add([ + 'users_id' => $values['User']['id'], + 'profiles_id' => $values['User']['profiles_id'], + 'entities_id' => $values['User']['entities_id'], + 'is_default_profile' => 1, + ]); + } else { + $profile_user->update([ + 'id' => $profile_user->fields['id'], + 'profiles_id' => $values['User']['profiles_id'], + 'is_default_profile' => 1 + ]); + } $user = new User(); $user->update([ 'id' => $values['User']['id'],