3 * Helper class for representing operations with transaction support.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup FileBackend
24 namespace Wikimedia\FileBackend\FileOps
;
27 use Wikimedia\FileBackend\FileBackend
;
30 * Delete a file at the given storage path from the backend.
31 * Parameters for this operation are outlined in FileBackend::doOperations().
33 class DeleteFileOp
extends FileOp
{
34 protected function allowedParams() {
35 return [ [ 'src' ], [ 'ignoreMissingSource' ], [ 'src' ] ];
38 protected function doPrecheck(
39 FileStatePredicates
$opPredicates,
40 FileStatePredicates
$batchPredicates
42 $status = StatusValue
::newGood();
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'] );
52 return $status; // nothing to do
54 $status->fatal( 'backend-fail-notexists', $this->params
['src'] );
58 } elseif ( $srcExists === FileBackend
::EXISTENCE_ERROR
) {
59 $status->fatal( 'backend-fail-stat', $this->params
['src'] );
64 // Update file existence predicates since the operation is expected to be allowed to run
65 $batchPredicates->assumeFileDoesNotExist( $this->params
['src'] );
67 return $status; // safe to call attempt()
70 protected function doAttempt() {
71 // Delete the source file
72 return $this->backend
->deleteInternal( $this->setFlags( $this->params
) );
75 public function storagePathsChanged() {
76 return [ $this->params
['src'] ];
80 /** @deprecated class alias since 1.43 */
81 class_alias( DeleteFileOp
::class, 'DeleteFileOp' );