MediaWiki master
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(
34 FileStatePredicates $opPredicates,
35 FileStatePredicates $batchPredicates
36 ) {
37 $status = StatusValue::newGood();
38
39 // Check source file existence
40 $srcExists = $this->resolveFileExistence( $this->params['src'], $opPredicates );
41 if ( $srcExists === false ) {
42 if ( $this->getParam( 'ignoreMissingSource' ) ) {
43 $this->noOp = true; // no-op
44 // Update file existence predicates (cache 404s)
45 $batchPredicates->assumeFileDoesNotExist( $this->params['src'] );
46
47 return $status; // nothing to do
48 } else {
49 $status->fatal( 'backend-fail-notexists', $this->params['src'] );
50
51 return $status;
52 }
53 } elseif ( $srcExists === FileBackend::EXISTENCE_ERROR ) {
54 $status->fatal( 'backend-fail-stat', $this->params['src'] );
55
56 return $status;
57 }
58
59 // Update file existence predicates since the operation is expected to be allowed to run
60 $batchPredicates->assumeFileDoesNotExist( $this->params['src'] );
61
62 return $status; // safe to call attempt()
63 }
64
65 protected function doAttempt() {
66 // Delete the source file
67 return $this->backend->deleteInternal( $this->setFlags( $this->params ) );
68 }
69
70 public function storagePathsChanged() {
71 return [ $this->params['src'] ];
72 }
73}
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(FileStatePredicates $opPredicates, FileStatePredicates $batchPredicates)
Do a dry-run precondition check of the operation in the context of op batch.
FileBackend helper class for representing operations.
Definition FileOp.php:37
resolveFileExistence( $source, FileStatePredicates $opPredicates)
Check if a file will exist in storage when this operation is attempted.
Definition FileOp.php:404
getParam( $name)
Get the value of the parameter with the given name.
Definition FileOp.php:123
setFlags(array $params)
Adjust params to FileBackendStore internal file calls.
Definition FileOp.php:310
Helper class for tracking counterfactual file states when pre-checking file operation batches.
assumeFileDoesNotExist(string $path)
Predicate that no file exists at the path.