PageRenderTime 33ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/app/Console/Commands/ImportFichierCliqueurs.php

https://bitbucket.org/hfab/webservice
PHP | 139 lines | 65 code | 27 blank | 47 comment | 14 complexity | 6d7f1590b8cf7b524ab503fccb894f16 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. // pour test
  5. use App\Classes\Routeurs\RouteurMaildrop;
  6. use App\Classes\Routeurs\RouteurPhoenix;
  7. use App\Classes\Routeurs\RouteurSmessage;
  8. class ImportFichierCliqueurs extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'import:fcliqueur {le_fichier} {info_envoi}';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = 'Importe les cliqueurs à partir de fichier texte';
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. \DB::disableQueryLog();
  39. $dataset = array();
  40. $counterchunck = 0;
  41. $today = date("Y-m-d H:i:s");
  42. $date_active = date("Y-m-d");
  43. $tabimport = array();
  44. $minitab = null;
  45. $info_envoi = $this->argument('info_envoi');
  46. // je dois recup le campagne_id et ajouter theme
  47. // var_dump($info_envoi);
  48. $file = storage_path().'/cliqueurs/'.$this->argument('le_fichier');
  49. if (!is_file($file)) {
  50. $this->error('File not found : '.$file);
  51. }
  52. $pdo = \DB::connection()->getPdo();
  53. $sql = "INSERT IGNORE INTO clics (campagne_id, destinataire_id, created_at, updated_at, theme_id, clic_file, date_active) VALUES (:v_campagne, :v_destinataire, :v_created_at, :v_updated_at, :v_theme_id, :v_clic_file, :v_date_active)";
  54. $stmt = $pdo->prepare($sql);
  55. $pdo->beginTransaction();
  56. $fh = fopen($file, 'r');
  57. while (!feof($fh)){
  58. $row = fgets($fh, 1024);
  59. $row = trim($row);
  60. if(empty($row) || $row == null || $row == false){
  61. // ligne non conforme
  62. } else {
  63. $destinataire = \DB::table('destinataires')->select('id')->where('base_id',$info_envoi->base_id)->where('mail', $row)->first();
  64. var_dump($row);
  65. // var_dump($destinataire);
  66. if(empty($destinataire) || $destinataire == null || $destinataire == false){
  67. // on ne fait rien car le desti n'est pas dans la bdd
  68. echo 'vide';
  69. } else {
  70. // on fait un tableau pour insert
  71. // v1
  72. //
  73. // \DB::table('clics')->insert(
  74. // ['campagne_id' => $info_envoi->id,
  75. // 'destinataire_id' => $destinataire->id,
  76. // 'created_at' => $today,
  77. // 'updated_at' => $today,
  78. // 'theme_id' => $info_envoi->theme_id,
  79. // 'clic_file' => $this->argument('le_fichier')
  80. //
  81. // ]
  82. // );
  83. // v2
  84. $dataset[] = ['campagne_id' => $info_envoi->id,
  85. 'destinataire_id' => $destinataire->id,
  86. 'created_at' => $today,
  87. 'updated_at' => $today,
  88. 'theme_id' => $info_envoi->theme_id,
  89. 'clic_file' => $this->argument('le_fichier')];
  90. $insertData = [$info_envoi->id,$destinataire->id, $today, $today, $info_envoi->theme_id, $this->argument('le_fichier'), $date_active];
  91. $stmt->execute($insertData);
  92. }
  93. }
  94. }
  95. echo 'INSERT Chunck' . "\n";
  96. // pdo jobs base import desti
  97. // a voir si les doublons etaient sur les meme campagnes
  98. // avoir si ca marche
  99. // $dataset = array_unique($dataset);
  100. // \DB::table('clics')->insert($dataset);
  101. // var_dump($insertData);
  102. $pdo->commit();
  103. // $dataset = array();
  104. }
  105. protected function getArguments()
  106. {
  107. return [
  108. ['le_fichier', InputArgument::REQUIRED, 'Nom du fichier'],
  109. ['info_envoi', InputArgument::REQUIRED, 'Le planning'],
  110. ];
  111. }
  112. }