Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update h5p packages #2291

Merged
merged 36 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e204997
Update h5p/h5p-core and h5p/h5p-editor Composer packages, use patch v…
chrieinv May 3, 2023
0f1f38e
Run php-cs-fixer
chrieinv May 3, 2023
11b2d53
Merge branch 'master' into update-h5p-packages-v2
chrieinv May 3, 2023
9e8d945
Fix export of content, rewrite functions to get library name and fold…
chrieinv May 5, 2023
ae0ecbf
Run php-cs-fixer
chrieinv May 5, 2023
297ae98
PHPStan fixes
chrieinv May 5, 2023
3faeb22
Merge branch 'master' into update-h5p-packages-v2
chrieinv May 8, 2023
aee9b12
Fix getUpgradeScript, add/fix unittests
chrieinv May 9, 2023
32b0e80
PHPStan fixes and baseline update
chrieinv May 9, 2023
28165e2
Fix libraries not able to load resources, fix/add unittest
chrieinv May 9, 2023
dcf5394
PHPStan baseline update
chrieinv May 9, 2023
f372f40
Merge branch 'master' into update-h5p-packages-v2
chrieinv May 9, 2023
a179651
Unittest fixes and adjustments
chrieinv May 10, 2023
9befcff
Merge branch 'master' into update-h5p-packages-v2
chrieinv May 23, 2023
0b9377e
Extract folder name functionality from getLibraryString() into getFol…
chrieinv May 23, 2023
3bce63b
Merge branch 'master' into update-h5p-packages-v2
chrieinv Jun 28, 2023
e57a562
Update to latest h5p-core
chrieinv Jun 29, 2023
528173f
PHPStan fix
chrieinv Jun 29, 2023
1ee03a9
Merge branch 'master' into update-h5p-packages-v2
chrieinv Jun 29, 2023
3dcd0e1
Update to latest h5p-core
chrieinv Jun 29, 2023
8dc8f85
Remove tests for deleted ViewConfig
chrieinv Jun 29, 2023
9b4b234
Update PHPStan baseline
chrieinv Jun 29, 2023
f0be231
Merge branch 'master' into update-h5p-packages-v2
chrieinv Jun 30, 2023
a97e41a
Merge branch 'master' into update-h5p-packages-v2
chrieinv Jul 4, 2023
eacf9b5
Adjust export of H5P
chrieinv Jul 4, 2023
12336e2
Merge branch 'update-h5p-packages-v2' of github.com:cerpus/Edlib into…
chrieinv Jul 4, 2023
adab991
Fix unittests
chrieinv Jul 4, 2023
009e581
Merge branch 'master' into update-h5p-packages-v2
chrieinv Jul 6, 2023
c26c53b
Fix unittest
chrieinv Jul 7, 2023
b37b97d
Merge branch 'master' into update-h5p-packages-v2
chrieinv Jul 7, 2023
f80c8bf
Merge branch 'master' into update-h5p-packages-v2
chrieinv Sep 4, 2023
75d20c8
Merge branch 'master' into update-h5p-packages-v2
chrieinv Sep 14, 2023
adceeac
For libraries with patch version: Fix error switching language in H5P…
chrieinv Sep 20, 2023
7439d86
CA tests: Remove excessive mocking, move misplaced test, add tests fo…
chrieinv Sep 25, 2023
49e79c8
Run php-cs-fixer
chrieinv Sep 25, 2023
1343263
Merge branch 'master' into update-h5p-packages-v2
chrieinv Sep 27, 2023
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
2 changes: 2 additions & 0 deletions sourcecode/apis/contentauthor/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ Homestead.json
!/public/js/videos/brightcove.js
!/public/js/videos/streamps.js
!/public/js/h5p/ndlah5p-youtube.js
!public/js/h5p/core-override
!public/css
/public/css/*
!/public/css/ndlah5p-youtube.css

mix-manifest.json
app/Libraries/oauth-php/example/server/cache/
ca1.sql
Expand Down
9 changes: 1 addition & 8 deletions sourcecode/apis/contentauthor/app/H5PContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,7 @@ public static function getContentTypeInfo(string $contentType): ?ContentTypeData

if ($library->has_icon) {
$h5pFramework = app(H5PFrameworkInterface::class);

$library_folder = H5PCore::libraryToString([
'machineName' => $library->machine_name,
'majorVersion' => $library->major_version,
'minorVersion' => $library->minor_version
], true);


$library_folder = $library->getLibraryString(true);
$icon_path = $h5pFramework->getLibraryFileUrl($library_folder, 'icon.svg');

if (!empty($icon_path)) {
Expand Down
16 changes: 11 additions & 5 deletions sourcecode/apis/contentauthor/app/H5PLibrariesHubCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,16 @@ public function libraries()

public function getLibraryString($folderName = false)
{
return \H5PCore::libraryToString([
'machineName' => $this->name,
'majorVersion' => $this->major_version,
'minorVersion' => $this->minor_version,
], $folderName);
return $folderName ?
\H5PCore::libraryToFolderName([
'machineName' => $this->name,
'majorVersion' => $this->major_version,
'minorVersion' => $this->minor_version,
]) :
\H5PCore::libraryToString([
'machineName' => $this->name,
'majorVersion' => $this->major_version,
'minorVersion' => $this->minor_version,
]);
}
}
73 changes: 70 additions & 3 deletions sourcecode/apis/contentauthor/app/H5PLibrary.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class H5PLibrary extends Model

protected $guarded = ['id'];

protected $casts = [
'patch_version_in_folder_name' => 'bool',
];

protected static function boot()
{
parent::boot();
Expand Down Expand Up @@ -117,9 +121,65 @@ public function getVersions($asModels = false)
return $asModels !== true ? $versions : $this->hydrate($versions->toArray());
}

public function getLibraryString($folderName = false)
/**
* @param bool $folderName True to get name suitable for folder
* @param bool|null $fullVersion Null to use patchVersionInFolderName, true/false to override
*/
public function getLibraryString(bool $folderName = false, ?bool $fullVersion = null): string
chrieinv marked this conversation as resolved.
Show resolved Hide resolved
{
return self::getLibraryName([
'machineName' => $this->name,
'majorVersion' => $this->major_version,
'minorVersion' => $this->minor_version,
'patchVersion' => $this->patch_version,
'patchVersionInFolderName' => $this->patch_version_in_folder_name,

], $folderName, $fullVersion);
}

/**
* @param array $libraryData Key names: machineName/name, majorVersion, minorVersion, patchVersion, patchVersionInFolderName
chrieinv marked this conversation as resolved.
Show resolved Hide resolved
* @param bool|null $fullVersion Null to use patchVersionInFolderName, true/false to override
* @throws \InvalidArgumentException If requesting full version without patchVersion present in data
*/
public static function libraryToFolderName(array $libraryData, ?bool $fullVersion = null): string
{
return self::getLibraryName($libraryData, true, $fullVersion);
}

/**
* @param array $libraryData Key names: machineName/name, majorVersion, minorVersion, patchVersion, patchVersionInFolderName
* @param bool|null $fullVersion Null to use patchVersionInFolderName, true/false to override
* @throws \InvalidArgumentException If requesting full version without patchVersion present in data
*/
public static function libraryToString(array $libraryData, ?bool $fullVersion = null): string
{
return \H5PCore::libraryToString($this->getLibraryH5PFriendly(), $folderName);
return self::getLibraryName($libraryData, false, $fullVersion);
}

/**
* @throws \InvalidArgumentException If requesting full version without patchVersion present in data
*/
private static function getLibraryName(array $libraryData, bool $asFolder, ?bool $fullVersion): string
{
$usePatch = $fullVersion === true || ($fullVersion === null && array_key_exists('patchVersionInFolderName', $libraryData) && $libraryData['patchVersionInFolderName']);
if ($usePatch && !isset($libraryData['patchVersion'])) {
throw new \InvalidArgumentException('Full version name requested but patch version missing');
}

if ($usePatch) {
$format = $asFolder ? '%s-%d.%d.%d' : '%s %d.%d.%d';
} else {
$format = $asFolder ? '%s-%d.%d' : '%s %d.%d';
}

return sprintf(
$format,
$libraryData['machineName'] ?? $libraryData['name'],
$libraryData['majorVersion'],
$libraryData['minorVersion'],
$libraryData['patchVersion'] ?? ''
);
}

public function getLibraryH5PFriendly($machineName = 'name')
Expand All @@ -128,12 +188,19 @@ public function getLibraryH5PFriendly($machineName = 'name')
'machineName' => $this->$machineName,
'majorVersion' => $this->major_version,
'minorVersion' => $this->minor_version,
'patchVersion' => $this->patch_version,
'patchVersionInFolderName' => $this->patch_version_in_folder_name,
];
}

public function getTitleAndVersionString()
{
return \H5PCore::libraryToString($this->getLibraryH5PFriendly('title'));
return self::getLibraryName([
'machineName' => $this->title,
'majorVersion' => $this->major_version,
'minorVersion' => $this->minor_version,
'patchVersion' => $this->patch_version,
], false, true);
}

public function scopeFromLibrary($query, $value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function create(Request $request, H5PCore $core, $contenttype = null): Vi
->latestVersion()
->first();
if (!empty($library)) {
$contenttype = $library->getLibraryString(false);
$contenttype = $library->getLibraryString(false, false);
} else {
$contenttype = false;
}
Expand Down Expand Up @@ -332,7 +332,7 @@ public function edit(Request $request, int $id): View

$state = H5PStateDataObject::create($displayOptions + [
'id' => $h5pContent->id,
'library' => $library->getLibraryString(),
'library' => $library->getLibraryString(false, false),
'libraryid' => $h5pContent->library_id,
'parameters' => $params,
'language_iso_639_3' => $contentLanguage,
Expand Down
10 changes: 5 additions & 5 deletions sourcecode/apis/contentauthor/app/Libraries/H5P/AjaxRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ private function libraryRebuild(Request $request): array

$libraries = collect();
$this->getLibraryDetails($H5PLibrary, $libraries);
if ($libraries->has($H5PLibrary->getLibraryString())) {
$libraryData = $libraries->get($H5PLibrary->getLibraryString());
if ($libraries->has($H5PLibrary->getLibraryString(false, false))) {
$libraryData = $libraries->get($H5PLibrary->getLibraryString(false, false));
if (array_key_exists('semantics', $libraryData)) {
$H5PLibrary->semantics = $libraryData['semantics'];
$H5PLibrary->save();
Expand Down Expand Up @@ -307,15 +307,15 @@ private function getLibraryDetails(H5PLibrary $H5PLibrary, Collection $affectedL
$libraryData = $validator->getLibraryData($H5PLibrary->getLibraryString(true), $tmpLibraryFolder, $tmpLibraries);
$libraryData['libraryId'] = $H5PLibrary->id;

if (!$affectedLibraries->has($H5PLibrary->getLibraryString())) {
$affectedLibraries->put($H5PLibrary->getLibraryString(), $libraryData);
if (!$affectedLibraries->has($H5PLibrary->getLibraryString(false, false))) {
$affectedLibraries->put($H5PLibrary->getLibraryString(false, false), $libraryData);
}
foreach (['preloadedDependencies', 'dynamicDependencies', 'editorDependencies'] as $value) {
if (!empty($libraryData[$value])) {
foreach ($libraryData[$value] as $library) {
/** @var H5PLibrary $dependentLibrary */
$dependentLibrary = H5PLibrary::fromLibrary($library)->first();
if (!$affectedLibraries->has($dependentLibrary->getLibraryString())) {
if (!$affectedLibraries->has($dependentLibrary->getLibraryString(false, false))) {
$affectedLibraries = $this->getLibraryDetails($dependentLibrary, $affectedLibraries);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getLibraries($libraries = null)
->map(function ($h5pLibrary) {
/** @var H5PLibrary $h5pLibrary */
$library = [
'uberName' => $h5pLibrary->getLibraryString(),
'uberName' => $h5pLibrary->getLibraryString(false, false),
'name' => $h5pLibrary->name,
'majorVersion' => $h5pLibrary->major_version,
'minorVersion' => $h5pLibrary->minor_version,
Expand Down Expand Up @@ -101,7 +101,7 @@ public function getLibraries($libraries = null)
$library->minorVersion = $library->minor_version;

// Add new library
$library->uberName = $library->getLibraryString();
$library->uberName = $library->getLibraryString(false, false);
if ($index > 0) {
$library->isOld = true;
}
Expand Down
60 changes: 55 additions & 5 deletions sourcecode/apis/contentauthor/app/Libraries/H5P/Framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Stringable;
use InvalidArgumentException;
use PDO;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -132,19 +133,35 @@ public function getPlatformInfo()
];
}

public function fetchExternalData($url, $data = null, $blocking = true, $stream = null): string|null
{
public function fetchExternalData(
$url,
$data = null,
$blocking = true,
$stream = null,
$fullData = false,
$headers = [],
$files = [],
$method = 'POST'
): string|array|null {
$method = $data ? 'POST' : 'GET';
$options = [RequestOptions::FORM_PARAMS => $data];
if ($stream !== null) {
$options[RequestOptions::SINK] = $stream;
}
$options[RequestOptions::HEADERS] = $headers;

return $this->httpClient->requestAsync($method, $url, $options)
->then(static function (ResponseInterface $response) use ($blocking) {
->then(static function (ResponseInterface $response) use ($blocking, $fullData) {
if (!$blocking) {
return null;
}
if ($fullData) {
return [
'status' => $response->getStatusCode(),
'headers' => $response->getHeaders(),
'data' => $response->getBody()->getContents(),
];
}

return $response->getBody()->getContents();
})
Expand Down Expand Up @@ -500,7 +517,8 @@ public function saveLibraryData(&$libraryData, $new = true)
'metadata_settings' => $libraryData['metadataSettings'],
'add_to' => $libraryData['addTo'],
'has_icon' => $libraryData['hasIcon'] ?? 0,
'tutorial_url' => ''
'tutorial_url' => '',
'patch_version_in_folder_name' => true,
]);
$libraryData['libraryId'] = $h5pLibrary->id;

Expand Down Expand Up @@ -819,13 +837,16 @@ public function loadLibrary($machineName, $majorVersion, $minorVersion): array|f
'preloadedCss' => $h5pLibrary->preloaded_css,
'dropLibraryCss' => $h5pLibrary->drop_library_css,
'semantics' => $h5pLibrary->semantics,
'patchVersionInFolderName' => $h5pLibrary->patch_version_in_folder_name,
];

foreach ($h5pLibrary->libraries as $dependency) {
$library[$dependency->dependency_type . 'Dependencies'][] = [
'machineName' => $dependency->requiredLibrary->name,
'majorVersion' => $dependency->requiredLibrary->major_version,
'minorVersion' => $dependency->requiredLibrary->minor_version,
'patchVersion' => $dependency->requiredLibrary->patch_version,
'patchVersionInFolderName' => $dependency->requiredLibrary->patch_version_in_folder_name,
];
}

Expand Down Expand Up @@ -907,10 +928,11 @@ public function deleteLibrary($library): void
throw new TypeError(sprintf('Expected object, %s given', get_debug_type($library)));
}

/** @var H5PLibrary $libraryModel */
$libraryModel = H5PLibrary::findOrFail($library->id);
$libraryModel->deleteOrFail();

app(CerpusStorageInterface::class)->deleteLibrary($libraryModel);
app(\H5PFileStorage::class)->deleteLibrary($libraryModel->getLibraryH5PFriendly());
}

/**
Expand Down Expand Up @@ -953,6 +975,8 @@ public function loadContent($id)
'libraryName' => $h5pcontent->library->name,
'libraryMajorVersion' => $h5pcontent->library->major_version,
'libraryMinorVersion' => $h5pcontent->library->minor_version,
'libraryPatchVersion' => $h5pcontent->library->patch_version,
'libraryFullVersionName' => $h5pcontent->library->getLibraryString(),
'libraryEmbedTypes' => $h5pcontent->library->embed_types,
'libraryFullscreen' => $h5pcontent->library->fullscreen,
'language' => $h5pcontent->metadata->default_language ?? null,
Expand Down Expand Up @@ -986,6 +1010,8 @@ public function loadContent($id)
* - preloadedJs(optional): comma separated string with js file paths
* - preloadedCss(optional): comma separated sting with css file paths
* - dropCss(optional): csv of machine names
* - dependencyType: editor or preloaded
* - patchVersionInFolderName: Is patch version a part of the folder name
*/
public function loadContentDependencies($id, $type = null)
{
Expand All @@ -1003,6 +1029,7 @@ public function loadContentDependencies($id, $type = null)
, hl.preloaded_js AS preloadedJs
, hcl.drop_css AS dropCss
, hcl.dependency_type AS dependencyType
, hl.patch_version_in_folder_name AS patchVersionInFolderName
FROM h5p_contents_libraries hcl
JOIN h5p_libraries hl ON hcl.library_id = hl.id
WHERE hcl.content_id = ?";
Expand Down Expand Up @@ -1334,4 +1361,27 @@ public function libraryHasUpgrade($library)
$h5pLibrary = H5PLibrary::fromLibrary($library)->first();
return !is_null($h5pLibrary) && $h5pLibrary->isUpgradable();
}

public function replaceContentHubMetadataCache($metadata, $lang)
{
// H5P Content Hub is not in use
}

public function getContentHubMetadataCache($lang = 'en')
{
// H5P Content Hub is not in use
return new Stringable();
}

public function getContentHubMetadataChecked($lang = 'en')
{
// H5P Content Hub is not in use
return now()->toRfc7231String();
}

public function setContentHubMetadataChecked($time, $lang = 'en')
{
// H5P Content Hub is not in use
return true;
}
}
13 changes: 8 additions & 5 deletions sourcecode/apis/contentauthor/app/Libraries/H5P/H5PExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use App\H5PLibrary;
use App\Libraries\H5P\Interfaces\H5PAdapterInterface;
use App\Libraries\H5P\Interfaces\H5PExternalProviderInterface;
use H5PCore;
use H5PExport as H5PDefaultExport;
use Illuminate\Support\Collection;

Expand All @@ -33,9 +32,13 @@ public function generateExport($convertMediaToLocal = false)
}
/** @var H5PLibrary $h5PLibrary */
$h5PLibrary = $this->content->library;
$library = H5PCore::libraryFromString($h5PLibrary->getLibraryString());
$library['libraryId'] = $h5PLibrary->id;
$library['name'] = $h5PLibrary->name;
$library = [
'machineName' => $h5PLibrary->name,
'majorVersion' => $h5PLibrary->major_version,
'minorVersion' => $h5PLibrary->minor_version,
'libraryId' => $h5PLibrary->id,
'name' => $h5PLibrary->name,
];

$contents = $this->content->toArray();
$contents['params'] = $this->content->parameters;
Expand All @@ -46,7 +49,7 @@ public function generateExport($convertMediaToLocal = false)
/** @var \H5PContentValidator $validator */
$validator = resolve(\H5PContentValidator::class);
$params = (object)[
'library' => $h5PLibrary->getLibraryString(),
'library' => $h5PLibrary->getLibraryString(false, false),
'params' => json_decode($this->content->parameters)
];
if (!$params->params) {
Expand Down
Loading