Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 55 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| GetLYFiles | |
0.00% |
0 / 49 |
|
0.00% |
0 / 2 |
72 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 32 |
|
0.00% |
0 / 1 |
56 | |||
| 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 2 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 along |
| 15 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * http://www.gnu.org/copyleft/gpl.html |
| 18 | * |
| 19 | * @file |
| 20 | * @ingroup Maintenance |
| 21 | */ |
| 22 | |
| 23 | use MediaWiki\Extension\Score\Score; |
| 24 | use MediaWiki\Maintenance\Maintenance; |
| 25 | |
| 26 | if ( getenv( 'MW_INSTALL_PATH' ) ) { |
| 27 | $IP = getenv( 'MW_INSTALL_PATH' ); |
| 28 | } else { |
| 29 | $IP = __DIR__ . '/../../..'; |
| 30 | } |
| 31 | |
| 32 | require_once "$IP/maintenance/Maintenance.php"; |
| 33 | |
| 34 | /** |
| 35 | * @ingroup Maintenance |
| 36 | */ |
| 37 | class GetLYFiles extends Maintenance { |
| 38 | |
| 39 | public function __construct() { |
| 40 | parent::__construct(); |
| 41 | $this->addDescription( |
| 42 | "Gets a count of the number of ly files and optionally writes them to disk" |
| 43 | ); |
| 44 | $this->addOption( |
| 45 | 'date', |
| 46 | 'Get ly files that were created after this date (e.g. 20170101000000)', |
| 47 | true, |
| 48 | true |
| 49 | ); |
| 50 | |
| 51 | $this->addOption( |
| 52 | 'outputdir', |
| 53 | 'Saves ly files matching date to this directory', |
| 54 | false, |
| 55 | true |
| 56 | ); |
| 57 | $this->requireExtension( "Score" ); |
| 58 | } |
| 59 | |
| 60 | public function execute() { |
| 61 | $backend = Score::getBackend(); |
| 62 | $baseStoragePath = $backend->getRootStoragePath() . '/score-render'; |
| 63 | |
| 64 | $files = $backend->getFileList( [ 'dir' => $baseStoragePath, 'adviseStat' => true ] ); |
| 65 | $count = iterator_count( $files ); |
| 66 | $this->output( "Total files (all extensions): $count\n" ); |
| 67 | |
| 68 | $date = $this->getOption( 'date' ); |
| 69 | |
| 70 | $targetFiles = []; |
| 71 | |
| 72 | foreach ( $files as $file ) { |
| 73 | $fullPath = $baseStoragePath . '/' . $file; |
| 74 | |
| 75 | if ( |
| 76 | pathinfo( $file, PATHINFO_EXTENSION ) === 'ly' && |
| 77 | $backend->getFileTimestamp( [ 'src' => $fullPath ] ) >= $date |
| 78 | ) { |
| 79 | $targetFiles[] = $fullPath; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | $targetFileCount = count( $targetFiles ); |
| 84 | |
| 85 | $this->output( "{$targetFileCount} ly files created on or after {$date}\n" ); |
| 86 | |
| 87 | if ( $this->hasOption( 'outputdir' ) ) { |
| 88 | $outputDir = $this->getOption( 'outputdir' ); |
| 89 | $this->output( "Outputting ly files to {$outputDir}:\n" ); |
| 90 | |
| 91 | $count = 0; |
| 92 | foreach ( array_chunk( $targetFiles, 1000 ) as $chunk ) { |
| 93 | $fileContents = $backend->getFileContentsMulti( |
| 94 | [ |
| 95 | 'srcs' => $chunk, |
| 96 | 'parallelize' => true, |
| 97 | ] |
| 98 | ); |
| 99 | |
| 100 | foreach ( $fileContents as $path => $contents ) { |
| 101 | $pathNoPrefix = str_replace( $baseStoragePath . '/', '', $path ); |
| 102 | wfMkdirParents( $outputDir . '/' . dirname( $pathNoPrefix ) ); |
| 103 | file_put_contents( $outputDir . '/' . $pathNoPrefix, $contents ); |
| 104 | } |
| 105 | $count += count( $chunk ); |
| 106 | $this->output( "$count...\n" ); |
| 107 | } |
| 108 | |
| 109 | $this->output( "Done!\n" ); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | } |
| 114 | |
| 115 | $maintClass = GetLYFiles::class; |
| 116 | require_once RUN_MAINTENANCE_IF_MAIN; |