|
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\Attachment; |
|
13
|
|
|
|
|
14
|
|
|
use Tinyissue\Contracts\Model\UserInterface; |
|
15
|
|
|
use Tinyissue\Model\Project; |
|
16
|
|
|
use Tinyissue\Repository\RepositoryUpdater; |
|
17
|
|
|
|
|
18
|
|
|
class Updater extends RepositoryUpdater |
|
19
|
|
|
{ |
|
20
|
|
|
public function __construct(Project\Issue\Attachment $model) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->model = $model; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function delete() |
|
26
|
|
|
{ |
|
27
|
|
|
$path = $this->getUploadStorage($this->model->issue->project, $this->model->upload_token); |
|
28
|
|
|
$this->deleteFile($path, $this->model->filename); |
|
29
|
|
|
|
|
30
|
|
|
return parent::delete(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Upload the attachment. |
|
35
|
|
|
* |
|
36
|
|
|
* @param array $input |
|
37
|
|
|
* @param Project $project |
|
38
|
|
|
* @param UserInterface $user |
|
39
|
|
|
* |
|
40
|
|
|
* @return Eloquent\Model |
|
41
|
|
|
*/ |
|
42
|
|
|
public function upload(array $input, Project $project, UserInterface $user) |
|
43
|
|
|
{ |
|
44
|
|
|
// Upload path |
|
45
|
|
|
$path = $this->getUploadStorage($project, $input['upload_token']); |
|
46
|
|
|
|
|
47
|
|
|
/* @var $uploadedFile \Symfony\Component\HttpFoundation\File\UploadedFile */ |
|
48
|
|
|
$uploadedFile = $input['upload']; |
|
49
|
|
|
$file = $uploadedFile->move($path, $uploadedFile->getClientOriginalName()); |
|
50
|
|
|
|
|
51
|
|
|
$this->model->uploaded_by = $user->id; |
|
|
|
|
|
|
52
|
|
|
$this->model->filename = $file->getFilename(); |
|
53
|
|
|
$this->model->fileextension = $file->getExtension(); |
|
54
|
|
|
$this->model->filesize = $file->getSize(); |
|
55
|
|
|
$this->model->upload_token = $input['upload_token']; |
|
56
|
|
|
|
|
57
|
|
|
return $this->save(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Remove a attachment that is pending from a issue/comment. |
|
62
|
|
|
* |
|
63
|
|
|
* @param array $input |
|
64
|
|
|
* @param Project $project |
|
65
|
|
|
* @param UserInterface $user |
|
66
|
|
|
* |
|
67
|
|
|
* @return void |
|
68
|
|
|
*/ |
|
69
|
|
|
public function remove(array $input, Project $project, UserInterface $user) |
|
70
|
|
|
{ |
|
71
|
|
|
$this->model->byUser($user)->forToken($input['upload_token'])->filename($input['filename'])->delete(); |
|
72
|
|
|
|
|
73
|
|
|
$path = $this->getUploadStorage($project, $input['upload_token']); |
|
74
|
|
|
$this->deleteFile($path, $input['filename']); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Delete the physical file of an attachment. |
|
79
|
|
|
* |
|
80
|
|
|
* @param string $path |
|
81
|
|
|
* @param string $filename |
|
82
|
|
|
*/ |
|
83
|
|
View Code Duplication |
public function deleteFile($path, $filename) |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
$file = $path . '/' . $filename; |
|
86
|
|
|
|
|
87
|
|
|
if (file_exists($file)) { |
|
88
|
|
|
unlink($file); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if (is_dir($path)) { |
|
92
|
|
|
rmdir($path); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function updateIssueToken($token, $uploadBy, $issueId) |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->model->forToken($token)->byUser($uploadBy)->update(['issue_id' => $issueId]); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function updateCommentToken($token, $uploadBy, $issueId, $commentId) |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->model->forToken($token)->byUser($uploadBy)->update([ |
|
104
|
|
|
'issue_id' => $issueId, |
|
105
|
|
|
'comment_id' => $commentId, |
|
106
|
|
|
]); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: