generatePhpCharToUpperMappings.php: Write output directly to json file
authorEd Sanders <esanders@wikimedia.org>
Wed, 10 Apr 2019 14:35:18 +0000 (15:35 +0100)
committerJames D. Forrester <jforrester@wikimedia.org>
Fri, 3 May 2019 01:33:19 +0000 (18:33 -0700)
Change-Id: Ic19e5c9899f19d9b6ebf4a65a81100670514aa14

maintenance/mediawiki.Title/generatePhpCharToUpperMappings.php

index 8073c7c..5dd9432 100755 (executable)
@@ -40,11 +40,13 @@ class GeneratePhpCharToUpperMappings extends Maintenance {
        }
 
        public function execute() {
-               global $wgContLang;
+               global $wgContLang, $IP;
 
                $data = [];
 
-               $result = Shell::command( [ 'node', __DIR__ . '/generateJsToUpperCaseList.js' ] )
+               $result = Shell::command(
+                               [ 'node', $IP . '/maintenance/mediawiki.Title/generateJsToUpperCaseList.js' ]
+                       )
                        // Node allocates lots of memory
                        ->limits( [ 'memory' => 1024 * 1024 ] )
                        ->execute();
@@ -69,9 +71,15 @@ class GeneratePhpCharToUpperMappings extends Maintenance {
                        }
                }
 
-               $this->output( str_replace( '    ', "\t",
+               $mappingJson = str_replace( '    ', "\t",
                        json_encode( $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE )
-               ) . "\n" );
+               ) . "\n";
+               $outputPath = '/resources/src/mediawiki.Title/phpCharToUpper.json';
+               $file = fopen( $IP . $outputPath, 'w' );
+               fwrite( $file, $mappingJson );
+
+               $this->output( count( $data ) . " differences found.\n" );
+               $this->output( "Written to $outputPath\n" );
        }
 }