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
22 * @author Aaron Schulz
26 * Delete a file at the given storage path from the backend.
27 * Parameters for this operation are outlined in FileBackend::doOperations().
29 class DeleteFileOp
extends FileOp
{
30 protected function allowedParams() {
31 return [ [ 'src' ], [ 'ignoreMissingSource' ], [ 'src' ] ];
34 protected function doPrecheck( array &$predicates ) {
35 $status = StatusValue
::newGood();
36 // Check if the source file exists
37 if ( !$this->fileExists( $this->params
['src'], $predicates ) ) {
38 if ( $this->getParam( 'ignoreMissingSource' ) ) {
39 $this->doOperation
= false; // no-op
40 // Update file existence predicates (cache 404s)
41 $predicates['exists'][$this->params
['src']] = false;
42 $predicates['sha1'][$this->params
['src']] = false;
44 return $status; // nothing to do
46 $status->fatal( 'backend-fail-notexists', $this->params
['src'] );
50 // Check if a file can be placed/changed at the source
51 } elseif ( !$this->backend
->isPathUsableInternal( $this->params
['src'] ) ) {
52 $status->fatal( 'backend-fail-usable', $this->params
['src'] );
53 $status->fatal( 'backend-fail-delete', $this->params
['src'] );
57 // Update file existence predicates
58 $predicates['exists'][$this->params
['src']] = false;
59 $predicates['sha1'][$this->params
['src']] = false;
61 return $status; // safe to call attempt()
64 protected function doAttempt() {
65 // Delete the source file
66 return $this->backend
->deleteInternal( $this->setFlags( $this->params
) );
69 public function storagePathsChanged() {
70 return [ $this->params
['src'] ];