Jelajahi Sumber

Merge pull request #1897 from visuddhinanda/laravel

导出支持索引下载
visuddhinanda 2 tahun lalu
induk
melakukan
9c0a432664

+ 2 - 2
app/Console/Commands/ExportChannel.php

@@ -16,7 +16,7 @@ class ExportChannel extends Command
      *
      * @var string
      */
-    protected $signature = 'export:channel';
+    protected $signature = 'export:channel {db}';
 
     /**
      * The console command description.
@@ -46,7 +46,7 @@ class ExportChannel extends Command
             return 0;
         }
         Log::debug('task export offline channel-table start');
-        $exportFile = storage_path('app/public/export/offline/wikipali-offline-'.date("Y-m-d").'.db3');
+        $exportFile = storage_path('app/public/export/offline/'.$this->argument('db').'-'.date("Y-m-d").'.db3');
         $dbh = new \PDO('sqlite:'.$exportFile, "", "", array(\PDO::ATTR_PERSISTENT => true));
         $dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
         $dbh->beginTransaction();

+ 3 - 2
app/Console/Commands/ExportChapterIndex.php

@@ -17,7 +17,7 @@ class ExportChapterIndex extends Command
      *
      * @var string
      */
-    protected $signature = 'export:chapter.index';
+    protected $signature = 'export:chapter.index {db : db file name wikipali-offline or wikipali-offline-index}';
 
     /**
      * The console command description.
@@ -47,7 +47,8 @@ class ExportChapterIndex extends Command
         if(\App\Tools\Tools::isStop()){
             return 0;
         }
-        $exportFile = storage_path('app/public/export/offline/wikipali-offline-'.date("Y-m-d").'.db3');
+
+        $exportFile = storage_path('app/public/export/offline/'.$this->argument('db').'-'.date("Y-m-d").'.db3');
         $dbh = new \PDO('sqlite:'.$exportFile, "", "", array(\PDO::ATTR_PERSISTENT => true));
         $dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
         $dbh->beginTransaction();

+ 9 - 3
app/Console/Commands/ExportCreateDb.php

@@ -43,9 +43,16 @@ class ExportCreateDb extends Command
         if(\App\Tools\Tools::isStop()){
             return 0;
         }
-        $sqlPath = database_path('export/sentence.sql');
+        $this->create('sentence.sql','wikipali-offline');
+        $this->create('sentence.sql','wikipali-offline-index');
+
+        return 0;
+    }
+
+    private function create($sqlFile,$dbFile){
+        $sqlPath = database_path('export/'.$sqlFile);
         $exportDir = storage_path('app/public/export/offline');
-        $exportFile = $exportDir.'/wikipali-offline-'.date("Y-m-d").'.db3';
+        $exportFile = $exportDir.'/'.$dbFile.'-'.date("Y-m-d").'.db3';
         $file = fopen($exportFile,'w');
         fclose($file);
         $dbh = new \PDO('sqlite:'.$exportFile, "", "", array(\PDO::ATTR_PERSISTENT => true));
@@ -58,6 +65,5 @@ class ExportCreateDb extends Command
             $dbh->query($_value . ';');
         }
         Log::debug('task export offline create-db finished');
-        return 0;
     }
 }

+ 25 - 9
app/Console/Commands/ExportOffline.php

@@ -16,7 +16,7 @@ class ExportOffline extends Command
      * php artisan export:offline lzma
      * @var string
      */
-    protected $signature = 'export:offline {format?  : zip file format 7z,lzma,gz } {--shortcut}';
+    protected $signature = 'export:offline {format?  : zip file format 7z,lzma,gz } {--shortcut}  {--driver=morus}';
 
     /**
      * The console command description.
@@ -67,7 +67,8 @@ class ExportOffline extends Command
 
         //导出channel
         $this->info('export channel start');
-        $this->call('export:channel');
+        $this->call('export:channel',['db'=>'wikipali-offline']);
+        $this->call('export:channel',['db'=>'wikipali-offline-index']);
 
         if(!$this->option('shortcut')){
             //tag
@@ -79,23 +80,38 @@ class ExportOffline extends Command
             $this->call('export:pali.text');
             //导出章节索引
             $this->info('export chapter start');
-            $this->call('export:chapter.index');
+            $this->call('export:chapter.index',['db'=>'wikipali-offline']);
+            $this->call('export:chapter.index',['db'=>'wikipali-offline-index']);
             //导出译文
             $this->info('export sentence start');
-            $this->call('export:sentence',['--type'=>'translation']);
-            $this->call('export:sentence',['--type'=>'nissaya']);
+            $this->call('export:sentence',['--type'=>'translation','--driver'=>$this->option('driver')]);
+            $this->call('export:sentence',['--type'=>'nissaya','--driver'=>$this->option('driver')]);
             //导出原文
-            $this->call('export:sentence',['--type'=>'original']);
+            $this->call('export:sentence',['--type'=>'original','--driver'=>$this->option('driver')]);
         }
 
         $this->info('zip');
         Log::info('export offline: db写入完毕 开始压缩');
 
         sleep(5);
-        $this->call('export:zip',['format'=>$this->argument('format')]);
-
-        unlink($exportStop);
+        $this->call('export:zip',[
+            'db'=>'wikipali-offline-index',
+            'format'=>$this->argument('format'),
+        ]);
+        $this->call('export:zip',[
+            'db'=>'wikipali-offline',
+            'format'=>$this->argument('format'),
+        ]);
 
+        //删除全部的旧文件
+        $fullPath = storage_path($exportPath);
+        foreach (scandir($exportDir) as $key => $file) {
+            if(is_file($exportDir.'/'.$file)){
+                if($file !== '.stop'){
+                    unlink($exportDir.'/'.$file);
+                }
+            }
+        }
         return 0;
     }
 }

+ 2 - 1
app/Console/Commands/ExportSentence.php

@@ -18,7 +18,7 @@ class ExportSentence extends Command
      *
      * @var string
      */
-    protected $signature = 'export:sentence {--channel=} {--type=translation}';
+    protected $signature = 'export:sentence {--channel=} {--type=translation} {--driver=morus}';
 
     /**
      * The console command description.
@@ -48,6 +48,7 @@ class ExportSentence extends Command
         if(\App\Tools\Tools::isStop()){
             return 0;
         }
+        \App\Tools\Markdown::driver($this->option('driver'));
         $channels = [];
         $channel_id = $this->option('channel');
         if($channel_id){

+ 4 - 3
app/Console/Commands/ExportZip.php

@@ -15,7 +15,7 @@ class ExportZip extends Command
      *
      * @var string
      */
-    protected $signature = 'export:zip {format?  : zip file format 7z,lzma,gz }';
+    protected $signature = 'export:zip {db : db filename} {format?  : zip file format 7z,lzma,gz }';
 
     /**
      * The console command description.
@@ -44,7 +44,8 @@ class ExportZip extends Command
         Log::debug('export offline: 开始压缩');
         $this->info('export offline: 开始压缩');
         $exportPath = 'app/public/export/offline';
-        $exportFile = 'wikipali-offline-'.date("Y-m-d").'.db3';
+        $exportFile = $this->argument('db').'-'.date("Y-m-d").'.db3';
+
         Log::debug('export offline: zip file {filename} {format}',
                     [
                         'filename'=>$exportFile,
@@ -141,7 +142,7 @@ class ExportZip extends Command
                    'filesize'=>filesize($zipFullFileName),
                    'min_app_ver'=>'1.3',
                     ];
-        RedisClusters::put('/offline/index',$info);
+        RedisClusters::put('/offline/index/'.$this->argument('db'),$info);
         unlink($exportFullFileName);
         return 0;
     }

+ 3 - 1
app/Console/Commands/UpgradeProgressChapter.php

@@ -21,7 +21,7 @@ class UpgradeProgressChapter extends Command
      * php artisan upgrade:progress.chapter --book=168 --para=915 --channel=19f53a65-81db-4b7d-8144-ac33f1217d34
      * @var string
      */
-    protected $signature = 'upgrade:progress.chapter  {--book=} {--para=} {--channel=}';
+    protected $signature = 'upgrade:progress.chapter  {--book=} {--para=} {--channel=} {--driver=morus}';
 
     /**
      * The console command description.
@@ -56,6 +56,8 @@ class UpgradeProgressChapter extends Command
         $para = $this->option('para');
         $channelId = $this->option('channel');
 
+        \App\Tools\Markdown::driver($this->option('driver'));
+
         $tagCount=0;
         #第一步 查询有多少书有译文
         if($book){

+ 8 - 3
app/Http/Controllers/OfflineIndexController.php

@@ -17,11 +17,16 @@ class OfflineIndexController extends Controller
      *
      * @return \Illuminate\Http\Response
      */
-    public function index()
+    public function index(Request $request)
     {
         //
-        if(RedisClusters::has('/offline/index')){
-            $fileInfo = RedisClusters::get('/offline/index');
+        $key = '/offline/index/wikipali-offline';
+        if($request->has('file')){
+            $key .= '-'.$request->get('file');
+        }
+
+        if(RedisClusters::has()){
+            $fileInfo = RedisClusters::get($key);
             foreach ($fileInfo as $key => $file) {
                 $zipFile = $file['filename'];
                 $bucket = config('mint.attachments.bucket_name.temporary');