Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 29 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
UpdateLYFileHeaders | |
0.00% |
0 / 23 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | /* |
4 | * This program is free software: you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation, either version 3 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | * |
17 | * @file |
18 | * @ingroup Maintenance |
19 | */ |
20 | |
21 | use MediaWiki\Extension\Score\Score; |
22 | |
23 | if ( getenv( 'MW_INSTALL_PATH' ) ) { |
24 | $IP = getenv( 'MW_INSTALL_PATH' ); |
25 | } else { |
26 | $IP = __DIR__ . '/../../..'; |
27 | } |
28 | |
29 | require_once "$IP/maintenance/Maintenance.php"; |
30 | |
31 | /** |
32 | * @ingroup Maintenance |
33 | */ |
34 | class UpdateLYFileHeaders extends Maintenance { |
35 | |
36 | public function __construct() { |
37 | parent::__construct(); |
38 | $this->addDescription( |
39 | "Updates the file headers of lilypond files" |
40 | ); |
41 | $this->requireExtension( "Score" ); |
42 | } |
43 | |
44 | public function execute() { |
45 | $headers = [ 'Content-Type' => 'text/x-lilypond; charset=utf-8' ]; |
46 | $backend = Score::getBackend(); |
47 | $baseStoragePath = $backend->getRootStoragePath() . '/score-render'; |
48 | |
49 | $files = $backend->getFileList( [ 'dir' => $baseStoragePath ] ); |
50 | |
51 | $backendOperations = []; |
52 | foreach ( $files as $file ) { |
53 | $fullPath = $baseStoragePath . '/' . $file; |
54 | |
55 | if ( |
56 | pathinfo( $file, PATHINFO_EXTENSION ) === 'ly' |
57 | ) { |
58 | $backendOperations[] = [ |
59 | 'op' => 'describe', 'src' => $fullPath, 'headers' => $headers |
60 | ]; |
61 | } |
62 | } |
63 | $count = count( $backendOperations ); |
64 | $this->output( "Updating the headers of $count lilypond files\n" ); |
65 | |
66 | foreach ( array_chunk( $backendOperations, 1000 ) as $chunk ) { |
67 | $status = $backend->doQuickOperations( $chunk ); |
68 | |
69 | if ( !$status->isGood() ) { |
70 | $this->error( "Encountered error: " . print_r( $status, true ) ); |
71 | } |
72 | } |
73 | $this->output( "Done!\n" ); |
74 | } |
75 | |
76 | } |
77 | |
78 | $maintClass = UpdateLYFileHeaders::class; |
79 | require_once RUN_MAINTENANCE_IF_MAIN; |