ExportIKPaliTeam.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\DhammaTerm;
  5. use Illuminate\Support\Facades\Redis;
  6. use Illuminate\Support\Facades\Log;
  7. class ExportIKPaliTeam extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. * php artisan export:ik.pali.team
  12. * @var string
  13. */
  14. protected $signature = 'export:ik.pali.team';
  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. $path = storage_path('app/export/fts');
  38. if (!is_dir($path)) {
  39. $res = mkdir($path, 0700, true);
  40. if (!$res) {
  41. Log::error('mkdir fail path=' . $path);
  42. return 1;
  43. }
  44. }
  45. $filename = "/pali_term.txt";
  46. $fp = fopen($path . $filename, 'w') or die("Unable to open file!");
  47. $wordsList = [];
  48. $teams = DhammaTerm::select(['meaning', 'other_meaning'])->get();
  49. foreach ($teams as $term) {
  50. if (!empty($term->meaning)) {
  51. $wordsList[$term->meaning] = 1;
  52. }
  53. }
  54. foreach ($wordsList as $word => $value) {
  55. fwrite($fp, $word . PHP_EOL);
  56. }
  57. // 关闭文件
  58. fclose($fp);
  59. $this->info('done');
  60. return 0;
  61. }
  62. }