You are here

public function MediaMigrationUuidOracle::getMediaUuid in Media Migration 8

Returns the UUID of a media entity based on its source ID.

Parameters

int $source_id: The original ID of the media entity in the source database.

bool $generate_if_missing: Whether a UUID should be generated if no prophecy was found.

Return value

string|null The UUID of the given media entity.

Throws

\LogicException

Overrides MediaMigrationUuidOracleInterface::getMediaUuid

File

src/MediaMigrationUuidOracle.php, line 57

Class

MediaMigrationUuidOracle
Media Migration's UUID oracle.

Namespace

Drupal\media_migration

Code

public function getMediaUuid(int $source_id, bool $generate = TRUE) : ?string {

  // If the media entity already exist, return its UUID.
  if ($media = $this->mediaStorage
    ->load($source_id)) {
    return $media
      ->uuid();
  }

  // If the media does not exist, try to get its UUID from our prophecy table.
  if (!($uuid_prophecy = $this
    ->getMediaUuidProphecy($source_id)) && $generate) {
    $uuid_prophecy = $this
      ->setMediaProphecy($source_id);
  }
  return $uuid_prophecy;
}