Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
87.50% |
21 / 24 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
DescribeFileOp | |
91.30% |
21 / 23 |
|
75.00% |
3 / 4 |
6.02 | |
0.00% |
0 / 1 |
allowedParams | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
doPrecheck | |
90.00% |
18 / 20 |
|
0.00% |
0 / 1 |
3.01 | |||
doAttempt | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
storagePathsChanged | |
100.00% |
1 / 1 |
|
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 | namespace Wikimedia\FileBackend\FileOps; |
25 | |
26 | use StatusValue; |
27 | use Wikimedia\FileBackend\FileBackend; |
28 | |
29 | /** |
30 | * Change metadata for a file at the given storage path in the backend. |
31 | * Parameters for this operation are outlined in FileBackend::doOperations(). |
32 | */ |
33 | class DescribeFileOp extends FileOp { |
34 | protected function allowedParams() { |
35 | return [ [ 'src' ], [ 'headers' ], [ 'src' ] ]; |
36 | } |
37 | |
38 | protected function doPrecheck( |
39 | FileStatePredicates $opPredicates, |
40 | FileStatePredicates $batchPredicates |
41 | ) { |
42 | $status = StatusValue::newGood(); |
43 | |
44 | // Check source file existence |
45 | $srcExists = $this->resolveFileExistence( $this->params['src'], $opPredicates ); |
46 | if ( $srcExists === false ) { |
47 | $status->fatal( 'backend-fail-notexists', $this->params['src'] ); |
48 | |
49 | return $status; |
50 | } elseif ( $srcExists === FileBackend::EXISTENCE_ERROR ) { |
51 | $status->fatal( 'backend-fail-stat', $this->params['src'] ); |
52 | |
53 | return $status; |
54 | } |
55 | |
56 | // Update file existence predicates since the operation is expected to be allowed to run |
57 | $srcSize = function () use ( $opPredicates ) { |
58 | static $size = null; |
59 | $size ??= $this->resolveFileSize( $this->params['src'], $opPredicates ); |
60 | return $size; |
61 | }; |
62 | $srcSha1 = function () use ( $opPredicates ) { |
63 | static $sha1 = null; |
64 | $sha1 ??= $this->resolveFileSha1Base36( $this->params['src'], $opPredicates ); |
65 | return $sha1; |
66 | }; |
67 | $batchPredicates->assumeFileExists( $this->params['src'], $srcSize, $srcSha1 ); |
68 | |
69 | return $status; // safe to call attempt() |
70 | } |
71 | |
72 | protected function doAttempt() { |
73 | // Update the source file's metadata |
74 | return $this->backend->describeInternal( $this->setFlags( $this->params ) ); |
75 | } |
76 | |
77 | public function storagePathsChanged() { |
78 | return [ $this->params['src'] ]; |
79 | } |
80 | } |
81 | |
82 | /** @deprecated class alias since 1.43 */ |
83 | class_alias( DescribeFileOp::class, 'DescribeFileOp' ); |