2018-04-28 04:32:08 +03:00
|
|
|
package server
|
2018-02-16 02:50:48 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"path"
|
2018-04-28 04:32:08 +03:00
|
|
|
|
|
|
|
"github.com/jcelliott/lumber"
|
2018-02-16 02:50:48 +03:00
|
|
|
)
|
|
|
|
|
2018-04-28 04:32:08 +03:00
|
|
|
func Migrate(pathToOldData, pathToData string, logger *lumber.ConsoleLogger) error {
|
2018-02-16 02:50:48 +03:00
|
|
|
files, err := ioutil.ReadDir(pathToOldData)
|
|
|
|
if len(files) == 0 {
|
|
|
|
return err
|
|
|
|
}
|
2018-04-28 05:30:13 +03:00
|
|
|
s := Site{PathToData: pathToData, Logger: lumber.NewConsoleLogger(lumber.TRACE)}
|
2018-02-16 02:50:48 +03:00
|
|
|
for _, f := range files {
|
|
|
|
if f.Mode().IsDir() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
fmt.Printf("Migrating %s", f.Name())
|
2018-04-28 05:30:13 +03:00
|
|
|
p := s.Open(f.Name())
|
2018-02-16 02:50:48 +03:00
|
|
|
bData, err := ioutil.ReadFile(path.Join(pathToOldData, f.Name()))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = p.Update(string(bData))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err = p.Save(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|