|
|
|
@ -20,6 +20,14 @@ class Utils {
|
|
|
|
|
if (!isset($context['results'])) { |
|
|
|
|
$context['results'] = []; |
|
|
|
|
} |
|
|
|
|
$file_types = [ |
|
|
|
|
'audio' => 'field_media_audio_file', |
|
|
|
|
'document' => 'field_media_document', |
|
|
|
|
'file' => 'field_media_file', |
|
|
|
|
'image' => 'field_media_image', |
|
|
|
|
'video' => 'field_media_video_file', |
|
|
|
|
]; |
|
|
|
|
$file_type = $file_types[$media_type] ?? 'field_media_file'; |
|
|
|
|
|
|
|
|
|
$logger = \Drupal::logger('islandora_inplace_media'); |
|
|
|
|
$fileSystem = \Drupal::service('file_system'); |
|
|
|
@ -27,12 +35,15 @@ class Utils {
|
|
|
|
|
$source_path = $dir . '/' . $file_name; |
|
|
|
|
$destination_path = $dest . '/' . $file_name; |
|
|
|
|
|
|
|
|
|
if (!file_exists($source_path)) { |
|
|
|
|
if (!\file_exists($source_path)) { |
|
|
|
|
$logger->warning('File does not exist: @file', ['@file' => $source_path]); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$moved_file = $fileSystem->move($source_path, $destination_path, FileSystemInterface::EXISTS_RENAME); |
|
|
|
|
$absolute_path = $fileSystem->realpath($destination_path); |
|
|
|
|
chown($absolute_path, 'www-data'); |
|
|
|
|
chgrp($absolute_path, 'lib-dev'); |
|
|
|
|
$new_file = File::create([ |
|
|
|
|
'uri' => $moved_file, |
|
|
|
|
'status' => 1, |
|
|
|
@ -43,13 +54,12 @@ class Utils {
|
|
|
|
|
if (preg_match('/^(\d+)_/', $file_name, $matches)) { |
|
|
|
|
$nid = $matches[1] ?? NULL; |
|
|
|
|
} |
|
|
|
|
unlink($source_path); |
|
|
|
|
|
|
|
|
|
if ($nid) { |
|
|
|
|
$media = Media::create([ |
|
|
|
|
"bundle" => $media_type, |
|
|
|
|
"name" => $file_name, |
|
|
|
|
"field_media_file" => [ |
|
|
|
|
$file_type => [ |
|
|
|
|
"target_id" => $new_file->id(), |
|
|
|
|
], |
|
|
|
|
'field_media_use' => [ |
|
|
|
|