Merge "Rename autonym for 'no' from 'norsk bokmål' to 'norsk'"
[lhc/web/wiklou.git] / includes / libs / filebackend / fileop / DescribeFileOp.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 * Change metadata for a file at the given storage path in the backend.
26 * Parameters for this operation are outlined in FileBackend::doOperations().
27 */
28 class DescribeFileOp extends FileOp {
29 protected function allowedParams() {
30 return [ [ 'src' ], [ 'headers' ], [ '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 $status->fatal( 'backend-fail-notexists', $this->params['src'] );
38
39 return $status;
40 // Check if a file can be placed/changed at the source
41 } elseif ( !$this->backend->isPathUsableInternal( $this->params['src'] ) ) {
42 $status->fatal( 'backend-fail-usable', $this->params['src'] );
43 $status->fatal( 'backend-fail-describe', $this->params['src'] );
44
45 return $status;
46 }
47 // Update file existence predicates
48 $predicates['exists'][$this->params['src']] =
49 $this->fileExists( $this->params['src'], $predicates );
50 $predicates['sha1'][$this->params['src']] =
51 $this->fileSha1( $this->params['src'], $predicates );
52
53 return $status; // safe to call attempt()
54 }
55
56 protected function doAttempt() {
57 // Update the source file's metadata
58 return $this->backend->describeInternal( $this->setFlags( $this->params ) );
59 }
60
61 public function storagePathsChanged() {
62 return [ $this->params['src'] ];
63 }
64 }