mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-23 03:36:30 +00:00
cleanup: remove Go migration code, rely solely on SQL migration 096
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -445,70 +444,3 @@ func pcParseInt(s string, defaultVal int) int {
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// MigrateLegacyPurchaseURL checks if the old purchase_subscription_url setting
|
||||
// exists and is enabled, and if so, migrates it to a custom_menu_item entry.
|
||||
// After migration, both purchase_subscription_enabled and purchase_subscription_url
|
||||
// are cleared since the functionality is fully replaced by custom menu items.
|
||||
// This is idempotent: it skips if a menu item with ID "migrated_purchase_subscription"
|
||||
// already exists.
|
||||
func (s *PaymentConfigService) MigrateLegacyPurchaseURL(ctx context.Context) error {
|
||||
enabled, _ := s.settingRepo.GetValue(ctx, SettingKeyPurchaseSubscriptionEnabled)
|
||||
if enabled != "true" {
|
||||
return nil
|
||||
}
|
||||
url, _ := s.settingRepo.GetValue(ctx, SettingKeyPurchaseSubscriptionURL)
|
||||
url = strings.TrimSpace(url)
|
||||
if url == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Read current custom_menu_items
|
||||
raw, _ := s.settingRepo.GetValue(ctx, SettingKeyCustomMenuItems)
|
||||
type menuItem struct {
|
||||
ID string `json:"id"`
|
||||
Label string `json:"label"`
|
||||
IconSVG string `json:"icon_svg"`
|
||||
URL string `json:"url"`
|
||||
Visibility string `json:"visibility"`
|
||||
SortOrder int `json:"sort_order"`
|
||||
}
|
||||
var items []menuItem
|
||||
if raw != "" {
|
||||
_ = json.Unmarshal([]byte(raw), &items)
|
||||
}
|
||||
|
||||
// Check if already migrated (same ID exists)
|
||||
for _, item := range items {
|
||||
if item.ID == "migrated_purchase_subscription" {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Append migrated item
|
||||
items = append(items, menuItem{
|
||||
ID: "migrated_purchase_subscription",
|
||||
Label: "Purchase Subscription",
|
||||
IconSVG: "",
|
||||
URL: url,
|
||||
Visibility: "user",
|
||||
SortOrder: 100,
|
||||
})
|
||||
|
||||
data, err := json.Marshal(items)
|
||||
if err != nil {
|
||||
return fmt.Errorf("marshal custom_menu_items: %w", err)
|
||||
}
|
||||
|
||||
// Save updated menu items and clear legacy settings entirely
|
||||
if err := s.settingRepo.SetMultiple(ctx, map[string]string{
|
||||
SettingKeyCustomMenuItems: string(data),
|
||||
SettingKeyPurchaseSubscriptionEnabled: "false",
|
||||
SettingKeyPurchaseSubscriptionURL: "",
|
||||
}); err != nil {
|
||||
return fmt.Errorf("save migrated settings: %w", err)
|
||||
}
|
||||
|
||||
slog.Info("[payment] Migrated legacy purchase_subscription_url to custom menu item", "url", url)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -149,11 +149,6 @@ func NewPaymentService(entClient *dbent.Client, registry *payment.Registry, load
|
||||
return &PaymentService{entClient: entClient, registry: registry, loadBalancer: loadBalancer, redeemService: redeemService, subscriptionSvc: subscriptionSvc, configService: configService, userRepo: userRepo, groupRepo: groupRepo}
|
||||
}
|
||||
|
||||
// Start performs one-time startup tasks.
|
||||
// Legacy purchase_subscription_url migration is handled by SQL migration 096.
|
||||
func (s *PaymentService) Start(_ context.Context) {
|
||||
}
|
||||
|
||||
func (s *PaymentService) CreateOrder(ctx context.Context, req CreateOrderRequest) (*CreateOrderResponse, error) {
|
||||
if req.OrderType == "" {
|
||||
req.OrderType = "balance"
|
||||
|
||||
Reference in New Issue
Block a user