Completed
Pull Request — master (#6975)
by Robin
13:17
created
lib/private/Files/ObjectStore/S3ObjectTrait.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,6 @@
 block discarded – undo
24 24
 use Aws\Exception\MultipartUploadException;
25 25
 use Aws\S3\MultipartUploader;
26 26
 use Aws\S3\S3Client;
27
-use Psr\Http\Message\StreamInterface;
28 27
 
29 28
 const S3_UPLOAD_PART_SIZE = 524288000; // 500MB
30 29
 
Please login to merge, or discard this patch.
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -29,101 +29,101 @@
 block discarded – undo
29 29
 const S3_UPLOAD_PART_SIZE = 524288000; // 500MB
30 30
 
31 31
 trait S3ObjectTrait {
32
-	/**
33
-	 * Returns the connection
34
-	 *
35
-	 * @return S3Client connected client
36
-	 * @throws \Exception if connection could not be made
37
-	 */
38
-	abstract protected function getConnection();
32
+    /**
33
+     * Returns the connection
34
+     *
35
+     * @return S3Client connected client
36
+     * @throws \Exception if connection could not be made
37
+     */
38
+    abstract protected function getConnection();
39 39
 
40
-	/**
41
-	 * @param string $urn the unified resource name used to identify the object
42
-	 * @return resource stream with the read data
43
-	 * @throws \Exception when something goes wrong, message will be logged
44
-	 * @since 7.0.0
45
-	 */
46
-	function readObject($urn) {
47
-		$client = $this->getConnection();
48
-		$command = $client->getCommand('GetObject', [
49
-			'Bucket' => $this->bucket,
50
-			'Key' => $urn
51
-		]);
52
-		$request = \Aws\serialize($command);
53
-		$opts = [
54
-			'http' => [
55
-				'header' => $request->getHeaders()
56
-			]
57
-		];
40
+    /**
41
+     * @param string $urn the unified resource name used to identify the object
42
+     * @return resource stream with the read data
43
+     * @throws \Exception when something goes wrong, message will be logged
44
+     * @since 7.0.0
45
+     */
46
+    function readObject($urn) {
47
+        $client = $this->getConnection();
48
+        $command = $client->getCommand('GetObject', [
49
+            'Bucket' => $this->bucket,
50
+            'Key' => $urn
51
+        ]);
52
+        $request = \Aws\serialize($command);
53
+        $opts = [
54
+            'http' => [
55
+                'header' => $request->getHeaders()
56
+            ]
57
+        ];
58 58
 
59
-		$context = stream_context_create($opts);
60
-		return fopen($request->getUri(), 'r', false, $context);
61
-	}
59
+        $context = stream_context_create($opts);
60
+        return fopen($request->getUri(), 'r', false, $context);
61
+    }
62 62
 
63
-	/**
64
-	 * @param string $urn the unified resource name used to identify the object
65
-	 * @param resource $stream stream with the data to write
66
-	 * @throws \Exception when something goes wrong, message will be logged
67
-	 * @since 7.0.0
68
-	 */
69
-	function writeObject($urn, $stream) {
70
-		$stat = fstat($stream);
63
+    /**
64
+     * @param string $urn the unified resource name used to identify the object
65
+     * @param resource $stream stream with the data to write
66
+     * @throws \Exception when something goes wrong, message will be logged
67
+     * @since 7.0.0
68
+     */
69
+    function writeObject($urn, $stream) {
70
+        $stat = fstat($stream);
71 71
 
72
-		if ($stat['size'] && $stat['size'] < S3_UPLOAD_PART_SIZE) {
73
-			$this->singlePartUpload($urn, $stream);
74
-		} else {
75
-			$this->multiPartUpload($urn, $stream);
76
-		}
72
+        if ($stat['size'] && $stat['size'] < S3_UPLOAD_PART_SIZE) {
73
+            $this->singlePartUpload($urn, $stream);
74
+        } else {
75
+            $this->multiPartUpload($urn, $stream);
76
+        }
77 77
 
78
-	}
78
+    }
79 79
 
80
-	protected function singlePartUpload($urn, $stream) {
81
-		$this->getConnection()->putObject([
82
-			'Bucket' => $this->bucket,
83
-			'Key' => $urn,
84
-			'Body' => $stream
85
-		]);
86
-	}
80
+    protected function singlePartUpload($urn, $stream) {
81
+        $this->getConnection()->putObject([
82
+            'Bucket' => $this->bucket,
83
+            'Key' => $urn,
84
+            'Body' => $stream
85
+        ]);
86
+    }
87 87
 
88
-	protected function multiPartUpload($urn, $stream) {
89
-		$uploader = new MultipartUploader($this->getConnection(), $stream, [
90
-			'bucket' => $this->bucket,
91
-			'key' => $urn,
92
-			'part_size' => S3_UPLOAD_PART_SIZE
93
-		]);
88
+    protected function multiPartUpload($urn, $stream) {
89
+        $uploader = new MultipartUploader($this->getConnection(), $stream, [
90
+            'bucket' => $this->bucket,
91
+            'key' => $urn,
92
+            'part_size' => S3_UPLOAD_PART_SIZE
93
+        ]);
94 94
 
95
-		$tries = 0;
95
+        $tries = 0;
96 96
 
97
-		do {
98
-			try {
99
-				$result = $uploader->upload();
100
-			} catch (MultipartUploadException $e) {
101
-				\OC::$server->getLogger()->logException($e);
102
-				rewind($stream);
103
-				$tries++;
97
+        do {
98
+            try {
99
+                $result = $uploader->upload();
100
+            } catch (MultipartUploadException $e) {
101
+                \OC::$server->getLogger()->logException($e);
102
+                rewind($stream);
103
+                $tries++;
104 104
 
105
-				if ($tries < 5) {
106
-					$uploader = new MultipartUploader($this->getConnection(), $stream, [
107
-						'state' => $e->getState()
108
-					]);
109
-				} else {
110
-					$this->getConnection()->abortMultipartUpload($e->getState()->getId());
111
-					throw $e;
112
-				}
113
-			}
114
-		} while (!isset($result) && $tries < 5);
115
-	}
105
+                if ($tries < 5) {
106
+                    $uploader = new MultipartUploader($this->getConnection(), $stream, [
107
+                        'state' => $e->getState()
108
+                    ]);
109
+                } else {
110
+                    $this->getConnection()->abortMultipartUpload($e->getState()->getId());
111
+                    throw $e;
112
+                }
113
+            }
114
+        } while (!isset($result) && $tries < 5);
115
+    }
116 116
 
117
-	/**
118
-	 * @param string $urn the unified resource name used to identify the object
119
-	 * @return void
120
-	 * @throws \Exception when something goes wrong, message will be logged
121
-	 * @since 7.0.0
122
-	 */
123
-	function deleteObject($urn) {
124
-		$this->getConnection()->deleteObject([
125
-			'Bucket' => $this->bucket,
126
-			'Key' => $urn
127
-		]);
128
-	}
117
+    /**
118
+     * @param string $urn the unified resource name used to identify the object
119
+     * @return void
120
+     * @throws \Exception when something goes wrong, message will be logged
121
+     * @since 7.0.0
122
+     */
123
+    function deleteObject($urn) {
124
+        $this->getConnection()->deleteObject([
125
+            'Bucket' => $this->bucket,
126
+            'Key' => $urn
127
+        ]);
128
+    }
129 129
 }
Please login to merge, or discard this patch.