UpgradeDictVocabulary.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\UserDict;
  4. use App\Models\Vocabulary;
  5. use App\Tools\Tools;
  6. use Illuminate\Console\Command;
  7. class UpgradeDictVocabulary extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. * php artisan upgrade:dict.vocabulary
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'upgrade:dict.vocabulary';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = 'Command description';
  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 int
  35. */
  36. public function handle()
  37. {
  38. if (Tools::isStop()) {
  39. return 0;
  40. }
  41. $words = UserDict::where('source', '_PAPER_')->selectRaw('word,count(*)')->groupBy('word')->cursor();
  42. $bar = $this->output->createProgressBar(230000);
  43. foreach ($words as $word) {
  44. $update = Vocabulary::firstOrNew(
  45. ['word' => $word->word],
  46. ['word_en' => Tools::getWordEn($word->word)]
  47. );
  48. $update->count = $word->count;
  49. $update->flag = 1;
  50. $update->strlen = mb_strlen($word->word, 'UTF-8');
  51. $update->save();
  52. $bar->advance();
  53. }
  54. $bar->finish();
  55. Vocabulary::where('flag', 0)->delete();
  56. return 0;
  57. }
  58. }