reset-invalid-emails.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/usr/bin/env php
  2. <?php
  3. /* Copyright (C) 2020 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file scripts/emailings/reset-invalid-emails.php
  20. * \ingroup mailing
  21. * \brief Script to reset (set email to empty) from a list of email
  22. */
  23. if (!defined('NOSESSION')) define('NOSESSION', '1');
  24. $sapi_type = php_sapi_name();
  25. $script_file = basename(__FILE__);
  26. $path = __DIR__.'/';
  27. // Test if batch mode
  28. if (substr($sapi_type, 0, 3) == 'cgi') {
  29. echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
  30. exit(-1);
  31. }
  32. if (!isset($argv[2]) || !$argv[2]) {
  33. print "Usage: ".$script_file." inputfile-with-invalid-emails type\n";
  34. print "- inputfile-with-invalid-emails is a file with list of invalid email\n";
  35. print "- type can be 'all' or 'thirdparties', 'contacts', 'members', 'users'\n";
  36. exit(-1);
  37. }
  38. $id = $argv[1];
  39. $type = $argv[2];
  40. require_once $path."../../htdocs/master.inc.php";
  41. require_once DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php";
  42. require_once DOL_DOCUMENT_ROOT."/comm/mailing/class/mailing.class.php";
  43. // Global variables
  44. $version = DOL_VERSION;
  45. $error = 0;
  46. /*
  47. * Main
  48. */
  49. @set_time_limit(0);
  50. print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n";
  51. $user = new User($db);
  52. // for signature, we use user send as parameter
  53. if (!empty($login))
  54. $user->fetch('', $login);
  55. $db->begin();
  56. // TODO Loop on the entry file to get the 100 first entries
  57. $groupofemails = array();
  58. // For each groupofemail, we update tables to set email field to empty
  59. if ($type == 'all' || $type == 'thirdparty')
  60. {
  61. // Loop on each record and update the email to null if email into $groupofemails
  62. // TODO
  63. }
  64. if ($type == 'all' || $type == 'contact')
  65. {
  66. // Loop on each record and update the email to null if email into $groupofemails
  67. // TODO
  68. }
  69. if ($type == 'all' || $type == 'user')
  70. {
  71. // Loop on each record and update the email to null if email into $groupofemails
  72. // TODO
  73. }
  74. if ($type == 'all' || $type == 'member')
  75. {
  76. // Loop on each record and update the email to null if email into $groupofemails
  77. // TODO
  78. }
  79. if (!$error) {
  80. $db->commit();
  81. } else {
  82. $db->rollback();
  83. }
  84. exit($error);