From fc786d165c8051cdefd202791b748e80d369cc86 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Fri, 13 Nov 2020 10:56:12 +0100 Subject: [PATCH] FIX : #15373 Reset invalid email script --- scripts/emailings/reset-invalid-emails.php | 84 +++++++++++++++------- 1 file changed, 57 insertions(+), 27 deletions(-) diff --git a/scripts/emailings/reset-invalid-emails.php b/scripts/emailings/reset-invalid-emails.php index de6b180e208..a961a00272e 100755 --- a/scripts/emailings/reset-invalid-emails.php +++ b/scripts/emailings/reset-invalid-emails.php @@ -23,6 +23,7 @@ */ if (!defined('NOSESSION')) define('NOSESSION', '1'); +if (!defined('MAXEMAILS')) define('MAXEMAILS', 100); $sapi_type = php_sapi_name(); $script_file = basename(__FILE__); @@ -40,7 +41,7 @@ if (!isset($argv[2]) || !$argv[2]) { print "- type can be 'all' or 'thirdparties', 'contacts', 'members', 'users'\n"; exit(-1); } -$id = $argv[1]; +$fileofinvalidemail = $argv[1]; $type = $argv[2]; require_once $path."../../htdocs/master.inc.php"; @@ -68,37 +69,66 @@ if (!empty($login)) $db->begin(); -// TODO Loop on the entry file to get the 100 first entries - -$groupofemails = array(); +$myfile = fopen($fileofinvalidemail, "r"); +if (!$myfile) +{ + echo "Failed to open file"; + exit(-1); +} +$tmp = 1; +while($tmp!=null) +{ + $groupofemails=array(); + for ($i=0; $i < MAXEMAILS; $i++) + { + $tmp =fgets($myfile); + if ($tmp == null) + { + break; + } + $groupofemails[$i] = trim($tmp, "\n"); + } // For each groupofemail, we update tables to set email field to empty - if ($type == 'all' || $type == 'thirdparty') + + $sql_base = "UPDATE ".MAIN_DB_PREFIX; + foreach ($groupofemails as $email) { - // Loop on each record and update the email to null if email into $groupofemails - // TODO + if ($type == 'all' || $type == 'thirdparty') + { + // Loop on each record and update the email to null if email into $groupofemails + + $sql=$sql_base."societe as s SET s.email = NULL WHERE s.email = '".$db->escape($email)."';"; + $db->query($sql); + } + + if ($type == 'all' || $type == 'contact') + { + // Loop on each record and update the email to null if email into $groupofemails + + $sql=$sql_base."socpeople as s SET s.email = NULL WHERE s.email = '".$db->escape($email)."';"; + $db->query($sql); + } + + if ($type == 'all' || $type == 'user') + { + // Loop on each record and update the email to null if email into $groupofemails + + $sql=$sql_base."user as u SET u.email = NULL WHERE u.email = '".$db->escape($email)."';"; + $db->query($sql); + } + + if ($type == 'all' || $type == 'member') + { + // Loop on each record and update the email to null if email into $groupofemails + + $sql=$sql_base."adherent as a SET a.email = NULL WHERE a.email = '".$db->escape($email)."';"; + $resql=$db->query($sql); + } + echo $email; } - - if ($type == 'all' || $type == 'contact') - { - // Loop on each record and update the email to null if email into $groupofemails - // TODO - } - - if ($type == 'all' || $type == 'user') - { - // Loop on each record and update the email to null if email into $groupofemails - // TODO - } - - if ($type == 'all' || $type == 'member') - { - // Loop on each record and update the email to null if email into $groupofemails - // TODO - } - - +} if (!$error) { $db->commit(); } else {