MediaWiki master
DescribeFileOp.php
Go to the documentation of this file.
1<?php
25
26use StatusValue;
28
33class 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
83class_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.
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:47
resolveFileSize( $source, FileStatePredicates $opPredicates)
Get the size a file in storage will have when this operation is attempted.
Definition FileOp.php:433
resolveFileSha1Base36( $source, FileStatePredicates $opPredicates)
Get the SHA-1 of a file in storage when this operation is attempted.
Definition FileOp.php:449
resolveFileExistence( $source, FileStatePredicates $opPredicates)
Check if a file will exist in storage when this operation is attempted.
Definition FileOp.php:413
setFlags(array $params)
Adjust params to FileBackendStore internal file calls.
Definition FileOp.php:319
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.