mirror of
https://github.com/Chouchen/Shikiryu_Backup.git
synced 2021-06-30 16:02:14 +02:00
Add some PHPCS corrections
This commit is contained in:
@@ -6,13 +6,13 @@ class Mysql extends BackupAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* @var $pdo \PDO
|
||||
*/
|
||||
* @var $pdo \PDO
|
||||
*/
|
||||
private $pdo;
|
||||
|
||||
/*
|
||||
* from config
|
||||
*/
|
||||
* from config
|
||||
*/
|
||||
protected $tables;
|
||||
protected $host;
|
||||
protected $database;
|
||||
@@ -20,47 +20,49 @@ class Mysql extends BackupAbstract
|
||||
protected $pwd;
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct(array $config = array()) {
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct(array $config = array())
|
||||
{
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $tables
|
||||
* @return $this|string
|
||||
*/
|
||||
* @param array $tables
|
||||
* @return $this|string
|
||||
*/
|
||||
private function fromTables($tables = array())
|
||||
{
|
||||
if(!empty($tables)) {
|
||||
if (!empty($tables)) {
|
||||
$this->tables = $tables;
|
||||
}
|
||||
$this->_streamsToBackup[sprintf('db-%s.sql', $this->database)] = $this->getFromTables();
|
||||
$this->streams_to_backup[sprintf('db-%s.sql', $this->database)] = $this->getFromTables();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the list of table to backup to all tables
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
private function everything() {
|
||||
* set the list of table to backup to all tables
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
private function everything()
|
||||
{
|
||||
$this->tables = array();
|
||||
foreach($this->pdo->query('SHOW TABLES') as $table) {
|
||||
foreach ($this->pdo->query('SHOW TABLES') as $table) {
|
||||
$this->tables[] = $table;
|
||||
}
|
||||
$this->_streamsToBackup[sprintf('db-%s.sql', $this->database)] = $this->getFromTables();
|
||||
$this->streams_to_backup[sprintf('db-%s.sql', $this->database)] = $this->getFromTables();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
* @return string
|
||||
*/
|
||||
private function getFromTables()
|
||||
{
|
||||
$return = "";
|
||||
foreach ($this->tables as $table) {
|
||||
if(is_array($table)) {
|
||||
if (is_array($table)) {
|
||||
$table = $table[0];
|
||||
}
|
||||
$result = $this->pdo->prepare('SELECT * FROM ' . $table);
|
||||
@@ -71,21 +73,21 @@ class Mysql extends BackupAbstract
|
||||
$result2->execute();
|
||||
$row2 = $result2->fetch();
|
||||
$return.= "\n\n" . $row2[1] . ";\n\n";
|
||||
foreach($result as $row){
|
||||
$return.= 'INSERT INTO ' . $table . ' VALUES(';
|
||||
for ($j = 0; $j < $num_fields; $j++) {
|
||||
$row[$j] = addslashes($row[$j]);
|
||||
// $row[$j] = preg_replace("\n", "\\n", $row[$j]);
|
||||
if (isset($row[$j])) {
|
||||
$return.= '"' . $row[$j] . '"';
|
||||
} else {
|
||||
$return.= '""';
|
||||
}
|
||||
if ($j < ($num_fields - 1)) {
|
||||
$return.= ',';
|
||||
}
|
||||
foreach ($result as $row) {
|
||||
$return.= 'INSERT INTO ' . $table . ' VALUES(';
|
||||
for ($j = 0; $j < $num_fields; $j++) {
|
||||
$row[$j] = addslashes($row[$j]);
|
||||
// $row[$j] = preg_replace("\n", "\\n", $row[$j]);
|
||||
if (isset($row[$j])) {
|
||||
$return.= '"' . $row[$j] . '"';
|
||||
} else {
|
||||
$return.= '""';
|
||||
}
|
||||
$return.= ");\n";
|
||||
if ($j < ($num_fields - 1)) {
|
||||
$return.= ',';
|
||||
}
|
||||
}
|
||||
$return.= ");\n";
|
||||
}
|
||||
$return.="\n\n\n";
|
||||
}
|
||||
@@ -93,36 +95,34 @@ class Mysql extends BackupAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
return !empty($this->_streamsToBackup);
|
||||
return !empty($this->streams_to_backup);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function that can be used to initialize the backup
|
||||
*/
|
||||
/**
|
||||
* Function that can be used to initialize the backup
|
||||
*/
|
||||
protected function preBuild()
|
||||
{
|
||||
$this->pdo = new \PDO('mysql:host='.$this->host.';dbname='.$this->database, $this->login, $this->pwd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function that can be used after the backup
|
||||
*/
|
||||
/**
|
||||
* Function that can be used after the backup
|
||||
*/
|
||||
protected function postBuild()
|
||||
{
|
||||
// TODO: Implement postBuild() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Mandatory function doing the backup
|
||||
*/
|
||||
/**
|
||||
* Mandatory function doing the backup
|
||||
*/
|
||||
protected function build()
|
||||
{
|
||||
empty($this->tables) || $this->tables == '*' ? $this->everything() : $this->fromTables($this->tables);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
Reference in New Issue
Block a user