I have a boolean field ( field\_rejected ) in my custom comment implementation ,I need to set this field to false if this comment is published

I tried hook\_comment\_update and hook\_comment\_insert, This didn't work as it says in the documentation :

> 
> "Note that hook implementations may not alter the stored entity data."
> 
> 
> 

Then I tried doing this using hook\_entity\_presave but this also didn't work as it results in an infinite loading or error code 500.

This is the code I used:

```
function custom_comments_notification_comment_presave($comment) {
  if ($comment->isPublished() && !$comment->original->isPublished()) {
    $comment->set('field_rejected', 0, $notify = true);
    $comment->save();
  }
}

```

Note that this is implemented in custom module's .module file.

How can I solve this? How can change the boolean 'field\_rejected' after publishing a comment?