MediaWiki master
DescribeFileOp.php
Go to the documentation of this file.
1<?php
11
12use StatusValue;
14
19class DescribeFileOp extends FileOp {
21 protected function allowedParams() {
22 return [ [ 'src' ], [ 'headers' ], [ 'src' ] ];
23 }
24
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
67 protected function doAttempt() {
68 // Update the source file's metadata
69 return $this->backend->describeInternal( $this->setFlags( $this->params ) );
70 }
71
73 public function storagePathsChanged() {
74 return [ $this->params['src'] ];
75 }
76}
77
79class_alias( DescribeFileOp::class, 'DescribeFileOp' );
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Base class for all file backend classes (including multi-write backends).
Change metadata for a file at the given storage path in the backend.
doPrecheck(FileStatePredicates $opPredicates, FileStatePredicates $batchPredicates)
Do a dry-run precondition check of the operation in the context of op batch.Updates the batch predica...
storagePathsChanged()
Get a list of storage paths written to for this operation.array
allowedParams()
Get the file operation parameters.array (required params list, optional params list,...
FileBackend helper class for representing operations.
Definition FileOp.php:32
resolveFileSize( $source, FileStatePredicates $opPredicates)
Get the size a file in storage will have when this operation is attempted.
Definition FileOp.php:408
resolveFileSha1Base36( $source, FileStatePredicates $opPredicates)
Get the SHA-1 of a file in storage when this operation is attempted.
Definition FileOp.php:424
resolveFileExistence( $source, FileStatePredicates $opPredicates)
Check if a file will exist in storage when this operation is attempted.
Definition FileOp.php:388
setFlags(array $params)
Adjust params to FileBackendStore internal file calls.
Definition FileOp.php:294
Helper class for tracking counterfactual file states when pre-checking file operation batches.
assumeFileExists(string $path, $size, $sha1Base36)
Predicate that a file exists at the path.