26if (!defined(
'NOSESSION')) {
27 define(
'NOSESSION',
'1');
29if (!defined(
'MAXEMAILS')) {
30 define(
'MAXEMAILS', 100);
33$sapi_type = php_sapi_name();
34$script_file = basename(__FILE__);
38if (substr($sapi_type, 0, 3) ==
'cgi') {
39 echo
"Error: You are using PHP for CGI. To execute ".$script_file.
" from command line, you must use PHP for CLI mode.\n";
43if (!isset($argv[3]) || !$argv[3]) {
44 print
"Usage: ".$script_file.
" inputfile-with-invalid-emails type [test|confirm]\n";
45 print
"- inputfile-with-invalid-emails is a file with list of invalid email\n";
46 print
"- type can be 'all' or 'thirdparties', 'contacts', 'members', 'users'\n";
49$fileofinvalidemail = $argv[1];
53require_once $path.
"../../htdocs/master.inc.php";
54require_once DOL_DOCUMENT_ROOT.
'/core/lib/functionscli.lib.php';
55require_once DOL_DOCUMENT_ROOT.
"/core/class/CMailFile.class.php";
56require_once DOL_DOCUMENT_ROOT.
"/comm/mailing/class/mailing.class.php";
64$version = DOL_VERSION;
67if (!isModEnabled(
'mailing')) {
68 print
'Module Emailing not enabled';
72$hookmanager->initHooks(array(
'cli'));
82print
"***** ".$script_file.
" (".$version.
") pid=".
dol_getmypid().
" *****\n";
84if (!in_array($type, array(
'all',
'thirdparties',
'contacts',
'users',
'members'))) {
85 print
"Bad value for parameter type.\n";
89if (!empty($dolibarr_main_db_readonly)) {
90 print
"Error: instance in read-onyl mode\n";
97$myfile = fopen($fileofinvalidemail,
"r");
99 echo
"Failed to open file";
107while ($tmp !=
null) {
108 $groupofemails = array();
109 for ($i = 0; $i < MAXEMAILS; $i++) {
110 $tmp = fgets($myfile);
114 $groupofemails[$i] = trim($tmp,
"\n");
119 foreach ($groupofemails as $email) {
120 $emailsin .= ($emailsin ?
", " :
"").
"'".$db->escape($email).
"'";
124 $nbingroup = count($groupofemails);
126 print
"Process group of ".$nbingroup.
" emails (".$counter.
" - ".($counter + $nbingroup - 1).
"), type = ".$type.
"\n";
130 $sql_base =
"UPDATE ".MAIN_DB_PREFIX;
132 if ($type ==
'all' || $type ==
'users') {
134 $sql = $sql_base.
"user as u SET u.email = NULL WHERE u.email IN (".$db->sanitize($emailsin, 1).
");";
135 print
"Try to update users, ";
136 $resql = $db->query($sql);
140 $numerased += $db->affected_rows($resql);
143 if ($type ==
'all' || $type ==
'thirdparties') {
145 $sql = $sql_base.
"societe as s SET s.email = NULL WHERE s.email IN (".$db->sanitize($emailsin, 1).
");";
146 print
"Try to update thirdparties, ";
147 $resql = $db->query($sql);
151 $numerased += $db->affected_rows($resql);
154 if ($type ==
'all' || $type ==
'contacts') {
157 $sql = $sql_base.
"socpeople as s SET s.email = NULL WHERE s.email IN (".$db->sanitize($emailsin, 1).
");";
158 print
"Try to update contacts, ";
159 $resql = $db->query($sql);
163 $numerased += $db->affected_rows($resql);
166 if ($type ==
'all' || $type ==
'members') {
169 $sql = $sql_base.
"adherent as a SET a.email = NULL WHERE a.email IN (".$db->sanitize($emailsin, 1).
");";
170 print
"Try to update members, ";
171 $resql = $db->query($sql);
175 $numerased += $db->affected_rows($resql);
178 $numerasedtotal += $numerased;
180 print $numerased.
" emails cleared.\n";
181 $counter = $counter + $nbingroup;
184if (!$error && $mode ==
'confirm') {
185 print
"Commit - ".$numerasedtotal.
" operations validated.\n";
188 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=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...