Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/worker/src/MWP/Incremen.../Database
File: MysqlDumpDumper.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
* This file is part of the ManageWP Worker plugin.
[2] Fix | Delete
*
[3] Fix | Delete
* (c) ManageWP LLC <contact@managewp.com>
[4] Fix | Delete
*
[5] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[6] Fix | Delete
* file that was distributed with this source code.
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
class MWP_IncrementalBackup_Database_MysqlDumpDumper implements MWP_IncrementalBackup_Database_DumperInterface
[10] Fix | Delete
{
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* @var MWP_IncrementalBackup_Database_Configuration
[14] Fix | Delete
*/
[15] Fix | Delete
private $configuration;
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* @var MWP_IncrementalBackup_Database_DumpOptions
[19] Fix | Delete
*/
[20] Fix | Delete
private $options;
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* @param MWP_IncrementalBackup_Database_Configuration $configuration
[24] Fix | Delete
* @param MWP_IncrementalBackup_Database_DumpOptions $options
[25] Fix | Delete
*/
[26] Fix | Delete
public function __construct(MWP_IncrementalBackup_Database_Configuration $configuration, MWP_IncrementalBackup_Database_DumpOptions $options)
[27] Fix | Delete
{
[28] Fix | Delete
$this->configuration = $configuration;
[29] Fix | Delete
$this->options = $options;
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* {@inheritdoc}
[34] Fix | Delete
*/
[35] Fix | Delete
public function dump($table, $realpath)
[36] Fix | Delete
{
[37] Fix | Delete
if (!mwp_is_shell_available()) {
[38] Fix | Delete
throw new MWP_Worker_Exception(MWP_Worker_Exception::SHELL_NOT_AVAILABLE, 'Shell not available.');
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
$mysqldump = mwp_container()->getExecutableFinder()->find('mysqldump', 'mysqldump');
[42] Fix | Delete
$processBuilder = $this->createProcessBuilder(array($table), $mysqldump);
[43] Fix | Delete
$processBuilder->add('--result-file='.$realpath);
[44] Fix | Delete
[45] Fix | Delete
$process = $processBuilder->getProcess();
[46] Fix | Delete
[47] Fix | Delete
mwp_logger()->info('Database dumping process starting', array(
[48] Fix | Delete
'executable_location' => $mysqldump,
[49] Fix | Delete
'command_line' => $process->getCommandLine(),
[50] Fix | Delete
'table' => $table,
[51] Fix | Delete
'destination' => $realpath,
[52] Fix | Delete
));
[53] Fix | Delete
[54] Fix | Delete
$process->mustRun();
[55] Fix | Delete
[56] Fix | Delete
mwp_logger()->info('Database dump complete', array(
[57] Fix | Delete
'table' => $table,
[58] Fix | Delete
'destination' => $realpath,
[59] Fix | Delete
'size' => @filesize($realpath),
[60] Fix | Delete
));
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
/**
[64] Fix | Delete
* {@inheritdoc}
[65] Fix | Delete
*/
[66] Fix | Delete
public function createStream(array $tables = array())
[67] Fix | Delete
{
[68] Fix | Delete
if (!mwp_is_shell_available()) {
[69] Fix | Delete
throw new MWP_Worker_Exception(MWP_Worker_Exception::SHELL_NOT_AVAILABLE, 'Shell not available.');
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
$mysqldump = mwp_container()->getExecutableFinder()->find('mysqldump', 'mysqldump');
[73] Fix | Delete
$processBuilder = $this->createProcessBuilder($tables, $mysqldump);
[74] Fix | Delete
[75] Fix | Delete
$process = $processBuilder->getProcess();
[76] Fix | Delete
[77] Fix | Delete
mwp_logger()->info('Database dumping process starting', array(
[78] Fix | Delete
'executable_location' => $mysqldump,
[79] Fix | Delete
'command_line' => $process->getCommandLine(),
[80] Fix | Delete
));
[81] Fix | Delete
[82] Fix | Delete
return new MWP_Stream_ProcessOutput($process);
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* @param array $tables
[87] Fix | Delete
* @param $mysqldump
[88] Fix | Delete
*
[89] Fix | Delete
* @return Symfony_Process_ProcessBuilder
[90] Fix | Delete
*/
[91] Fix | Delete
protected function createProcessBuilder(array $tables, $mysqldump)
[92] Fix | Delete
{
[93] Fix | Delete
$processBuilder = Symfony_Process_ProcessBuilder::create()
[94] Fix | Delete
->setWorkingDirectory(untrailingslashit(ABSPATH))
[95] Fix | Delete
->setTimeout(3600)
[96] Fix | Delete
->setPrefix($mysqldump)
[97] Fix | Delete
// Continue even if we get an SQL error.
[98] Fix | Delete
->add('--force')
[99] Fix | Delete
// User for login if not current user.
[100] Fix | Delete
->add('--user='.$this->configuration->getUsername())
[101] Fix | Delete
// Password to use when connecting to server. If password is not given it's solicited on the tty.
[102] Fix | Delete
->add('--password='.$this->configuration->getPassword())
[103] Fix | Delete
// Add a DROP TABLE before each create.
[104] Fix | Delete
->add('--add-drop-table');
[105] Fix | Delete
[106] Fix | Delete
if ($this->options->isSkipLockTables()) {
[107] Fix | Delete
// Don't lock all tables for read.
[108] Fix | Delete
$processBuilder->add('--lock-tables=false');
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
if ($this->options->isSkipExtendedInsert()) {
[112] Fix | Delete
$processBuilder->add('--extended-insert=false');
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
$processBuilder->add($this->configuration->getDatabase());
[116] Fix | Delete
[117] Fix | Delete
// Dump only specific tables
[118] Fix | Delete
foreach ($tables as $table) {
[119] Fix | Delete
$processBuilder->add($table);
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
if ($this->configuration->isSocket()) {
[123] Fix | Delete
$processBuilder->add('--socket='.$this->configuration->getSocketPath());
[124] Fix | Delete
} else {
[125] Fix | Delete
$processBuilder->add('--host='.$this->configuration->getHost());
[126] Fix | Delete
if (($port = $this->configuration->getPort()) !== null) {
[127] Fix | Delete
$processBuilder->add('--port='.$port);
[128] Fix | Delete
}
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
return $processBuilder;
[132] Fix | Delete
}
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function