Quellcode durchsuchen

DhammaTerm->cursor() 提取到foreach外面

visuddhinanda vor 3 Wochen
Ursprung
Commit
ef765ee9ca
1 geänderte Dateien mit 9 neuen und 6 gelöschten Zeilen
  1. 9 6
      api-v13/app/Console/Commands/ExportTerm.php

+ 9 - 6
api-v13/app/Console/Commands/ExportTerm.php

@@ -65,9 +65,8 @@ class ExportTerm extends Command
             return 1;
         }
 
-        $bar = $this->output->createProgressBar(DhammaTerm::count());
-        foreach (
-            DhammaTerm::select([
+        $total = DhammaTerm::count();
+        $channels = DhammaTerm::select([
                 'guid',
                 'word',
                 'word_en',
@@ -83,8 +82,8 @@ class ExportTerm extends Command
                 "updated_at",
                 "deleted_at"
             ])
-                ->cursor() as $row
-        ) {
+                ->cursor();
+        foreach ($channels as $key => $row) {
             $currData = array(
                 $row->guid,
                 $row->word,
@@ -102,7 +101,11 @@ class ExportTerm extends Command
                 $row->deleted_at,
             );
             $stmt->execute($currData);
-            $bar->advance();
+            
+            if($key % 1000 ===0){
+                $precent = (int)($key*100/$total);
+                $this->line("[{$precent}%]");
+            }
         }
         $dbh->commit();
         $bar->finish();