Change comments table structure (drop foreign key on user_id)
This commit is contained in:
@@ -42,7 +42,7 @@ class Comment extends Base
|
||||
->table(self::TABLE)
|
||||
->columns(
|
||||
self::TABLE.'.id',
|
||||
self::TABLE.'.date',
|
||||
self::TABLE.'.date_creation',
|
||||
self::TABLE.'.task_id',
|
||||
self::TABLE.'.user_id',
|
||||
self::TABLE.'.comment',
|
||||
@@ -51,7 +51,7 @@ class Comment extends Base
|
||||
User::TABLE.'.email'
|
||||
)
|
||||
->join(User::TABLE, 'id', 'user_id')
|
||||
->orderBy(self::TABLE.'.date', 'ASC')
|
||||
->orderBy(self::TABLE.'.date_creation', 'ASC')
|
||||
->eq(self::TABLE.'.task_id', $task_id)
|
||||
->findAll();
|
||||
}
|
||||
@@ -71,7 +71,7 @@ class Comment extends Base
|
||||
self::TABLE.'.id',
|
||||
self::TABLE.'.task_id',
|
||||
self::TABLE.'.user_id',
|
||||
self::TABLE.'.date',
|
||||
self::TABLE.'.date_creation',
|
||||
self::TABLE.'.comment',
|
||||
User::TABLE.'.username',
|
||||
User::TABLE.'.name'
|
||||
@@ -105,7 +105,7 @@ class Comment extends Base
|
||||
*/
|
||||
public function create(array $values)
|
||||
{
|
||||
$values['date'] = time();
|
||||
$values['date_creation'] = time();
|
||||
$comment_id = $this->persist(self::TABLE, $values);
|
||||
|
||||
if ($comment_id) {
|
||||
@@ -158,7 +158,6 @@ class Comment extends Base
|
||||
public function validateCreation(array $values)
|
||||
{
|
||||
$rules = array(
|
||||
new Validators\Required('user_id', t('This value is required')),
|
||||
new Validators\Required('task_id', t('This value is required')),
|
||||
);
|
||||
|
||||
|
||||
@@ -302,11 +302,21 @@ class User extends Base
|
||||
{
|
||||
return $this->db->transaction(function ($db) use ($user_id) {
|
||||
|
||||
// All assigned tasks are now unassigned
|
||||
// All assigned tasks are now unassigned (no foreign key)
|
||||
if (! $db->table(Task::TABLE)->eq('owner_id', $user_id)->update(array('owner_id' => 0))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// All assigned subtasks are now unassigned (no foreign key)
|
||||
if (! $db->table(Subtask::TABLE)->eq('user_id', $user_id)->update(array('user_id' => 0))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// All comments are not assigned anymore (no foreign key)
|
||||
if (! $db->table(Comment::TABLE)->eq('user_id', $user_id)->update(array('user_id' => 0))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// All private projects are removed
|
||||
$project_ids = $db->table(Project::TABLE)
|
||||
->eq('is_private', 1)
|
||||
|
||||
Reference in New Issue
Block a user