PageRenderTime 50ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/app/Console/Commands/UnsubscribeTor.php

https://bitbucket.org/hfab/webservice
PHP | 127 lines | 100 code | 7 blank | 20 comment | 1 complexity | fe705dfcd4717e9f701e927bbe52865b MD5 | raw file
Possible License(s): BSD-2-Clause, Apache-2.0, MIT, GPL-3.0, LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. class UnsubscribeTor extends Command
  5. {
  6. /**
  7. * The name and signature of the console command.
  8. *
  9. * @var string
  10. */
  11. protected $signature = 'unsubscribe:get';
  12. /**
  13. * The console command description.
  14. *
  15. * @var string
  16. */
  17. protected $description = 'Command description';
  18. /**
  19. * Create a new command instance.
  20. *
  21. * @return void
  22. */
  23. public function __construct()
  24. {
  25. parent::__construct();
  26. }
  27. /**
  28. * Execute the console command.
  29. *
  30. * @return mixed
  31. */
  32. public function handle()
  33. {
  34. $datedujour = date('Ymd');
  35. $hier = date("Ymd",strtotime("-1 day")); // for Mindbaz, because their files are generated at 5:00 AM
  36. if(empty(getenv('SERVERS_TEAM')))
  37. {
  38. \Log::info(".env n'a pas la variable SERVERS_TEAM");
  39. exit;
  40. }
  41. $tor_ami = getenv('SERVERS_TEAM');
  42. $servers = explode(',',$tor_ami);
  43. foreach ($servers as $s)
  44. {
  45. // Partie Phoenix
  46. $url = $s . 'mailexport/unsubscribe/phoenix/unsubscribe_ph_' . $datedujour . '.csv';
  47. $url_name = parse_url($s, PHP_URL_HOST);
  48. $test_url = get_headers($url);
  49. if($test_url[0] !== "HTTP/1.0 500 Internal Server Error"){
  50. $content_url = file_get_contents($url);
  51. $handle = fopen(storage_path()."/desinscrits/". $url_name ."_unsubscribe_ph_" . $datedujour . ".csv", 'w');
  52. fwrite($handle, $content_url);
  53. \Artisan::call('base:import_desinscrits', ['file' => $url_name . "_unsubscribe_ph_" . $datedujour . ".csv"]);
  54. \Log::info("Fichier unsubscribe PH importé avec succès");
  55. } else {
  56. \Log::info("Fichier unsubscribe PH du jour introuvable");
  57. }
  58. // Partie MailDrop
  59. $url = $s . 'mailexport/unsubscribe/maildrop/unsubscribe_md_' . $datedujour . '.csv';
  60. $url_name = parse_url($s, PHP_URL_HOST);
  61. $test_url = get_headers($url);
  62. if($test_url[0] !== "HTTP/1.0 500 Internal Server Error"){
  63. $content_url = file_get_contents($url);
  64. $handle = fopen(storage_path()."/desinscrits/". $url_name ."_unsubscribe_md_" . $datedujour . ".csv", 'w');
  65. fwrite($handle, $content_url);
  66. \Artisan::call('base:import_desinscrits', ['file' => $url_name . "_unsubscribe_md_" . $datedujour . ".csv"]);
  67. \Log::info("Fichier unsubscribe MD importé avec succès");
  68. } else {
  69. \Log::info("Fichier unsubscribe MD du jour introuvable");
  70. }
  71. // Partie SMessage
  72. $url = $s . 'mailexport/unsubscribe/smessage/unsubscribe_sm_' . $datedujour . '.csv';
  73. $url_name = parse_url($s, PHP_URL_HOST);
  74. $test_url = get_headers($url);
  75. if($test_url[0] !== "HTTP/1.0 500 Internal Server Error"){
  76. $content_url = file_get_contents($url);
  77. $handle = fopen(storage_path()."/desinscrits/". $url_name ."_unsubscribe_sm_" . $datedujour . ".csv", 'w');
  78. fwrite($handle, $content_url);
  79. \Artisan::call('base:import_desinscrits', ['file' => $url_name . "_unsubscribe_sm_" . $datedujour . ".csv"]);
  80. \Log::info("Fichier unsubscribe SM importé avec succès");
  81. } else {
  82. \Log::info("Fichier unsubscribe SM du jour introuvable");
  83. }
  84. // Partie Mailforyou
  85. $url = $s . 'mailexport/unsubscribe/smessage/unsubscribe_m4y_' . $datedujour . '.csv';
  86. $url_name = parse_url($s, PHP_URL_HOST);
  87. $test_url = get_headers($url);
  88. if($test_url[0] !== "HTTP/1.0 500 Internal Server Error"){
  89. $content_url = file_get_contents($url);
  90. $handle = fopen(storage_path()."/desinscrits/". $url_name ."_unsubscribe_m4y_" . $datedujour . ".csv", 'w');
  91. fwrite($handle, $content_url);
  92. \Artisan::call('base:import_desinscrits', ['file' => $url_name . "_unsubscribe_m4y_" . $datedujour . ".csv"]);
  93. \Log::info("Fichier unsubscribe M4Y importé avec succès");
  94. } else {
  95. \Log::info("Fichier unsubscribe M4Y du jour introuvable");
  96. }
  97. // Partie Mindbaz
  98. $url = $s . 'mailexport/unsubscribe/smessage/unsubscribe_mb_' . $datedujour . '.csv';
  99. $url_name = parse_url($s, PHP_URL_HOST);
  100. $test_url = get_headers($url);
  101. if($test_url[0] !== "HTTP/1.0 500 Internal Server Error"){
  102. $content_url = file_get_contents($url);
  103. $handle = fopen(storage_path()."/desinscrits/". $url_name ."_unsubscribe_mb_" . $hier . ".csv", 'w');
  104. fwrite($handle, $content_url);
  105. \Artisan::call('base:import_desinscrits', ['file' => $url_name . "_unsubscribe_mb_" . $hier . ".csv"]);
  106. \Log::info("Fichier unsubscribe MB importé avec succès");
  107. } else {
  108. \Log::info("Fichier unsubscribe MB du jour introuvable");
  109. }
  110. }
  111. \Log::info("Fin du script de récupération des désinscrits des autres TOR");
  112. // verifier que les fichiers existent
  113. // modifier base import desabo pour savoir le nombre de update
  114. }
  115. }