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 // Check source file existence
33 $srcExists = $this->resolveFileExistence( $this->params['src'], $opPredicates );
34 if ( $srcExists === false ) {
35 $status->fatal( 'backend-fail-notexists', $this->params['src'] );
36
37 return $status;
38 } elseif ( $srcExists === FileBackend::EXISTENCE_ERROR ) {
39 $status->fatal( 'backend-fail-stat', $this->params['src'] );
40
41 return $status;
42 }
43
44 // Update file existence predicates since the operation is expected to be allowed to run
45 $srcSize = function () use ( $opPredicates ) {
46 static $size = null;
47 $size ??= $this->resolveFileSize( $this->params['src'], $opPredicates );
48 return $size;
49 };
50 $srcSha1 = function () use ( $opPredicates ) {
51 static $sha1 = null;
52 $sha1 ??= $this->resolveFileSha1Base36( $this->params['src'], $opPredicates );
53 return $sha1;
54 };
55 $batchPredicates->assumeFileExists( $this->params['src'], $srcSize, $srcSha1 );
56
57 return $status; // safe to call attempt()
58 }
59
61 protected function doAttempt() {
62 // Update the source file's metadata
63 return $this->backend->describeInternal( $this->setFlags( $this->params ) );
64 }
65
67 public function storagePathsChanged() {
68 return [ $this->params['src'] ];
69 }
70}
71
73class_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:418
resolveFileSha1Base36( $source, FileStatePredicates $opPredicates)
Get the SHA-1 of a file in storage when this operation is attempted.
Definition FileOp.php:434
resolveFileExistence( $source, FileStatePredicates $opPredicates)
Check if a file will exist in storage when this operation is attempted.
Definition FileOp.php:398
setFlags(array $params)
Adjust params to FileBackendStore internal file calls.
Definition FileOp.php:304
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.