ExportChapterIndex.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\Storage;
  5. use App\Models\ProgressChapter;
  6. class ExportChapterIndex extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'export:chapter.index';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'export chapter index';
  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/chapter.csv";
  37. Storage::disk('local')->put($filename, "");
  38. $file = fopen(storage_path("app/{$filename}"),"w");
  39. fputcsv($file,['id','book','paragraph','language','title','channel_id','progress','updated_at']);
  40. $bar = $this->output->createProgressBar(ProgressChapter::count());
  41. foreach (ProgressChapter::select(['uid','book','para','lang','title','channel_id','progress','updated_at'])->cursor() as $chapter) {
  42. fputcsv($file,[
  43. $chapter->uid,
  44. $chapter->book,
  45. $chapter->para,
  46. $chapter->lang,
  47. $chapter->title,
  48. $chapter->channel_id,
  49. $chapter->progress,
  50. $chapter->updated_at,
  51. ]);
  52. $bar->advance();
  53. }
  54. fclose($file);
  55. $bar->finish();
  56. return 0;
  57. }
  58. }