UpdraftPlus WordPress Backup Plugin - Version 1.11.17

Version Description

  • 13/Nov/2015 =

  • FIX: Resolve a conflict with "Simple Calendar" (formerly "Google Calendar Events") since their re-written 3.0 release, when using Google Drive storage

Download this release

Release Info

Developer DavidAnderson
Plugin Icon 128x128 UpdraftPlus WordPress Backup Plugin
Version 1.11.17
Comparing to
See all releases

Code changes from version 1.11.15 to 1.11.17

includes/google-extensions.php ADDED
@@ -0,0 +1,323 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if (!defined('UPDRAFTPLUS_DIR')) die('No direct access allowed.');
4
+
5
+ /*
6
+
7
+ // Unfortunately, since the variables we want to access are private, not protected, we can't just extend the class. Instead, we have to clone it, and add these methods into our cloned copy.
8
+
9
+ class UpdraftPlus_Google_Http_MediaFileUpload extends Google_Http_MediaFileUpload {
10
+ public function updraftplus_setResumeUri($resumeUri) { $this->resumeUri = $resumeUri; }
11
+ public function updraftplus_setProgress($progress) { $this->progress = $progress; }
12
+ // N.B. a public method getResumeUri already exists - and does something completely different
13
+ public function updraftplus_getResumeUri() { return empty($this->resumeUri) ? '' : $this->resumeUri; }
14
+ }
15
+ */
16
+
17
+ /**
18
+ * Copyright 2012 Google Inc.
19
+ *
20
+ * Licensed under the Apache License, Version 2.0 (the "License");
21
+ * you may not use this file except in compliance with the License.
22
+ * You may obtain a copy of the License at
23
+ *
24
+ * http://www.apache.org/licenses/LICENSE-2.0
25
+ *
26
+ * Unless required by applicable law or agreed to in writing, software
27
+ * distributed under the License is distributed on an "AS IS" BASIS,
28
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29
+ * See the License for the specific language governing permissions and
30
+ * limitations under the License.
31
+ */
32
+
33
+ if (!class_exists('Google_Client')) {
34
+ require_once dirname(__FILE__) . '/../autoload.php';
35
+ }
36
+
37
+ /**
38
+ * Manage large file uploads, which may be media but can be any type
39
+ * of sizable data.
40
+ */
41
+ class UpdraftPlus_Google_Http_MediaFileUpload
42
+ {
43
+
44
+ public function updraftplus_setResumeUri($resumeUri) { $this->resumeUri = $resumeUri; }
45
+ public function updraftplus_setProgress($progress) { $this->progress = $progress; }
46
+ //N.B. a public method getResumeUri already exists - and does something completely different
47
+ public function updraftplus_getResumeUri() { return $this->resumeUri; }
48
+
49
+ const UPLOAD_MEDIA_TYPE = 'media';
50
+ const UPLOAD_MULTIPART_TYPE = 'multipart';
51
+ const UPLOAD_RESUMABLE_TYPE = 'resumable';
52
+
53
+ /** @var string $mimeType */
54
+ private $mimeType;
55
+
56
+ /** @var string $data */
57
+ private $data;
58
+
59
+ /** @var bool $resumable */
60
+ private $resumable;
61
+
62
+ /** @var int $chunkSize */
63
+ private $chunkSize;
64
+
65
+ /** @var int $size */
66
+ private $size;
67
+
68
+ /** @var string $resumeUri */
69
+ private $resumeUri;
70
+
71
+ /** @var int $progress */
72
+ private $progress;
73
+
74
+ /** @var Google_Client */
75
+ private $client;
76
+
77
+ /** @var Google_Http_Request */
78
+ private $request;
79
+
80
+ /** @var string */
81
+ private $boundary;
82
+
83
+ /**
84
+ * Result code from last HTTP call
85
+ * @var int
86
+ */
87
+ private $httpResultCode;
88
+
89
+ /**
90
+ * @param $mimeType string
91
+ * @param $data string The bytes you want to upload.
92
+ * @param $resumable bool
93
+ * @param bool $chunkSize File will be uploaded in chunks of this many bytes.
94
+ * only used if resumable=True
95
+ */
96
+ public function __construct(
97
+ Google_Client $client,
98
+ Google_Http_Request $request,
99
+ $mimeType,
100
+ $data,
101
+ $resumable = false,
102
+ $chunkSize = false,
103
+ $boundary = false
104
+ ) {
105
+ $this->client = $client;
106
+ $this->request = $request;
107
+ $this->mimeType = $mimeType;
108
+ $this->data = $data;
109
+ $this->size = strlen($this->data);
110
+ $this->resumable = $resumable;
111
+ if (!$chunkSize) {
112
+ $chunkSize = 256 * 1024;
113
+ }
114
+ $this->chunkSize = $chunkSize;
115
+ $this->progress = 0;
116
+ $this->boundary = $boundary;
117
+
118
+ // Process Media Request
119
+ $this->process();
120
+ }
121
+
122
+ /**
123
+ * Set the size of the file that is being uploaded.
124
+ * @param $size - int file size in bytes
125
+ */
126
+ public function setFileSize($size)
127
+ {
128
+ $this->size = $size;
129
+ }
130
+
131
+ /**
132
+ * Return the progress on the upload
133
+ * @return int progress in bytes uploaded.
134
+ */
135
+ public function getProgress()
136
+ {
137
+ return $this->progress;
138
+ }
139
+
140
+ /**
141
+ * Return the HTTP result code from the last call made.
142
+ * @return int code
143
+ */
144
+ public function getHttpResultCode()
145
+ {
146
+ return $this->httpResultCode;
147
+ }
148
+
149
+ /**
150
+ * Send the next part of the file to upload.
151
+ * @param [$chunk] the next set of bytes to send. If false will used $data passed
152
+ * at construct time.
153
+ */
154
+ public function nextChunk($chunk = false)
155
+ {
156
+ if (false == $this->resumeUri) {
157
+ $this->resumeUri = $this->getResumeUri();
158
+ }
159
+
160
+ if (false == $chunk) {
161
+ $chunk = substr($this->data, $this->progress, $this->chunkSize);
162
+ }
163
+
164
+ $lastBytePos = $this->progress + strlen($chunk) - 1;
165
+ $headers = array(
166
+ 'content-range' => "bytes $this->progress-$lastBytePos/$this->size",
167
+ 'content-type' => $this->request->getRequestHeader('content-type'),
168
+ 'content-length' => $this->chunkSize,
169
+ 'expect' => '',
170
+ );
171
+
172
+ $httpRequest = new Google_Http_Request(
173
+ $this->resumeUri,
174
+ 'PUT',
175
+ $headers,
176
+ $chunk
177
+ );
178
+
179
+ if ($this->client->getClassConfig("Google_Http_Request", "enable_gzip_for_uploads")) {
180
+ $httpRequest->enableGzip();
181
+ } else {
182
+ $httpRequest->disableGzip();
183
+ }
184
+
185
+ $response = $this->client->getIo()->makeRequest($httpRequest);
186
+ $response->setExpectedClass($this->request->getExpectedClass());
187
+ $code = $response->getResponseHttpCode();
188
+ $this->httpResultCode = $code;
189
+
190
+ if (308 == $code) {
191
+ // Track the amount uploaded.
192
+ $range = explode('-', $response->getResponseHeader('range'));
193
+ $this->progress = $range[1] + 1;
194
+
195
+ // Allow for changing upload URLs.
196
+ $location = $response->getResponseHeader('location');
197
+ if ($location) {
198
+ $this->resumeUri = $location;
199
+ }
200
+
201
+ // No problems, but upload not complete.
202
+ return false;
203
+ } else {
204
+ return Google_Http_REST::decodeHttpResponse($response, $this->client);
205
+ }
206
+ }
207
+
208
+ /**
209
+ * @param $meta
210
+ * @param $params
211
+ * @return array|bool
212
+ * @visible for testing
213
+ */
214
+ private function process()
215
+ {
216
+ $postBody = false;
217
+ $contentType = false;
218
+
219
+ $meta = $this->request->getPostBody();
220
+ $meta = is_string($meta) ? json_decode($meta, true) : $meta;
221
+
222
+ $uploadType = $this->getUploadType($meta);
223
+ $this->request->setQueryParam('uploadType', $uploadType);
224
+ $this->transformToUploadUrl();
225
+ $mimeType = $this->mimeType ?
226
+ $this->mimeType :
227
+ $this->request->getRequestHeader('content-type');
228
+
229
+ if (self::UPLOAD_RESUMABLE_TYPE == $uploadType) {
230
+ $contentType = $mimeType;
231
+ $postBody = is_string($meta) ? $meta : json_encode($meta);
232
+ } else if (self::UPLOAD_MEDIA_TYPE == $uploadType) {
233
+ $contentType = $mimeType;
234
+ $postBody = $this->data;
235
+ } else if (self::UPLOAD_MULTIPART_TYPE == $uploadType) {
236
+ // This is a multipart/related upload.
237
+ $boundary = $this->boundary ? $this->boundary : mt_rand();
238
+ $boundary = str_replace('"', '', $boundary);
239
+ $contentType = 'multipart/related; boundary=' . $boundary;
240
+ $related = "--$boundary\r\n";
241
+ $related .= "Content-Type: application/json; charset=UTF-8\r\n";
242
+ $related .= "\r\n" . json_encode($meta) . "\r\n";
243
+ $related .= "--$boundary\r\n";
244
+ $related .= "Content-Type: $mimeType\r\n";
245
+ $related .= "Content-Transfer-Encoding: base64\r\n";
246
+ $related .= "\r\n" . base64_encode($this->data) . "\r\n";
247
+ $related .= "--$boundary--";
248
+ $postBody = $related;
249
+ }
250
+
251
+ $this->request->setPostBody($postBody);
252
+
253
+ if (isset($contentType) && $contentType) {
254
+ $contentTypeHeader['content-type'] = $contentType;
255
+ $this->request->setRequestHeaders($contentTypeHeader);
256
+ }
257
+ }
258
+
259
+ private function transformToUploadUrl()
260
+ {
261
+ $base = $this->request->getBaseComponent();
262
+ $this->request->setBaseComponent($base . '/upload');
263
+ }
264
+
265
+ /**
266
+ * Valid upload types:
267
+ * - resumable (UPLOAD_RESUMABLE_TYPE)
268
+ * - media (UPLOAD_MEDIA_TYPE)
269
+ * - multipart (UPLOAD_MULTIPART_TYPE)
270
+ * @param $meta
271
+ * @return string
272
+ * @visible for testing
273
+ */
274
+ public function getUploadType($meta)
275
+ {
276
+ if ($this->resumable) {
277
+ return self::UPLOAD_RESUMABLE_TYPE;
278
+ }
279
+
280
+ if (false == $meta && $this->data) {
281
+ return self::UPLOAD_MEDIA_TYPE;
282
+ }
283
+
284
+ return self::UPLOAD_MULTIPART_TYPE;
285
+ }
286
+
287
+ private function getResumeUri()
288
+ {
289
+ $result = null;
290
+ $body = $this->request->getPostBody();
291
+ if ($body) {
292
+ $headers = array(
293
+ 'content-type' => 'application/json; charset=UTF-8',
294
+ 'content-length' => Google_Utils::getStrLen($body),
295
+ 'x-upload-content-type' => $this->mimeType,
296
+ 'x-upload-content-length' => $this->size,
297
+ 'expect' => '',
298
+ );
299
+ $this->request->setRequestHeaders($headers);
300
+ }
301
+
302
+ $response = $this->client->getIo()->makeRequest($this->request);
303
+ $location = $response->getResponseHeader('location');
304
+ $code = $response->getResponseHttpCode();
305
+
306
+ if (200 == $code && true == $location) {
307
+ return $location;
308
+ }
309
+ $message = $code;
310
+ $body = @json_decode($response->getResponseBody());
311
+ if (!empty( $body->error->errors ) ) {
312
+ $message .= ': ';
313
+ foreach ($body->error->errors as $error) {
314
+ $message .= "{$error->domain}, {$error->message};";
315
+ }
316
+ $message = rtrim($message, ';');
317
+ }
318
+
319
+ $error = "Failed to start the resumable upload (HTTP {$message})";
320
+ $this->client->getLogger()->error($error);
321
+ throw new Google_Exception($error);
322
+ }
323
+ }
methods/googledrive.php CHANGED
@@ -481,6 +481,10 @@ class UpdraftPlus_BackupModule_googledrive {
481
  require_once(UPDRAFTPLUS_DIR.'/includes/Google/autoload.php');
482
  }
483
 
 
 
 
 
484
  $config = new Google_Config();
485
  $config->setClassConfig('Google_IO_Abstract', 'request_timeout_seconds', 60);
486
  # In our testing, $service->about->get() fails if gzip is not disabled when using the stream wrapper
@@ -711,7 +715,8 @@ class UpdraftPlus_BackupModule_googledrive {
711
  }
712
  }
713
 
714
- $media = new Google_Http_MediaFileUpload(
 
715
  $client,
716
  $request,
717
  (('.zip' == substr($basename, -4, 4)) ? 'application/zip' : 'application/octet-stream'),
@@ -722,8 +727,10 @@ class UpdraftPlus_BackupModule_googledrive {
722
  $media->setFileSize($local_size);
723
 
724
  if (!empty($possible_location)) {
725
- $media->resumeUri = $possible_location[0];
726
- $media->progress = $possible_location[1];
 
 
727
  $size = $possible_location[1];
728
  }
729
  if ($size >= $local_size) return true;
@@ -748,7 +755,7 @@ class UpdraftPlus_BackupModule_googledrive {
748
  # Error handling??
749
  $pointer += strlen($chunk);
750
  $status = $media->nextChunk($chunk);
751
- $updraftplus->jobdata_set($transkey, array($media->resumeUri, $media->getProgress()));
752
  $updraftplus->record_uploaded_chunk(round(100*$pointer/$local_size, 1), $media->getProgress(), $file);
753
  }
754
 
481
  require_once(UPDRAFTPLUS_DIR.'/includes/Google/autoload.php');
482
  }
483
 
484
+ if (!class_exists('UpdraftPlus_Google_Http_MediaFileUpload')) {
485
+ require_once(UPDRAFTPLUS_DIR.'/includes/google-extensions.php');
486
+ }
487
+
488
  $config = new Google_Config();
489
  $config->setClassConfig('Google_IO_Abstract', 'request_timeout_seconds', 60);
490
  # In our testing, $service->about->get() fails if gzip is not disabled when using the stream wrapper
715
  }
716
  }
717
 
718
+ // UpdraftPlus_Google_Http_MediaFileUpload extends Google_Http_MediaFileUpload, with a few extra methods to change private properties to public ones
719
+ $media = new UpdraftPlus_Google_Http_MediaFileUpload(
720
  $client,
721
  $request,
722
  (('.zip' == substr($basename, -4, 4)) ? 'application/zip' : 'application/octet-stream'),
727
  $media->setFileSize($local_size);
728
 
729
  if (!empty($possible_location)) {
730
+ // $media->resumeUri = $possible_location[0];
731
+ // $media->progress = $possible_location[1];
732
+ $media->updraftplus_setResumeUri($possible_location[0]);
733
+ $media->updraftplus_setProgress($possible_location[1]);
734
  $size = $possible_location[1];
735
  }
736
  if ($size >= $local_size) return true;
755
  # Error handling??
756
  $pointer += strlen($chunk);
757
  $status = $media->nextChunk($chunk);
758
+ $updraftplus->jobdata_set($transkey, array($media->updraftplus_getResumeUri(), $media->getProgress()));
759
  $updraftplus->record_uploaded_chunk(round(100*$pointer/$local_size, 1), $media->getProgress(), $file);
760
  }
761
 
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: Backup with UpdraftPlus, DavidAnderson, DNutbourne, LCahill
3
  Tags: backup, backups, restore, amazon backup, s3 backup, dropbox backup, google drive backup, rackspace cloud files, rackspace backup, dreamhost, dreamobjects backup, ftp backup, webdav backup, google cloud storage, onedrive, microsoft one drive, back up, multisite, restoration, sftp backup, ftps, scp backup, migrate, duplicate, copy, mysql backup, database backup, db backups, website backup, wordpress backup, full backup, openstack backup, sicherung
4
  Requires at least: 3.2
5
- Tested up to: 4.3
6
- Stable tag: 1.11.15
7
  Author URI: https://updraftplus.com
8
  Donate link: http://david.dw-perspective.org.uk/donate
9
  License: GPLv3 or later
@@ -118,7 +118,11 @@ Thanks for asking; yes, we've got a few. Check out this profile page - https://p
118
 
119
  The <a href="https://updraftplus.com/news/">UpdraftPlus backup blog</a> is the best place to learn in more detail about any important changes.
120
 
121
- N.B. Paid versions of UpdraftPlus Backup / Restore have a version number which is 1 higher in the first digit, and has an extra component on the end, but the changelog below still applies. i.e. changes listed for 1.11.15 of the free version correspond to changes made in 1.11.15.x of the paid version.
 
 
 
 
122
 
123
  = 1.11.15 - 28/Oct/2015 =
124
 
@@ -1674,4 +1678,4 @@ We recognise and thank the following for code and/or libraries used and/or modif
1674
 
1675
 
1676
  == Upgrade Notice ==
1677
- * 1.11.15: Google Cloud Storage (in UD Premium); various other tweaks, optimisations + fixes.
2
  Contributors: Backup with UpdraftPlus, DavidAnderson, DNutbourne, LCahill
3
  Tags: backup, backups, restore, amazon backup, s3 backup, dropbox backup, google drive backup, rackspace cloud files, rackspace backup, dreamhost, dreamobjects backup, ftp backup, webdav backup, google cloud storage, onedrive, microsoft one drive, back up, multisite, restoration, sftp backup, ftps, scp backup, migrate, duplicate, copy, mysql backup, database backup, db backups, website backup, wordpress backup, full backup, openstack backup, sicherung
4
  Requires at least: 3.2
5
+ Tested up to: 4.4
6
+ Stable tag: 1.11.17
7
  Author URI: https://updraftplus.com
8
  Donate link: http://david.dw-perspective.org.uk/donate
9
  License: GPLv3 or later
118
 
119
  The <a href="https://updraftplus.com/news/">UpdraftPlus backup blog</a> is the best place to learn in more detail about any important changes.
120
 
121
+ N.B. Paid versions of UpdraftPlus Backup / Restore have a version number which is 1 higher in the first digit, and has an extra component on the end, but the changelog below still applies. i.e. changes listed for 1.11.17 of the free version correspond to changes made in 2.11.17.x of the paid version.
122
+
123
+ = 1.11.17 - 13/Nov/2015 =
124
+
125
+ * FIX: Resolve a conflict with "Simple Calendar" (formerly "Google Calendar Events") since their re-written 3.0 release, when using Google Drive storage
126
 
127
  = 1.11.15 - 28/Oct/2015 =
128
 
1678
 
1679
 
1680
  == Upgrade Notice ==
1681
+ * 1.11.17: Fix a conflict with Simple Calendar (f.k.a. "Google Calendar Events") when using Google Drive
updraftplus.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: UpdraftPlus - Backup/Restore
4
  Plugin URI: https://updraftplus.com
5
  Description: Backup and restore: take backups locally, or backup to Amazon S3, Dropbox, Google Drive, Rackspace, (S)FTP, WebDAV & email, on automatic schedules.
6
  Author: UpdraftPlus.Com, DavidAnderson
7
- Version: 1.11.15
8
  Donate link: http://david.dw-perspective.org.uk/donate
9
  License: GPLv3 or later
10
  Text Domain: updraftplus
4
  Plugin URI: https://updraftplus.com
5
  Description: Backup and restore: take backups locally, or backup to Amazon S3, Dropbox, Google Drive, Rackspace, (S)FTP, WebDAV & email, on automatic schedules.
6
  Author: UpdraftPlus.Com, DavidAnderson
7
+ Version: 1.11.17
8
  Donate link: http://david.dw-perspective.org.uk/donate
9
  License: GPLv3 or later
10
  Text Domain: updraftplus