MediaWiki  1.34.0
CopyFileOp.php
Go to the documentation of this file.
1 <?php
28 class CopyFileOp extends FileOp {
29  protected function allowedParams() {
30  return [
31  [ 'src', 'dst' ],
32  [ 'overwrite', 'overwriteSame', 'ignoreMissingSource', 'headers' ],
33  [ 'src', 'dst' ]
34  ];
35  }
36 
37  protected function doPrecheck( array &$predicates ) {
39 
40  // Check source file existence
41  $srcExists = $this->fileExists( $this->params['src'], $predicates );
42  if ( $srcExists === false ) {
43  if ( $this->getParam( 'ignoreMissingSource' ) ) {
44  $this->doOperation = false; // no-op
45  // Update file existence predicates (cache 404s)
46  $predicates['exists'][$this->params['src']] = false;
47  $predicates['sha1'][$this->params['src']] = false;
48 
49  return $status; // nothing to do
50  } else {
51  $status->fatal( 'backend-fail-notexists', $this->params['src'] );
52 
53  return $status;
54  }
55  } elseif ( $srcExists === FileBackend::EXISTENCE_ERROR ) {
56  $status->fatal( 'backend-fail-stat', $this->params['src'] );
57 
58  return $status;
59  }
60  // Check if destination file exists
61  $status->merge( $this->precheckDestExistence( $predicates ) );
62  $this->params['dstExists'] = $this->destExists; // see FileBackendStore::setFileCache()
63  if ( $status->isOK() ) {
64  // Update file existence predicates
65  $predicates['exists'][$this->params['dst']] = true;
66  $predicates['sha1'][$this->params['dst']] = $this->sourceSha1;
67  }
68 
69  return $status; // safe to call attempt()
70  }
71 
72  protected function doAttempt() {
73  if ( $this->overwriteSameCase ) {
74  $status = StatusValue::newGood(); // nothing to do
75  } elseif ( $this->params['src'] === $this->params['dst'] ) {
76  // Just update the destination file headers
77  $headers = $this->getParam( 'headers' ) ?: [];
78  $status = $this->backend->describeInternal( $this->setFlags( [
79  'src' => $this->params['dst'], 'headers' => $headers
80  ] ) );
81  } else {
82  // Copy the file to the destination
83  $status = $this->backend->copyInternal( $this->setFlags( $this->params ) );
84  }
85 
86  return $status;
87  }
88 
89  public function storagePathsRead() {
90  return [ $this->params['src'] ];
91  }
92 
93  public function storagePathsChanged() {
94  return [ $this->params['dst'] ];
95  }
96 }
FileOp\$sourceSha1
string $sourceSha1
Definition: FileOp.php:61
CopyFileOp\doAttempt
doAttempt()
Definition: CopyFileOp.php:72
FileOp
FileBackend helper class for representing operations.
Definition: FileOp.php:36
FileOp\$destExists
bool $destExists
Definition: FileOp.php:67
CopyFileOp
Copy a file from one storage path to another in the backend.
Definition: CopyFileOp.php:28
CopyFileOp\allowedParams
allowedParams()
Get the file operation parameters.
Definition: CopyFileOp.php:29
FileOp\setFlags
setFlags(array $params)
Adjust params to FileBackendStore internal file calls.
Definition: FileOp.php:346
CopyFileOp\doPrecheck
doPrecheck(array &$predicates)
Definition: CopyFileOp.php:37
FileOp\getParam
getParam( $name)
Get the value of the parameter with the given name.
Definition: FileOp.php:139
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
CopyFileOp\storagePathsRead
storagePathsRead()
Get a list of storage paths read from for this operation.
Definition: CopyFileOp.php:89
CopyFileOp\storagePathsChanged
storagePathsChanged()
Get a list of storage paths written to for this operation.
Definition: CopyFileOp.php:93
$status
return $status
Definition: SyntaxHighlight.php:347
FileOp\fileExists
fileExists( $source, array $predicates)
Check if a file will exist in storage when this operation is attempted.
Definition: FileOp.php:433
FileOp\precheckDestExistence
precheckDestExistence(array $predicates)
Check for errors with regards to the destination file already existing.
Definition: FileOp.php:376