mirror of https://github.com/mastodon/mastodon
Migrate to new theming infrastructure (#37612)
parent
fb89198460
commit
75ba314e6b
@ -1 +0,0 @@
|
||||
@use 'common';
|
||||
@ -1 +0,0 @@
|
||||
@use 'common';
|
||||
@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class MigrateDefaultThemeSetting < ActiveRecord::Migration[8.0]
|
||||
class Setting < ApplicationRecord; end
|
||||
|
||||
def up
|
||||
Setting.reset_column_information
|
||||
|
||||
setting = Setting.find_by(var: 'theme')
|
||||
return unless setting.present? && setting.attributes['value'].present? && %w(mastodon-light contrast system).include?(setting.attributes['value'])
|
||||
|
||||
Setting.upsert(
|
||||
{
|
||||
var: 'theme',
|
||||
value: "--- default\n",
|
||||
},
|
||||
unique_by: index_exists?(:settings, [:thing_type, :thing_id, :var]) ? [:thing_type, :thing_id, :var] : :var
|
||||
)
|
||||
end
|
||||
|
||||
def down; end
|
||||
end
|
||||
@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class MigrateUserTheme < ActiveRecord::Migration[8.0]
|
||||
disable_ddl_transaction!
|
||||
|
||||
# Dummy classes, to make migration possible across version changes
|
||||
class User < ApplicationRecord; end
|
||||
|
||||
def up
|
||||
User.where.not(settings: nil).find_each do |user|
|
||||
settings = Oj.load(user.attributes_before_type_cast['settings'])
|
||||
next if settings.nil? || settings['theme'].blank? || %w(system default mastodon-light contrast).exclude?(settings['theme'])
|
||||
|
||||
case settings['theme']
|
||||
when 'default'
|
||||
settings['web.color_scheme'] = 'dark'
|
||||
settings['web.contrast'] = 'auto'
|
||||
when 'contrast'
|
||||
settings['web.color_scheme'] = 'dark'
|
||||
settings['web.contrast'] = 'high'
|
||||
when 'mastodon-light'
|
||||
settings['web.color_scheme'] = 'light'
|
||||
settings['web.contrast'] = 'auto'
|
||||
end
|
||||
|
||||
settings['theme'] = 'default'
|
||||
|
||||
user.update_column('settings', Oj.dump(settings))
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue