mimeTypes->getMimeTypes($convertTo)[0] ?? null; if (null === $newMimeType) { throw new \UnexpectedValueException(sprintf('could not find a preferred mime type for conversion to %s', $convertTo)); } $currentVersion = $storedObject->getCurrentVersion(); if ($currentVersion->getType() === $newMimeType) { throw new \UnexpectedValueException('Already at the same mime type'); } $content = $this->storedObjectManager->read($currentVersion); try { $converted = $this->wopiConverter->convert($lang, $content, $newMimeType, $convertTo); } catch (\RuntimeException $e) { throw new \RuntimeException('could not store a new version for document', previous: $e); } $pointInTime = new StoredObjectPointInTime($currentVersion, StoredObjectPointInTimeReasonEnum::KEEP_BEFORE_CONVERSION); $version = $this->storedObjectManager->write($storedObject, $converted, $newMimeType); return [$pointInTime, $version]; } }