const BOOKSHELF_DELETE = 'bookshelf_delete';
const COMMENTED_ON = 'commented_on';
+ const COMMENT_CREATE = 'comment_create';
+ const COMMENT_UPDATE = 'comment_update';
+ const COMMENT_DELETE = 'comment_delete';
+
const PERMISSIONS_UPDATE = 'permissions_update';
const REVISION_RESTORE = 'revision_restore';
$comment->parent_id = $parent_id;
$entity->comments()->save($comment);
+ ActivityService::add(ActivityType::COMMENT_CREATE, $comment);
ActivityService::add(ActivityType::COMMENTED_ON, $entity);
return $comment;
$comment->html = $this->commentToHtml($text);
$comment->save();
+ ActivityService::add(ActivityType::COMMENT_UPDATE, $comment);
+
return $comment;
}
public function delete(Comment $comment): void
{
$comment->delete();
+
+ ActivityService::add(ActivityType::COMMENT_DELETE, $comment);
}
/**
* @property string $html
* @property int|null $parent_id
* @property int $local_id
+ * @property string $entity_type
+ * @property int $entity_id
*/
-class Comment extends Model
+class Comment extends Model implements Loggable
{
use HasFactory;
use HasCreatorAndUpdater;
{
return $this->updated_at->diffForHumans();
}
+
+ public function logDescriptor(): string
+ {
+ return "Comment #{$this->local_id} (ID: {$this->id}) for {$this->entity_type} (ID: {$this->entity_id})";
+ }
}
use BookStack\Activity\Models\Activity;
use BookStack\Activity\Models\Loggable;
use BookStack\Activity\Models\Webhook;
+use BookStack\App\Model;
use BookStack\Entities\Models\Entity;
use BookStack\Facades\Theme;
use BookStack\Theming\ThemeEvents;
{
/**
* Add a generic activity event to the database.
- *
- * @param string|Loggable $detail
*/
public function add(string $type, $detail = '')
{
* and instead uses the 'extra' field with the entities name.
* Used when an entity is deleted.
*/
- public function removeEntity(Entity $entity)
+ public function removeEntity(Entity $entity): void
{
$entity->activity()->update([
'detail' => $entity->name,
}
}
- /**
- * @param string|Loggable $detail
- */
- protected function dispatchWebhooks(string $type, $detail): void
+ protected function dispatchWebhooks(string $type, string|Loggable $detail): void
{
$webhooks = Webhook::query()
->whereHas('trackedEvents', function (Builder $query) use ($type) {
* Log out a failed login attempt, Providing the given username
* as part of the message if the '%u' string is used.
*/
- public function logFailedLogin(string $username)
+ public function logFailedLogin(string $username): void
{
$message = config('logging.failed_login.message');
if (!$message) {