rdbms: Avoid selectDB() call in LoadMonitor new connections
[mediawiki.git] / includes / export / Dump7ZipOutput.php
blob31c945c05e31722b490a7a28e7a6f057cb078b7c
1 <?php
2 /**
3 * Sends dump output via the p7zip compressor.
5 * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
6 * https://www.mediawiki.org/
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
23 * @file
26 /**
27 * @ingroup Dump
29 class Dump7ZipOutput extends DumpPipeOutput {
30 /**
31 * @var int
33 protected $compressionLevel;
35 /**
36 * @param string $file
37 * @param int $cmpLevel Compression level passed to 7za command's -mx
39 function __construct( $file, $cmpLevel = 4 ) {
40 $this->compressionLevel = $cmpLevel;
41 $command = $this->setup7zCommand( $file );
42 parent::__construct( $command );
43 $this->filename = $file;
46 /**
47 * @param string $file
48 * @return string
50 function setup7zCommand( $file ) {
51 $command = "7za a -bd -si -mx=";
52 $command .= wfEscapeShellArg( $this->compressionLevel ) . ' ';
53 $command .= wfEscapeShellArg( $file );
54 // Suppress annoying useless crap from p7zip
55 // Unfortunately this could suppress real error messages too
56 $command .= ' >' . wfGetNull() . ' 2>&1';
57 return $command;
60 /**
61 * @param string $newname
62 * @param bool $open
64 function closeAndRename( $newname, $open = false ) {
65 $newname = $this->checkRenameArgCount( $newname );
66 if ( $newname ) {
67 fclose( $this->handle );
68 proc_close( $this->procOpenResource );
69 $this->renameOrException( $newname );
70 if ( $open ) {
71 $command = $this->setup7zCommand( $this->filename );
72 $this->startCommand( $command );