UpgradeDictVocabulary.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\Vocabulary;
  5. use App\Models\UserDict;
  6. use App\Tools\Tools;
  7. class UpgradeDictVocabulary extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'upgrade:dict.vocabulary';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Command description';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return int
  34. */
  35. public function handle()
  36. {
  37. $words = UserDict::where('source','_PAPER_')->selectRaw('word,count(*)')->groupBy('word')->cursor();
  38. $bar = $this->output->createProgressBar(200000);
  39. foreach ($words as $word) {
  40. $update = Vocabulary::where('word',$word->word)->updateOrCreate(
  41. ['count' => $word->count, 'flag' => 1],
  42. ['word' => $word->word, 'word_en'=>Tools::getWordEn($word->word)]
  43. );
  44. $bar->advance();
  45. }
  46. $bar->finish();
  47. return 0;
  48. }
  49. }