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