ExportSentence.php 2.0 KB

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