MediaWiki master
DeleteFileOp.php
Go to the documentation of this file.
1<?php
25
26use StatusValue;
28
33class DeleteFileOp extends FileOp {
34 protected function allowedParams() {
35 return [ [ 'src' ], [ 'ignoreMissingSource' ], [ 'src' ] ];
36 }
37
38 protected function doPrecheck(
39 FileStatePredicates $opPredicates,
40 FileStatePredicates $batchPredicates
41 ) {
42 $status = StatusValue::newGood();
43
44 // Check source file existence
45 $srcExists = $this->resolveFileExistence( $this->params['src'], $opPredicates );
46 if ( $srcExists === false ) {
47 if ( $this->getParam( 'ignoreMissingSource' ) ) {
48 $this->noOp = true; // no-op
49 // Update file existence predicates (cache 404s)
50 $batchPredicates->assumeFileDoesNotExist( $this->params['src'] );
51
52 return $status; // nothing to do
53 } else {
54 $status->fatal( 'backend-fail-notexists', $this->params['src'] );
55
56 return $status;
57 }
58 } elseif ( $srcExists === FileBackend::EXISTENCE_ERROR ) {
59 $status->fatal( 'backend-fail-stat', $this->params['src'] );
60
61 return $status;
62 }
63
64 // Update file existence predicates since the operation is expected to be allowed to run
65 $batchPredicates->assumeFileDoesNotExist( $this->params['src'] );
66
67 return $status; // safe to call attempt()
68 }
69
70 protected function doAttempt() {
71 // Delete the source file
72 return $this->backend->deleteInternal( $this->setFlags( $this->params ) );
73 }
74
75 public function storagePathsChanged() {
76 return [ $this->params['src'] ];
77 }
78}
79
81class_alias( DeleteFileOp::class, 'DeleteFileOp' );
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Base class for all file backend classes (including multi-write backends).
Delete a file at the given storage path from the backend.
doPrecheck(FileStatePredicates $opPredicates, FileStatePredicates $batchPredicates)
Do a dry-run precondition check of the operation in the context of op batch.
allowedParams()
Get the file operation parameters.
storagePathsChanged()
Get a list of storage paths written to for this operation.
FileBackend helper class for representing operations.
Definition FileOp.php:47
getParam( $name)
Get the value of the parameter with the given name.
Definition FileOp.php:132
resolveFileExistence( $source, FileStatePredicates $opPredicates)
Check if a file will exist in storage when this operation is attempted.
Definition FileOp.php:413
setFlags(array $params)
Adjust params to FileBackendStore internal file calls.
Definition FileOp.php:319
Helper class for tracking counterfactual file states when pre-checking file operation batches.
assumeFileDoesNotExist(string $path)
Predicate that no file exists at the path.