ExportOffline.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\Storage;
  5. class ExportOffline extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'export:offline';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'Command description';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return int
  32. */
  33. public function handle()
  34. {
  35. //建表
  36. $this->info('create db');
  37. $this->call('export:create.db');
  38. //导出channel
  39. $this->info('channel');
  40. $this->call('export:channel');
  41. //tag
  42. $this->info('tag');
  43. $this->call('export:tag');
  44. $this->call('export:tag.map');
  45. //
  46. $this->info('pali text');
  47. $this->call('export:pali.text');
  48. //导出章节索引
  49. $this->info('chapter');
  50. $this->call('export:chapter.index');
  51. //导出译文
  52. $this->info('sentence');
  53. $this->call('export:sentence',['--type'=>'translation']);
  54. $this->call('export:sentence',['--type'=>'nissaya']);
  55. //导出原文
  56. $this->call('export:sentence',['--type'=>'original']);
  57. $this->info('zip');
  58. $exportPath = 'app/public/export/offline';
  59. $exportFile = 'sentence-'.date("Y-m-d").'.db3';
  60. $zipFile = "sentence-".date("Y-m-d").".db3.gz";
  61. shell_exec("cd ".storage_path($exportPath));
  62. shell_exec("gzip -k -q --best -c {$exportFile} > {$zipFile}");
  63. shell_exec("chmod 600 {$zipFile}");
  64. $info = array();
  65. $info[] = ['filename'=>$exportFile,
  66. 'create_at'=>date("Y-m-d H:i:s"),
  67. 'chapter'=>Cache::get("/export/chapter/count"),
  68. 'filesize'=>filename($zipFile),
  69. ];
  70. Storage::disk('local')->put("public/export/offline/index.json", json_encode($info));
  71. return 0;
  72. }
  73. }