Merge "Fix some FSFileBackend IDEA errors"
[lhc/web/wiklou.git] / includes / export / Dump7ZipOutput.php
1 <?php
2 /**
3 * Sends dump output via the p7zip compressor.
4 *
5 * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
6 * https://www.mediawiki.org/
7 *
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.
12 *
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.
17 *
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
22 *
23 * @file
24 */
25
26 /**
27 * @ingroup Dump
28 */
29 class Dump7ZipOutput extends DumpPipeOutput {
30 /**
31 * @param string $file
32 */
33 function __construct( $file ) {
34 $command = $this->setup7zCommand( $file );
35 parent::__construct( $command );
36 $this->filename = $file;
37 }
38
39 /**
40 * @param string $file
41 * @return string
42 */
43 function setup7zCommand( $file ) {
44 $command = "7za a -bd -si -mx=4 " . wfEscapeShellArg( $file );
45 // Suppress annoying useless crap from p7zip
46 // Unfortunately this could suppress real error messages too
47 $command .= ' >' . wfGetNull() . ' 2>&1';
48 return $command;
49 }
50
51 /**
52 * @param string $newname
53 * @param bool $open
54 */
55 function closeAndRename( $newname, $open = false ) {
56 $newname = $this->checkRenameArgCount( $newname );
57 if ( $newname ) {
58 fclose( $this->handle );
59 proc_close( $this->procOpenResource );
60 $this->renameOrException( $newname );
61 if ( $open ) {
62 $command = $this->setup7zCommand( $this->filename );
63 $this->startCommand( $command );
64 }
65 }
66 }
67 }