]> BookStack Code Mirror - bookstack/blobdiff - app/Actions/CommentRepo.php
Reverted shift change to old migration
[bookstack] / app / Actions / CommentRepo.php
index c0f008137c87bac251ea8f8637c3cea68e302161..85fb6498a92bca35897e65845f00b87e2ba64a95 100644 (file)
@@ -1,20 +1,21 @@
-<?php namespace BookStack\Actions;
+<?php
 
-use BookStack\Entities\Entity;
+namespace BookStack\Actions;
+
+use BookStack\Entities\Models\Entity;
+use BookStack\Facades\Activity as ActivityService;
 use League\CommonMark\CommonMarkConverter;
 
 /**
- * Class CommentRepo
+ * Class CommentRepo.
  */
 class CommentRepo
 {
-
     /**
-     * @var Comment $comment
+     * @var Comment
      */
     protected $comment;
 
-
     public function __construct(Comment $comment)
     {
         $this->comment = $comment;
@@ -44,7 +45,8 @@ class CommentRepo
         $comment->parent_id = $parent_id;
 
         $entity->comments()->save($comment);
-        Activity::add($entity, ActivityType::COMMENTED_ON, $entity->book->id);
+        ActivityService::addForEntity($entity, ActivityType::COMMENTED_ON);
+
         return $comment;
     }
 
@@ -57,6 +59,7 @@ class CommentRepo
         $comment->text = $text;
         $comment->html = $this->commentToHtml($text);
         $comment->save();
+
         return $comment;
     }
 
@@ -74,8 +77,8 @@ class CommentRepo
     public function commentToHtml(string $commentText): string
     {
         $converter = new CommonMarkConverter([
-            'html_input' => 'strip',
-            'max_nesting_level' => 10,
+            'html_input'         => 'strip',
+            'max_nesting_level'  => 10,
             'allow_unsafe_links' => false,
         ]);
 
@@ -88,6 +91,7 @@ class CommentRepo
     protected function getNextLocalId(Entity $entity): int
     {
         $comments = $entity->comments(false)->orderBy('local_id', 'desc')->first();
+
         return ($comments->local_id ?? 0) + 1;
     }
 }