| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
> |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
use MediaWiki\Shell\Shell; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
class DumpPipeOutput extends DumpFileOutput { |
| 34 |
|
| 35 |
protected $command; |
| 36 |
|
| 37 |
protected $filename; |
| 38 |
|
| 39 |
protected $procOpenResource = false; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public function __construct( $command, $file = null ) { |
| 46 |
if ( $file !== null ) { |
| 47 |
$command .= " > " . Shell::escape( $file ); |
| 48 |
} |
| 49 |
|
| 50 |
$this->startCommand( $command ); |
| 51 |
$this->command = $command; |
| 52 |
$this->filename = $file; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public function writeCloseStream( $string ) { |
| 59 |
parent::writeCloseStream( $string ); |
| 60 |
if ( $this->procOpenResource ) { |
| 61 |
proc_close( $this->procOpenResource ); |
| 62 |
$this->procOpenResource = false; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public function startCommand( $command ) { |
| 70 |
$spec = [ |
| 71 |
0 => [ "pipe", "r" ], |
| 72 |
]; |
| 73 |
$pipes = []; |
| 74 |
$this->procOpenResource = proc_open( $command, $spec, $pipes ); |
| 75 |
$this->handle = $pipes[0]; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public function closeRenameAndReopen( $newname ) { |
| 82 |
$this->closeAndRename( $newname, true ); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
public function closeAndRename( $newname, $open = false ) { |
| 89 |
$newname = $this->checkRenameArgCount( $newname ); |
| 90 |
if ( $newname ) { |
| 91 |
if ( $this->handle ) { |
| 92 |
fclose( $this->handle ); |
| 93 |
$this->handle = false; |
| 94 |
} |
| 95 |
if ( $this->procOpenResource ) { |
| 96 |
proc_close( $this->procOpenResource ); |
| 97 |
$this->procOpenResource = false; |
| 98 |
} |
| 99 |
$this->renameOrException( $newname ); |
| 100 |
if ( $open ) { |
| 101 |
$command = $this->command; |
| 102 |
$command .= " > " . Shell::escape( $this->filename ); |
| 103 |
$this->startCommand( $command ); |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
} |