MediaWiki 1.42.0
DescribeFileOp.php
Go to the documentation of this file.
1<?php
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}
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.
storagePathsChanged()
Get a list of storage paths written to for this operation.
allowedParams()
Get the file operation parameters.
FileBackend helper class for representing operations.
Definition FileOp.php:37
resolveFileExistence( $source, FileStatePredicates $opPredicates)
Check if a file will exist in storage when this operation is attempted.
Definition FileOp.php:404
setFlags(array $params)
Adjust params to FileBackendStore internal file calls.
Definition FileOp.php:310
resolveFileSha1Base36( $source, FileStatePredicates $opPredicates)
Get the SHA-1 of a file in storage when this operation is attempted.
Definition FileOp.php:440
resolveFileSize( $source, FileStatePredicates $opPredicates)
Get the size a file in storage will have when this operation is attempted.
Definition FileOp.php:424
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.