BackupEngineMysql::getFileExtension()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Cornford\Backup\Engines;
4
5
class BackupEngineMysql extends BackupEngineAbstract
6
{
7
    private const ENGINE_NAME = 'mysql';
8
    private const ENGINE_EXTENSION = 'sql';
9
    private const ENGINE_EXPORT_PROCESS = 'mysqldump';
10
    private const ENGINE_RESTORE_PROCESS = 'mysql';
11
12
    /**
13
     * Get export process.
14
     *
15
     * @return string
16
     */
17
    public function getExportProcess()
18
    {
19
        return self::ENGINE_EXPORT_PROCESS;
20
    }
21
22
    /**
23
     * Get restore process.
24
     *
25
     * @return string
26
     */
27
    public function getRestoreProcess()
28
    {
29
        return self::ENGINE_RESTORE_PROCESS;
30
    }
31
32
    /**
33
     * Get database file extension.
34
     *
35
     * @return string
36
     */
37
    public function getFileExtension()
38
    {
39
        return self::ENGINE_EXTENSION;
40
    }
41
42
    /**
43
     * Export the database to a file path.
44
     *
45
     * @param string $filepath
46
     *
47
     * @return bool
48
     */
49
    public function export($filepath)
50
    {
51
        $command = sprintf(
52
            '%s --user=%s --password=%s --host=%s --port=%s %s > %s',
53
            $this->getExportCommand(),
54
            escapeshellarg($this->getUsername()),
55
            escapeshellarg($this->getPassword()),
56
            escapeshellarg($this->getHostname()),
57
            escapeshellarg($this->getPort()),
58
            escapeshellarg($this->getDatabase()),
59
            escapeshellarg($filepath)
60
        );
61
62
        return $this->getBackupProcess()->run($command, __FUNCTION__);
63
    }
64
65
    /**
66
     * Restore the database from a file path.
67
     *
68
     * @param string $filepath
69
     *
70
     * @return bool
71
     */
72
    public function restore($filepath)
73
    {
74
        $command = sprintf(
75
            '%s --user=%s --password=%s --host=%s --port=%s %s < %s',
76
            $this->getRestoreCommand(),
77
            escapeshellarg($this->getUsername()),
78
            escapeshellarg($this->getPassword()),
79
            escapeshellarg($this->getHostname()),
80
            escapeshellarg($this->getPort()),
81
            escapeshellarg($this->getDatabase()),
82
            escapeshellarg($filepath)
83
        );
84
85
        return $this->getBackupProcess()->run($command, __FUNCTION__);
86
    }
87
}
88