private function MediaMigrateCommands::calculateBinaryHash in Migrate File Entities to Media Entities 8
2 calls to MediaMigrateCommands::calculateBinaryHash()
- MediaMigrateCommands::duplicateImageDetection in src/
Commands/ MediaMigrateCommands.php - Find duplicate file entities.
- MediaMigrateCommands::duplicateMediaImageDetection in src/
Commands/ MediaMigrateCommands.php - Calculate hash values of media entities. Can later be used together with migrate:duplicate-file-detection to find existing media files.
File
- src/
Commands/ MediaMigrateCommands.php, line 462
Class
- MediaMigrateCommands
- Drush 9 commands for migrate_file_to_media.
Namespace
Drupal\migrate_file_to_media\CommandsCode
private function calculateBinaryHash(File $file) {
// For rokka files, we can use the metadata table to get the correct
// binary_hash value.
$rokka_metadata = NULL;
if (strpos($file
->getFileUri(), 'rokka://') === 0) {
$query = $this->connection
->select('rokka_metadata', 'rokka');
$query
->fields('rokka');
$query
->condition('uri', $file
->getFileUri(), '=');
$rokka_metadata = $query
->execute()
->fetchObject();
$data = 'empty';
}
else {
$data = file_get_contents(urldecode($file
->getFileUri()));
}
$binary_hash = NULL;
if (!empty($data)) {
$binary_hash = $rokka_metadata ? $rokka_metadata->binary_hash : sha1($data);
}
return $binary_hash;
}