Convert existing date formats to the new config system.
function system_update_8045() {
// Get the date config object.
$config = config('system.date');
// Fetch all date types from {date_format_type}.
$date_formats = db_query('SELECT * FROM {date_format_type}')
->fetchAllAssoc('type', PDO::FETCH_ASSOC);
if (!empty($date_formats)) {
foreach ($date_formats as $type => $format) {
// Set name and locked properties.
$config
->set("formats.{$type}.name", $format['title']);
$config
->set("formats.{$type}.locked", $format['locked']);
// Get the default date format for this type.
$variable_name = 'date_format_' . $type;
$default_format = update_variable_get($variable_name, NULL);
if ($default_format) {
// In Drupal 7 we only used PHP date types.
$config
->set("formats.{$type}.pattern.php", $default_format);
// Delete the migrated variables.
update_variable_del($variable_name);
}
}
// Save the date configuration object.
$config
->save();
}
}