Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
UploadFromUrlJob | |
0.00% |
0 / 20 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getDeduplicationInfo | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
getUpload | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
logJobParams | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | use MediaWiki\Status\Status; |
22 | |
23 | /** |
24 | * Upload a file by URL, via the jobqueue. |
25 | * |
26 | */ |
27 | class UploadFromUrlJob extends Job implements GenericParameterJob { |
28 | use UploadJobTrait; |
29 | |
30 | public function __construct( array $params ) { |
31 | // @TODO: fix the invokation of Job::__construct in the parent class |
32 | parent::__construct( 'UploadFromUrl', $params ); |
33 | $this->removeDuplicates = true; |
34 | $this->user = null; |
35 | $this->cacheKey = UploadFromUrl::getCacheKey( $this->params ); |
36 | } |
37 | |
38 | /** |
39 | * Deduplicate on title, url alone. |
40 | * |
41 | * Please note that this could cause some |
42 | * edge case failure, when the image at the |
43 | * same remote url is changed before the first upload |
44 | * is ran. |
45 | * |
46 | * @return array |
47 | */ |
48 | public function getDeduplicationInfo() { |
49 | $info = parent::getDeduplicationInfo(); |
50 | if ( is_array( $info['params'] ) ) { |
51 | $info['params'] = [ 'url' => $info['params']['url'], 'title' => $info['params']['filename'] ]; |
52 | } |
53 | |
54 | return $info; |
55 | } |
56 | |
57 | /** |
58 | * getter for the upload |
59 | * |
60 | * @return UploadBase |
61 | */ |
62 | protected function getUpload(): UploadBase { |
63 | if ( $this->upload === null ) { |
64 | $this->upload = new UploadFromUrl; |
65 | $this->upload->initialize( $this->params['filename'], $this->params['url'] ); |
66 | } |
67 | return $this->upload; |
68 | } |
69 | |
70 | /** |
71 | * Get the parameters for job logging |
72 | * |
73 | * @param Status[] $status |
74 | * @return array |
75 | */ |
76 | public function logJobParams( $status ): array { |
77 | return [ |
78 | 'stage' => $status['stage'] ?? '-', |
79 | 'result' => $status['result'] ?? '-', |
80 | 'status' => (string)( $status['status'] ?? '-' ), |
81 | 'url' => $this->params['url'], |
82 | 'filename' => $this->params['filename'], |
83 | 'user' => $this->user->getName(), |
84 | ]; |
85 | } |
86 | |
87 | } |