Add logging
This commit is contained in:
parent
1e30b2dee1
commit
b9aab001ad
@ -20,6 +20,7 @@ import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"code.vikunja.io/api/pkg/db"
|
||||
"code.vikunja.io/api/pkg/log"
|
||||
"code.vikunja.io/api/pkg/models"
|
||||
"code.vikunja.io/api/pkg/modules/migration"
|
||||
"code.vikunja.io/api/pkg/user"
|
||||
@ -30,6 +31,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const logPrefix = "[Vikunja File Import] "
|
||||
|
||||
type VikunjaFileMigrator struct {
|
||||
}
|
||||
|
||||
@ -43,6 +46,8 @@ func (v *VikunjaFileMigrator) Migrate(user *user.User, file io.ReaderAt, size in
|
||||
return fmt.Errorf("could not open import file: %s", err)
|
||||
}
|
||||
|
||||
log.Debugf(logPrefix+"Importing a zip file containing %d files", len(r.File))
|
||||
|
||||
var dataFile *zip.File
|
||||
var filterFile *zip.File
|
||||
storedFiles := make(map[int64]*zip.File)
|
||||
@ -54,18 +59,25 @@ func (v *VikunjaFileMigrator) Migrate(user *user.User, file io.ReaderAt, size in
|
||||
return fmt.Errorf("could not convert file id: %s", err)
|
||||
}
|
||||
storedFiles[id] = f
|
||||
log.Debugf(logPrefix + "Found a blob file")
|
||||
continue
|
||||
}
|
||||
if f.Name == "data.json" {
|
||||
dataFile = f
|
||||
log.Debugf(logPrefix + "Found a data file")
|
||||
continue
|
||||
}
|
||||
if f.Name == "filters.json" {
|
||||
filterFile = f
|
||||
log.Debugf(logPrefix + "Found a filter file")
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: check we have all files
|
||||
if dataFile == nil {
|
||||
return fmt.Errorf("no data file provided")
|
||||
}
|
||||
|
||||
log.Debugf(logPrefix + "")
|
||||
|
||||
//////
|
||||
// Import the bulk of Vikunja data
|
||||
@ -117,6 +129,11 @@ func (v *VikunjaFileMigrator) Migrate(user *user.User, file io.ReaderAt, size in
|
||||
return fmt.Errorf("could not insert data: %s", err)
|
||||
}
|
||||
|
||||
if filterFile == nil {
|
||||
log.Debugf(logPrefix + "No filter file found")
|
||||
return nil
|
||||
}
|
||||
|
||||
///////
|
||||
// Import filters
|
||||
ff, err := filterFile.Open()
|
||||
@ -135,6 +152,8 @@ func (v *VikunjaFileMigrator) Migrate(user *user.User, file io.ReaderAt, size in
|
||||
return fmt.Errorf("could not read filter data: %s", err)
|
||||
}
|
||||
|
||||
log.Debugf(logPrefix+"Importing %d saved filters", len(filters))
|
||||
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user