1
|
|
|
<?php |
2
|
|
|
namespace AL\Common\DAO; |
3
|
|
|
|
4
|
|
|
require_once __DIR__."/../../lib/Db.php" ; |
5
|
|
|
require_once __DIR__."/../Model/Dump/MediaScan.php" ; |
6
|
|
|
require_once __DIR__."/../Model/Dump/MediaScanType.php" ; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* DAO for MediaScan |
10
|
|
|
*/ |
11
|
|
|
class MediaScanDAO { |
12
|
|
|
private $mysqli; |
13
|
|
|
|
14
|
|
|
public function __construct($mysqli) { |
15
|
|
|
$this->mysqli = $mysqli; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Add a mediaScan to a media |
20
|
|
|
* |
21
|
|
|
* @param int release_id |
22
|
|
|
* @param int media_type_id |
|
|
|
|
23
|
|
|
*/ |
24
|
|
|
public function addMediaScanToMedia($media_id, $scan_type_id, $media_scan_save_path, $image) { |
25
|
|
|
|
26
|
|
|
foreach ($image['tmp_name'] as $key => $tmp_name) { |
27
|
|
|
if ($tmp_name !== 'none') { |
28
|
|
|
// Check what extention the file has and if it is allowed. |
29
|
|
|
$ext = ""; |
30
|
|
|
$type_image = $image['type'][$key]; |
31
|
|
|
|
32
|
|
|
// set extension |
33
|
|
|
if ($type_image == 'image/png') { |
34
|
|
|
$ext = 'png'; |
35
|
|
|
} elseif ($type_image == 'image/x-png') { |
36
|
|
|
$ext = 'png'; |
37
|
|
|
} elseif ($type_image == 'image/gif') { |
38
|
|
|
$ext = 'gif'; |
39
|
|
|
} elseif ($type_image == 'image/jpeg') { |
40
|
|
|
$ext = 'jpg'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if ($ext !== "") { |
44
|
|
|
$stmt = \AL\Db\execute_query( |
45
|
|
|
"MediaScanDAO: addMediaScanToMedia", |
46
|
|
|
$this->mysqli, |
47
|
|
|
"INSERT INTO media_scan (`media_id`, `media_scan_type_id`, `imgext`) VALUES (?, ?, ?)", |
48
|
|
|
"iis", $media_id, $scan_type_id, $ext |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
$last_id = $stmt->insert_id; |
52
|
|
|
|
53
|
|
|
// Rename the uploaded file to its autoincrement number and move it to its proper place. |
54
|
|
|
$file_data = rename($image['tmp_name'][$key], "$media_scan_save_path$last_id.$ext"); |
|
|
|
|
55
|
|
|
chmod("$media_scan_save_path$last_id.$ext", 0777); |
56
|
|
|
|
57
|
|
|
$stmt->close(); |
58
|
|
|
} else { |
59
|
|
|
exit("This file extension is not allowed"); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get all MediaScans from this media |
67
|
|
|
* |
68
|
|
|
* @return \AL\Common\Model\Dump\MediaScan[] An array of mediascans |
69
|
|
|
*/ |
70
|
|
|
public function getAllMediaScansFromMedia($media_id) { |
71
|
|
|
$stmt = \AL\Db\execute_query( |
72
|
|
|
"MediaScanDAO: getAllMediaScansFromMedia", |
73
|
|
|
$this->mysqli, |
74
|
|
|
"SELECT media_scan.id, media_scan.imgext, media_scan_type.id, media_scan_type.name FROM media_scan |
75
|
|
|
LEFT JOIN media_scan_type ON (media_scan.media_scan_type_id = media_scan_type.id) |
76
|
|
|
WHERE media_scan.media_id = ?", |
77
|
|
|
"i", $media_id |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
\AL\Db\bind_result( |
81
|
|
|
"MediaScanDAO: getAllMediaScansFromMedia", |
82
|
|
|
$stmt, |
83
|
|
|
$media_scan_id, $media_scan_imgext, $media_scan_type_id, $media_scan_type_name |
|
|
|
|
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
$media_scan = []; |
87
|
|
|
while ($stmt->fetch()) { |
88
|
|
|
$media_scan[] = new \AL\Common\Model\Dump\MediaScan( |
89
|
|
|
$media_scan_id, $media_id, $media_scan_imgext, |
90
|
|
|
($media_scan_type_name != null) |
91
|
|
|
? new \AL\Common\Model\dump\MediaScanType($media_scan_type_id, $media_scan_type_name) |
92
|
|
|
: null |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$stmt->close(); |
97
|
|
|
|
98
|
|
|
return $media_scan; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/* |
102
|
|
|
* delete scan from a media |
103
|
|
|
* |
104
|
|
|
* @param int media_scan_id |
|
|
|
|
105
|
|
|
*/ |
106
|
|
|
public function deleteScanFromMedia($media_scan_id, $media_scan_save_path, $ext) { |
107
|
|
|
$stmt = \AL\Db\execute_query( |
108
|
|
|
"MediaScanDAO: deleteScanFromMedia", |
109
|
|
|
$this->mysqli, |
110
|
|
|
"DELETE FROM media_scan WHERE id = ?", |
111
|
|
|
"i", $media_scan_id |
112
|
|
|
); |
113
|
|
|
|
114
|
|
|
$new_path = $media_scan_save_path; |
115
|
|
|
$new_path .= $media_scan_id; |
116
|
|
|
$new_path .= "."; |
117
|
|
|
$new_path .= $ext; |
118
|
|
|
|
119
|
|
|
unlink("$new_path"); |
120
|
|
|
|
121
|
|
|
$stmt->close(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/* |
125
|
|
|
* check is scantype exist on media |
126
|
|
|
* |
127
|
|
|
* @param int media_id |
128
|
|
|
* @param int scan_type_id |
|
|
|
|
129
|
|
|
*/ |
130
|
|
|
public function checkForScanType($media_id, $scan_type_id) { |
131
|
|
|
$stmt = \AL\Db\execute_query( |
132
|
|
|
"MediaScanDAO: checkForScanType", |
133
|
|
|
$this->mysqli, |
134
|
|
|
"SELECT id FROM media_scan |
135
|
|
|
WHERE media_id = ? and media_scan_type_id = ?", |
136
|
|
|
"ii", $media_id, $scan_type_id |
137
|
|
|
); |
138
|
|
|
|
139
|
|
|
\AL\Db\bind_result( |
140
|
|
|
"MediaScanDAO: checkForScanType", |
141
|
|
|
$stmt, |
142
|
|
|
$media_scan_id |
143
|
|
|
); |
144
|
|
|
|
145
|
|
|
$media_scan_id = null; |
146
|
|
|
if ($stmt->fetch()) { |
147
|
|
|
$media_scan_id = new \AL\Common\Model\Dump\MediaScan( |
148
|
|
|
$media_scan_id, null, null, null |
149
|
|
|
); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
$stmt->close(); |
153
|
|
|
|
154
|
|
|
return $media_scan_id; |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths