MediaWiki  master
DeleteFileOp.php
Go to the documentation of this file.
1 <?php
28 class DeleteFileOp extends FileOp {
29  protected function allowedParams() {
30  return [ [ 'src' ], [ 'ignoreMissingSource' ], [ '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  if ( $this->getParam( 'ignoreMissingSource' ) ) {
40  $this->cancelled = true; // no-op
41  // Update file existence predicates (cache 404s)
42  $predicates[self::ASSUMED_EXISTS][$this->params['src']] = false;
43  $predicates[self::ASSUMED_SIZE][$this->params['src']] = false;
44  $predicates[self::ASSUMED_SHA1][$this->params['src']] = false;
45 
46  return $status; // nothing to do
47  } else {
48  $status->fatal( 'backend-fail-notexists', $this->params['src'] );
49 
50  return $status;
51  }
52  } elseif ( $srcExists === FileBackend::EXISTENCE_ERROR ) {
53  $status->fatal( 'backend-fail-stat', $this->params['src'] );
54 
55  return $status;
56  }
57 
58  // Update file existence predicates since the operation is expected to be allowed to run
59  $predicates[self::ASSUMED_EXISTS][$this->params['src']] = false;
60  $predicates[self::ASSUMED_SIZE][$this->params['src']] = false;
61  $predicates[self::ASSUMED_SHA1][$this->params['src']] = false;
62 
63  return $status; // safe to call attempt()
64  }
65 
66  protected function doAttempt() {
67  // Delete the source file
68  return $this->backend->deleteInternal( $this->setFlags( $this->params ) );
69  }
70 
71  public function storagePathsChanged() {
72  return [ $this->params['src'] ];
73  }
74 }
DeleteFileOp\doAttempt
doAttempt()
Definition: DeleteFileOp.php:66
DeleteFileOp
Delete a file at the given storage path from the backend.
Definition: DeleteFileOp.php:28
FileOp
FileBackend helper class for representing operations.
Definition: FileOp.php:36
FileOp\ASSUMED_EXISTS
const ASSUMED_EXISTS
Definition: FileOp.php:73
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
DeleteFileOp\storagePathsChanged
storagePathsChanged()
Get a list of storage paths written to for this operation.
Definition: DeleteFileOp.php:71
FileOp\getParam
getParam( $name)
Get the value of the parameter with the given name.
Definition: FileOp.php:141
DeleteFileOp\doPrecheck
doPrecheck(array &$predicates)
Definition: DeleteFileOp.php:33
DeleteFileOp\allowedParams
allowedParams()
Get the file operation parameters.
Definition: DeleteFileOp.php:29
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