|
6 | 6 | "fmt" |
7 | 7 | "goblog/auth" |
8 | 8 | "goblog/blog" |
| 9 | + gplugin "goblog/plugin" |
9 | 10 | "gorm.io/gorm" |
10 | 11 | "log" |
11 | 12 | "regexp" |
@@ -272,16 +273,6 @@ func seedDefaultSettings(db *gorm.DB) { |
272 | 273 | {Key: "site_tags", Type: "text", Value: "Decentralization, Mesh Net"}, |
273 | 274 | {Key: "landing_page_image", Type: "file", Value: "/img/profile.png"}, |
274 | 275 | {Key: "favicon", Type: "file", Value: "/img/favicon.ico"}, |
275 | | - {Key: "github_url", Type: "text", Value: "https://www.github.com/compscidr"}, |
276 | | - {Key: "linkedin_url", Type: "text", Value: "https://www.linkedin.com/in/jasonernst/"}, |
277 | | - {Key: "x_url", Type: "text", Value: "https://www.x.com/compscidr"}, |
278 | | - {Key: "keybase_url", Type: "text", Value: "https://keybase.io/compscidr"}, |
279 | | - {Key: "instagram_url", Type: "text", Value: "https://www.instagram.com/compscidr"}, |
280 | | - {Key: "facebook_url", Type: "text", Value: "https://www.facebook.com/jason.b.ernst"}, |
281 | | - {Key: "strava_url", Type: "text", Value: "https://www.strava.com/athletes/2021127"}, |
282 | | - {Key: "spotify_url", Type: "text", Value: "https://open.spotify.com/user/csgrad"}, |
283 | | - {Key: "xbox_url", Type: "text", Value: "https://account.xbox.com/en-us/profile?gamertag=Compscidr"}, |
284 | | - {Key: "steam_url", Type: "text", Value: "https://steamcommunity.com/id/compscidr"}, |
285 | 276 | {Key: "custom_header_code", Type: "textarea", Value: ""}, |
286 | 277 | {Key: "custom_footer_code", Type: "textarea", Value: ""}, |
287 | 278 | {Key: "theme", Type: "text", Value: "default"}, |
@@ -379,11 +370,53 @@ func Migrate(db *gorm.DB) error { |
379 | 370 | seedDefaultPages(db) |
380 | 371 | linkWritingPagesToPostType(db) |
381 | 372 | cleanupEmptyTags(db) |
| 373 | + migrateSocialURLsToPlugin(db) |
382 | 374 | cleanupPluginSettingsFromMainTable(db) |
383 | 375 |
|
384 | 376 | return nil |
385 | 377 | } |
386 | 378 |
|
| 379 | +// migrateSocialURLsToPlugin moves social URL settings from the main settings |
| 380 | +// table to the plugin_settings table under the "socialicons" plugin. |
| 381 | +func migrateSocialURLsToPlugin(db *gorm.DB) { |
| 382 | + socialKeys := []string{ |
| 383 | + "github_url", "linkedin_url", "x_url", "keybase_url", |
| 384 | + "instagram_url", "facebook_url", "strava_url", "spotify_url", |
| 385 | + "xbox_url", "steam_url", |
| 386 | + } |
| 387 | + |
| 388 | + // Ensure plugin_settings table exists |
| 389 | + db.AutoMigrate(&gplugin.PluginSetting{}) |
| 390 | + |
| 391 | + for _, key := range socialKeys { |
| 392 | + var setting blog.Setting |
| 393 | + if err := db.Where("key = ?", key).First(&setting).Error; err != nil { |
| 394 | + continue // not found, skip |
| 395 | + } |
| 396 | + if setting.Value == "" { |
| 397 | + continue |
| 398 | + } |
| 399 | + // Migrate to plugin_settings if not already there |
| 400 | + ps := gplugin.PluginSetting{ |
| 401 | + PluginName: "socialicons", |
| 402 | + Key: key, |
| 403 | + Value: setting.Value, |
| 404 | + } |
| 405 | + db.Where("plugin_name = ? AND key = ?", "socialicons", key).FirstOrCreate(&ps) |
| 406 | + } |
| 407 | + |
| 408 | + // Also ensure the enabled setting exists |
| 409 | + db.Where("plugin_name = ? AND key = ?", "socialicons", "enabled"). |
| 410 | + FirstOrCreate(&gplugin.PluginSetting{ |
| 411 | + PluginName: "socialicons", |
| 412 | + Key: "enabled", |
| 413 | + Value: "true", |
| 414 | + }) |
| 415 | + |
| 416 | + // Remove migrated keys from main settings table |
| 417 | + db.Where("key IN ?", socialKeys).Delete(&blog.Setting{}) |
| 418 | +} |
| 419 | + |
387 | 420 | // cleanupPluginSettingsFromMainTable removes any dot-namespaced keys |
388 | 421 | // from the main settings table that belong in plugin_settings instead. |
389 | 422 | func cleanupPluginSettingsFromMainTable(db *gorm.DB) { |
|
0 commit comments