MediaWiki REL1_37
DeleteFileOp.php
Go to the documentation of this file.
1<?php
28class 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}
Delete a file at the given storage path from the backend.
allowedParams()
Get the file operation parameters.
storagePathsChanged()
Get a list of storage paths written to for this operation.
doPrecheck(array &$predicates)
FileBackend helper class for representing operations.
Definition FileOp.php:36
fileExists( $source, array $predicates)
Check if a file will exist in storage when this operation is attempted.
Definition FileOp.php:483
const ASSUMED_EXISTS
Definition FileOp.php:73
getParam( $name)
Get the value of the parameter with the given name.
Definition FileOp.php:141
const ASSUMED_SIZE
Definition FileOp.php:74
const ASSUMED_SHA1
Definition FileOp.php:72
setFlags(array $params)
Adjust params to FileBackendStore internal file calls.
Definition FileOp.php:368