MediaWiki  1.34.0
DumpPipeOutput.php
Go to the documentation of this file.
1 <?php
29 
34  protected $command, $filename;
36  protected $procOpenResource = false;
37 
42  function __construct( $command, $file = null ) {
43  if ( !is_null( $file ) ) {
44  $command .= " > " . Shell::escape( $file );
45  }
46 
47  $this->startCommand( $command );
48  $this->command = $command;
49  $this->filename = $file;
50  }
51 
55  function writeCloseStream( $string ) {
56  parent::writeCloseStream( $string );
57  if ( $this->procOpenResource ) {
58  proc_close( $this->procOpenResource );
59  $this->procOpenResource = false;
60  }
61  }
62 
66  function startCommand( $command ) {
67  $spec = [
68  0 => [ "pipe", "r" ],
69  ];
70  $pipes = [];
71  $this->procOpenResource = proc_open( $command, $spec, $pipes );
72  $this->handle = $pipes[0];
73  }
74 
78  function closeRenameAndReopen( $newname ) {
79  $this->closeAndRename( $newname, true );
80  }
81 
85  function closeAndRename( $newname, $open = false ) {
86  $newname = $this->checkRenameArgCount( $newname );
87  if ( $newname ) {
88  if ( $this->handle ) {
89  fclose( $this->handle );
90  $this->handle = false;
91  }
92  if ( $this->procOpenResource ) {
93  proc_close( $this->procOpenResource );
94  $this->procOpenResource = false;
95  }
96  $this->renameOrException( $newname );
97  if ( $open ) {
99  $command .= " > " . Shell::escape( $this->filename );
100  $this->startCommand( $command );
101  }
102  }
103  }
104 }
MediaWiki\Shell\Shell
Executes shell commands.
Definition: Shell.php:44
DumpPipeOutput\closeRenameAndReopen
closeRenameAndReopen( $newname)
Close the old file, move it to a specified name, and reopen new file with the old name....
Definition: DumpPipeOutput.php:78
DumpFileOutput\checkRenameArgCount
checkRenameArgCount( $newname)
Definition: DumpFileOutput.php:83
DumpPipeOutput\startCommand
startCommand( $command)
Definition: DumpPipeOutput.php:66
DumpPipeOutput\$filename
$filename
Definition: DumpPipeOutput.php:34
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
DumpPipeOutput\closeAndRename
closeAndRename( $newname, $open=false)
Close the old file, and move it to a specified name.Use this for the last piece of a file written out...
Definition: DumpPipeOutput.php:85
DumpFileOutput\renameOrException
renameOrException( $newname)
Definition: DumpFileOutput.php:72
DumpPipeOutput\writeCloseStream
writeCloseStream( $string)
Definition: DumpPipeOutput.php:55
DumpPipeOutput\__construct
__construct( $command, $file=null)
Definition: DumpPipeOutput.php:42
DumpPipeOutput\$procOpenResource
resource bool $procOpenResource
Definition: DumpPipeOutput.php:36
DumpPipeOutput
Definition: DumpPipeOutput.php:33
DumpPipeOutput\$command
$command
Definition: DumpPipeOutput.php:34
DumpFileOutput
Definition: DumpFileOutput.php:29