Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
PublishStashedFileJob | |
0.00% |
0 / 19 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getDeduplicationInfo | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
logJobParams | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
getUpload | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 |
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 | * @defgroup JobQueue JobQueue |
20 | */ |
21 | |
22 | use MediaWiki\Status\Status; |
23 | |
24 | /** |
25 | * Upload a file from the upload stash into the local file repo. |
26 | * |
27 | * @ingroup Upload |
28 | * @ingroup JobQueue |
29 | */ |
30 | class PublishStashedFileJob extends Job implements GenericParameterJob { |
31 | use UploadJobTrait; |
32 | |
33 | public function __construct( array $params ) { |
34 | parent::__construct( 'PublishStashedFile', $params ); |
35 | $this->removeDuplicates = true; |
36 | $this->initialiseUploadJob( $this->params['filekey'] ); |
37 | } |
38 | |
39 | public function getDeduplicationInfo() { |
40 | $info = parent::getDeduplicationInfo(); |
41 | if ( is_array( $info['params'] ) ) { |
42 | $info['params'] = [ 'filekey' => $info['params']['filekey'] ]; |
43 | } |
44 | |
45 | return $info; |
46 | } |
47 | |
48 | /** |
49 | * Get the parameters for job logging |
50 | * |
51 | * @param Status[] $status |
52 | * @return array |
53 | */ |
54 | public function logJobParams( $status ): array { |
55 | return [ |
56 | 'stage' => $status['stage'] ?? '-', |
57 | 'result' => $status['result'] ?? '-', |
58 | 'status' => (string)( $status['status'] ?? '-' ), |
59 | 'filekey' => $this->params['filekey'], |
60 | 'filename' => $this->params['filename'], |
61 | 'user' => $this->user->getName(), |
62 | ]; |
63 | } |
64 | |
65 | /** |
66 | * getter for the upload |
67 | * |
68 | * @return UploadFromStash |
69 | */ |
70 | protected function getUpload(): UploadBase { |
71 | if ( $this->upload === null ) { |
72 | $this->upload = new UploadFromStash( $this->user ); |
73 | // @todo initialize() causes a GET, ideally we could frontload the antivirus |
74 | // checks and anything else to the stash stage (which includes concatenation and |
75 | // the local file is thus already there). That way, instead of GET+PUT, there could |
76 | // just be a COPY operation from the stash to the public zone. |
77 | $this->upload->initialize( $this->params['filekey'], $this->params['filename'] ); |
78 | } |
79 | return $this->upload; |
80 | } |
81 | } |