MediaWiki  master
DescribeFileOp.php
Go to the documentation of this file.
1 <?php
28 class DescribeFileOp extends FileOp {
29  protected function allowedParams() {
30  return [ [ 'src' ], [ 'headers' ], [ 'src' ] ];
31  }
32 
33  protected function doPrecheck( array &$predicates ) {
34  $status = StatusValue::newGood();
35 
36  // Check source file existence
37  $srcExists = $this->fileExists( $this->params['src'], $predicates );
38  if ( $srcExists === false ) {
39  $status->fatal( 'backend-fail-notexists', $this->params['src'] );
40 
41  return $status;
42  } elseif ( $srcExists === FileBackend::EXISTENCE_ERROR ) {
43  $status->fatal( 'backend-fail-stat', $this->params['src'] );
44 
45  return $status;
46  }
47 
48  // Update file existence predicates since the operation is expected to be allowed to run
49  $predicates[self::ASSUMED_EXISTS][$this->params['src']] = $srcExists;
50  $predicates[self::ASSUMED_SIZE][$this->params['src']] =
51  $this->fileSize( $this->params['src'], $predicates );
52  $predicates[self::ASSUMED_SHA1][$this->params['src']] =
53  $this->fileSha1( $this->params['src'], $predicates );
54 
55  return $status; // safe to call attempt()
56  }
57 
58  protected function doAttempt() {
59  // Update the source file's metadata
60  return $this->backend->describeInternal( $this->setFlags( $this->params ) );
61  }
62 
63  public function storagePathsChanged() {
64  return [ $this->params['src'] ];
65  }
66 }
FileOp\fileSha1
fileSha1( $source, array $predicates)
Get the SHA-1 of a file in storage when this operation is attempted.
Definition: FileOp.php:526
DescribeFileOp
Change metadata for a file at the given storage path in the backend.
Definition: DescribeFileOp.php:28
FileOp
FileBackend helper class for representing operations.
Definition: FileOp.php:36
FileOp\ASSUMED_EXISTS
const ASSUMED_EXISTS
Definition: FileOp.php:73
DescribeFileOp\allowedParams
allowedParams()
Get the file operation parameters.
Definition: DescribeFileOp.php:29
FileOp\ASSUMED_SHA1
const ASSUMED_SHA1
Definition: FileOp.php:72
FileOp\setFlags
setFlags(array $params)
Adjust params to FileBackendStore internal file calls.
Definition: FileOp.php:368
FileOp\fileSize
fileSize( $source, array $predicates)
Get the size a file in storage will have when this operation is attempted.
Definition: FileOp.php:504
DescribeFileOp\storagePathsChanged
storagePathsChanged()
Get a list of storage paths written to for this operation.
Definition: DescribeFileOp.php:63
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
FileOp\ASSUMED_SIZE
const ASSUMED_SIZE
Definition: FileOp.php:74
FileOp\fileExists
fileExists( $source, array $predicates)
Check if a file will exist in storage when this operation is attempted.
Definition: FileOp.php:483
DescribeFileOp\doPrecheck
doPrecheck(array &$predicates)
Definition: DescribeFileOp.php:33
DescribeFileOp\doAttempt
doAttempt()
Definition: DescribeFileOp.php:58