Răsfoiți Sursa

同时支持gzip 和 7z

visuddhinanda 2 ani în urmă
părinte
comite
69f48dc211
1 a modificat fișierele cu 14 adăugiri și 3 ștergeri
  1. 14 3
      app/Console/Commands/ExportOffline.php

+ 14 - 3
app/Console/Commands/ExportOffline.php

@@ -13,7 +13,7 @@ class ExportOffline extends Command
      *
      * @var string
      */
-    protected $signature = 'export:offline';
+    protected $signature = 'export:offline {format?}';
 
     /**
      * The console command description.
@@ -65,14 +65,25 @@ class ExportOffline extends Command
         $this->info('zip');
         $exportPath = 'app/public/export/offline';
         $exportFile = 'sentence-'.date("Y-m-d").'.db3';
-        $zipFile = "sentence-".date("Y-m-d").".db3.gz";
+        $zipFile = "sentence-".date("Y-m-d").".db3.";
+        if($this->argument('format')==='7z'){
+            $zipFile .= "7z";
+        }else{
+            $zipFile .= "gz";
+        }
+        //
+
 
         $exportFullFileName = storage_path($exportPath.'/'.$exportFile);
         $zipFullFileName = storage_path($exportPath.'/'.$zipFile);
 
         shell_exec("cd ".storage_path($exportPath));
-        shell_exec("gzip -k -q --best -c {$exportFullFileName} > {$zipFullFileName}");
         shell_exec("chmod 600 {$zipFullFileName}");
+        if($this->argument('format')==='7z'){
+            shell_exec("7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on {$zipFullFileName} {$exportFullFileName}");
+        }else{
+            shell_exec("gzip -k -q --best -c {$exportFullFileName} > {$zipFullFileName}");
+        }
 
         $info = array();
         $info[] = ['filename'=>$exportFile,