MDL-68921 core_h5p: Add H5P libraries metadata settings

An upgrade step updates installed H5P libraries
This commit is contained in:
Victor Deniz Falcon
2020-08-25 00:30:02 +01:00
parent bd1eaea02b
commit e29edbe89e
7 changed files with 53 additions and 4 deletions
+1
View File
@@ -164,6 +164,7 @@ class api {
unset($library->major_version);
$library->minorVersion = (int) $library->minorversion;
unset($library->minorversion);
$library->metadataSettings = json_decode($library->metadatasettings);
// If we already add this library means that it is an old version,as the previous query was sorted by version.
if (isset($added[$library->name])) {
+3 -2
View File
@@ -228,7 +228,7 @@ class editor_framework implements H5peditorStorage {
if ($libraries !== null) {
// Get details for the specified libraries.
$librariesin = [];
$fields = 'title, runnable';
$fields = 'title, runnable, metadatasettings';
foreach ($libraries as $library) {
$params = [
@@ -242,11 +242,12 @@ class editor_framework implements H5peditorStorage {
if ($details) {
$library->title = $details->title;
$library->runnable = $details->runnable;
$library->metadataSettings = json_decode($details->metadatasettings);
$librariesin[] = $library;
}
}
} else {
$fields = 'id, machinename as name, title, majorversion, minorversion';
$fields = 'id, machinename as name, title, majorversion, minorversion, metadatasettings';
$librariesin = api::get_contenttype_libraries($fields);
}
+4
View File
@@ -685,6 +685,9 @@ class framework implements \H5PFrameworkInterface {
* - dropLibraryCss(optional): list of associative arrays containing:
* - machineName: machine name for the librarys that are to drop their css
* - semantics(optional): Json describing the content structure for the library
* - metadataSettings(optional): object containing:
* - disable: 1 if metadata is disabled completely
* - disableExtraTitleField: 1 if the title field is hidden in the form
* @param bool $new Whether it is a new or existing library.
*/
public function saveLibraryData(&$librarydata, $new = true) {
@@ -722,6 +725,7 @@ class framework implements \H5PFrameworkInterface {
'addto' => isset($librarydata['addTo']) ? json_encode($librarydata['addTo']) : null,
'coremajor' => isset($librarydata['coreApi']['majorVersion']) ? $librarydata['coreApi']['majorVersion'] : null,
'coreminor' => isset($librarydata['coreApi']['majorVersion']) ? $librarydata['coreApi']['minorVersion'] : null,
'metadatasettings' => isset($librarydata['metadataSettings']) ? $librarydata['metadataSettings'] : null,
);
if ($new) {
+1
View File
@@ -246,6 +246,7 @@ class generator_testcase extends \advanced_testcase {
'addto' => '/regex11/',
'coremajor' => null,
'coreminor' => null,
'metadatasettings' => null,
];
$this->assertEquals($expected, $data);
+2 -1
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20200625" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20200804" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
@@ -4187,6 +4187,7 @@
<FIELD NAME="addto" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Plugin configuration data"/>
<FIELD NAME="coremajor" TYPE="int" LENGTH="4" NOTNULL="false" SEQUENCE="false" COMMENT="H5P core API major version required"/>
<FIELD NAME="coreminor" TYPE="int" LENGTH="4" NOTNULL="false" SEQUENCE="false" COMMENT="H5P core API minor version required"/>
<FIELD NAME="metadatasettings" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Library metadata settings"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+41
View File
@@ -2539,5 +2539,46 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2020072300.01);
}
if ($oldversion < 2020081400.01) {
// Define field metadatasettings to be added to h5p_libraries.
$table = new xmldb_table('h5p_libraries');
$field = new xmldb_field('metadatasettings', XMLDB_TYPE_TEXT, null, null, null, null, null, 'coreminor');
// Conditionally launch add field metadatasettings.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Get installed library files that have no metadata settings value.
$params = [
'component' => 'core_h5p',
'filearea' => 'libraries',
'filename' => 'library.json',
];
$sql = "SELECT l.id, f.id as fileid
FROM {files} f
LEFT JOIN {h5p_libraries} l ON f.itemid = l.id
WHERE f.component = :component
AND f.filearea = :filearea
AND f.filename = :filename";
$libraries = $DB->get_records_sql($sql, $params);
// Update metadatasettings field when the attribute is present in the library.json file.
$fs = get_file_storage();
foreach ($libraries as $library) {
$jsonfile = $fs->get_file_by_id($library->fileid);
$jsoncontent = json_decode($jsonfile->get_content());
if (isset($jsoncontent->metadataSettings)) {
unset($library->fileid);
$library->metadatasettings = json_encode($jsoncontent->metadataSettings);
$DB->update_record('h5p_libraries', $library);
}
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2020081400.01);
}
return true;
}
+1 -1
View File
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2020081400.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2020081400.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '3.10dev (Build: 20200814)';// Human-friendly version name