Merge "resourceloader: Add basic tests for getScript() and buildContent()"
[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 * @author Aaron Schulz
23 */
24
25 /**
26 * Change metadata for a file at the given storage path in the backend.
27 * Parameters for this operation are outlined in FileBackend::doOperations().
28 */
29 class DescribeFileOp extends FileOp {
30 protected function allowedParams() {
31 return [ [ 'src' ], [ 'headers' ], [ 'src' ] ];
32 }
33
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 $status->fatal( 'backend-fail-notexists', $this->params['src'] );
39
40 return $status;
41 // Check if a file can be placed/changed at the source
42 } elseif ( !$this->backend->isPathUsableInternal( $this->params['src'] ) ) {
43 $status->fatal( 'backend-fail-usable', $this->params['src'] );
44 $status->fatal( 'backend-fail-describe', $this->params['src'] );
45
46 return $status;
47 }
48 // Update file existence predicates
49 $predicates['exists'][$this->params['src']] =
50 $this->fileExists( $this->params['src'], $predicates );
51 $predicates['sha1'][$this->params['src']] =
52 $this->fileSha1( $this->params['src'], $predicates );
53
54 return $status; // safe to call attempt()
55 }
56
57 protected function doAttempt() {
58 // Update the source file's metadata
59 return $this->backend->describeInternal( $this->setFlags( $this->params ) );
60 }
61
62 public function storagePathsChanged() {
63 return [ $this->params['src'] ];
64 }
65 }