Add logging
This commit is contained in:
parent
1e30b2dee1
commit
b9aab001ad
|
@ -20,6 +20,7 @@ import (
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
"bytes"
|
"bytes"
|
||||||
"code.vikunja.io/api/pkg/db"
|
"code.vikunja.io/api/pkg/db"
|
||||||
|
"code.vikunja.io/api/pkg/log"
|
||||||
"code.vikunja.io/api/pkg/models"
|
"code.vikunja.io/api/pkg/models"
|
||||||
"code.vikunja.io/api/pkg/modules/migration"
|
"code.vikunja.io/api/pkg/modules/migration"
|
||||||
"code.vikunja.io/api/pkg/user"
|
"code.vikunja.io/api/pkg/user"
|
||||||
|
@ -30,6 +31,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const logPrefix = "[Vikunja File Import] "
|
||||||
|
|
||||||
type VikunjaFileMigrator struct {
|
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)
|
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 dataFile *zip.File
|
||||||
var filterFile *zip.File
|
var filterFile *zip.File
|
||||||
storedFiles := make(map[int64]*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)
|
return fmt.Errorf("could not convert file id: %s", err)
|
||||||
}
|
}
|
||||||
storedFiles[id] = f
|
storedFiles[id] = f
|
||||||
|
log.Debugf(logPrefix + "Found a blob file")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if f.Name == "data.json" {
|
if f.Name == "data.json" {
|
||||||
dataFile = f
|
dataFile = f
|
||||||
|
log.Debugf(logPrefix + "Found a data file")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if f.Name == "filters.json" {
|
if f.Name == "filters.json" {
|
||||||
filterFile = f
|
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
|
// 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)
|
return fmt.Errorf("could not insert data: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if filterFile == nil {
|
||||||
|
log.Debugf(logPrefix + "No filter file found")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
///////
|
///////
|
||||||
// Import filters
|
// Import filters
|
||||||
ff, err := filterFile.Open()
|
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)
|
return fmt.Errorf("could not read filter data: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debugf(logPrefix+"Importing %d saved filters", len(filters))
|
||||||
|
|
||||||
s := db.NewSession()
|
s := db.NewSession()
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue