ExportOffline.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. use Illuminate\Support\Facades\Log;
  7. use App\Tools\RedisClusters;
  8. use Illuminate\Support\Facades\Redis;
  9. class ExportOffline extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. * php artisan export:offline lzma
  14. * @var string
  15. */
  16. protected $signature = 'export:offline {format? : zip file format 7z,lzma,gz } {--shortcut}';
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = 'export offline data for app';
  23. /**
  24. * Create a new command instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. }
  32. /**
  33. * Execute the console command.
  34. *
  35. * @return int
  36. */
  37. public function handle()
  38. {
  39. if(\App\Tools\Tools::isStop()){
  40. return 0;
  41. }
  42. $exportDir = storage_path('app/public/export/offline');
  43. if(!is_dir($exportDir)){
  44. $res = mkdir($exportDir,0755,true);
  45. if(!$res){
  46. Log::error('mkdir fail path='.$exportDir);
  47. return 1;
  48. }
  49. }
  50. $exportStop = $exportDir.'/.stop';
  51. $file = fopen($exportStop,'w');
  52. fclose($file);
  53. //建表
  54. $this->info('create db');
  55. $this->call('export:create.db');
  56. //term
  57. $this->info('term');
  58. $this->call('export:term');
  59. //导出channel
  60. $this->info('channel');
  61. $this->call('export:channel');
  62. if(!$this->option('shortcut')){
  63. //tag
  64. $this->info('tag');
  65. $this->call('export:tag');
  66. $this->call('export:tag.map');
  67. //
  68. $this->info('pali text');
  69. $this->call('export:pali.text');
  70. //导出章节索引
  71. $this->info('chapter');
  72. $this->call('export:chapter.index');
  73. //导出译文
  74. $this->info('sentence');
  75. $this->call('export:sentence',['--type'=>'translation']);
  76. $this->call('export:sentence',['--type'=>'nissaya']);
  77. //导出原文
  78. $this->call('export:sentence',['--type'=>'original']);
  79. }
  80. $this->info('zip');
  81. Log::debug('export offline: db写入完毕');
  82. sleep(5);
  83. $this->call('export:zip',['format'=>$this->argument('format')]);
  84. unlink($exportStop);
  85. return 0;
  86. }
  87. }