mirror of
https://github.com/Chouchen/Shikiryu_Backup.git
synced 2021-06-30 16:02:14 +02:00
Made Files & Email work
This commit is contained in:
parent
6eaf2f0176
commit
091dd4cf22
@ -21,14 +21,10 @@ class Scenario {
|
|||||||
|
|
||||||
public static function autoload($class)
|
public static function autoload($class)
|
||||||
{
|
{
|
||||||
// Autoload only "sub-namespaced" class
|
|
||||||
if (strpos($class, __NAMESPACE__.'\\') === 0)
|
if (strpos($class, __NAMESPACE__.'\\') === 0)
|
||||||
{
|
{
|
||||||
// Delete current namespace from class one
|
|
||||||
$relative_NS = str_replace(__NAMESPACE__, '', $class);
|
$relative_NS = str_replace(__NAMESPACE__, '', $class);
|
||||||
// Translate namespace structure into directory structure
|
|
||||||
$translated_path = str_replace('\\', '/', $relative_NS);
|
$translated_path = str_replace('\\', '/', $relative_NS);
|
||||||
// Load class suffixed by ".class.php"
|
|
||||||
require __DIR__ . '/' . $translated_path . '.php';
|
require __DIR__ . '/' . $translated_path . '.php';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,26 +41,51 @@ class Scenario {
|
|||||||
|
|
||||||
public function send()
|
public function send()
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$this->transport->send();
|
$this->transport->send();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launch the whole job
|
||||||
|
*
|
||||||
|
* @param $scenario
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
public static function launch($scenario)
|
public static function launch($scenario)
|
||||||
{
|
{
|
||||||
// add autoloader
|
// add autoloader
|
||||||
static::register();
|
static::register();
|
||||||
|
|
||||||
|
$scenario = __DIR__.'/../scenario/'.$scenario;
|
||||||
|
|
||||||
// check the given scenario
|
// check the given scenario
|
||||||
if (is_readable($scenario)) {
|
if (is_readable($scenario)) {
|
||||||
$scenario = json_decode(file_get_contents($scenario), true);
|
$scenario = json_decode(file_get_contents($scenario), true);
|
||||||
if (!is_null($scenario) && static::isValid($scenario)) {
|
if (!is_null($scenario) && static::isValid($scenario)) {
|
||||||
|
try {
|
||||||
$scenario = new self($scenario);
|
$scenario = new self($scenario);
|
||||||
$scenario->send();
|
$scenario->send();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
throw new \Exception('invalid scenario.');
|
throw new \Exception('invalid scenario.');
|
||||||
}
|
}
|
||||||
throw new \Exception('scenario not found.');
|
throw new \Exception('scenario not found.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check given scenario validation
|
||||||
|
*
|
||||||
|
* @param array $scenario
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public static function isValid(array $scenario)
|
public static function isValid(array $scenario)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
|
@ -152,7 +152,7 @@ class Email extends TransportAbstract
|
|||||||
$this->to = $this->config['to'];
|
$this->to = $this->config['to'];
|
||||||
$this->from = $this->config['from'];
|
$this->from = $this->config['from'];
|
||||||
$this->encoding = $this->config['encoding'];
|
$this->encoding = $this->config['encoding'];
|
||||||
$this->subjet = $this->config['subject'];
|
$this->subject = $this->config['subject'];
|
||||||
$this->message = $this->config['message'];
|
$this->message = $this->config['message'];
|
||||||
$this->encoding = $this->config['encoding'];
|
$this->encoding = $this->config['encoding'];
|
||||||
}
|
}
|
||||||
@ -229,25 +229,28 @@ class Email extends TransportAbstract
|
|||||||
* Send the mail
|
* Send the mail
|
||||||
*
|
*
|
||||||
* @see #mail
|
* @see #mail
|
||||||
*
|
|
||||||
* @return bool
|
* @return bool
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function send() {
|
public function send()
|
||||||
|
{
|
||||||
|
|
||||||
// Checking files are selected
|
// Checking files are selected
|
||||||
$zip = new \ZipArchive(); // Load zip library
|
$zip = new \ZipArchive(); // Load zip library
|
||||||
$zip_name = time().".zip"; // Zip name
|
$zip_name = time().".zip"; // Zip name
|
||||||
if ($zip->open(TEMP_DIR.$zip_name, \ZIPARCHIVE::CREATE)==TRUE) {
|
if ($zip->open(TEMP_DIR.$zip_name, \ZIPARCHIVE::CREATE)==TRUE) {
|
||||||
if(!empty($this->files)) {
|
if(!empty($this->files)) {
|
||||||
foreach($this->files as $file)
|
foreach($this->files as $file => $name)
|
||||||
{
|
{
|
||||||
$zip->addFile($file); // Adding files into zip
|
$zip->addFile($file, $name); // Adding files into zip
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$zip->close();
|
$zip->close();
|
||||||
|
} else {
|
||||||
|
throw new \Exception('Transport::Email::Can\'t zip the given backup.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->files = array(TEMP_DIR.$zip_name=>dirname(__FILE__).'/bu/'.$zip_name);
|
$this->files = array(TEMP_DIR.$zip_name=>$zip_name);
|
||||||
|
|
||||||
$random_hash = md5(date('r', time()));
|
$random_hash = md5(date('r', time()));
|
||||||
$headers = "From: " . $this->from . "\r\nReply-To: " . $this->from;
|
$headers = "From: " . $this->from . "\r\nReply-To: " . $this->from;
|
||||||
@ -262,8 +265,6 @@ Content-Transfer-Encoding: 8bit
|
|||||||
|
|
||||||
if(!empty($this->files))
|
if(!empty($this->files))
|
||||||
foreach($this->files as $file => $name) {
|
foreach($this->files as $file => $name) {
|
||||||
$name = explode('/', $name);
|
|
||||||
$name = end($name);
|
|
||||||
$output .= "
|
$output .= "
|
||||||
--$random_hash
|
--$random_hash
|
||||||
Content-Type: " . self::getMimeType($file) . "; name=" . $name . "
|
Content-Type: " . self::getMimeType($file) . "; name=" . $name . "
|
||||||
|
Loading…
Reference in New Issue
Block a user