Browse Source

Merge pull request #1691 from visuddhinanda/laravel

rpc.host 拆成 host + port
visuddhinanda 2 years ago
parent
commit
3087d05108
5 changed files with 51 additions and 34 deletions
  1. 24 8
      app/Console/Commands/CopyUserBook.php
  2. 1 1
      app/Tools/Export.php
  3. 1 1
      app/Tools/Markdown.php
  4. 9 17
      app/Tools/PaliSearch.php
  5. 16 7
      config/mint.php

+ 24 - 8
app/Console/Commands/CopyUserBook.php

@@ -16,7 +16,7 @@ class CopyUserBook extends Command
      *
      *
      * @var string
      * @var string
      */
      */
-    protected $signature = 'copy:user.book {--lang}';
+    protected $signature = 'copy:user.book {--lang} {--book=}';
 
 
     /**
     /**
      * The console command description.
      * The console command description.
@@ -53,29 +53,39 @@ class CopyUserBook extends Command
         $userBooks = CustomBookSentence::select('book')->groupBy('book')->get();
         $userBooks = CustomBookSentence::select('book')->groupBy('book')->get();
         $this->info('book '. count($userBooks));
         $this->info('book '. count($userBooks));
         foreach ($userBooks as $key => $book) {
         foreach ($userBooks as $key => $book) {
+            $queryBook = $this->option('book');
+            if(!empty($queryBook)){
+                if($book->book != $queryBook){
+                    continue;
+                }
+            }
             $this->info('doing book '. $book->book);
             $this->info('doing book '. $book->book);
             $bookInfo = CustomBookSentence::where('book',$book->book)->first();
             $bookInfo = CustomBookSentence::where('book',$book->book)->first();
             $bookLang = $bookInfo->lang;
             $bookLang = $bookInfo->lang;
+            //|| $bookLang === 'false' || $bookLang === 'null'
             if(empty($bookLang) || $bookLang === 'false' || $bookLang === 'null'){
             if(empty($bookLang) || $bookLang === 'false' || $bookLang === 'null'){
-                $this->error('language can not be empty book='.$book->book);
-                Log::error('copy:user.book language can not be empty , book='.$book->book);
-                continue;
+                $this->info('language can not be empty change to pa, book='.$book->book);
+                Log::warning('copy:user.book language can not be empty ,change to pa, book='.$book->book);
+                $bookLang = 'pa';
             }
             }
-            $channelName = '_user_book_'.$bookInfo->lang;
+            $channelName = '_user_book_'.$bookLang;
             $channel = Channel::where('owner_uid',$bookInfo->owner)
             $channel = Channel::where('owner_uid',$bookInfo->owner)
                             ->where('name',$channelName)->first();
                             ->where('name',$channelName)->first();
             if($channel === null){
             if($channel === null){
+                $channelUuid = Str::uuid();
                 $channel = new Channel;
                 $channel = new Channel;
                 $channel->id = app('snowflake')->id();
                 $channel->id = app('snowflake')->id();
+                $channel->uid = $channelUuid;
                 $channel->owner_uid = $bookInfo->owner;
                 $channel->owner_uid = $bookInfo->owner;
                 $channel->name = $channelName;
                 $channel->name = $channelName;
                 $channel->type = 'original';
                 $channel->type = 'original';
-                $channel->lang = $bookInfo->lang;
+                $channel->lang = $bookLang;
                 $channel->editor_id = 0;
                 $channel->editor_id = 0;
                 $channel->create_time = time()*1000;
                 $channel->create_time = time()*1000;
                 $channel->modify_time = time()*1000;
                 $channel->modify_time = time()*1000;
                 $channel->status = $bookInfo->status;
                 $channel->status = $bookInfo->status;
                 $channel->save();
                 $channel->save();
+                Log::debug('copy user book : create channel name='.$channelName);
             }
             }
 
 
             $bar = $this->output->createProgressBar(CustomBookSentence::where('book',$book->book)
             $bar = $this->output->createProgressBar(CustomBookSentence::where('book',$book->book)
@@ -103,8 +113,14 @@ class CopyUserBook extends Command
                 $newRow->strlen = mb_strlen($sentence->content,"UTF-8");
                 $newRow->strlen = mb_strlen($sentence->content,"UTF-8");
                 $newRow->status = $sentence->status;
                 $newRow->status = $sentence->status;
                 $newRow->content_type = $sentence->content_type;
                 $newRow->content_type = $sentence->content_type;
-                $newRow->language = $sentence->lang;
-                $newRow->save();
+                $newRow->language = $channel->lang;
+                if(empty($newRow->channel_uid)){
+                    $this->error('channel uuid is null book='.$sentence->book .' para='.$sentence->paragraph);
+                    Log::error('channel uuid is null ',['sentence'=>$sentence->book]);
+                }else{
+                    $newRow->save();
+                }
+
             }
             }
             $bar->finish();
             $bar->finish();
             $this->info("book {$book->book} finished");
             $this->info("book {$book->book} finished");

+ 1 - 1
app/Tools/Export.php

@@ -17,7 +17,7 @@ class Export
             //Log::info($value['name']);
             //Log::info($value['name']);
             //Log::info($value['content']);
             //Log::info($value['content']);
         }
         }
-        $host = config('mint.server.rpc.lily');
+        $host = config('mint.server.rpc.lily.host') . ':' . config('mint.server.rpc.lily.port');
         $client = new \Palm\Lily\V1\TexClient($host, [
         $client = new \Palm\Lily\V1\TexClient($host, [
             'credentials' => \Grpc\ChannelCredentials::createInsecure(),
             'credentials' => \Grpc\ChannelCredentials::createInsecure(),
         ]);
         ]);

+ 1 - 1
app/Tools/Markdown.php

@@ -28,7 +28,7 @@ class Markdown
     }
     }
 
 
     public static function morus($text){
     public static function morus($text){
-        $host = config('mint.server.rpc.morus');
+        $host = config('mint.server.rpc.morus.host') . ':'. config('mint.server.rpc.morus.port');
         Log::debug('morus host='.$host);
         Log::debug('morus host='.$host);
         $client = new \Mint\Morus\V1\MarkdownClient($host, [
         $client = new \Mint\Morus\V1\MarkdownClient($host, [
             'credentials' => \Grpc\ChannelCredentials::createInsecure(),
             'credentials' => \Grpc\ChannelCredentials::createInsecure(),

+ 9 - 17
app/Tools/PaliSearch.php

@@ -5,12 +5,16 @@ use Illuminate\Support\Facades\Log;
 
 
 class PaliSearch
 class PaliSearch
 {
 {
-    public static function search($words,$books,$matchMode='case',$index=0,$size=10){
-        $host = config('mint.server.rpc.tulip');
+    public static function connect(){
+        $host = config('mint.server.rpc.tulip.host') . ':' . config('mint.server.rpc.tulip.port');
         Log::debug('tulip host='.$host);
         Log::debug('tulip host='.$host);
         $client = new \Mint\Tulip\V1\SearchClient($host, [
         $client = new \Mint\Tulip\V1\SearchClient($host, [
             'credentials' => \Grpc\ChannelCredentials::createInsecure(),
             'credentials' => \Grpc\ChannelCredentials::createInsecure(),
         ]);
         ]);
+        return $client;
+    }
+    public static function search($words,$books,$matchMode='case',$index=0,$size=10){
+        $client = PaliSearch::connect();
 
 
         $request = new \Mint\Tulip\V1\SearchRequest();
         $request = new \Mint\Tulip\V1\SearchRequest();
         $request->setKeywords($words);
         $request->setKeywords($words);
@@ -42,11 +46,7 @@ class PaliSearch
     }
     }
 
 
     public static function book_list($words,$books,$matchMode='case',$index=0,$size=10){
     public static function book_list($words,$books,$matchMode='case',$index=0,$size=10){
-        $host = config('mint.server.rpc.tulip');
-        Log::debug('tulip host='.$host);
-        $client = new \Mint\Tulip\V1\SearchClient($host, [
-            'credentials' => \Grpc\ChannelCredentials::createInsecure(),
-        ]);
+        $client = PaliSearch::connect();
 
 
         $request = new \Mint\Tulip\V1\SearchRequest();
         $request = new \Mint\Tulip\V1\SearchRequest();
         $request->setKeywords($words);
         $request->setKeywords($words);
@@ -74,11 +74,7 @@ class PaliSearch
     }
     }
 
 
     public static function upload_dict($data){
     public static function upload_dict($data){
-        $host = config('mint.server.rpc.tulip');
-        Log::debug('tulip host='.$host);
-        $client = new \Mint\Tulip\V1\SearchClient($host, [
-            'credentials' => \Grpc\ChannelCredentials::createInsecure(),
-        ]);
+        $client = PaliSearch::connect();
 
 
         $request = new \Mint\Tulip\V1\UploadDictionaryRequest();
         $request = new \Mint\Tulip\V1\UploadDictionaryRequest();
         $request->setData($data);
         $request->setData($data);
@@ -94,11 +90,7 @@ class PaliSearch
     public static function update($book,$paragraph,
     public static function update($book,$paragraph,
                                   $bold1,$bold2,$bold3,
                                   $bold1,$bold2,$bold3,
                                   $content,$pcd_book_id){
                                   $content,$pcd_book_id){
-        $host = config('mint.server.rpc.tulip');
-        Log::debug('tulip host='.$host);
-        $client = new \Mint\Tulip\V1\SearchClient($host, [
-            'credentials' => \Grpc\ChannelCredentials::createInsecure(),
-        ]);
+        $client = PaliSearch::connect();
 
 
         $request = new \Mint\Tulip\V1\UpdateRequest();
         $request = new \Mint\Tulip\V1\UpdateRequest();
         $request->setBook($book);
         $request->setBook($book);

+ 16 - 7
config/mint.php

@@ -15,13 +15,22 @@ return [
 
 
     'server' => [
     'server' => [
         'rpc' => [
         'rpc' => [
-            'grpc' => env('GRPC_WEB_SERVER', "http://localhost:9999"),
-
-            'morus' => env('MORUS_GRPC_SERVER', "http://localhost:9999"),
-
-            'lily' => env('LILY_GRPC_SERVER', "http://localhost:9000"),
-
-            'tulip' => env('TULIP_GRPC_SERVER', "http://localhost:9990"),
+            'grpc' =>  env('GRPC_WEB_SERVER', "http://localhost:9999"),
+
+            'morus' => [
+                'host' => env('MORUS_GRPC_HOST', "localhost"),
+                'port' => env('MORUS_GRPC_PORT', 9999),
+            ],
+
+            'lily' => [
+                'host' => env('LILY_GRPC_HOST', "localhost"),
+                'port' => env('LILY_GRPC_PORT', 9000),
+            ],
+
+            'tulip' => [
+                'host' => env('LILY_GRPC_HOST', "localhost"),
+                'port' => env('LILY_GRPC_PORT', 9990),
+            ],
         ],
         ],
 
 
         'assets' => env('ASSETS_SERVER', "localhost:9999"),
         'assets' => env('ASSETS_SERVER', "localhost:9999"),