MediaWiki master
DeleteFileOp.php
Go to the documentation of this file.
1<?php
25
30class DeleteFileOp extends FileOp {
31 protected function allowedParams() {
32 return [ [ 'src' ], [ 'ignoreMissingSource' ], [ 'src' ] ];
33 }
34
35 protected function doPrecheck(
36 FileStatePredicates $opPredicates,
37 FileStatePredicates $batchPredicates
38 ) {
39 $status = StatusValue::newGood();
40
41 // Check source file existence
42 $srcExists = $this->resolveFileExistence( $this->params['src'], $opPredicates );
43 if ( $srcExists === false ) {
44 if ( $this->getParam( 'ignoreMissingSource' ) ) {
45 $this->noOp = true; // no-op
46 // Update file existence predicates (cache 404s)
47 $batchPredicates->assumeFileDoesNotExist( $this->params['src'] );
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
61 // Update file existence predicates since the operation is expected to be allowed to run
62 $batchPredicates->assumeFileDoesNotExist( $this->params['src'] );
63
64 return $status; // safe to call attempt()
65 }
66
67 protected function doAttempt() {
68 // Delete the source file
69 return $this->backend->deleteInternal( $this->setFlags( $this->params ) );
70 }
71
72 public function storagePathsChanged() {
73 return [ $this->params['src'] ];
74 }
75}
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:40
resolveFileExistence( $source, FileStatePredicates $opPredicates)
Check if a file will exist in storage when this operation is attempted.
Definition FileOp.php:407
getParam( $name)
Get the value of the parameter with the given name.
Definition FileOp.php:126
setFlags(array $params)
Adjust params to FileBackendStore internal file calls.
Definition FileOp.php:313
Helper class for tracking counterfactual file states when pre-checking file operation batches.
assumeFileDoesNotExist(string $path)
Predicate that no file exists at the path.
Base class for all file backend classes (including multi-write backends).