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"
|
2022-10-15 21:54:11 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/get"
|
2021-11-18 13:13:48 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/query"
|
2021-11-12 05:09:17 +01:00
|
|
|
)
|
|
|
|
|
2023-02-14 11:37:22 +01:00
|
|
|
// PlacesCommand configures the command name, flags, and action.
|
2021-11-12 05:09:17 +01:00
|
|
|
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.
|
2022-10-04 12:27:40 +02:00
|
|
|
conf, err := InitConfig(ctx)
|
2021-11-12 05:09:17 +01:00
|
|
|
|
|
|
|
_, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2022-10-04 12:27:40 +02:00
|
|
|
if err != nil {
|
2021-11-12 05:09:17 +01:00
|
|
|
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.
|
2022-10-15 21:54:11 +02:00
|
|
|
if w := get.Places(); w != nil {
|
2021-11-18 13:13:48 +01:00
|
|
|
_, err := w.Start()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run moments worker.
|
2022-10-15 21:54:11 +02:00
|
|
|
if w := get.Moments(); w != nil {
|
2021-11-18 13:13:48 +01:00
|
|
|
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
|
|
|
|
}
|