ExportIKPaliTeam.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\DhammaTerm;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Facades\Log;
  6. class ExportIKPaliTeam extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. * php artisan export:ik.pali.team
  11. *
  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 exit('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. }