Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
88.24% covered (warning)
88.24%
15 / 17
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
DeleteFileOp
88.24% covered (warning)
88.24%
15 / 17
75.00% covered (warning)
75.00%
3 / 4
7.08
0.00% covered (danger)
0.00%
0 / 1
 allowedParams
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 doPrecheck
85.71% covered (warning)
85.71%
12 / 14
0.00% covered (danger)
0.00%
0 / 1
4.05
 doAttempt
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 storagePathsChanged
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Helper class for representing operations with transaction support.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup FileBackend
22 */
23
24/**
25 * Delete a file at the given storage path from the backend.
26 * Parameters for this operation are outlined in FileBackend::doOperations().
27 */
28class DeleteFileOp extends FileOp {
29    protected function allowedParams() {
30        return [ [ 'src' ], [ 'ignoreMissingSource' ], [ 'src' ] ];
31    }
32
33    protected function doPrecheck(
34        FileStatePredicates $opPredicates,
35        FileStatePredicates $batchPredicates
36    ) {
37        $status = StatusValue::newGood();
38
39        // Check source file existence
40        $srcExists = $this->resolveFileExistence( $this->params['src'], $opPredicates );
41        if ( $srcExists === false ) {
42            if ( $this->getParam( 'ignoreMissingSource' ) ) {
43                $this->noOp = true; // no-op
44                // Update file existence predicates (cache 404s)
45                $batchPredicates->assumeFileDoesNotExist( $this->params['src'] );
46
47                return $status; // nothing to do
48            } else {
49                $status->fatal( 'backend-fail-notexists', $this->params['src'] );
50
51                return $status;
52            }
53        } elseif ( $srcExists === FileBackend::EXISTENCE_ERROR ) {
54            $status->fatal( 'backend-fail-stat', $this->params['src'] );
55
56            return $status;
57        }
58
59        // Update file existence predicates since the operation is expected to be allowed to run
60        $batchPredicates->assumeFileDoesNotExist( $this->params['src'] );
61
62        return $status; // safe to call attempt()
63    }
64
65    protected function doAttempt() {
66        // Delete the source file
67        return $this->backend->deleteInternal( $this->setFlags( $this->params ) );
68    }
69
70    public function storagePathsChanged() {
71        return [ $this->params['src'] ];
72    }
73}