Skip to content

Commit 88ae2ad

Browse files
Activate 'dropbox' support, still failing in phar mode :(
1 parent 352705c commit 88ae2ad

File tree

4 files changed

+117
-13
lines changed

4 files changed

+117
-13
lines changed

build.xml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,25 @@
105105

106106
<exec executable="${basedir}/build/phar-manifest.php" output="${basedir}/build/phar/manifest.txt"/>
107107

108+
<copy file="${basedir}/vendor/dropbox/dropbox-sdk/License.txt" tofile="${basedir}/build/phar/dropbox/LICENSE"/>
109+
<copy todir="${basedir}/build/phar/dropbox">
110+
<fileset dir="${basedir}/vendor/dropbox/dropbox-sdk/lib/Dropbox">
111+
<include name="**/*.php" />
112+
<include name="**/*.crt" />
113+
<exclude name="**/autoload.php" />
114+
<exclude name="**/strict.php" />
115+
</fileset>
116+
</copy>
117+
118+
<copy file="${basedir}/vendor/phpseclib/phpseclib/LICENSE" tofile="${basedir}/build/phar/phpseclib/LICENSE"/>
119+
<copy todir="${basedir}/build/phar/phpseclib">
120+
<fileset dir="${basedir}/vendor/phpseclib/phpseclib/phpseclib">
121+
<include name="**/*.php" />
122+
<include name="**/*.cnf" />
123+
<exclude name="**/autoload.php" />
124+
</fileset>
125+
</copy>
126+
108127
<copy file="${basedir}/vendor/phpunit/php-timer/LICENSE" tofile="${basedir}/build/phar/php-timer/LICENSE"/>
109128
<copy todir="${basedir}/build/phar/php-timer">
110129
<fileset dir="${basedir}/vendor/phpunit/php-timer/PHP">
@@ -128,15 +147,6 @@
128147
</fileset>
129148
</copy>
130149

131-
<copy file="${basedir}/vendor/phpseclib/phpseclib/LICENSE" tofile="${basedir}/build/phar/phpseclib/LICENSE"/>
132-
<copy todir="${basedir}/build/phar/phpseclib">
133-
<fileset dir="${basedir}/vendor/phpseclib/phpseclib/phpseclib">
134-
<include name="**/*.php" />
135-
<include name="**/*.cnf" />
136-
<exclude name="**/autoload.php" />
137-
</fileset>
138-
</copy>
139-
140150
<copy file="${basedir}/vendor/swiftmailer/swiftmailer/LICENSE" tofile="${basedir}/build/phar/swiftmailer/LICENSE"/>
141151
<copy todir="${basedir}/build/phar/swiftmailer">
142152
<fileset dir="${basedir}/vendor/swiftmailer/swiftmailer/lib">

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"ext-dom": "*",
2828
"ext-json": "*",
2929
"ext-spl": "*",
30+
"dropbox/dropbox-sdk": "1.1.*"
3031
"phpseclib/phpseclib": "2.0.*@dev",
3132
"phpunit/php-timer": "~1.0.2",
3233
"sebastian/environment": "~1.1",
@@ -35,7 +36,6 @@
3536
},
3637
"require-dev": {
3738
"squizlabs/php_codesniffer": "1.*",
38-
"dropbox/dropbox-sdk": "1.1.*"
3939
},
4040
"bin": [
4141
"phpbu"

doc/config/sync/dropbox.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<sync type="dropbox">
3+
<!-- mandatory -->
4+
<option name="token" value="mycrazylongapitokenthatigotfromdropbox" />
5+
6+
<!-- mandatory -->
7+
<option name="path" value="/some/dir" />
8+
</sync>

src/Backup/Sync/Dropbox.php

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,107 @@
11
<?php
22
namespace phpbu\Backup\Sync;
33

4+
use Dropbox as dbx;
45
use phpbu\App\Result;
56
use phpbu\Backup\Sync;
67
use phpbu\Backup\Target;
78

9+
/**
10+
* Dropbox
11+
*
12+
* @package phpbu
13+
* @subpackage Backup
14+
* @author Sebastian Feldmann <sebastian@phpbu.de>
15+
* @copyright Sebastian Feldmann <sebastian@phpbu.de>
16+
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
17+
* @link http://www.phpbu.de/
18+
* @since Class available since Release 1.1.1
19+
*/
820
class Dropbox implements Sync
921
{
10-
protected $config;
22+
/**
23+
* API access token
24+
*
25+
* Goto https://www.dropbox.com/developers/apps
26+
* create your app
27+
* - dropbox api app
28+
* - files and datastore
29+
* - yes
30+
* - provide some app name "my-dropbox-app"
31+
* - generate access token to authenticate connection to your dropbox
32+
*
33+
* @var string
34+
*/
35+
protected $token;
1136

37+
/**
38+
* Remote path
39+
*
40+
* @var string
41+
*/
42+
protected $path;
43+
44+
/**
45+
* (non-PHPdoc)
46+
* @see \phpbu\Backup\Sync::setup()
47+
*/
1248
public function setup(array $config)
1349
{
14-
$this->config = $config;
50+
if (!isset($config['token']) || '' == $config['token']) {
51+
throw new Exception('API access token is mandatory');
52+
}
53+
if (!isset($config['path']) || '' == $config['path']) {
54+
throw new Exception('dropbox path is mandatory');
55+
}
56+
$this->token = $config['token'];
57+
$this->path = $config['path'] . ( substr($config['path'], -1) !== '/' ? '/' : '' );
1558
}
1659

60+
/**
61+
* (non-PHPdoc)
62+
* @see \phpbu\Backup\Sync::sync()
63+
*/
1764
public function sync(Target $target, Result $result)
1865
{
19-
throw new Exception('NotImplementedException');
66+
$sourcePath = $target->getPathnameCompressed();
67+
$dropboxPath = $this->path . $target->getFilenameCompressed();
68+
69+
$client = new dbx\Client($this->token, "phpbu/1.1.0");
70+
71+
$pathError = dbx\Path::findErrorNonRoot($dropboxPath);
72+
if ($pathError !== null) {
73+
throw new Exception('Invalid <dropbox-path>: ' . $pathError);
74+
}
75+
76+
$size = null;
77+
if (stream_is_local($sourcePath)) {
78+
$size = filesize($sourcePath);
79+
}
80+
81+
try {
82+
$fp = fopen($sourcePath, 'rb');
83+
$res = $client->uploadFile($dropboxPath, dbx\WriteMode::add(), $fp, $size);
84+
fclose($fp);
85+
} catch (\Exception $e) {
86+
fclose($fp);
87+
throw new Exception($e->getMessage(), null, $e);
88+
}
89+
$result->debug('upload: done (' . $res['size'] . ')');
90+
/*
91+
$res
92+
[revision] => somerevisionmumber
93+
[bytes] => 12345
94+
[thumb_exists] =>
95+
[rev] => somerevisionhash
96+
[modified] => Day, DD Mon YYYY HH:MM:SS +0000
97+
[shareable] =>
98+
[mime_type] => application/octet-stream
99+
[path] => uploaded file
100+
[is_dir] =>
101+
[size] => XX.X KB
102+
[root] => dropbox
103+
[client_mtime] => Fri, 06 Feb 2015 21:44:33 +0000
104+
[icon] => page_white_compressed
105+
*/
20106
}
21107
}

0 commit comments

Comments
 (0)