This commit is contained in:
2026-08-16 23:42:00 +02:00
parent 6e77154228
commit 92f046b542
32 changed files with 1443 additions and 105 deletions
+24 -4
View File
@@ -211,9 +211,10 @@ func FixCatalogHygieneWithIDs(ctx context.Context, pool *pgxpool.Pool, companyID
return out, ids, nil
}
// NormalizeProcessedDescriptions rewrites processed_description to the plain-text
// form produced by PlainDescriptionFromAny (unwraps JSON arrays, strips HTML). When
// processed_description is empty, normalizes from description. Returns rows updated.
// NormalizeProcessedDescriptions rewrites processed_description to a single
// string form via DescriptionFromAny (unwraps JSON arrays, preserves formula
// HTML). When processed_description is empty, normalizes from description.
// Returns rows updated.
func NormalizeProcessedDescriptions(ctx context.Context, pool *pgxpool.Pool, companyID uuid.UUID) (int, error) {
if pool == nil {
return 0, fmt.Errorf("normalize descriptions: nil pool")
@@ -245,7 +246,7 @@ func NormalizeProcessedDescriptions(ctx context.Context, pool *pgxpool.Pool, com
if raw == "" {
continue
}
plain := plainDescriptionFromStored(raw)
plain := descriptionFromStored(raw)
if plain == "" || plain == strings.TrimSpace(processedDesc) {
continue
}
@@ -265,7 +266,26 @@ func NormalizeProcessedDescriptions(ctx context.Context, pool *pgxpool.Pool, com
return updated, nil
}
// descriptionFromStored handles DB text that may itself be a JSON array/string,
// preserving formula HTML tags for process/API consumers.
func descriptionFromStored(raw string) string {
raw = strings.TrimSpace(raw)
if raw == "" {
return ""
}
if strings.HasPrefix(raw, "[") || strings.HasPrefix(raw, "{") {
var decoded any
if err := json.Unmarshal([]byte(raw), &decoded); err == nil {
if s := DescriptionFromAny(decoded); s != "" {
return s
}
}
}
return DescriptionFromAny(raw)
}
// plainDescriptionFromStored handles DB text that may itself be a JSON array/string.
// Strips HTML — prefer descriptionFromStored when formula markup must be kept.
func plainDescriptionFromStored(raw string) string {
raw = strings.TrimSpace(raw)
if raw == "" {