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 | use MediaWiki\Maintenance\Maintenance; |
| 23 | |
| 24 | if ( getenv( 'MW_INSTALL_PATH' ) ) { |
| 25 | $IP = getenv( 'MW_INSTALL_PATH' ); |
| 26 | } else { |
| 27 | $IP = __DIR__ . '/../../..'; |
| 28 | } |
| 29 | |
| 30 | require_once "$IP/maintenance/Maintenance.php"; |
| 31 | |
| 32 | /** |
| 33 | * @ingroup Maintenance |
| 34 | */ |
| 35 | class UpdateLYFileHeaders extends Maintenance { |
| 36 | |
| 37 | public function __construct() { |
| 38 | parent::__construct(); |
| 39 | $this->addDescription( |
| 40 | "Updates the file headers of lilypond files" |
| 41 | ); |
| 42 | $this->requireExtension( "Score" ); |
| 43 | } |
| 44 | |
| 45 | public function execute() { |
| 46 | $headers = [ 'Content-Type' => 'text/x-lilypond; charset=utf-8' ]; |
| 47 | $backend = Score::getBackend(); |
| 48 | $baseStoragePath = $backend->getRootStoragePath() . '/score-render'; |
| 49 | |
| 50 | $files = $backend->getFileList( [ 'dir' => $baseStoragePath ] ); |
| 51 | |
| 52 | $backendOperations = []; |
| 53 | foreach ( $files as $file ) { |
| 54 | $fullPath = $baseStoragePath . '/' . $file; |
| 55 | |
| 56 | if ( |
| 57 | pathinfo( $file, PATHINFO_EXTENSION ) === 'ly' |
| 58 | ) { |
| 59 | $backendOperations[] = [ |
| 60 | 'op' => 'describe', 'src' => $fullPath, 'headers' => $headers |
| 61 | ]; |
| 62 | } |
| 63 | } |
| 64 | $count = count( $backendOperations ); |
| 65 | $this->output( "Updating the headers of $count lilypond files\n" ); |
| 66 | |
| 67 | foreach ( array_chunk( $backendOperations, 1000 ) as $chunk ) { |
| 68 | $status = $backend->doQuickOperations( $chunk ); |
| 69 | |
| 70 | if ( !$status->isGood() ) { |
| 71 | $this->error( "Encountered error: " . print_r( $status, true ) ); |
| 72 | } |
| 73 | } |
| 74 | $this->output( "Done!\n" ); |
| 75 | } |
| 76 | |
| 77 | } |
| 78 | |
| 79 | $maintClass = UpdateLYFileHeaders::class; |
| 80 | require_once RUN_MAINTENANCE_IF_MAIN; |