2015-08-18 17:02:37 +02:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Shikiryu\Backup\Transport;
|
|
|
|
|
|
2020-02-03 17:34:52 +01:00
|
|
|
|
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 = '';
|
2020-02-03 17:34:52 +01:00
|
|
|
|
// protected $app = '';
|
2015-08-18 17:02:37 +02:00
|
|
|
|
protected $folder = '';
|
|
|
|
|
|
|
|
|
|
public function __construct($backup, $config)
|
|
|
|
|
{
|
|
|
|
|
parent::__construct($backup, $config);
|
2020-02-03 17:34:52 +01:00
|
|
|
|
$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');
|
2020-02-03 17:34:52 +01:00
|
|
|
|
$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) {
|
2020-02-03 17:34:52 +01:00
|
|
|
|
$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
|
|
|
|
}
|