|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Tinyissue package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Mohamed Alsharaf <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Tinyissue\Repository\Project\Issue\Comment; |
|
13
|
|
|
|
|
14
|
|
|
use Tinyissue\Contracts\Repository\Project\Issue\Comment\UpdaterRepository as CommentUpdater; |
|
15
|
|
|
use Tinyissue\Model\Project\Issue\Comment; |
|
16
|
|
|
use Tinyissue\Model\User; |
|
17
|
|
|
use Tinyissue\Repository\RepositoryUpdater; |
|
18
|
|
|
|
|
19
|
|
|
class UpdaterRepository extends RepositoryUpdater implements CommentUpdater |
|
20
|
|
|
{ |
|
21
|
|
|
public function __construct(Comment $model) |
|
22
|
|
|
{ |
|
23
|
|
|
$this->model = $model; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Create new comment. |
|
28
|
|
|
* |
|
29
|
|
|
* @param array $input |
|
30
|
|
|
* |
|
31
|
|
|
* @return $this |
|
32
|
|
|
*/ |
|
33
|
|
|
public function create(array $input) |
|
34
|
|
|
{ |
|
35
|
|
|
$fill = [ |
|
36
|
|
|
'created_by' => $this->model->user->id, |
|
37
|
|
|
'project_id' => $this->model->project->id, |
|
38
|
|
|
'issue_id' => $this->model->issue->id, |
|
39
|
|
|
'comment' => $input['comment'], |
|
40
|
|
|
]; |
|
41
|
|
|
|
|
42
|
|
|
$this->model->fill($fill); |
|
43
|
|
|
|
|
44
|
|
|
// Add event on successful save |
|
45
|
|
|
static::saved(function (Issue\Comment $comment) { |
|
|
|
|
|
|
46
|
|
|
$this->queueAdd($comment, $comment->user); |
|
|
|
|
|
|
47
|
|
|
}); |
|
48
|
|
|
|
|
49
|
|
|
$this->save(); |
|
50
|
|
|
|
|
51
|
|
|
/* Add to user's activity log */ |
|
52
|
|
|
$this->model->activity()->save(new User\Activity([ |
|
53
|
|
|
'type_id' => Activity::TYPE_COMMENT, |
|
54
|
|
|
'parent_id' => $this->project->id, |
|
|
|
|
|
|
55
|
|
|
'item_id' => $this->issue->id, |
|
|
|
|
|
|
56
|
|
|
'user_id' => $this->user->id, |
|
|
|
|
|
|
57
|
|
|
])); |
|
58
|
|
|
|
|
59
|
|
|
/* Add attachments to issue */ |
|
60
|
|
|
Attachment::where('upload_token', '=', $input['upload_token']) |
|
61
|
|
|
->where('uploaded_by', '=', $this->user->id) |
|
62
|
|
|
->update(['issue_id' => $this->issue->id, 'comment_id' => $this->id]); |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
/* Update the project */ |
|
65
|
|
|
$this->model->issue->changeUpdatedBy($this->model->user->id); |
|
66
|
|
|
|
|
67
|
|
|
return $this; |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Update comment body. |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $body |
|
74
|
|
|
* @param UserInterface $user |
|
75
|
|
|
* |
|
76
|
|
|
* @return Eloquent\Model |
|
77
|
|
|
*/ |
|
78
|
|
|
public function updateBody($body, UserInterface $user) |
|
79
|
|
|
{ |
|
80
|
|
|
$this->model->fill([ |
|
81
|
|
|
'comment' => $body, |
|
82
|
|
|
]); |
|
83
|
|
|
|
|
84
|
|
|
// Add event on successful save |
|
85
|
|
|
static::saved(function (Issue\Comment $comment) use ($user) { |
|
|
|
|
|
|
86
|
|
|
$this->queueUpdate($comment, $user); |
|
|
|
|
|
|
87
|
|
|
}); |
|
88
|
|
|
|
|
89
|
|
|
return $this->save(); |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function delete() |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->transaction('deleteComment'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Delete a comment and its attachments. |
|
99
|
|
|
* |
|
100
|
|
|
* @param UserInterface $user |
|
|
|
|
|
|
101
|
|
|
* |
|
102
|
|
|
* @return Eloquent\Model |
|
103
|
|
|
* |
|
104
|
|
|
* @throws \Exception |
|
105
|
|
|
*/ |
|
106
|
|
|
protected function deleteComment() |
|
107
|
|
|
{ |
|
108
|
|
|
$this->model->activity()->delete(); |
|
109
|
|
|
|
|
110
|
|
View Code Duplication |
foreach ($this->model->attachments as $attachment) { |
|
|
|
|
|
|
111
|
|
|
$path = config('filesystems.disks.local.root') |
|
112
|
|
|
. '/' . config('tinyissue.uploads_dir') |
|
113
|
|
|
. '/' . $this->model->project_id |
|
114
|
|
|
. '/' . $attachment->upload_token; |
|
115
|
|
|
$attachment->deleteFile($path, $attachment->filename); |
|
116
|
|
|
$attachment->delete(); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
// Add event on successful delete |
|
120
|
|
|
static::deleted(function (Issue\Comment $comment) { |
|
|
|
|
|
|
121
|
|
|
$this->queueDelete($comment, $this->getLoggedUser()); |
|
|
|
|
|
|
122
|
|
|
}); |
|
123
|
|
|
|
|
124
|
|
|
return $this->model->delete(); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.