From 5ef140fba29b915a6dca00f84964fbee474883ad Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 3 Jun 2024 17:38:54 +0200 Subject: [PATCH] fix(tasklist): migrate old tasklist format Resolves https://community.vikunja.io/t/task-list-from-0-21-0-0-23-0/2340 Resolves https://community.vikunja.io/t/general-feedback-after-trying-out-vikunja/1943/6 --- pkg/migration/20240603172746.go | 84 +++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 pkg/migration/20240603172746.go diff --git a/pkg/migration/20240603172746.go b/pkg/migration/20240603172746.go new file mode 100644 index 000000000..5dae0fdb1 --- /dev/null +++ b/pkg/migration/20240603172746.go @@ -0,0 +1,84 @@ +// Vikunja is a to-do list application to facilitate your life. +// Copyright 2018-present Vikunja and contributors. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public Licensee as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public Licensee for more details. +// +// You should have received a copy of the GNU Affero General Public Licensee +// along with this program. If not, see . + +package migration + +import ( + "regexp" + "strings" + + "src.techknowlogick.com/xormigrate" + "xorm.io/xorm" +) + +func convertChecklistInDescription(tx *xorm.Engine, table string, column string) (err error) { + items := []map[string]interface{}{} + err = tx.Table(table). + Select("id, " + column). + Find(&items) + if err != nil { + return + } + + for _, item := range items { + if !strings.Contains(item[column].(string), "
  • [") { + continue + } + + var re = regexp.MustCompile(`
      (\n)?
    • `) + item[column] = re.ReplaceAllString(item[column].(string), `
      • `) + + item[column] = strings.ReplaceAll(item[column].(string), "
      • [ ] ", `
      • `) + item[column] = strings.ReplaceAll(item[column].(string), "
      • [x] ", `
      • `) + + _, err = tx.Where("id = ?", item["id"]). + Table(table). + Cols(column). + Update(item) + if err != nil { + return + } + } + + return nil +} + +func init() { + migrations = append(migrations, &xormigrate.Migration{ + ID: "20240603172746", + Description: "Convert unconverted checklists to proper html", + Migrate: func(tx *xorm.Engine) (err error) { + for _, table := range []string{ + "tasks", + "labels", + "projects", + "saved_filters", + "teams", + } { + err = convertChecklistInDescription(tx, table, "description") + if err != nil { + return + } + } + + err = convertChecklistInDescription(tx, "task_comments", "comment") + return + }, + Rollback: func(tx *xorm.Engine) error { + return nil + }, + }) +}