25if (!defined(
'NOSESSION')) {
26 define(
'NOSESSION',
'1');
28if (!defined(
'MAXEMAILS')) {
29 define(
'MAXEMAILS', 100);
32$sapi_type = php_sapi_name();
33$script_file = basename(__FILE__);
37if (substr($sapi_type, 0, 3) ==
'cgi') {
38 echo
"Error: You are using PHP for CGI. To execute ".$script_file.
" from command line, you must use PHP for CLI mode.\n";
42if (!isset($argv[3]) || !$argv[3]) {
43 print
"Usage: ".$script_file.
" inputfile-with-invalid-emails type [test|confirm]\n";
44 print
"- inputfile-with-invalid-emails is a file with list of invalid email\n";
45 print
"- type can be 'all' or 'thirdparties', 'contacts', 'members', 'users'\n";
48$fileofinvalidemail = $argv[1];
52require_once $path.
"../../htdocs/master.inc.php";
53require_once DOL_DOCUMENT_ROOT.
"/core/class/CMailFile.class.php";
54require_once DOL_DOCUMENT_ROOT.
"/comm/mailing/class/mailing.class.php";
57$version = DOL_VERSION;
60if (!isModEnabled(
'mailing')) {
61 print
'Module Emailing not enabled';
73print
"***** ".$script_file.
" (".$version.
") pid=".
dol_getmypid().
" *****\n";
75if (!in_array($type, array(
'all',
'thirdparties',
'contacts',
'users',
'members'))) {
76 print
"Bad value for parameter type.\n";
80if (!empty($dolibarr_main_db_readonly)) {
81 print
"Error: instance in read-onyl mode\n";
88$myfile = fopen($fileofinvalidemail,
"r");
90 echo
"Failed to open file";
99 $groupofemails = array();
100 for ($i = 0; $i < MAXEMAILS; $i++) {
101 $tmp = fgets($myfile);
105 $groupofemails[$i] = trim($tmp,
"\n");
110 foreach ($groupofemails as $email) {
111 $emailsin .= ($emailsin ?
", " :
"").
"'".$db->escape($email).
"'";
115 $nbingroup = count($groupofemails);
117 print
"Process group of ".$nbingroup.
" emails (".$counter.
" - ".($counter + $nbingroup - 1).
"), type = ".$type.
"\n";
121 $sql_base =
"UPDATE ".MAIN_DB_PREFIX;
123 if ($type ==
'all' || $type ==
'users') {
125 $sql = $sql_base.
"user as u SET u.email = NULL WHERE u.email IN (".$db->sanitize($emailsin, 1).
");";
126 print
"Try to update users, ";
127 $resql = $db->query($sql);
131 $numerased += $db->affected_rows($resql);
134 if ($type ==
'all' || $type ==
'thirdparties') {
136 $sql = $sql_base.
"societe as s SET s.email = NULL WHERE s.email IN (".$db->sanitize($emailsin, 1).
");";
137 print
"Try to update thirdparties, ";
138 $resql = $db->query($sql);
142 $numerased += $db->affected_rows($resql);
145 if ($type ==
'all' || $type ==
'contacts') {
148 $sql = $sql_base.
"socpeople as s SET s.email = NULL WHERE s.email IN (".$db->sanitize($emailsin, 1).
");";
149 print
"Try to update contacts, ";
150 $resql = $db->query($sql);
154 $numerased += $db->affected_rows($resql);
157 if ($type ==
'all' || $type ==
'members') {
160 $sql = $sql_base.
"adherent as a SET a.email = NULL WHERE a.email IN (".$db->sanitize($emailsin, 1).
");";
161 print
"Try to update members, ";
162 $resql = $db->query($sql);
166 $numerased += $db->affected_rows($resql);
169 $numerasedtotal += $numerased;
171 print $numerased.
" emails cleared.\n";
172 $counter = $counter + $nbingroup;
175if (!$error && $mode ==
'confirm') {
176 print
"Commit - ".$numerasedtotal.
" operations validated.\n";
179 print
"Rollback - ".$numerasedtotal.
" Operations canceled.\n";
Class to manage Dolibarr users.
dol_getmypid()
Return getmypid() or random PID when function is disabled Some web hosts disable this php function fo...
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...