Skip to content
This repository was archived by the owner on Sep 23, 2023. It is now read-only.

Commit ba59cd3

Browse files
edg2sMatmaRex
authored andcommitted
Use $env argument of Process::fromShellCommandline
1 parent af2575e commit ba59cd3

File tree

2 files changed

+41
-45
lines changed

2 files changed

+41
-45
lines changed

includes.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -276,20 +276,16 @@ function format_linked_tasks( array $linkedTasks ): string {
276276
return $linkedTasks ?: '<em>No tasks</em>';
277277
}
278278

279-
function make_shell_command( array $env, string $cmd ): string {
279+
function shell_echo( string $cmd, array $env = [] ): int {
280+
echo '<pre>';
281+
280282
$prefix = '';
281283
foreach ( $env as $key => $value ) {
282284
$value = escapeshellarg( $value );
283285
$prefix .= "$key=$value ";
284286
}
285-
286-
return "$prefix$cmd 2>&1";
287-
}
288-
289-
function shell_echo( string $cmd ): int {
290-
echo '<pre>';
291-
echo htmlspecialchars( "$cmd\n" );
292-
$process = Process::fromShellCommandline( $cmd, null, [] );
287+
echo htmlspecialchars( "$prefix$cmd\n" );
288+
$process = Process::fromShellCommandline( $cmd, null, $env );
293289
$process->setTimeout( null );
294290
$error = $process->run( static function ( $type, $buffer ) {
295291
echo htmlspecialchars( $buffer );
@@ -298,8 +294,8 @@ function shell_echo( string $cmd ): int {
298294
return $error;
299295
}
300296

301-
function shell( $cmd ): ?string {
302-
$process = Process::fromShellCommandline( $cmd, null, [] );
297+
function shell( $cmd, array $env = [] ): ?string {
298+
$process = Process::fromShellCommandline( $cmd, null, $env );
303299
$process->setTimeout( null );
304300
$error = $process->run();
305301
return $error ? null : $process->getOutput();
@@ -314,11 +310,12 @@ function delete_wiki( string $wiki ): int {
314310
return 'Wiki already deleted.';
315311
}
316312

317-
$cmd = make_shell_command( [
318-
'PATCHDEMO' => __DIR__,
319-
'WIKI' => $wiki
320-
], __DIR__ . '/deletewiki.sh' );
321-
$error = shell_echo( $cmd );
313+
$error = shell_echo( __DIR__ . '/deletewiki.sh',
314+
[
315+
'PATCHDEMO' => __DIR__,
316+
'WIKI' => $wiki
317+
]
318+
);
322319

323320
foreach ( $wikiData['announcedTasks'] as $task ) {
324321
// TODO: Deduplicate server/serverPath with variables in new.php

new.php

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,11 @@ function set_progress( float $pc, string $label ) {
324324
$repoProgress = $start;
325325

326326
foreach ( $repos as $source => $target ) {
327-
$cmd = make_shell_command( $baseEnv + [
328-
'REPOSITORIES' => "$source $target",
329-
], __DIR__ . '/new/updaterepos.sh' );
330-
331-
$error = shell_echo( $cmd );
327+
$error = shell_echo( __DIR__ . '/new/updaterepos.sh',
328+
$baseEnv + [
329+
'REPOSITORIES' => "$source $target",
330+
]
331+
);
332332
if ( $error ) {
333333
abandon( "Could not update repository <em>$source</em>" );
334334
}
@@ -343,50 +343,49 @@ function set_progress( float $pc, string $label ) {
343343
return "$k $v";
344344
}, array_keys( $repos ), array_values( $repos ) ) );
345345

346-
$cmd = make_shell_command( $baseEnv + [
347-
'BRANCH' => $branch,
348-
'COMPOSER_HOME' => __DIR__ . '/composer',
349-
'REPOSITORIES' => $reposString,
350-
], __DIR__ . '/new/checkout.sh' );
351-
352-
$error = shell_echo( $cmd );
346+
$error = shell_echo( __DIR__ . '/new/checkout.sh',
347+
$baseEnv + [
348+
'BRANCH' => $branch,
349+
'COMPOSER_HOME' => __DIR__ . '/composer',
350+
'REPOSITORIES' => $reposString,
351+
]
352+
);
353353
if ( $error ) {
354354
abandon( "Could not check out wiki." );
355355
}
356356

357357
set_progress( 60, 'Installing your wiki...' );
358358

359-
$cmd = make_shell_command( $baseEnv + [
360-
'WIKINAME' => $wikiName,
361-
'SERVER' => $server,
362-
'SERVERPATH' => $serverPath,
363-
'LANGUAGE' => $language,
364-
], __DIR__ . '/new/install.sh' );
365-
366-
$error = shell_echo( $cmd );
359+
$error = shell_echo( __DIR__ . '/new/install.sh',
360+
$baseEnv + [
361+
'WIKINAME' => $wikiName,
362+
'SERVER' => $server,
363+
'SERVERPATH' => $serverPath,
364+
'LANGUAGE' => $language,
365+
]
366+
);
367367
if ( $error ) {
368368
abandon( "Could not install wiki." );
369369
}
370370

371371
set_progress( 80, 'Fetching and applying patches...' );
372372

373373
foreach ( $commands as $i => $command ) {
374-
$cmd = make_shell_command( $baseEnv + $command[0], $command[1] );
375-
$error = shell_echo( $cmd );
374+
$error = shell_echo( $command[1], $baseEnv + $command[0] );
376375
if ( $error ) {
377376
abandon( "Could not apply patch {$patchesApplied[$i]}." );
378377
}
379378
}
380379

381380
set_progress( 90, 'Setting up wiki content...' );
382381

383-
$cmd = make_shell_command( $baseEnv + [
384-
'MAINPAGE' => $mainPage,
385-
'USE_PROXY' => $useProxy,
386-
'USE_INSTANT_COMMONS' => $useInstantCommons,
387-
], __DIR__ . '/new/postinstall.sh' );
388-
389-
$error = shell_echo( $cmd );
382+
$error = shell_echo( __DIR__ . '/new/postinstall.sh',
383+
$baseEnv + [
384+
'MAINPAGE' => $mainPage,
385+
'USE_PROXY' => $useProxy,
386+
'USE_INSTANT_COMMONS' => $useInstantCommons,
387+
]
388+
);
390389
if ( $error ) {
391390
abandon( "Could not setup wiki content." );
392391
}

0 commit comments

Comments
 (0)