- RecordSaved with a change outside golem15.sitemap.lastmod_ignore moves the lastmod of the record's rows (only the changed locale's for a translated change); a no-op save, an ignored change or a rebuild does not - RecordDeleted takes the record's rows out of the files at once - record events queue one rebuild per golem15.sitemap.rebuild_delay_seconds (rebuild_pending_until, P33-12); the job clears it when it starts - sitemap:rebuild [--queue], scheduled nightly at 03:00 (pact.HasSchedule)
60 lines
2.2 KiB
Go
60 lines
2.2 KiB
Go
package console
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.golem15.com/golem15/sm-sitemap-plugin/classes"
|
|
"git.golem15.com/golem15/summercms/modules/backpack"
|
|
"git.golem15.com/golem15/summercms/modules/bonfire"
|
|
)
|
|
|
|
// Rebuild is sitemap:rebuild [--queue]: it rebuilds the sitemap files now
|
|
// (classes.Rebuild), or with --queue dispatches the rebuild job for a
|
|
// worker. The scheduler runs it every night at 03:00.
|
|
func Rebuild(app *backpack.App) bonfire.Command {
|
|
return bonfire.Command{
|
|
Name: "sitemap:rebuild",
|
|
Description: "Rebuild the sitemap files from the content types and the additional addresses",
|
|
Long: `Reads the published records of every content type and the additional
|
|
addresses, writes them into the sitemap's address table and numbers the
|
|
files: existing addresses keep their files, new ones are appended, and only a
|
|
changed file size renumbers. It runs in this process and ends with
|
|
"Rebuilt the sitemaps: N addresses in N files (N added, N changed, N
|
|
removed)."
|
|
|
|
--queue dispatches the rebuild job instead, for a worker to run. The
|
|
scheduler runs this command every night at 03:00; record changes and a save
|
|
of the sitemap settings queue a rebuild too.`,
|
|
Flags: []bonfire.Flag{
|
|
{Name: "queue", Description: "Dispatch the rebuild job for a worker instead of rebuilding here", Bare: true},
|
|
},
|
|
Examples: []bonfire.Example{
|
|
{Command: "sitemap:rebuild", Description: "Rebuild the sitemap files now"},
|
|
{Command: "sitemap:rebuild --queue", Description: "Queue a rebuild for the worker"},
|
|
},
|
|
Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
|
|
_, done, err := lookupDB(ctx, app)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer done()
|
|
if flagOn(in, "queue") {
|
|
id, err := classes.DispatchRebuild(ctx, app)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
out.Success(fmt.Sprintf("Queued the sitemap rebuild (job %d).", id))
|
|
return nil
|
|
}
|
|
res, err := classes.Rebuild(ctx, app)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
out.Success(fmt.Sprintf("Rebuilt the sitemaps: %d addresses in %d files (%d added, %d changed, %d removed).",
|
|
res.Listed, res.Files, len(res.Added), len(res.Changed), len(res.Removed)))
|
|
return nil
|
|
},
|
|
}
|
|
}
|