Shikiryu_Backup/app/code/Transport/Dropbox.php

52 lines
1.3 KiB
PHP
Raw Normal View History

2015-08-18 17:02:37 +02:00
<?php
namespace Shikiryu\Backup\Transport;
use Spatie\Dropbox\Client;
2015-08-18 17:02:37 +02:00
class Dropbox extends TransportAbstract
{
2016-07-03 21:54:35 +02:00
/**
* Dropbox Client
*
* @var Client
*/
2015-08-18 17:02:37 +02:00
private $dropbox;
protected $token = '';
// protected $app = '';
2015-08-18 17:02:37 +02:00
protected $folder = '';
public function __construct($backup, $config)
{
parent::__construct($backup, $config);
$this->dropbox = new Client($this->token);
2015-08-18 17:02:37 +02:00
}
/**
* @return bool
*/
public function send()
{
$sent = true;
2019-01-25 22:19:50 +01:00
$files = $this->backup->getFilesToBackup();
2015-08-18 17:02:37 +02:00
foreach ($files as $file => $name) {
2019-01-25 22:19:50 +01:00
$file = fopen($file, 'rb');
$upload = $this->dropbox->upload($this->folder.'/'.$name, $file);
2015-08-18 17:02:37 +02:00
if (!$upload) {
$sent = false;
2016-07-03 21:54:35 +02:00
echo 'DROPBOX upload manqu<71>e de '.$file.' vers '.$this->folder.$name;
2015-08-18 17:02:37 +02:00
}
}
2019-01-25 22:19:50 +01:00
$streams = $this->backup->getStreamsToBackup();
2015-08-18 17:02:37 +02:00
foreach ($streams as $stream => $name) {
$upload = $this->dropbox->upload($this->folder . '/' . $name, $stream);
2015-08-18 17:02:37 +02:00
if (!$upload) {
$sent = false;
2019-01-25 22:19:50 +01:00
echo 'DROPBOX upload manquée de ' . $file . ' vers '.$this->folder.$name;
2015-08-18 17:02:37 +02:00
}
}
return $sent;
}
2016-07-03 21:54:35 +02:00
}