3 * Stream outputter to send data to a file via some filter program.
4 * Even if compression is available in a library, using a separate
5 * program can allow us to make use of a multi-processor system.
7 * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
8 * https://www.mediawiki.org/
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
31 class DumpPipeOutput
extends DumpFileOutput
{
32 protected $command, $filename;
33 protected $procOpenResource = false;
36 * @param string $command
39 function __construct( $command, $file = null ) {
40 if ( !is_null( $file ) ) {
41 $command .= " > " . wfEscapeShellArg( $file );
44 $this->startCommand( $command );
45 $this->command
= $command;
46 $this->filename
= $file;
50 * @param string $string
52 function writeCloseStream( $string ) {
53 parent
::writeCloseStream( $string );
54 if ( $this->procOpenResource
) {
55 proc_close( $this->procOpenResource
);
56 $this->procOpenResource
= false;
61 * @param string $command
63 function startCommand( $command ) {
68 $this->procOpenResource
= proc_open( $command, $spec, $pipes );
69 $this->handle
= $pipes[0];
73 * @param string $newname
75 function closeRenameAndReopen( $newname ) {
76 $this->closeAndRename( $newname, true );
80 * @param string $newname
83 function closeAndRename( $newname, $open = false ) {
84 $newname = $this->checkRenameArgCount( $newname );
86 if ( $this->handle
) {
87 fclose( $this->handle
);
88 $this->handle
= false;
90 if ( $this->procOpenResource
) {
91 proc_close( $this->procOpenResource
);
92 $this->procOpenResource
= false;
94 $this->renameOrException( $newname );
96 $command = $this->command
;
97 $command .= " > " . wfEscapeShellArg( $this->filename
);
98 $this->startCommand( $command );