mirror of
https://github.com/Chouchen/Shikiryu_Backup.git
synced 2021-06-30 16:02:14 +02:00
Correction after some tests
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Shikiryu\Backup\Transport;
|
||||
|
||||
use Shikiryu\Backup\Backup\BackupAbstract;
|
||||
|
||||
abstract class TransportAbstract
|
||||
{
|
||||
|
||||
protected $backup;
|
||||
protected $config;
|
||||
|
||||
public function __construct(BackupAbstract $backup)
|
||||
{
|
||||
$config = parse_ini_file(dirname(__FILE__).'/../config/config.ini');
|
||||
$classname = get_class($this);
|
||||
$type = substr($classname, strrpos($classname, '_')+1);
|
||||
$this->config = $config[ucfirst(strtolower($type))];
|
||||
$this->backup = $backup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public abstract function send();
|
||||
}
|
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Shikiryu\Backup\Transport;
|
||||
|
||||
use Shikiryu\Backup\Backup\BackupAbstract;
|
||||
|
||||
class Email extends TransportAbstract
|
||||
{
|
||||
|
||||
@@ -141,10 +143,10 @@ class Email extends TransportAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Shikiryu_Backup_Abstract $backup
|
||||
* @param BackupAbstract $backup
|
||||
*/
|
||||
public function __construct(Shikiryu_Backup_Abstract $backup) {
|
||||
parent::__construct($backup);
|
||||
public function __construct(BackupAbstract $backup, array $config) {
|
||||
parent::__construct($backup, $config);
|
||||
$this->setFiles($this->backup->getFilesToBackup());
|
||||
$this->setStreams($this->backup->getStreamsToBackup());
|
||||
$this->to = $this->config['to'];
|
||||
@@ -233,9 +235,9 @@ class Email extends TransportAbstract
|
||||
public function send() {
|
||||
|
||||
// Checking files are selected
|
||||
$zip = new ZipArchive(); // Load zip library
|
||||
$zip = new \ZipArchive(); // Load zip library
|
||||
$zip_name = time().".zip"; // Zip name
|
||||
if($zip->open(dirname(__FILE__).'/bu/'.$zip_name, ZIPARCHIVE::CREATE)==TRUE) {
|
||||
if($zip->open(TEMP_DIR.$zip_name, \ZIPARCHIVE::CREATE)==TRUE) {
|
||||
if(!empty($this->files)) {
|
||||
foreach($this->files as $file)
|
||||
{
|
||||
@@ -245,7 +247,7 @@ class Email extends TransportAbstract
|
||||
$zip->close();
|
||||
}
|
||||
|
||||
$this->files = array(dirname(__FILE__).'/bu/'.$zip_name=>dirname(__FILE__).'/bu/'.$zip_name);
|
||||
$this->files = array(TEMP_DIR.$zip_name=>dirname(__FILE__).'/bu/'.$zip_name);
|
||||
|
||||
$random_hash = md5(date('r', time()));
|
||||
$headers = "From: " . $this->from . "\r\nReply-To: " . $this->from;
|
||||
@@ -259,8 +261,9 @@ Content-Transfer-Encoding: 8bit
|
||||
" . $this->message . "\r\n";
|
||||
|
||||
if(!empty($this->files))
|
||||
foreach($this->files as $file=>$name) {
|
||||
$name = end(explode('/', $name));
|
||||
foreach($this->files as $file => $name) {
|
||||
$name = explode('/', $name);
|
||||
$name = end($name);
|
||||
$output .= "
|
||||
--$random_hash
|
||||
Content-Type: " . self::getMimeType($file) . "; name=" . $name . "
|
||||
|
@@ -2,20 +2,22 @@
|
||||
|
||||
namespace Shikiryu\Backup\Transport;
|
||||
|
||||
use Shikiryu\Backup\Backup\BackupAbstract;
|
||||
|
||||
class Factory
|
||||
{
|
||||
/**
|
||||
* @param $type
|
||||
* @param Shikiryu_Backup_Abstract $backup
|
||||
*
|
||||
* @return bool
|
||||
* @param BackupAbstract $backup
|
||||
* @param array $config
|
||||
*
|
||||
* @return TransportAbstract|null
|
||||
*/
|
||||
public static function build(array $config)
|
||||
public static function build(BackupAbstract $backup, array $config)
|
||||
{
|
||||
$class = array_keys($config)[0];
|
||||
$class = __NAMESPACE__.'\\'.array_keys($config)[0];
|
||||
if (class_exists($class)) {
|
||||
/* @var $instance BackupAbstract */
|
||||
return new $class(array_values($config));
|
||||
return new $class($backup, array_values($config)[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
23
app/code/Transport/TransportAbstract.php
Normal file
23
app/code/Transport/TransportAbstract.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Shikiryu\Backup\Transport;
|
||||
|
||||
use Shikiryu\Backup\Backup\BackupAbstract;
|
||||
|
||||
abstract class TransportAbstract
|
||||
{
|
||||
|
||||
protected $backup;
|
||||
protected $config;
|
||||
|
||||
public function __construct(BackupAbstract $backup, array $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->backup = $backup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public abstract function send();
|
||||
}
|
Reference in New Issue
Block a user