1111 * See the License for the specific language governing permissions and
1212 * limitations under the License.
1313 **/
14+
1415use App \Events \UserCreated ;
1516use App \Events \UserLocked ;
1617use App \Events \UserSpamStateUpdated ;
18+ use App \Jobs \AddUserAction ;
1719use App \libs \Auth \Models \IGroupSlugs ;
1820use App \libs \Auth \Models \UserRegistrationRequest ;
1921use App \libs \Utils \PunnyCodeHelper ;
4446use Doctrine \Common \Collections \ArrayCollection ;
4547use App \Models \Utils \BaseEntity ;
4648use Doctrine \ORM \Mapping AS ORM ;
49+ use Utils \IPHelper ;
4750
4851/**
4952 * @ORM\Entity(repositoryClass="App\Repositories\DoctrineUserRepository")
@@ -2003,4 +2006,76 @@ public function createdByOTP():bool{
20032006 return !is_null ($ this ->created_by_otp );
20042007 }
20052008
2009+ /**
2010+ * @ORM\PostUpdate:
2011+ */
2012+ public function updated ($ args )
2013+ {
2014+
2015+ }
2016+
2017+ private function formatFieldValue (string $ field , $ value ):string {
2018+ if ($ field === 'password ' ) $ value = "******** " ;
2019+ if ($ value instanceof \DateTime)
2020+ $ value = $ value ->format ('Y-m-d H:i:s ' );
2021+ return sprintf ("%s: %s " , $ field , $ value );
2022+ }
2023+ /**
2024+ * @ORM\PreUpdate:
2025+ */
2026+ public function updating (PreUpdateEventArgs $ args )
2027+ {
2028+ $ fields_2_check = [
2029+ 'identifier ' ,
2030+ 'public_profile_show_photo ' ,
2031+ 'public_profile_show_fullname ' ,
2032+ 'public_profile_show_email ' ,
2033+ 'public_profile_allow_chat_with_me ' ,
2034+ 'active ' ,
2035+ 'first_name ' ,
2036+ 'last_name ' ,
2037+ 'email ' ,
2038+ 'address1 ' ,
2039+ 'address2 ' ,
2040+ 'state ' ,
2041+ 'city ' ,
2042+ 'post_code ' ,
2043+ 'country_iso_code ' ,
2044+ 'second_email ' ,
2045+ 'third_email ' ,
2046+ 'gender ' ,
2047+ 'gender_specify ' ,
2048+ 'statement_of_interest ' ,
2049+ 'bio ' ,
2050+ 'irc ' ,
2051+ 'linked_in_profile ' ,
2052+ 'twitter_name ' ,
2053+ 'github_user ' ,
2054+ 'wechat_user ' ,
2055+ 'password ' ,
2056+ 'email_verified ' ,
2057+ 'language ' ,
2058+ 'birthday ' ,
2059+ 'company ' ,
2060+ 'job_title ' ,
2061+ 'phone_number ' ,
2062+ ];
2063+ $ old_fields_changed = [];
2064+ $ new_fields_changed = [];
2065+
2066+ foreach ($ fields_2_check as $ field ){
2067+ if ($ args ->hasChangedField ($ field )){
2068+ $ old_fields_changed [] = sprintf ("%s: %s " , $ field , self ::formatFieldValue ($ field , $ args ->getOldValue ($ field )));
2069+ $ new_fields_changed [] = sprintf ("%s: %s " , $ field , self ::formatFieldValue ($ field , $ args ->getNewValue ($ field )));
2070+ }
2071+ }
2072+
2073+ $ action = sprintf
2074+ (
2075+ "User %s updated from %s to %s " , $ this ->email , implode (", " , $ old_fields_changed ), implode (", " , $ new_fields_changed )
2076+ );
2077+
2078+ Event::dispatch (new AddUserAction ($ this ->id , IPHelper::getUserIp (), $ action ));
2079+ }
2080+
20062081}
0 commit comments