Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Dump7ZipOutput
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 setup7zCommand
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 closeAndRename
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2/**
3 * Sends dump output via the p7zip compressor.
4 *
5 * Copyright © 2003, 2005, 2006 Brooke Vibber <bvibber@wikimedia.org>
6 * https://www.mediawiki.org/
7 *
8 * @license GPL-2.0-or-later
9 * @file
10 */
11
12namespace MediaWiki\Export;
13
14use MediaWiki\Shell\Shell;
15
16/**
17 * @ingroup Dump
18 */
19class Dump7ZipOutput extends DumpPipeOutput {
20    /**
21     * @var int
22     */
23    protected $compressionLevel;
24
25    /**
26     * @param string $file
27     * @param int $cmpLevel Compression level passed to 7za command's -mx
28     */
29    public function __construct( $file, $cmpLevel = 4 ) {
30        $this->compressionLevel = $cmpLevel;
31        $command = $this->setup7zCommand( $file );
32        parent::__construct( $command );
33        $this->filename = $file;
34    }
35
36    /**
37     * @param string $file
38     * @return string
39     */
40    private function setup7zCommand( $file ) {
41        $command = "7za a -bd -si -mx=";
42        $command .= Shell::escape( (string)$this->compressionLevel ) . ' ';
43        $command .= Shell::escape( $file );
44        // Suppress annoying useless crap from p7zip
45        // Unfortunately this could suppress real error messages too
46        $command .= ' >' . wfGetNull() . ' 2>&1';
47        return $command;
48    }
49
50    /**
51     * @inheritDoc
52     */
53    public function closeAndRename( $newname, $open = false ) {
54        $newname = $this->checkRenameArgCount( $newname );
55        if ( $newname ) {
56            fclose( $this->handle );
57            proc_close( $this->procOpenResource );
58            $this->renameOrException( $newname );
59            if ( $open ) {
60                $command = $this->setup7zCommand( $this->filename );
61                $this->startCommand( $command );
62            }
63        }
64    }
65}
66
67/** @deprecated class alias since 1.46 */
68class_alias( Dump7ZipOutput::class, 'Dump7ZipOutput' );