Bläddra i källkod

PDOException $e =》 \PDOException $e

visuddhinanda 1 vecka sedan
förälder
incheckning
d3f86ddc23

+ 32 - 20
api-v13/app/Console/Commands/ExportChannel.php

@@ -1,7 +1,9 @@
 <?php
+
 /**
  * 导出离线用的channel数据
  */
+
 namespace App\Console\Commands;
 
 use Illuminate\Console\Command;
@@ -42,40 +44,50 @@ class ExportChannel extends Command
      */
     public function handle()
     {
-        if(\App\Tools\Tools::isStop()){
+        if (\App\Tools\Tools::isStop()) {
             return 0;
         }
         Log::debug('task export offline channel-table start');
-        $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));
+        $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();
 
         $query = "INSERT INTO channel ( id , name , type , language ,
                                     summary , owner_id , setting,created_at )
                                     VALUES ( ? , ? , ? , ? , ? , ? , ? , ?  )";
-        try{
+        try {
             $stmt = $dbh->prepare($query);
-        }catch(PDOException $e){
+        } catch (\PDOException $e) {
             Log::error($e->getMessage(), ['exception' => $e]);
             return 1;
         }
 
-        $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 $row) {
-                $currData = array(
-                            $row->uid,
-                            $row->name,
-                            $row->type,
-                            $row->lang,
-                            $row->summary,
-                            $row->owner_uid,
-                            $row->setting,
-                            $row->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 $row
+        ) {
+            $currData = array(
+                $row->uid,
+                $row->name,
+                $row->type,
+                $row->lang,
+                $row->summary,
+                $row->owner_uid,
+                $row->setting,
+                $row->created_at,
+            );
             $stmt->execute($currData);
             $bar->advance();
         }

+ 43 - 34
api-v13/app/Console/Commands/ExportSentence.php

@@ -45,26 +45,26 @@ class ExportSentence extends Command
     public function handle()
     {
         Log::debug('task export offline sentence-table start');
-        if(\App\Tools\Tools::isStop()){
+        if (\App\Tools\Tools::isStop()) {
             return 0;
         }
         \App\Tools\Markdown::driver($this->option('driver'));
         $channels = [];
         $channel_id = $this->option('channel');
-        if($channel_id){
+        if ($channel_id) {
             $file_suf = $channel_id;
             $channels[] = $channel_id;
-        }else{
+        } else {
             $channel_type = $this->option('type');
             $file_suf = $channel_type;
-            if($channel_type === "original"){
+            if ($channel_type === "original") {
                 $pali_channel = ChannelApi::getSysChannel("_System_Pali_VRI_");
-                if($pali_channel === false){
+                if ($pali_channel === false) {
                     return 0;
                 }
                 $channels[] = $pali_channel;
-            }else{
-                $nissaya_channel = Channel::where('type',$channel_type)->where('status',30)->select('uid')->get();
+            } else {
+                $nissaya_channel = Channel::where('type', $channel_type)->where('status', 30)->select('uid')->get();
                 foreach ($nissaya_channel as $key => $value) {
                     # code...
                     $channels[] = $value->uid;
@@ -73,53 +73,62 @@ class ExportSentence extends Command
         }
 
 
-        $exportFile = storage_path('app/public/export/offline/wikipali-offline-'.date("Y-m-d").'.db3');
-        $dbh = new \PDO('sqlite:'.$exportFile, "", "", array(\PDO::ATTR_PERSISTENT => true));
+        $exportFile = storage_path('app/public/export/offline/wikipali-offline-' . 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();
 
-        if($channel_type === "original"){
+        if ($channel_type === "original") {
             $table = 'sentence';
-        }else{
+        } else {
             $table = 'sentence_translation';
         }
 
         $query = "INSERT INTO {$table} ( book , paragraph ,
                                     word_start , word_end , content , channel_id  )
                                     VALUES ( ? , ? , ? , ? , ? , ? )";
-        try{
+        try {
             $stmt = $dbh->prepare($query);
-        }catch(PDOException $e){
+        } catch (\PDOException $e) {
             Log::error($e->getMessage(), ['exception' => $e]);
             return 1;
         }
 
-        $db = Sentence::whereIn('channel_uid',$channels);
+        $db = Sentence::whereIn('channel_uid', $channels);
         $bar = $this->output->createProgressBar($db->count());
-        $srcDb = $db->select(['uid','book_id','paragraph',
-                                'word_start','word_end',
-                                'content','content_type','channel_uid',
-                                'editor_uid','language','updated_at'])->cursor();
+        $srcDb = $db->select([
+            'uid',
+            'book_id',
+            'paragraph',
+            'word_start',
+            'word_end',
+            'content',
+            'content_type',
+            'channel_uid',
+            'editor_uid',
+            'language',
+            'updated_at'
+        ])->cursor();
         foreach ($srcDb as $sent) {
-            if(Str::isUuid($sent->channel_uid)){
+            if (Str::isUuid($sent->channel_uid)) {
                 $channel = ChannelApi::getById($sent->channel_uid);
                 $currData = array(
-                        $sent->book_id,
-                        $sent->paragraph,
-                        $sent->word_start,
-                        $sent->word_end,
-                        MdRender::render($sent->content,
-                                        [$sent->channel_uid],
-                                        null,
-                                        'read',
-                                        $channel['type'],
-                                        $sent->content_type,
-                                        'unity',
-                                        ),
-                        $sent->channel_uid,
-                    );
+                    $sent->book_id,
+                    $sent->paragraph,
+                    $sent->word_start,
+                    $sent->word_end,
+                    MdRender::render(
+                        $sent->content,
+                        [$sent->channel_uid],
+                        null,
+                        'read',
+                        $channel['type'],
+                        $sent->content_type,
+                        'unity',
+                    ),
+                    $sent->channel_uid,
+                );
                 $stmt->execute($currData);
-
             }
             $bar->advance();
         }

+ 6 - 6
api-v13/app/Console/Commands/ExportTag.php

@@ -41,26 +41,26 @@ class ExportTag extends Command
     public function handle()
     {
         Log::debug('task: export offline data tag-table start');
-        if(\App\Tools\Tools::isStop()){
+        if (\App\Tools\Tools::isStop()) {
             return 0;
         }
-        $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));
+        $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();
 
         $query = "INSERT INTO tag ( id , name ,
                                     description , color , owner_id  )
                                     VALUES ( ? , ? , ? , ? , ?  )";
-        try{
+        try {
             $stmt = $dbh->prepare($query);
-        }catch(PDOException $e){
+        } catch (\PDOException $e) {
             Log::error($e->getMessage(), ['exception' => $e]);
             return 1;
         }
 
         $bar = $this->output->createProgressBar(Tag::count());
-        foreach (Tag::select(['id','name','description','color','owner_id'])->cursor() as $row) {
+        foreach (Tag::select(['id', 'name', 'description', 'color', 'owner_id'])->cursor() as $row) {
             $currData = array(
                 $row->id,
                 $row->name,

+ 9 - 9
api-v13/app/Console/Commands/ExportTagmap.php

@@ -41,29 +41,29 @@ class ExportTagmap extends Command
     public function handle()
     {
         Log::debug('task: export offline tagmap-table start');
-        if(\App\Tools\Tools::isStop()){
+        if (\App\Tools\Tools::isStop()) {
             return 0;
         }
-        $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));
+        $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();
 
         $query = "INSERT INTO tag_map ( anchor_id , tag_id )
                                     VALUES ( ? , ? )";
-        try{
+        try {
             $stmt = $dbh->prepare($query);
-        }catch(PDOException $e){
+        } catch (\PDOException $e) {
             Log::error($e->getMessage(), ['exception' => $e]);
             return 1;
         }
 
         $bar = $this->output->createProgressBar(TagMap::count());
-        foreach (TagMap::select(['id','table_name','anchor_id','tag_id'])->cursor() as $row) {
+        foreach (TagMap::select(['id', 'table_name', 'anchor_id', 'tag_id'])->cursor() as $row) {
             $currData = array(
-                            $row->anchor_id,
-                            $row->tag_id,
-                            );
+                $row->anchor_id,
+                $row->tag_id,
+            );
             $stmt->execute($currData);
             $bar->advance();
         }

+ 41 - 28
api-v13/app/Console/Commands/ExportTerm.php

@@ -42,11 +42,11 @@ class ExportTerm extends Command
     {
         Log::info('task export offline term-table start');
         $startAt = time();
-        if(\App\Tools\Tools::isStop()){
+        if (\App\Tools\Tools::isStop()) {
             return 0;
         }
-        $exportFile = storage_path('app/public/export/offline/wikipali-offline-'.date("Y-m-d").'.db3');
-        $dbh = new \PDO('sqlite:'.$exportFile, "", "", array(\PDO::ATTR_PERSISTENT => true));
+        $exportFile = storage_path('app/public/export/offline/wikipali-offline-' . 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();
 
@@ -58,42 +58,55 @@ class ExportTerm extends Command
                                             ? , ? , ? , ? ,
                                             ?, ?, ?,
                                             ?, ?, ? )";
-        try{
+        try {
             $stmt = $dbh->prepare($query);
-        }catch(PDOException $e){
+        } catch (\PDOException $e) {
             Log::error($e->getMessage(), ['exception' => $e]);
             return 1;
         }
 
         $bar = $this->output->createProgressBar(DhammaTerm::count());
-        foreach (DhammaTerm::select(['guid','word','word_en','meaning',
-                          'other_meaning','note','tag','channal',
-                          'language',"owner","editor_id",
-                          "created_at","updated_at","deleted_at"
-                          ])
-                          ->cursor() as $row) {
-                $currData = array(
-                            $row->guid,
-                            $row->word,
-                            $row->word_en,
-                            $row->meaning,
-                            $row->other_meaning,
-                            $row->note,
-                            $row->tag,
-                            $row->channal,
-                            $row->language,
-                            $row->owner,
-                            $row->editor_id,
-                            $row->created_at,
-                            $row->updated_at,
-                            $row->deleted_at,
-                            );
+        foreach (
+            DhammaTerm::select([
+                'guid',
+                'word',
+                'word_en',
+                'meaning',
+                'other_meaning',
+                'note',
+                'tag',
+                'channal',
+                'language',
+                "owner",
+                "editor_id",
+                "created_at",
+                "updated_at",
+                "deleted_at"
+            ])
+                ->cursor() as $row
+        ) {
+            $currData = array(
+                $row->guid,
+                $row->word,
+                $row->word_en,
+                $row->meaning,
+                $row->other_meaning,
+                $row->note,
+                $row->tag,
+                $row->channal,
+                $row->language,
+                $row->owner,
+                $row->editor_id,
+                $row->created_at,
+                $row->updated_at,
+                $row->deleted_at,
+            );
             $stmt->execute($currData);
             $bar->advance();
         }
         $dbh->commit();
         $bar->finish();
-        $this->info(' time='.(time()-$startAt).'s');
+        $this->info(' time=' . (time() - $startAt) . 's');
         Log::info('task export offline term-table finished');
         return 0;
     }