ExportOffline.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 {format?}';
  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.";
  62. if($this->argument('format')==='7z'){
  63. $zipFile .= "7z";
  64. }else{
  65. $zipFile .= "gz";
  66. }
  67. //
  68. $exportFullFileName = storage_path($exportPath.'/'.$exportFile);
  69. $zipFullFileName = storage_path($exportPath.'/'.$zipFile);
  70. shell_exec("cd ".storage_path($exportPath));
  71. shell_exec("chmod 600 {$zipFullFileName}");
  72. if($this->argument('format')==='7z'){
  73. shell_exec("7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on {$zipFullFileName} {$exportFullFileName}");
  74. }else{
  75. shell_exec("gzip -k -q --best -c {$exportFullFileName} > {$zipFullFileName}");
  76. }
  77. $info = array();
  78. $info[] = ['filename'=>$exportFile,
  79. 'create_at'=>date("Y-m-d H:i:s"),
  80. 'chapter'=>Cache::get("/export/chapter/count"),
  81. 'filesize'=>filesize($zipFullFileName),
  82. ];
  83. Storage::disk('local')->put("public/export/offline/index.json", json_encode($info));
  84. return 0;
  85. }
  86. }