2021-11-12 05:09:17 +01:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2021-11-18 00:46:34 +01:00
|
|
|
"github.com/manifoldco/promptui"
|
2021-11-12 05:09:17 +01:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
2021-11-18 13:13:48 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
|
|
|
"github.com/photoprism/photoprism/internal/query"
|
2021-11-12 05:09:17 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/service"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PlacesCommand registers the places subcommands.
|
|
|
|
var PlacesCommand = cli.Command{
|
|
|
|
Name: "places",
|
2021-11-28 13:52:27 +01:00
|
|
|
Usage: "Maps and location details subcommands",
|
2021-11-12 05:09:17 +01:00
|
|
|
Subcommands: []cli.Command{
|
|
|
|
{
|
2021-11-28 13:52:27 +01:00
|
|
|
Name: "update",
|
|
|
|
Usage: "Retrieves updated location details",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "yes, y",
|
|
|
|
Hidden: true,
|
|
|
|
Usage: "assume \"yes\" as answer to all prompts and run non-interactively",
|
|
|
|
},
|
|
|
|
},
|
2021-11-12 05:09:17 +01:00
|
|
|
Action: placesUpdateAction,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-11-12 06:32:58 +01:00
|
|
|
// placesUpdateAction fetches updated location data.
|
2021-11-12 05:09:17 +01:00
|
|
|
func placesUpdateAction(ctx *cli.Context) error {
|
2021-11-18 13:13:48 +01:00
|
|
|
// Load config.
|
2021-11-12 05:09:17 +01:00
|
|
|
conf := config.NewConfig(ctx)
|
|
|
|
service.SetConfig(conf)
|
|
|
|
|
|
|
|
_, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
if err := conf.Init(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-11-22 11:27:53 +01:00
|
|
|
if !conf.Sponsor() && !conf.Test() {
|
|
|
|
log.Errorf(config.MsgSponsorCommand)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
conf.InitDb()
|
|
|
|
defer conf.Shutdown()
|
|
|
|
|
2021-11-28 13:52:27 +01:00
|
|
|
if !ctx.Bool("yes") {
|
|
|
|
confirmPrompt := promptui.Prompt{
|
|
|
|
Label: "Interrupting the update may result in inconsistent location details. Proceed?",
|
|
|
|
IsConfirm: true,
|
|
|
|
}
|
2021-11-22 11:27:53 +01:00
|
|
|
|
2021-11-28 13:52:27 +01:00
|
|
|
// Abort?
|
|
|
|
if _, err := confirmPrompt.Run(); err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
2021-11-22 11:27:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
start := time.Now()
|
|
|
|
|
2021-11-12 05:09:17 +01:00
|
|
|
// Run places worker.
|
2021-11-18 13:13:48 +01:00
|
|
|
if w := service.Places(); w != nil {
|
|
|
|
_, err := w.Start()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run moments worker.
|
|
|
|
if w := service.Moments(); w != nil {
|
|
|
|
err := w.Start()
|
2021-11-12 05:09:17 +01:00
|
|
|
|
2021-11-18 13:13:48 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-11-12 05:09:17 +01:00
|
|
|
}
|
|
|
|
|
2021-11-18 13:13:48 +01:00
|
|
|
// Hide missing album contents.
|
|
|
|
if err := query.UpdateMissingAlbumEntries(); err != nil {
|
|
|
|
log.Errorf("index: %s (update album entries)", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update precalculated photo and file counts.
|
|
|
|
if err := entity.UpdateCounts(); err != nil {
|
|
|
|
log.Warnf("index: %s (update counts)", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update album, subject, and label cover thumbs.
|
|
|
|
if err := query.UpdateCovers(); err != nil {
|
|
|
|
log.Warnf("index: %s (update covers)", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Infof("completed in %s", time.Since(start))
|
|
|
|
|
2021-11-12 05:09:17 +01:00
|
|
|
return nil
|
|
|
|
}
|