27if (!defined(
'NOSESSION')) {
28 define(
'NOSESSION',
'1');
30if (!defined(
'MAXEMAILS')) {
31 define(
'MAXEMAILS', 100);
34$sapi_type = php_sapi_name();
35$script_file = basename(__FILE__);
39if (substr($sapi_type, 0, 3) ==
'cgi') {
40 echo
"Error: You are using PHP for CGI. To execute ".$script_file.
" from command line, you must use PHP for CLI mode.\n";
44if (!isset($argv[3]) || !$argv[3]) {
45 print
"Usage: ".$script_file.
" inputfile-with-invalid-emails type [test|confirm]\n";
46 print
"- inputfile-with-invalid-emails is a file with list of invalid email\n";
47 print
"- type can be 'all' or 'thirdparties', 'contacts', 'members', 'users'\n";
50$fileofinvalidemail = $argv[1];
54require_once $path.
"../../htdocs/master.inc.php";
55require_once DOL_DOCUMENT_ROOT.
'/core/lib/functionscli.lib.php';
56require_once DOL_DOCUMENT_ROOT.
"/core/class/CMailFile.class.php";
57require_once DOL_DOCUMENT_ROOT.
"/comm/mailing/class/mailing.class.php";
65$version = DOL_VERSION;
69 print
'Module Emailing not enabled';
73$hookmanager->initHooks(array(
'cli'));
83print
"***** ".$script_file.
" (".$version.
") pid=".dol_getmypid().
" *****\n";
85if (!in_array($type, array(
'all',
'thirdparties',
'contacts',
'users',
'members'))) {
86 print
"Bad value for parameter type.\n";
90if (!empty($dolibarr_main_db_readonly)) {
91 print
"Error: instance in read-onyl mode\n";
98$myfile = fopen($fileofinvalidemail,
"r");
100 echo
"Failed to open file";
108while ($tmp !=
null) {
109 $groupofemails = array();
110 for ($i = 0; $i < MAXEMAILS; $i++) {
111 $tmp = fgets($myfile);
115 $groupofemails[$i] = trim($tmp,
"\n");
120 foreach ($groupofemails as $email) {
121 $emailsin .= ($emailsin ?
", " :
"").
"'".$db->escape($email).
"'";
125 $nbingroup = count($groupofemails);
127 print
"Process group of ".$nbingroup.
" emails (".$counter.
" - ".($counter + $nbingroup - 1).
"), type = ".$type.
"\n";
131 $sql_base =
"UPDATE ".MAIN_DB_PREFIX;
133 if ($type ==
'all' || $type ==
'users') {
135 $sql = $sql_base.
"user as u SET u.email = NULL WHERE u.email IN (".$db->sanitize($emailsin, 1).
");";
136 print
"Try to update users, ";
137 $resql = $db->query($sql);
141 $numerased += $db->affected_rows($resql);
144 if ($type ==
'all' || $type ==
'thirdparties') {
146 $sql = $sql_base.
"societe as s SET s.email = NULL WHERE s.email IN (".$db->sanitize($emailsin, 1).
");";
147 print
"Try to update thirdparties, ";
148 $resql = $db->query($sql);
152 $numerased += $db->affected_rows($resql);
155 if ($type ==
'all' || $type ==
'contacts') {
158 $sql = $sql_base.
"socpeople as s SET s.email = NULL WHERE s.email IN (".$db->sanitize($emailsin, 1).
");";
159 print
"Try to update contacts, ";
160 $resql = $db->query($sql);
164 $numerased += $db->affected_rows($resql);
167 if ($type ==
'all' || $type ==
'members') {
170 $sql = $sql_base.
"adherent as a SET a.email = NULL WHERE a.email IN (".$db->sanitize($emailsin, 1).
");";
171 print
"Try to update members, ";
172 $resql = $db->query($sql);
176 $numerased += $db->affected_rows($resql);
179 $numerasedtotal += $numerased;
181 print $numerased.
" emails cleared.\n";
182 $counter += $nbingroup;
185if (!$error && $mode ==
'confirm') {
186 print
"Commit - ".$numerasedtotal.
" operations validated.\n";
189 print
"Rollback - ".$numerasedtotal.
" Operations canceled.\n";
Class to manage Dolibarr users.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
isModEnabled($module)
Is Dolibarr module enabled.