UpgradeDictVocabulary.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. * php artisan upgrade:dict.vocabulary
  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. if(\App\Tools\Tools::isStop()){
  38. return 0;
  39. }
  40. $words = UserDict::where('source','_PAPER_')->selectRaw('word,count(*)')->groupBy('word')->cursor();
  41. $bar = $this->output->createProgressBar(230000);
  42. foreach ($words as $word) {
  43. $update = Vocabulary::firstOrNew(
  44. ['word' => $word->word],
  45. ['word_en'=>Tools::getWordEn($word->word)]
  46. );
  47. $update->count = $word->count;
  48. $update->flag = 1;
  49. $update->strlen = mb_strlen($word->word,"UTF-8");
  50. $update->save();
  51. $bar->advance();
  52. }
  53. $bar->finish();
  54. Vocabulary::where('flag',0)->delete();
  55. return 0;
  56. }
  57. }