MediaWiki master
DumpPipeOutput.php
Go to the documentation of this file.
1<?php
14namespace MediaWiki\Export;
15
17
23 protected $command;
25 protected $filename;
27 protected $procOpenResource = false;
28
33 public function __construct( $command, $file = null ) {
34 if ( $file !== null ) {
35 $command .= " > " . Shell::escape( $file );
36 }
37
38 $this->startCommand( $command );
39 $this->command = $command;
40 $this->filename = $file;
41 }
42
46 public function writeCloseStream( $string ) {
47 parent::writeCloseStream( $string );
48 if ( $this->procOpenResource ) {
49 proc_close( $this->procOpenResource );
50 $this->procOpenResource = false;
51 }
52 }
53
57 public function startCommand( $command ) {
58 $spec = [
59 0 => [ "pipe", "r" ],
60 ];
61 $pipes = [];
62 $this->procOpenResource = proc_open( $command, $spec, $pipes );
63 $this->handle = $pipes[0];
64 }
65
69 public function closeRenameAndReopen( $newname ) {
70 $this->closeAndRename( $newname, true );
71 }
72
76 public function closeAndRename( $newname, $open = false ) {
77 $newname = $this->checkRenameArgCount( $newname );
78 if ( $newname ) {
79 if ( $this->handle ) {
80 fclose( $this->handle );
81 $this->handle = false;
82 }
83 if ( $this->procOpenResource ) {
84 proc_close( $this->procOpenResource );
85 $this->procOpenResource = false;
86 }
87 $this->renameOrException( $newname );
88 if ( $open ) {
90 $command .= " > " . Shell::escape( $this->filename );
91 $this->startCommand( $command );
92 }
93 }
94 }
95}
96
98class_alias( DumpPipeOutput::class, 'DumpPipeOutput' );
closeRenameAndReopen( $newname)
Close the old file, move it to a specified name, and reopen new file with the old name....
__construct( $command, $file=null)
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...
Executes shell commands.
Definition Shell.php:32