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:
@@ -7,7 +7,11 @@ use Shikiryu\Backup\Transport\TransportAbstract;
|
||||
|
||||
class Dropbox extends TransportAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Dropbox Client
|
||||
*
|
||||
* @var Client
|
||||
*/
|
||||
private $dropbox;
|
||||
|
||||
protected $token = '';
|
||||
@@ -26,23 +30,23 @@ class Dropbox extends TransportAbstract
|
||||
public function send()
|
||||
{
|
||||
$sent = true;
|
||||
$files = $this->backup->getFilesToBackup();
|
||||
$files = $this->backup->getFilesTobackup();
|
||||
foreach ($files as $file => $name) {
|
||||
$file = fopen($file, 'r');
|
||||
$upload = $this->dropbox->uploadFile($this->folder.'/'.$name, \Dropbox\WriteMode::force(), $file);
|
||||
if (!$upload) {
|
||||
$sent = false;
|
||||
echo 'DROPBOX upload manqu<71>e de '.$file.' vers '.$this->folder.$name;
|
||||
echo 'DROPBOX upload manqu<71>e de '.$file.' vers '.$this->folder.$name;
|
||||
}
|
||||
}
|
||||
$streams = $this->backup->getStreamsToBackup();
|
||||
$streams = $this->backup->getStreamsTobackup();
|
||||
foreach ($streams as $stream => $name) {
|
||||
$upload = $this->dropbox->uploadFileFromString($this->folder.'/'.$name, \Dropbox\WriteMode::force(), $stream);
|
||||
if (!$upload) {
|
||||
$sent = false;
|
||||
echo 'DROPBOX upload manqu<71>e de '.$file.' vers '.$this->folder.$name;
|
||||
echo 'DROPBOX upload manqu<71>e de '.$file.' vers '.$this->folder.$name;
|
||||
}
|
||||
}
|
||||
return $sent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -147,8 +147,8 @@ class Email extends TransportAbstract
|
||||
*/
|
||||
public function __construct(BackupAbstract $backup, array $config) {
|
||||
parent::__construct($backup, $config);
|
||||
$this->setFiles($this->backup->getFilesToBackup());
|
||||
$this->setStreams($this->backup->getStreamsToBackup());
|
||||
$this->setFiles($this->backup->getFilesTobackup());
|
||||
$this->setStreams($this->backup->getStreamsTobackup());
|
||||
$this->email_to = $this->config['to'];
|
||||
$this->email_from = $this->config['from'];
|
||||
$this->encoding = $this->config['encoding'];
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Shikiryu\Backup\Transport;
|
||||
|
||||
class Ftp extends TransportAbstract
|
||||
@@ -14,12 +15,13 @@ class Ftp extends TransportAbstract
|
||||
private $files;
|
||||
private $streams;
|
||||
|
||||
public function __construct($backup, $config) {
|
||||
public function __construct($backup, $config)
|
||||
{
|
||||
parent::__construct($backup, $config);
|
||||
|
||||
// $this->path = $this->config['path'];
|
||||
if (!empty($this->folder)) {
|
||||
$this->folder = sprintf('/%s/', ltrim(rtrim($this->folder, '/'),'/'));
|
||||
$this->folder = sprintf('/%s/', ltrim(rtrim($this->folder, '/'), '/'));
|
||||
}
|
||||
|
||||
$this->connection = ftp_connect($this->host);
|
||||
@@ -29,13 +31,14 @@ class Ftp extends TransportAbstract
|
||||
|
||||
$login = @ftp_login($this->connection, $this->login, $this->password);
|
||||
if ($login === false) {
|
||||
throw new \Exception(sprintf('Connexion FTP %s refusée avec %s et %s', $this->host, $this->login, $this->password));
|
||||
$msg = sprintf('Connexion FTP %s refusée avec %s et %s', $this->host, $this->login, $this->password);
|
||||
throw new \Exception($msg);
|
||||
}
|
||||
|
||||
$this->setFiles($this->backup->getFilesToBackup());
|
||||
$this->setStreams($this->backup->getStreamsToBackup());
|
||||
$this->setFiles($this->backup->getFilesTobackup());
|
||||
$this->setStreams($this->backup->getStreamsTobackup());
|
||||
}
|
||||
|
||||
|
||||
private function setFiles($files = array())
|
||||
{
|
||||
if (is_array($files) && !empty($files)) {
|
||||
@@ -44,13 +47,14 @@ class Ftp extends TransportAbstract
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function setStreams($streams = array()) {
|
||||
private function setStreams($streams = array())
|
||||
{
|
||||
if (is_array($streams) && !empty($streams)) {
|
||||
$this->streams = $streams;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
@@ -58,7 +62,7 @@ class Ftp extends TransportAbstract
|
||||
{
|
||||
$sent = true;
|
||||
ftp_pasv($this->connection, true);
|
||||
if (!empty($this->files)){
|
||||
if (!empty($this->files)) {
|
||||
foreach ($this->files as $file => $name) {
|
||||
$upload = ftp_put($this->connection, $this->folder.$name, $file, FTP_BINARY);
|
||||
if (!$upload) {
|
||||
@@ -67,11 +71,12 @@ class Ftp extends TransportAbstract
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->streams)){
|
||||
|
||||
if (!empty($this->streams)) {
|
||||
foreach ($this->streams as $name => $stream) {
|
||||
if (count(explode('.', $name)) < 2)
|
||||
if (count(explode('.', $name)) < 2) {
|
||||
$name = 'backup' . $name . '.txt';
|
||||
}
|
||||
file_put_contents($name, $stream);
|
||||
$upload = ftp_put($this->connection, $this->folder.$name, $name, FTP_ASCII);
|
||||
if (!$upload) {
|
||||
@@ -85,23 +90,12 @@ class Ftp extends TransportAbstract
|
||||
if (!$sent) {
|
||||
throw new \Exception('At least an upload didnt work.');
|
||||
}
|
||||
|
||||
|
||||
return $sent;
|
||||
}
|
||||
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
ftp_close($this->connection);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
|
@@ -21,4 +21,4 @@ class Factory
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,43 +2,46 @@
|
||||
|
||||
namespace Shikiryu\Backup\Transport;
|
||||
|
||||
|
||||
use Shikiryu\Backup\Backup\BackupAbstract;
|
||||
|
||||
class Folder extends TransportAbstract
|
||||
{
|
||||
/** @var string */
|
||||
protected $folder;
|
||||
/**
|
||||
* Folder to backup
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $folder;
|
||||
|
||||
public function __construct(BackupAbstract $backup, array $config = array())
|
||||
{
|
||||
parent::__construct($backup, $config);
|
||||
public function __construct(BackupAbstract $backup, array $config = array())
|
||||
{
|
||||
parent::__construct($backup, $config);
|
||||
|
||||
if (!empty($this->folder)) {
|
||||
$this->folder = sprintf('%s/', rtrim($this->folder, '/'));
|
||||
}
|
||||
}
|
||||
if (!empty($this->folder)) {
|
||||
$this->folder = sprintf('%s/', rtrim($this->folder, '/'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
foreach ($this->backup->getFilesToBackup() as $file => $name) {
|
||||
if (copy($file, $this->folder . $name) === false) {
|
||||
throw new \Exception(sprintf('Copy of %s in %s failed', $name, $this->folder));
|
||||
};
|
||||
}
|
||||
foreach ($this->backup->getStreamsToBackup() as $name => $file) {
|
||||
if (count(explode('.', $name)) < 2) {
|
||||
$name = 'backup' . $name . '.txt';
|
||||
}
|
||||
if (file_put_contents($this->folder . $name, $file) === false) {
|
||||
throw new \Exception(sprintf('Saving of %s in %s failed', $name, $this->folder));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
foreach ($this->backup->getFilesTobackup() as $file => $name) {
|
||||
if (copy($file, $this->folder . $name) === false) {
|
||||
throw new \Exception(sprintf('Copy of %s in %s failed', $name, $this->folder));
|
||||
};
|
||||
}
|
||||
foreach ($this->backup->getStreamsTobackup() as $name => $file) {
|
||||
if (count(explode('.', $name)) < 2) {
|
||||
$name = 'backup' . $name . '.txt';
|
||||
}
|
||||
if (file_put_contents($this->folder . $name, $file) === false) {
|
||||
throw new \Exception(sprintf('Saving of %s in %s failed', $name, $this->folder));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ use phpseclib\Net\SFTP as LibSFTP;
|
||||
|
||||
class Sftp extends TransportAbstract
|
||||
{
|
||||
/** @var string */
|
||||
/** @var string */
|
||||
protected $host;
|
||||
/** @var int */
|
||||
protected $port = 22;
|
||||
@@ -16,7 +16,7 @@ class Sftp extends TransportAbstract
|
||||
protected $password;
|
||||
/** @var string */
|
||||
protected $folder;
|
||||
/** @var LibSFTP */
|
||||
/** @var LibSFTP */
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
@@ -36,29 +36,29 @@ class Sftp extends TransportAbstract
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
$sent = true;
|
||||
$files = $this->backup->getFilesToBackup();
|
||||
if (!empty($files)){
|
||||
$files = $this->backup->getFilesTobackup();
|
||||
if (!empty($files)) {
|
||||
foreach ($files as $file => $name) {
|
||||
$upload = $this->connection->put($this->folder.'/'.$name, $file, LibSFTP::SOURCE_LOCAL_FILE);
|
||||
if (!$upload) {
|
||||
$sent = false;
|
||||
echo 'SFTP upload manqu<71>e de '.$file.' vers '.$this->folder.$name;
|
||||
echo 'SFTP upload manqu<71>e de '.$file.' vers '.$this->folder.$name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$streams = $this->backup->getStreamsToBackup();
|
||||
if (!empty($streams)){
|
||||
$streams = $this->backup->getStreamsTobackup();
|
||||
if (!empty($streams)) {
|
||||
foreach ($streams as $name => $stream) {
|
||||
$upload = $this->connection->put($this->folder.'/'.$name, $stream);
|
||||
if (!$upload) {
|
||||
echo 'SFTP upload manqu<71>e de '.$name.' vers '.$this->folder.$name;
|
||||
echo 'SFTP upload manqu<71>e de '.$name.' vers '.$this->folder.$name;
|
||||
$sent = false;
|
||||
}
|
||||
}
|
||||
@@ -69,4 +69,4 @@ class Sftp extends TransportAbstract
|
||||
}
|
||||
return $sent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ use Shikiryu\Backup\Backup\BackupAbstract;
|
||||
abstract class TransportAbstract
|
||||
{
|
||||
|
||||
/** @var BackupAbstract */
|
||||
/** @var BackupAbstract */
|
||||
protected $backup;
|
||||
/** @var array */
|
||||
protected $config;
|
||||
@@ -25,5 +25,5 @@ abstract class TransportAbstract
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public abstract function send();
|
||||
}
|
||||
abstract public function send();
|
||||
}
|
||||
|
Reference in New Issue
Block a user