ExportPalitext.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\Storage;
  5. use App\Models\PaliText;
  6. class ExportPalitext extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'export:pali.text';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '导出离线用的巴利段落数据';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return int
  33. */
  34. public function handle()
  35. {
  36. $filename = "public/export/offline/pali_text.csv";
  37. Storage::disk('local')->put($filename, "");
  38. $file = fopen(storage_path("app/{$filename}"),"w");
  39. fputcsv($file,['id','book','paragraph','level','toc','length','chapter_len','next_chapter','prev_chapter','parent','chapter_strlen']);
  40. $bar = $this->output->createProgressBar(PaliText::count());
  41. foreach (PaliText::select(['uid','book','paragraph','level','toc','lenght','chapter_len','next_chapter','prev_chapter','parent','chapter_strlen'])
  42. ->orderBy('book')
  43. ->orderBy('paragraph')
  44. ->cursor() as $chapter) {
  45. fputcsv($file,[
  46. $chapter->uid,
  47. $chapter->book,
  48. $chapter->paragraph,
  49. $chapter->level,
  50. $chapter->toc,
  51. $chapter->lenght,
  52. $chapter->chapter_len,
  53. $chapter->next_chapter,
  54. $chapter->prev_chapter,
  55. $chapter->parent,
  56. $chapter->chapter_strlen,
  57. ]);
  58. $bar->advance();
  59. }
  60. fclose($file);
  61. $bar->finish();
  62. return 0;
  63. }
  64. }