Commit 54dbe61c authored by Emma's avatar Emma

add the notion of soft deletion

parent b8e84ec4
<?php
namespace Raddit\AppBundle\DoctrineMigrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
class Version20170103055453 extends AbstractMigration {
/**
* @param Schema $schema
*/
public function up(Schema $schema) {
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE comments ADD soft_deleted BOOLEAN DEFAULT FALSE NOT NULL');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema) {
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE comments DROP soft_deleted');
}
}
......@@ -84,6 +84,13 @@ class Comment implements BodyInterface, VotableInterface {
*/
private $votes;
/**
* @ORM\Column(type="boolean")
*
* @var bool
*/
private $softDeleted = false;
/**
* Creates a new comment with an implicit upvote from the comment author.
*
......@@ -260,4 +267,27 @@ class Comment implements BodyInterface, VotableInterface {
return $vote;
}
/**
* @return bool
*/
public function isSoftDeleted() {
return $this->softDeleted;
}
/**
* @param bool $softDeleted
*/
public function setSoftDeleted($softDeleted) {
$this->softDeleted = $softDeleted;
}
/**
* Delete a comment without deleting its replies.
*/
public function softDelete() {
$this->softDeleted = true;
$this->body = '';
$this->rawBody = '';
}
}
comments:
author_deleted: '[deleted]'
comments: Comments
permalink: Permalink
parent: Parent
......
......@@ -25,7 +25,7 @@
{%- block comment -%}
{%- from '@RadditApp/macros/votes.html.twig' import vote -%}
<article class="comment {{ level|default(0) ? 'comment-level-'~level : 'comment-top-level' }}">
<article class="comment {{ level|default(0) ? 'comment-level-'~level : 'comment-top-level' }} {{ comment.softDeleted ? 'comment-soft-deleted' }}">
<div class="comment-inner">
{{ vote(comment, path('raddit_app_comment_vote', {id: comment.id})) }}
......@@ -71,9 +71,13 @@
{%- endblock -%}
{%- block comment_info_user -%}
<a href="{{ path('raddit_app_user', {username: comment.user.username}) }}" class="comment-user">
{{- comment.user.username -}}
</a>
{%- if not comment.softDeleted -%}
<a href="{{ path('raddit_app_user', {username: comment.user.username}) }}" class="comment-user">
{{- comment.user.username -}}
</a>
{%- else -%}
{{- 'comments.author_deleted'|trans -}}
{%- endif -%}
{%- endblock -%}
{%- block comment_info_timestamp -%}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment