MediaWiki  master
DumpPipeOutput.php
Go to the documentation of this file.
1 <?php
29 
35  protected $command;
37  protected $filename;
39  protected $procOpenResource = false;
40 
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 
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 
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 
81  public function closeRenameAndReopen( $newname ) {
82  $this->closeAndRename( $newname, true );
83  }
84 
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 ) {
102  $command .= " > " . Shell::escape( $this->filename );
103  $this->startCommand( $command );
104  }
105  }
106  }
107 }
MediaWiki\Shell\Shell
Executes shell commands.
Definition: Shell.php:45
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:81
DumpFileOutput\checkRenameArgCount
checkRenameArgCount( $newname)
Definition: DumpFileOutput.php:83
DumpPipeOutput\startCommand
startCommand( $command)
Definition: DumpPipeOutput.php:69
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
DumpPipeOutput\$procOpenResource
resource false $procOpenResource
Definition: DumpPipeOutput.php:39
DumpPipeOutput\$command
string $command
Definition: DumpPipeOutput.php:35
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:88
DumpFileOutput\renameOrException
renameOrException( $newname)
Definition: DumpFileOutput.php:72
DumpPipeOutput\writeCloseStream
writeCloseStream( $string)
Definition: DumpPipeOutput.php:58
DumpPipeOutput\__construct
__construct( $command, $file=null)
Definition: DumpPipeOutput.php:45
DumpPipeOutput
Definition: DumpPipeOutput.php:33
DumpPipeOutput\$filename
string null $filename
Definition: DumpPipeOutput.php:37
DumpFileOutput
Definition: DumpFileOutput.php:29