Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
BatchExport | |
0.00% |
0 / 22 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @ingroup Maintenance |
19 | */ |
20 | |
21 | use MediaWiki\User\User; |
22 | use UtfNormal\Utils; |
23 | |
24 | require_once __DIR__ . '/../../../maintenance/Maintenance.php'; |
25 | |
26 | class BatchExport extends Maintenance { |
27 | |
28 | public function __construct() { |
29 | parent::__construct(); |
30 | $this->addDescription( "Exports submissions to a folder. \n Each run is named after the " . |
31 | "following convention: \n \$userName-\$runName-\$runId.csv" ); |
32 | $this->addArg( 'dir', 'The output directory', true ); |
33 | $this->requireExtension( 'MathSearch' ); |
34 | } |
35 | |
36 | public function execute() { |
37 | $dir = $this->getArg( 0 ); |
38 | if ( !is_dir( $dir ) ) { |
39 | $this->output( "{$dir} is not a directory.\n" ); |
40 | exit( 1 ); |
41 | } |
42 | $dbr = $this->getServiceContainer() |
43 | ->getConnectionProvider() |
44 | ->getReplicaDatabase(); |
45 | // runId INT PRIMARY KEY AUTO_INCREMENT NOT NULL, |
46 | // runName VARCHAR(45), |
47 | // userId INT UNSIGNED, |
48 | // isDraft TINYINT NOT NULL, |
49 | $res = $dbr->select( 'math_wmc_runs', '*' ); |
50 | // TODO: Implement support for isDraft. |
51 | foreach ( $res as $row ) { |
52 | $user = User::newFromId( $row->userId ); |
53 | $username = $user->getName(); |
54 | $runName = preg_replace( "#/#", "_", Utils::escapeSingleString( $row->runName ) ); |
55 | $fn = "$dir/$username-$runName-{$row->runId}.csv"; |
56 | $this->output( "Export to file $fn.\n" ); |
57 | $fh = fopen( $fn, 'w' ); |
58 | fwrite( $fh, SpecialMathDownloadResult::run2CSV( $row->runId ) ); |
59 | fclose( $fh ); |
60 | } |
61 | } |
62 | } |
63 | |
64 | $maintClass = BatchExport::class; |
65 | /** @noinspection PhpIncludeInspection */ |
66 | require_once RUN_MAINTENANCE_IF_MAIN; |