Browse Source

add is_system

visuddhinanda 2 years ago
parent
commit
b19e1c9b57

+ 21 - 5
app/Console/Commands/CopyUserBook.php

@@ -58,6 +58,8 @@ class CopyUserBook extends Command
         }
 
         $this->info('给CustomBook 添加channel');
+        $newChannel = 0;
+
         foreach (CustomBook::get() as $key => $customBook) {
             $this->info('doing book='.$customBook->book_id);
             if(empty($customBook->channel_id)){
@@ -82,28 +84,34 @@ class CopyUserBook extends Command
                     $channel->type = 'original';
                     $channel->lang = $bookLang;
                     $channel->editor_id = 0;
+                    $channel->is_system = true;
                     $channel->create_time = time()*1000;
                     $channel->modify_time = time()*1000;
                     $channel->status = $customBook->status;
                     if(!$this->option('test')){
                         $saveOk = $channel->save();
                         if($saveOk){
+                            $newChannel++;
                             Log::debug('copy user book : create channel success name='.$channelName);
                         }else{
-                            Log::error('copy user book : create channel fail.',['channel'=>$channelName,'book'=>$book->book]);
+                            Log::error('copy user book : create channel fail.',['channel'=>$channelName,'book'=>$customBook->book_id]);
                             $this->error('copy user book : create channel fail.  name='.$channelName);
                             continue;
                         }
                     }
                 }
                 if(!Str::isUuid($channel->uid)){
-                    Log::error('copy user book : channel id error.',['channel'=>$channelName,'book'=>$book->book]);
+                    Log::error('copy user book : channel id error.',['channel'=>$channelName,'book'=>$customBook->book_id]);
                     $this->error('copy user book : channel id error.  name='.$channelName);
                     continue;
                 }
                 $customBook->channel_id = $channel->uid;
                 if(!$this->option('test')){
-                    $customBook->save();
+                    $ok = $customBook->save();
+                    if(!$ok){
+                        Log::error('copy user book : create channel fail.',['book'=>$customBook->book_id]);
+                        continue;
+                    }
                 }
             }
         }
@@ -111,7 +119,9 @@ class CopyUserBook extends Command
 
         $userBooks = CustomBook::get();
         $this->info('book '. count($userBooks));
+        $copySent = 0;
         foreach ($userBooks as $key => $book) {
+
             $queryBook = $this->option('book');
             if(!empty($queryBook)){
                 if($book->book_id != $queryBook){
@@ -152,13 +162,19 @@ class CopyUserBook extends Command
                     Log::error('channel uuid is null ',['sentence'=>$sentence->book]);
                 }else{
                     if(!$this->option('test')){
-                        $newRow->save();
+                        $ok = $newRow->save();
+                        if(!$ok){
+                            Log::error('copy fail ',['sentence'=>$sentence->id]);
+                        }
+                        $copySent++;
                     }
                 }
             }
             $this->info("book {$book->book} finished");
         }
-        $this->info('all done');
+        $this->info('all done ');
+        $this->info('channel create '.$newChannel);
+        $this->info('sentence copy '.$copySent);
         return 0;
     }
 }

+ 1 - 0
app/Http/Api/ChannelApi.php

@@ -92,6 +92,7 @@ class ChannelApi{
         $channel->type = 'original';
         $channel->lang = $bookLang;
         $channel->editor_id = 0;
+        $channel->is_system = true;
         $channel->create_time = time()*1000;
         $channel->modify_time = time()*1000;
         $channel->status = $customBook->status;

+ 1 - 1
app/Http/Controllers/ArticleController.php

@@ -511,7 +511,7 @@ class ArticleController extends Controller
             $newBook->lang = $anthology->lang;
             $newBook->status = $anthology->status;
             //查询anthology所在的studio有没有符合要求的channel 没有的话,建立
-            $channelId = ChannelApi::userBookGetOrCreate($anthology->owner,$anthology->lang);
+            $channelId = ChannelApi::userBookGetOrCreate($anthology->owner,$anthology->lang,true);
             if($channelId === false){
                 throw new \Exception('user book get fail studio='.$anthology->owner.' language='.$anthology->lang);
             }

+ 10 - 4
app/Http/Controllers/ChannelController.php

@@ -36,7 +36,7 @@ class ChannelController extends Controller
 		$result=false;
 		$indexCol = ['uid','name','summary',
                     'type','owner_uid','lang',
-                    'status','updated_at','created_at'];
+                    'status','is_system','updated_at','created_at'];
 		switch ($request->get('view')) {
             case 'public':
                 $table = Channel::select($indexCol)
@@ -510,7 +510,7 @@ class ChannelController extends Controller
     public function show($id)
     {
         //
-        $indexCol = ['uid','name','summary','type','owner_uid','lang','status','updated_at','created_at'];
+        $indexCol = ['uid','name','summary','type','owner_uid','lang','is_system','status','updated_at','created_at'];
 		$channel = Channel::where("uid",$id)->select($indexCol)->first();
         $studio = StudioApi::getById($channel->owner_uid);
         $channel->studio = $studio;
@@ -530,13 +530,16 @@ class ChannelController extends Controller
         //鉴权
         $user = AuthApi::current($request);
         if(!$user){
-            return $this->error(__('auth.failed'),[],401);
+            return $this->error(__('auth.failed'),401,401);
+        }
+        if($channel->is_system){
+            return $this->error('system channel',403,403);
         }
         if($channel->owner_uid !== $user["user_uid"]){
             //判断是否为协作
             $power = ShareApi::getResPower($user["user_uid"],$request->get('id'));
             if($power < 30){
-                return $this->error(__('auth.failed'),[],403);
+                return $this->error(__('auth.failed'),403,403);
             }
         }
         $channel->name = $request->get('name');
@@ -561,6 +564,9 @@ class ChannelController extends Controller
         if(!$user){
             return $this->error(__('auth.failed'),[],401);
         }
+        if($channel->is_system){
+            return $this->error('system channel',403,403);
+        }
         if($channel->owner_uid !== $user["user_uid"]){
             //判断是否为协作
             $power = ShareApi::getResPower($user["user_uid"],$request->get('id'));

+ 1 - 0
app/Http/Resources/ChannelResource.php

@@ -22,6 +22,7 @@ class ChannelResource extends JsonResource
             "type" => $this->type,
             "studio" => StudioApi::getById($this->owner_uid),
             "lang" => $this->lang,
+            "is_system" => $this->is_system,
             "status" => $this->status,
             "created_at" => $this->created_at,
             "updated_at" => $this->updated_at,