Shikiryu_Backup/app/code/Transport/Dropbox.php

57 lines
1.5 KiB
PHP
Raw Normal View History

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;
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');
2015-08-18 17:02:37 +02:00
$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
}
}
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) {
2019-01-25 22:19:50 +01:00
$upload = $this->dropbox->uploadFileFromString(
$this->folder . '/' . $name,
\Dropbox\WriteMode::force(),
$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
}