@@ -1675,7 +1675,7 @@ public static function update_user(
16751675 [
16761676 'item_id ' => $ user ->getId (),
16771677 'variable ' => 'password_updated_at ' ,
1678- 'value ' => $ date
1678+ 'value ' => $ date,
16791679 ]
16801680 );
16811681 }
@@ -1803,8 +1803,6 @@ public static function update_user(
18031803 null ,
18041804 $ creatorEmail
18051805 );
1806-
1807-
18081806 } else {
18091807 $ layoutContent = $ tplContent ->get_template ('mail/user_edit_content.tpl ' );
18101808 $ emailBody = $ tplContent ->fetch ($ layoutContent );
@@ -7709,7 +7707,7 @@ public static function redirectToResetPassword($userId)
77097707 );
77107708
77117709 if (!empty ($ askPassword ) && isset ($ askPassword ['ask_new_password ' ]) &&
7712- 1 === (int )$ askPassword ['ask_new_password ' ]
7710+ 1 === (int ) $ askPassword ['ask_new_password ' ]
77137711 ) {
77147712 $ uniqueId = api_get_unique_id ();
77157713 $ userObj = api_get_user_entity ($ userId );
@@ -8044,6 +8042,59 @@ public static function getScriptFunctionForActiveFilter(): string
80448042 } ' ;
80458043 }
80468044
8045+ /**
8046+ * Get a list of users with the given e-mail address + their "active" field value (0 or 1).
8047+ *
8048+ * @param string $mail User id
8049+ *
8050+ * @return array List of users e-mails + active field
8051+ */
8052+ public static function getUsersByMail (string $ mail ): array
8053+ {
8054+ $ resultData = Database::select (
8055+ 'id, active ' ,
8056+ Database::get_main_table (TABLE_MAIN_USER ),
8057+ [
8058+ 'where ' => ['email = ? ' => $ mail ],
8059+ ],
8060+ 'all ' ,
8061+ null
8062+ );
8063+
8064+ if ($ resultData === false ) {
8065+ return [];
8066+ }
8067+
8068+ return $ resultData ;
8069+ }
8070+
8071+ /**
8072+ * Get whether we can send an e-mail or not.
8073+ * If the e-mail is not in the database, send the mail.
8074+ * If the e-mail is in the database but none of its occurences is active, don't send.
8075+ *
8076+ * @param string $mail The e-mail address to check
8077+ *
8078+ * @return bool Whether we can send an e-mail or not
8079+ */
8080+ public function isEmailingAllowed (string $ mail ): bool
8081+ {
8082+ $ list = self ::getUsersByMail ($ mail );
8083+ if (empty ($ list )) {
8084+ // No e-mail matches, send the mail
8085+ return true ;
8086+ }
8087+ $ send = false ;
8088+ foreach ($ list as $ id => $ user ) {
8089+ if ($ user ['active ' ] == 1 ) {
8090+ // as soon as we find at least one active user, send the mail
8091+ return true ;
8092+ }
8093+ }
8094+
8095+ return false ;
8096+ }
8097+
80478098 /**
80488099 * @return EncoderFactory
80498100 */
@@ -8137,55 +8188,4 @@ private static function getGravatar(
81378188
81388189 return $ url ;
81398190 }
8140-
8141- /**
8142- * Get a list of users with the given e-mail address + their "active" field value (0 or 1)
8143- *
8144- * @param string $mail User id
8145- *
8146- * @return array List of users e-mails + active field
8147- */
8148- public static function getUsersByMail (string $ mail ): array
8149- {
8150- $ resultData = Database::select (
8151- 'id, active ' ,
8152- Database::get_main_table (TABLE_MAIN_USER ),
8153- [
8154- 'where ' => ['email = ? ' => $ mail ],
8155- ],
8156- 'all ' ,
8157- null
8158- );
8159-
8160- if ($ resultData === false ) {
8161- return [];
8162- }
8163-
8164- return $ resultData ;
8165- }
8166-
8167- /**
8168- * Get whether we can send an e-mail or not.
8169- * If the e-mail is not in the database, send the mail.
8170- * If the e-mail is in the database but none of its occurences is active, don't send.
8171- * @param string $mail The e-mail address to check
8172- * @return bool Whether we can send an e-mail or not
8173- */
8174- public function isEmailingAllowed (string $ mail ): bool
8175- {
8176- $ list = self ::getUsersByMail ($ mail );
8177- if (empty ($ list )) {
8178- // No e-mail matches, send the mail
8179- return true ;
8180- }
8181- $ send = false ;
8182- foreach ($ list as $ id => $ user ) {
8183- if ($ user ['active ' ] == 1 ) {
8184- // as soon as we find at least one active user, send the mail
8185- return true ;
8186- }
8187- }
8188-
8189- return false ;
8190- }
81918191}
0 commit comments