Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
91.30% covered (success)
91.30%
21 / 23
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
DescribeFileOp
91.30% covered (success)
91.30%
21 / 23
75.00% covered (warning)
75.00%
3 / 4
6.02
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
90.00% covered (success)
90.00%
18 / 20
0.00% covered (danger)
0.00%
0 / 1
3.01
 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 * Change metadata for a file at the given storage path in the backend.
26 * Parameters for this operation are outlined in FileBackend::doOperations().
27 */
28class DescribeFileOp extends FileOp {
29    protected function allowedParams() {
30        return [ [ 'src' ], [ 'headers' ], [ '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            $status->fatal( 'backend-fail-notexists', $this->params['src'] );
43
44            return $status;
45        } elseif ( $srcExists === FileBackend::EXISTENCE_ERROR ) {
46            $status->fatal( 'backend-fail-stat', $this->params['src'] );
47
48            return $status;
49        }
50
51        // Update file existence predicates since the operation is expected to be allowed to run
52        $srcSize = function () use ( $opPredicates ) {
53            static $size = null;
54            $size ??= $this->resolveFileSize( $this->params['src'], $opPredicates );
55            return $size;
56        };
57        $srcSha1 = function () use ( $opPredicates ) {
58            static $sha1 = null;
59            $sha1 ??= $this->resolveFileSha1Base36( $this->params['src'], $opPredicates );
60            return $sha1;
61        };
62        $batchPredicates->assumeFileExists( $this->params['src'], $srcSize, $srcSha1 );
63
64        return $status; // safe to call attempt()
65    }
66
67    protected function doAttempt() {
68        // Update the source file's metadata
69        return $this->backend->describeInternal( $this->setFlags( $this->params ) );
70    }
71
72    public function storagePathsChanged() {
73        return [ $this->params['src'] ];
74    }
75}