Physikerwelt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/182036

Change subject: Add option for admis to export all submissions
......................................................................

Add option for admis to export all submissions

Change-Id: I02950763641628902762c80c6820a95762534b48
---
A maintenance/BatchExport.php
1 file changed, 64 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MathSearch 
refs/changes/36/182036/1

diff --git a/maintenance/BatchExport.php b/maintenance/BatchExport.php
new file mode 100644
index 0000000..c27503b
--- /dev/null
+++ b/maintenance/BatchExport.php
@@ -0,0 +1,64 @@
+<?php
+/**
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @ingroup Maintenance
+ */
+
+require_once( __DIR__ . '/../../../maintenance/Maintenance.php' );
+
+class BatchExport extends Maintenance {
+       /**
+        *
+        */
+       public function __construct() {
+               parent::__construct();
+               $this->mDescription = "Exports  submissions to a folder. \n 
Each run is named after the following convention: \n \$userName-\$runName.csv";
+               $this->addArg( "dir", "The directory to be read", true );
+       }
+
+       /**
+        *
+        */
+       public function execute() {
+               $dir = $this->getArg( 0 );
+               if ( ! is_dir($dir) ){
+                       $this->output("{$dir} is not a directory.\n");
+                       exit(1);
+               }
+               $dbr = wfGetDB( DB_SLAVE );
+               //runId INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
+               //runName VARCHAR(45),
+               //userId INT UNSIGNED,
+               //isDraft TINYINT NOT NULL,
+               $res = $dbr->select( "math_wmc_runs", "*" );
+               //TODO: Implement support for isDraft.
+               foreach ( $res as $row ) {
+                       $user = User::newFromId( $row->userId );
+                       $username = $user->getName();
+                       $runName = preg_replace( "#/#","_", escapeSingleString( 
$row->runName ));
+                       $fn = "$dir/$username-$runName-{$row->runId}.csv";
+                       $this->output("Export to file $fn.\n");
+                       $fh =  fopen( $fn, 'w' );
+                       fwrite( $fh, SpecialMathDownloadResult::run2CSV( 
$row->runId ) );
+                       fclose( $fh );
+               }
+       }
+}
+
+$maintClass = "BatchExport";
+require_once( RUN_MAINTENANCE_IF_MAIN );

-- 
To view, visit https://gerrit.wikimedia.org/r/182036
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I02950763641628902762c80c6820a95762534b48
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MathSearch
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to