diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index 105a9bbe85324..bcb4004487690 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -296,6 +296,12 @@ protected function uninstallRepeatableFieldsPlugin() */ $mapping = []; + /** + * Store name of media fields which we need to convert data from old format (string) to new + * format (json) during the migration + */ + $mediaFields = []; + // If this repeatable fields actually had child-fields (normally this is always the case) if (isset($oldFieldparams->fields) && is_object($oldFieldparams->fields)) { @@ -342,6 +348,11 @@ protected function uninstallRepeatableFieldsPlugin() $data['type'] = 'text'; } + if ($data['type'] == 'media') + { + $mediaFields[] = $oldField->fieldname; + } + // Reset the state because else \Joomla\CMS\MVC\Model\AdminModel will take an already // existing value (e.g. from previous save) and do an UPDATE instead of INSERT. $fieldModel->setState('field.id', 0); @@ -402,7 +413,7 @@ protected function uninstallRepeatableFieldsPlugin() $db->setQuery( $db->getQuery(true) ->update('#__fields') - ->set($db->quoteName('type') . ' = ' . $db->quote('subfields')) + ->set($db->quoteName('type') . ' = ' . $db->quote('subform')) ->set($db->quoteName('fieldparams') . ' = ' . $db->quote(json_encode($newFieldparams))) ->where($db->quoteName('id') . ' = ' . $db->quote($row->id)) )->execute(); @@ -440,13 +451,21 @@ protected function uninstallRepeatableFieldsPlugin() continue; } + $rowIndex = 0; + foreach ($fieldValue as $rowKey => $rowValue) { - $rowKey = str_replace('repeatable', 'row', $rowKey); + $rowKey = 'row' . ($rowIndex++); $newFieldValue[$rowKey] = []; foreach ($rowValue as $subFieldName => $subFieldValue) { + // This is a media field, so we need to convert data to new format required in Joomla! 4 + if (in_array($subFieldName, $mediaFields)) + { + $subFieldValue = ['imagefile' => $subFieldValue, 'alt_text' => '']; + } + if (isset($mapping[$subFieldName])) { $newFieldValue[$rowKey][$mapping[$subFieldName]] = $subFieldValue;