public function S3FileMapper::relocateS3File in Acquia Content Hub 8.2
Relocates s3 file if it comes from external bucket.
@todo Activate the feature when auto update disabling has been resolved. @todo acquia_contenthub_unsubscribe module
Parameters
\Drupal\file\FileInterface $file: The file entity in question.
Throws
\Exception
File
- modules/
acquia_contenthub_s3/ src/ S3FileMapper.php, line 106
Class
- S3FileMapper
- S3FileMapper for tracking S3 files.
Namespace
Drupal\acquia_contenthub_s3Code
public function relocateS3File(FileInterface $file) {
$uuid = $file
->uuid();
$mapping = $this->s3FileMap
->getFileByUuid($uuid);
$origin = $this->configFactory
->get('acquia_contenthub.admin_settings')
->get('origin');
if (!$mapping || $mapping->origin_uuid === $origin) {
return;
}
$s3fs_settings = $this->configFactory
->get('s3fs.settings');
$stream_wrapper = $this->swManager
->getViaUri($file
->getFileUri());
$data = file_get_contents($stream_wrapper
->getExternalUrl());
$this->s3FileMap
->record($file
->uuid(), $s3fs_settings
->get('bucket'), $s3fs_settings
->get('root_folder'), $origin);
// The fully qualified s3 uri will be constructed from the previously saved
// data of s3 file map. Therefore the stream wrapper can operate with the
// updated data of the table.
$this->fileSystem
->saveData($data, $file
->getFileUri(), FileSystemInterface::EXISTS_REPLACE);
$this
->invalidateFileCache($file);
}