Skip to content

Commit 290d07b

Browse files
authored
Merge pull request #30 from kodinkat/29-multisite-duplicate-site-ids-storage-keys
ST#29 - Multisite Duplicate Site IDs Storage Keys
2 parents bc9ab3f + 2020ed9 commit 290d07b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

disciple-tools-storage-filters.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,15 @@ function dt_storage_connections_obj_upload( $response, $storage_connection_id, $
236236
//Create a folder for the current site in case a bucket is shared between multiple sites.
237237
$dt_site_id = get_option( 'dt_site_id' );
238238
$site_key = substr( $dt_site_id, 0, 30 );
239-
$key = $site_key . '/' . $key;
240239

240+
// Ensure duplicate site id prefixes are handled accordingly.
241+
$site_id_prefix = $site_key . '/';
242+
$site_id_dup_count = substr_count( $key, $site_id_prefix );
243+
if ( $site_id_dup_count === 0 ) {
244+
$key = $site_id_prefix . $key;
245+
} elseif ( $site_id_dup_count > 1 ) {
246+
$key = $site_id_prefix . str_replace( $site_id_prefix, '', $key, $site_id_dup_count );
247+
}
241248

242249
// Generate complete file key name to be used moving forward.
243250
$key_name = ( isset( $storage_connection_type['prefix_bucket_name_to_obj_key'] ) && $storage_connection_type['prefix_bucket_name_to_obj_key'] ) ? ( $bucket .'/'. $key ) : $key;

0 commit comments

Comments
 (0)