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 // Check source file existence
33 $srcExists = $this->resolveFileExistence( $this->params['src'], $opPredicates );
34 if ( $srcExists === false ) {
35 if ( $this->getParam( 'ignoreMissingSource' ) ) {
36 $this->noOp = true; // no-op
37 // Update file existence predicates (cache 404s)
38 $batchPredicates->assumeFileDoesNotExist( $this->params['src'] );
39
40 return $status; // nothing to do
41 } else {
42 $status->fatal( 'backend-fail-notexists', $this->params['src'] );
43
44 return $status;
45 }
46 } elseif ( $srcExists === FileBackend::EXISTENCE_ERROR ) {
47 $status->fatal( 'backend-fail-stat', $this->params['src'] );
48
49 return $status;
50 }
51
52 // Update file existence predicates since the operation is expected to be allowed to run
53 $batchPredicates->assumeFileDoesNotExist( $this->params['src'] );
54
55 return $status; // safe to call attempt()
56 }
57
59 protected function doAttempt() {
60 // Delete the source file
61 return $this->backend->deleteInternal( $this->setFlags( $this->params ) );
62 }
63
65 public function storagePathsChanged() {
66 return [ $this->params['src'] ];
67 }
68}
69
71class_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:398
setFlags(array $params)
Adjust params to FileBackendStore internal file calls.
Definition FileOp.php:304
Helper class for tracking counterfactual file states when pre-checking file operation batches.
assumeFileDoesNotExist(string $path)
Predicate that no file exists at the path.