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
UploadFromUrlJob
0.00% covered (danger)
0.00%
0 / 20
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 / 4
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
 getUpload
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
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/**
22 * Upload a file by URL, via the jobqueue.
23 *
24 */
25class UploadFromUrlJob extends Job implements GenericParameterJob {
26    use UploadJobTrait;
27
28    public function __construct( array $params ) {
29        // @TODO: fix the invokation of Job::__construct in the parent class
30        parent::__construct( 'UploadFromUrl', $params );
31        $this->removeDuplicates = true;
32        $this->user = null;
33        $this->cacheKey = UploadFromUrl::getCacheKey( $this->params );
34    }
35
36    /**
37     * Deduplicate on title, url alone.
38     *
39     * Please note that this could cause some
40     * edge case failure, when the image at the
41     * same remote url is changed before the first upload
42     * is ran.
43     *
44     * @return array
45     */
46    public function getDeduplicationInfo() {
47        $info = parent::getDeduplicationInfo();
48        if ( is_array( $info['params'] ) ) {
49            $info['params'] = [ 'url' => $info['params']['url'], 'title' => $info['params']['filename'] ];
50        }
51
52        return $info;
53    }
54
55    /**
56     * getter for the upload
57     *
58     * @return UploadBase
59     */
60    protected function getUpload(): UploadBase {
61        if ( $this->upload === null ) {
62            $this->upload = new UploadFromUrl;
63            $this->upload->initialize( $this->params['filename'], $this->params['url'] );
64        }
65        return $this->upload;
66    }
67
68    /**
69     * Get the parameters for job logging
70     *
71     * @param Status[] $status
72     * @return array
73     */
74    public function logJobParams( $status ): array {
75        return [
76            'stage' => $status['stage'] ?? '-',
77            'result' => $status['result'] ?? '-',
78            'status' => (string)( $status['status'] ?? '-' ),
79            'url' => $this->params['url'],
80            'filename' => $this->params['filename'],
81            'user' => $this->user->getName(),
82        ];
83    }
84
85}