PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 3.1.22.4
JetBackup – Backup, Restore & Migrate v3.1.22.4
3.1.22.4 3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / src / JetBackup / Destination / Vendors / OneDrive / ChunkedUpload.php
backup / src / JetBackup / Destination / Vendors / OneDrive Last commit date
Client 3 days ago .htaccess 1 year ago ChunkedDownload.php 1 year ago ChunkedUpload.php 1 year ago DirIterator.php 1 year ago OneDrive.php 1 year ago index.html 1 year ago web.config 1 year ago
ChunkedUpload.php
90 lines
1 <?php
2
3 namespace JetBackup\Destination\Vendors\OneDrive;
4
5 use JetBackup\Destination\Integration\DestinationChunkedUpload;
6 use JetBackup\Destination\Vendors\OneDrive\Client\ClientException;
7 use JetBackup\Exception\IOException;
8 use JetBackup\Web\File\FileChunk;
9
10 if (!defined( '__JETBACKUP__')) die('Direct access is not allowed');
11
12 class ChunkedUpload implements DestinationChunkedUpload {
13
14 private OneDrive $_client;
15 private string $_destination;
16 private object $_data;
17
18 public function __construct(OneDrive $client, $destination) {
19 $this->_client = $client;
20 $this->_destination = $destination;
21 $this->_data = new \stdClass();
22 }
23
24 /**
25 * @return object
26 * @throws ClientException
27 */
28 public function prepare():object {
29
30 $this->_client->getLogController()->logDebug("[ChunkedUpload] [prepare]");
31 $output = new \stdClass();
32 $response = $this->_client->client('createUploadSession', OneDrive::DRIVE_ROOT . ':' . $this->_destination);
33 $output->upload_url = $response->Body->uploadUrl;
34 return $output;
35 }
36
37 public function setData(object $data):void {
38 $this->_data = $data;
39 }
40
41 /**
42 * @return int
43 * @throws ClientException
44 * @throws IOException
45 */
46 public function getOffset():int {
47
48 if(!isset($this->_data->upload_url)) throw new IOException("No upload url was found");
49
50 $response = $this->_client->client('checkUploadSession', $this->_data->upload_url);
51
52 $this->_client->getLogController()->logDebug("[ChunkedUpload] [getOffset]");
53 $range = $response->Body->nextExpectedRanges[0];
54
55 // no range, start from the beginning
56 if (empty($range)) {
57 $this->_client->getLogController()->logDebug("[ChunkedUpload] [getOffset] No Range, Start from beginning");
58 return 0;
59 }
60
61 list($offset) = explode('-', $range);
62 $this->_client->getLogController()->logDebug("[ChunkedUpload] [getOffset] Offset: $offset");
63
64 return (int) $offset;
65
66 }
67
68 /**
69 * @return int|null
70 */
71 public function getChunkSize():?int { return null; }
72
73 /**
74 * @param FileChunk $chunk
75 *
76 * @return void
77 * @throws ClientException
78 * @throws IOException
79 */
80 public function upload(FileChunk $chunk):void {
81 $this->_client->getLogController()->logDebug("..uploading chunk [" . $chunk->getSize() . " Bytes]");
82 if(!isset($this->_data->upload_url)) throw new IOException("No upload url was found");
83 $this->_client->client('putChunk', $chunk, $this->_data->upload_url);
84 }
85
86 /**
87 * @return void
88 */
89 public function finalize():void {}
90 }