Browse Source

:construction: create export

visuddhinanda 3 years ago
parent
commit
b2d05c41e2

+ 63 - 0
app/Console/Commands/ExportChannel.php

@@ -0,0 +1,63 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Storage;
+use App\Models\Channel;
+
+class ExportChannel extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'export:channel';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Command description';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return int
+     */
+    public function handle()
+    {
+        Storage::disk('local')->put("public/export/channel.csv", "");
+        $file = fopen(storage_path('app/public/export/channel.csv'),"w");
+        fputcsv($file,['id','name','type','language','summary','owner_id','setting','created_at']);
+        $bar = $this->output->createProgressBar(Channel::where('status',30)->count());
+        foreach (Channel::where('status',30)->select(['uid','name','type','lang','summary','owner_uid','setting','created_at'])->cursor() as $chapter) {
+            fputcsv($file,[
+                            $chapter->uid,
+                            $chapter->name,
+                            $chapter->type,
+                            $chapter->lang,
+                            $chapter->summary,
+                            $chapter->owner_uid,
+                            $chapter->setting,
+                            $chapter->created_at,
+                            ]);
+            $bar->advance();
+        }
+        fclose($file);
+        $bar->finish();
+        return 0;
+    }
+}

+ 63 - 0
app/Console/Commands/ExportChapterIndex.php

@@ -0,0 +1,63 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Storage;
+use App\Models\ProgressChapter;
+
+class ExportChapterIndex extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'export:chapter.index';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'export chapter index';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return int
+     */
+    public function handle()
+    {
+        Storage::disk('local')->put("public/export/chapter.csv", "");
+        $file = fopen(storage_path('app/public/export/chapter.csv'),"w");
+        fputcsv($file,['id','book','paragraph','language','title','channel_id','progress','updated_at']);
+        $bar = $this->output->createProgressBar(ProgressChapter::count());
+        foreach (ProgressChapter::select(['uid','book','para','lang','title','channel_id','progress','updated_at'])->cursor() as $chapter) {
+            fputcsv($file,[
+                            $chapter->uid,
+                            $chapter->book,
+                            $chapter->para,
+                            $chapter->lang,
+                            $chapter->title,
+                            $chapter->channel_id,
+                            $chapter->progress,
+                            $chapter->updated_at,
+                            ]);
+            $bar->advance();
+        }
+        fclose($file);
+        $bar->finish();
+        return 0;
+    }
+}

+ 67 - 0
app/Console/Commands/ExportSentence.php

@@ -0,0 +1,67 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Storage;
+use App\Models\Sentence;
+
+class ExportSentence extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'export:sentence';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Command description';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return int
+     */
+    public function handle()
+    {
+        Storage::disk('local')->put("public/export/sentence.csv", "");
+        $file = fopen(storage_path('app/public/export/sentence.csv'),"w");
+        fputcsv($file,['id','book','paragraph','word_start','word_end','content','content_type','html','channel_id','editor_id','language','updated_at']);
+        $bar = $this->output->createProgressBar(Sentence::where('status',30)->count());
+        foreach (Sentence::where('status',30)->select(['uid','book_id','paragraph','word_start','word_end','content','content_type','channel_uid','editor_uid','language','updated_at'])->cursor() as $chapter) {
+            fputcsv($file,[
+                            $chapter->uid,
+                            $chapter->book_id,
+                            $chapter->paragraph,
+                            $chapter->word_start,
+                            $chapter->word_end,
+                            $chapter->content,
+                            $chapter->content_type,
+                            $chapter->content,
+                            $chapter->channel_uid,
+                            $chapter->editor_uid,
+                            $chapter->language,
+                            $chapter->updated_at,
+                            ]);
+            $bar->advance();
+        }
+        fclose($file);
+        $bar->finish();
+        return 0;
+    }
+}