mirror of
https://github.com/Chouchen/Shikiryu_Backup.git
synced 2021-06-30 16:02:14 +02:00
53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
||
|
||
namespace Shikiryu\Backup\Transport;
|
||
|
||
use Dropbox\Client;
|
||
use Shikiryu\Backup\Transport\TransportAbstract;
|
||
|
||
class Dropbox extends TransportAbstract
|
||
{
|
||
/**
|
||
* Dropbox Client
|
||
*
|
||
* @var Client
|
||
*/
|
||
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;
|
||
$files = $this->backup->getFilesTobackup();
|
||
foreach ($files as $file => $name) {
|
||
$file = fopen($file, 'r');
|
||
$upload = $this->dropbox->uploadFile($this->folder.'/'.$name, \Dropbox\WriteMode::force(), $file);
|
||
if (!$upload) {
|
||
$sent = false;
|
||
echo 'DROPBOX upload manqu<71>e de '.$file.' vers '.$this->folder.$name;
|
||
}
|
||
}
|
||
$streams = $this->backup->getStreamsTobackup();
|
||
foreach ($streams as $stream => $name) {
|
||
$upload = $this->dropbox->uploadFileFromString($this->folder.'/'.$name, \Dropbox\WriteMode::force(), $stream);
|
||
if (!$upload) {
|
||
$sent = false;
|
||
echo 'DROPBOX upload manqu<71>e de '.$file.' vers '.$this->folder.$name;
|
||
}
|
||
}
|
||
return $sent;
|
||
}
|
||
}
|