Merge ".mailmap: Correct two contributor names"
[mediawiki.git] / includes / export / Dump7ZipOutput.php
blob6b432bde3ad0fb491b9d67dd54bcc744c90723b9
1 <?php
2 /**
3 * Sends dump output via the p7zip compressor.
5 * Copyright © 2003, 2005, 2006 Brooke Vibber <bvibber@wikimedia.org>
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 use MediaWiki\Shell\Shell;
28 /**
29 * @ingroup Dump
31 class Dump7ZipOutput extends DumpPipeOutput {
32 /**
33 * @var int
35 protected $compressionLevel;
37 /**
38 * @param string $file
39 * @param int $cmpLevel Compression level passed to 7za command's -mx
41 public function __construct( $file, $cmpLevel = 4 ) {
42 $this->compressionLevel = $cmpLevel;
43 $command = $this->setup7zCommand( $file );
44 parent::__construct( $command );
45 $this->filename = $file;
48 /**
49 * @param string $file
50 * @return string
52 private function setup7zCommand( $file ) {
53 $command = "7za a -bd -si -mx=";
54 $command .= Shell::escape( (string)$this->compressionLevel ) . ' ';
55 $command .= Shell::escape( $file );
56 // Suppress annoying useless crap from p7zip
57 // Unfortunately this could suppress real error messages too
58 $command .= ' >' . wfGetNull() . ' 2>&1';
59 return $command;
62 /**
63 * @inheritDoc
65 public function closeAndRename( $newname, $open = false ) {
66 $newname = $this->checkRenameArgCount( $newname );
67 if ( $newname ) {
68 fclose( $this->handle );
69 proc_close( $this->procOpenResource );
70 $this->renameOrException( $newname );
71 if ( $open ) {
72 $command = $this->setup7zCommand( $this->filename );
73 $this->startCommand( $command );