Skip to content

Commit 7acc2ac

Browse files
authored
Merge pull request #25 from kodinkat/19-use-a-different-method-to-test-connection
S#19 - Use A Different Method To Test Connection
2 parents 8b3ee9f + 2b1f7a3 commit 7acc2ac

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

disciple-tools-storage-filters.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,26 @@ function dt_storage_connection_validation( $response, $connection_type_api, $det
146146
'endpoint' => $details['endpoint']
147147
] );
148148

149-
// A successful listing of buckets, shall constitute as a validated connection.
150-
$buckets = $s3->listBuckets( [] );
149+
// Attempt to upload an empty dummy file.
150+
$key = 'validated';
151+
$dummy_file = tmpfile();
152+
fwrite( $dummy_file, Disciple_Tools_Storage_API::generate_random_string( 24 ) );
153+
rewind( $dummy_file );
154+
$dummy_file_metadata = stream_get_meta_data( $dummy_file );
155+
156+
$uploaded_dummy_key = dt_storage_connections_obj_upload_s3( $s3, $details['bucket'], $key, [
157+
'name' => $key,
158+
'full_path' => $key,
159+
'type' => 'text/plain',
160+
'tmp_name' => $dummy_file_metadata['uri'],
161+
'error' => 0,
162+
'size' => filesize( $dummy_file_metadata['uri'] )
163+
] );
164+
165+
fclose( $dummy_file );
151166

152-
$response = !is_wp_error( $buckets ) && !empty( $buckets['Buckets'] );
167+
// A valid returned object key, shall constitute as a validated connection.
168+
$response = !is_wp_error( $uploaded_dummy_key ) && !empty( $uploaded_dummy_key );
153169

154170
}catch ( Exception $e ) {
155171
$response = false;

0 commit comments

Comments
 (0)