HFP-2328 Reset metadata fields if needed

semi-fullscreen
Paal Joergensen 2018-10-23 14:59:50 +02:00
parent f661248b5a
commit 2e305ded71
1 changed files with 3 additions and 3 deletions

View File

@ -85,13 +85,13 @@ abstract class H5PMetadata {
continue; continue;
} }
if (isset($metadata[$key])) { if ($metadata[$key] === null || isset($metadata[$key])) {
$value = $metadata[$key]; $value = $metadata[$key];
$db_field_name = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $key)); $db_field_name = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $key));
switch ($config['type']) { switch ($config['type']) {
case 'text': case 'text':
if (strlen($value) > $config['maxLength']) { if ($value !== null && strlen($value) > $config['maxLength']) {
$value = mb_substr($value, 0, $config['maxLength']); $value = mb_substr($value, 0, $config['maxLength']);
} }
$types[] = '%s'; $types[] = '%s';
@ -103,7 +103,7 @@ abstract class H5PMetadata {
break; break;
case 'json': case 'json':
$value = json_encode($value); $value = ($value !== null) ? json_encode($value) : null;
$types[] = '%s'; $types[] = '%s';
break; break;
} }