Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@
class AdminContentMigrateController extends Controller
{
public function __construct(
private readonly h5p $h5p,
private readonly H5PCore $h5pCore,
private readonly H5PFrameworkInterface $framework,
private readonly SignerInterface $signer,
private readonly h5p $h5p,
private readonly H5PCore $h5pCore,
private readonly H5PFrameworkInterface $framework,
private readonly SignerInterface $signer,
private readonly ContentItemsSerializerInterface $serializer,
) {}
)
{
}

public function index(Request $request): View
{
$pageSize = 25;
$page = (int) $request->get('page', 1);
$page = (int)$request->get('page', 1);
$contents = [];
$count = 0;

Expand Down Expand Up @@ -125,7 +127,7 @@ private function migrate(H5pLibrary $fromLibrary, H5pLibrary $toLibrary, array $
$logData['toContentId'] = $newH5pContent->id;
$logData['error'] = false;
$this->createHubVersion($hubData['update_url'], $newH5pContent);
} catch (RuntimeException | GuzzleException | JsonException $e) {
} catch (RuntimeException|GuzzleException|JsonException $e) {
Log::error('Failed to migrate content: ' . $e->getMessage());
$result['message'] = 'Failed to migrate content: ' . $e->getMessage();
$logData['error'] = true;
Expand All @@ -150,6 +152,18 @@ private function alterParameters(string $parameters): string
{
$content = json_decode($parameters, associative: true);
$content['threeImage']['wasConvertedFromVirtualTour'] = true;
for ($i = 0; $i < count($contentJson["threeImage"]["scenes"] ?? []); $i++) {
$contentJson["threeImage"]["scenes"][$i]["enableZoom"] = true;
/*
* From code at https://github.com/NDLANO/h5p-vt2er/blob/c11a34b9cdaa6842c1430a79912e78531ca21bcb/h5p-vt2er/app/H5PVT2ER.php#L299
* May or may not be interested in adding this as well
for ($j = 0; $j < count($contentJson["threeImage"]["scenes"][$i]["interactions"] ?? []); $j++) {
$contentJson["threeImage"]["scenes"][$i]["interactions"][$j]["iconTypeTextBox"] = "text-icon";
$contentJson["threeImage"]["scenes"][$i]["interactions"][$j]["showAsHotspot"] = false;
$contentJson["threeImage"]["scenes"][$i]["interactions"][$j]["showAsOpenSceneContent"] = false;
}
*/
}

return json_encode($content, flags: JSON_THROW_ON_ERROR);
}
Expand All @@ -171,7 +185,7 @@ private function save(H5pContent $sourceH5p, string $params, H5PLibrary $fromLib
$request->attributes->set('library', $toLibrary->getLibraryString(false));
$request->attributes->set('title', $sourceH5p->title);
$request->attributes->set('parameters', json_encode(
(object) [
(object)[
'params' => json_decode($params, associative: true, flags: JSON_THROW_ON_ERROR),
'metadata' => $sourceH5p->getMetadataStructure(),
],
Expand Down Expand Up @@ -267,8 +281,7 @@ private function createHubVersion(string $returnUrl, H5PContent $content): void
->withShared($data->shared)
->withTags($data->tags)
->withContentType($data->machineName)
->withContentTypeName($data->machineDisplayName)
;
->withContentTypeName($data->machineDisplayName);

$returnRequest = new Oauth1Request('POST', $returnUrl, [
'content_items' => json_encode($this->serializer->serialize([$item]), flags: JSON_THROW_ON_ERROR),
Expand Down Expand Up @@ -299,13 +312,13 @@ private function fixDependencies(H5PContent $h5pContent): void

// Get the dependencies based on the new main library
$validator = new H5PContentValidator($this->framework, $this->h5pCore);
$params = (object) [
$params = (object)[
'library' => $h5pContent->library->getLibraryString(false),
'params' => json_decode($h5pContent->parameters),
];
$validator->validateLibrary($params, (object) [
$validator->validateLibrary($params, (object)[
'options' => [
(object) [
(object)[
'name' => $params->library,
],
],
Expand Down
Loading