MediaWiki master
DeleteFileOp.php
Go to the documentation of this file.
1<?php
11
12use StatusValue;
14
19class DeleteFileOp extends FileOp {
21 protected function allowedParams() {
22 return [ [ 'src' ], [ 'ignoreMissingSource' ], [ 'src' ] ];
23 }
24
26 protected function doPrecheck(
27 FileStatePredicates $opPredicates,
28 FileStatePredicates $batchPredicates
29 ) {
30 $status = StatusValue::newGood();
31
32 if (
33 !$this->getParam( 'ignoreMissingSource' ) &&
34 !$this->backend->isPathUsableInternal( $this->params['src'] )
35 ) {
36 $status->fatal( 'backend-fail-usable', $this->params['src'] );
37
38 return $status;
39 }
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
68 protected function doAttempt() {
69 // Delete the source file
70 return $this->backend->deleteInternal( $this->setFlags( $this->params ) );
71 }
72
74 public function storagePathsChanged() {
75 return [ $this->params['src'] ];
76 }
77}
78
80class_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.Updates the batch predica...
allowedParams()
Get the file operation parameters.array (required params list, optional params list,...
storagePathsChanged()
Get a list of storage paths written to for this operation.array
FileBackend helper class for representing operations.
Definition FileOp.php:32
getParam( $name)
Get the value of the parameter with the given name.
Definition FileOp.php:117
resolveFileExistence( $source, FileStatePredicates $opPredicates)
Check if a file will exist in storage when this operation is attempted.
Definition FileOp.php:388
setFlags(array $params)
Adjust params to FileBackendStore internal file calls.
Definition FileOp.php:294
Helper class for tracking counterfactual file states when pre-checking file operation batches.
assumeFileDoesNotExist(string $path)
Predicate that no file exists at the path.