Skip to content

Commit

Permalink
Merge branch 'MDL-68921-39' of git://github.com/vmdef/moodle into MOO…
Browse files Browse the repository at this point in the history
…DLE_39_STABLE
  • Loading branch information
abgreeve committed Aug 25, 2020
2 parents 8b25444 + fde9d44 commit 3513964
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 5 deletions.
1 change: 1 addition & 0 deletions h5p/classes/api.php
Expand Up @@ -164,6 +164,7 @@ public static function get_contenttype_libraries(?string $fields = ''): array {
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])) {
Expand Down
5 changes: 3 additions & 2 deletions h5p/classes/editor_framework.php
Expand Up @@ -228,7 +228,7 @@ public function getLibraries($libraries = null): ?array {
if ($libraries !== null) {
// Get details for the specified libraries.
$librariesin = [];
$fields = 'title, runnable';
$fields = 'title, runnable, metadatasettings';

foreach ($libraries as $library) {
$params = [
Expand All @@ -242,11 +242,12 @@ public function getLibraries($libraries = null): ?array {
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);
}

Expand Down
4 changes: 4 additions & 0 deletions h5p/classes/framework.php
Expand Up @@ -685,6 +685,9 @@ public function set_file(\stored_file $file): void {
* - 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) {
Expand Down Expand Up @@ -722,6 +725,7 @@ public function saveLibraryData(&$librarydata, $new = true) {
'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) {
Expand Down
1 change: 1 addition & 0 deletions h5p/tests/generator_test.php
Expand Up @@ -246,6 +246,7 @@ public function test_create_library_record() {
'addto' => '/regex11/',
'coremajor' => null,
'coreminor' => null,
'metadatasettings' => null,
];

$this->assertEquals($expected, $data);
Expand Down
5 changes: 3 additions & 2 deletions lib/db/install.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20200504" 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"
>
Expand Down Expand Up @@ -4184,6 +4184,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"/>
Expand Down Expand Up @@ -4273,4 +4274,4 @@
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>
41 changes: 41 additions & 0 deletions lib/db/upgrade.php
Expand Up @@ -2548,5 +2548,46 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2020061501.09);
}

if ($oldversion < 2020061501.11) {

// 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, 2020061501.11);
}

return true;
}
2 changes: 1 addition & 1 deletion version.php
Expand Up @@ -29,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

$version = 2020061501.10; // 20200615 = branching date YYYYMMDD - do not modify!
$version = 2020061501.11; // 20200615 = branching date YYYYMMDD - do not modify!
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '3.9.1+ (Build: 20200822)'; // Human-friendly version name
Expand Down

0 comments on commit 3513964

Please sign in to comment.