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