Merge "Remove "@author Aaron Schulz" annotations"
[lhc/web/wiklou.git] / includes / libs / filebackend / fileop / DeleteFileOp.php
1 <?php
2 /**
3 * Helper class for representing operations with transaction support.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup FileBackend
22 */
23
24 /**
25 * Delete a file at the given storage path from the backend.
26 * Parameters for this operation are outlined in FileBackend::doOperations().
27 */
28 class DeleteFileOp extends FileOp {
29 protected function allowedParams() {
30 return [ [ 'src' ], [ 'ignoreMissingSource' ], [ 'src' ] ];
31 }
32
33 protected function doPrecheck( array &$predicates ) {
34 $status = StatusValue::newGood();
35 // Check if the source file exists
36 if ( !$this->fileExists( $this->params['src'], $predicates ) ) {
37 if ( $this->getParam( 'ignoreMissingSource' ) ) {
38 $this->doOperation = false; // no-op
39 // Update file existence predicates (cache 404s)
40 $predicates['exists'][$this->params['src']] = false;
41 $predicates['sha1'][$this->params['src']] = false;
42
43 return $status; // nothing to do
44 } else {
45 $status->fatal( 'backend-fail-notexists', $this->params['src'] );
46
47 return $status;
48 }
49 // Check if a file can be placed/changed at the source
50 } elseif ( !$this->backend->isPathUsableInternal( $this->params['src'] ) ) {
51 $status->fatal( 'backend-fail-usable', $this->params['src'] );
52 $status->fatal( 'backend-fail-delete', $this->params['src'] );
53
54 return $status;
55 }
56 // Update file existence predicates
57 $predicates['exists'][$this->params['src']] = false;
58 $predicates['sha1'][$this->params['src']] = false;
59
60 return $status; // safe to call attempt()
61 }
62
63 protected function doAttempt() {
64 // Delete the source file
65 return $this->backend->deleteInternal( $this->setFlags( $this->params ) );
66 }
67
68 public function storagePathsChanged() {
69 return [ $this->params['src'] ];
70 }
71 }