ExportOffline.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\Storage;
  5. use Illuminate\Support\Facades\Cache;
  6. class ExportOffline extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'export:offline';
  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. //建表
  37. $this->info('create db');
  38. $this->call('export:create.db');
  39. //导出channel
  40. $this->info('channel');
  41. $this->call('export:channel');
  42. //tag
  43. $this->info('tag');
  44. $this->call('export:tag');
  45. $this->call('export:tag.map');
  46. //
  47. $this->info('pali text');
  48. $this->call('export:pali.text');
  49. //导出章节索引
  50. $this->info('chapter');
  51. $this->call('export:chapter.index');
  52. //导出译文
  53. $this->info('sentence');
  54. $this->call('export:sentence',['--type'=>'translation']);
  55. $this->call('export:sentence',['--type'=>'nissaya']);
  56. //导出原文
  57. $this->call('export:sentence',['--type'=>'original']);
  58. $this->info('zip');
  59. $exportPath = 'app/public/export/offline';
  60. $exportFile = 'sentence-'.date("Y-m-d").'.db3';
  61. $zipFile = "sentence-".date("Y-m-d").".db3.gz";
  62. $exportFullFileName = storage_path($exportPath.'/'.$exportFile);
  63. $zipFullFileName = storage_path($exportPath.'/'.$zipFile);
  64. shell_exec("cd ".storage_path($exportPath));
  65. shell_exec("gzip -k -q --best -c {$exportFullFileName} > {$zipFullFileName}");
  66. shell_exec("chmod 600 {$zipFullFileName}");
  67. $info = array();
  68. $info[] = ['filename'=>$exportFile,
  69. 'create_at'=>date("Y-m-d H:i:s"),
  70. 'chapter'=>Cache::get("/export/chapter/count"),
  71. 'filesize'=>filename($zipFullFileName),
  72. ];
  73. Storage::disk('local')->put("public/export/offline/index.json", json_encode($info));
  74. return 0;
  75. }
  76. }