2015-08-18 17:02:37 +02:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Shikiryu\Backup\Transport;
|
|
|
|
|
|
|
|
|
|
use Dropbox\Client;
|
|
|
|
|
use Shikiryu\Backup\Transport\TransportAbstract;
|
|
|
|
|
|
|
|
|
|
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 = '';
|
|
|
|
|
protected $folder = '';
|
|
|
|
|
|
|
|
|
|
public function __construct($backup, $config)
|
|
|
|
|
{
|
|
|
|
|
parent::__construct($backup, $config);
|
|
|
|
|
$this->dropbox = new Client($this->token, $this->app);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function send()
|
|
|
|
|
{
|
|
|
|
|
$sent = true;
|
2016-07-03 21:54:35 +02:00
|
|
|
|
$files = $this->backup->getFilesTobackup();
|
2015-08-18 17:02:37 +02:00
|
|
|
|
foreach ($files as $file => $name) {
|
|
|
|
|
$file = fopen($file, 'r');
|
|
|
|
|
$upload = $this->dropbox->uploadFile($this->folder.'/'.$name, \Dropbox\WriteMode::force(), $file);
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-03 21:54:35 +02:00
|
|
|
|
$streams = $this->backup->getStreamsTobackup();
|
2015-08-18 17:02:37 +02:00
|
|
|
|
foreach ($streams as $stream => $name) {
|
|
|
|
|
$upload = $this->dropbox->uploadFileFromString($this->folder.'/'.$name, \Dropbox\WriteMode::force(), $stream);
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $sent;
|
|
|
|
|
}
|
2016-07-03 21:54:35 +02:00
|
|
|
|
}
|