diff --git a/cmd/elasticsearch/elasticsearch.go b/cmd/elasticsearch/elasticsearch.go new file mode 100644 index 0000000..5a32b8e --- /dev/null +++ b/cmd/elasticsearch/elasticsearch.go @@ -0,0 +1,32 @@ +package elasticsearch + +import ( + "log" + "os" + + "github.com/CanastaWiki/Canasta-CLI-Go/internal/config" + "github.com/spf13/cobra" +) + +var ( + instance config.Installation + pwd string + err error +) + +func NewCmdCreate() *cobra.Command { + elasticsearchCmd := &cobra.Command{ + Use: "elasticsearch", + Short: "Manage Elasticsearch indices and clusters for Canasta", + } + + elasticsearchCmd.AddCommand(indexCmdCreate()) + if pwd, err = os.Getwd(); err != nil { + log.Fatal(err) + } + + elasticsearchCmd.PersistentFlags().StringVarP(&instance.Id, "id", "i", "", "Canasta instance ID") + elasticsearchCmd.PersistentFlags().StringVarP(&instance.Path, "path", "p", pwd, "Canasta installation directory") + + return elasticsearchCmd +} diff --git a/cmd/elasticsearch/index.go b/cmd/elasticsearch/index.go new file mode 100644 index 0000000..6d1f216 --- /dev/null +++ b/cmd/elasticsearch/index.go @@ -0,0 +1,34 @@ +package elasticsearch + +import ( + "fmt" + + "github.com/CanastaWiki/Canasta-CLI-Go/internal/canasta" + "github.com/CanastaWiki/Canasta-CLI-Go/internal/config" + "github.com/CanastaWiki/Canasta-CLI-Go/internal/orchestrators" + "github.com/spf13/cobra" +) + +// indexCmd represents the index command +func indexCmdCreate() *cobra.Command { + var updateCmd = &cobra.Command{ + Use: "index", + Short: "Initialize search index for Canasta instance", + PreRunE: func(cmd *cobra.Command, args []string) error { + instance, err = canasta.CheckCanastaId(instance) + return err + }, + Run: func(cmd *cobra.Command, args []string) { + initializeIndex(instance) + }, + } + return updateCmd +} + +func initializeIndex(instance config.Installation) { + fmt.Println("Running search index initialization process...") + orchestrators.Exec(instance.Path, instance.Orchestrator, "web", "php extensions/CirrusSearch/maintenance/UpdateSearchIndexConfig.php --startOver") + orchestrators.Exec(instance.Path, instance.Orchestrator, "web", "php extensions/CirrusSearch/maintenance/ForceSearchIndex.php --skipLinks --indexOnSkip") + orchestrators.Exec(instance.Path, instance.Orchestrator, "web", "php extensions/CirrusSearch/maintenance/ForceSearchIndex.php --skipParse") + fmt.Println("Search index initialization completed") +} diff --git a/cmd/root/root.go b/cmd/root/root.go index 9c723e4..3e06439 100644 --- a/cmd/root/root.go +++ b/cmd/root/root.go @@ -3,6 +3,7 @@ package cmd import ( createCmd "github.com/CanastaWiki/Canasta-CLI-Go/cmd/create" deleteCmd "github.com/CanastaWiki/Canasta-CLI-Go/cmd/delete" + elasticCmd "github.com/CanastaWiki/Canasta-CLI-Go/cmd/elasticsearch" extensionCmd "github.com/CanastaWiki/Canasta-CLI-Go/cmd/extension" importCmd "github.com/CanastaWiki/Canasta-CLI-Go/cmd/import" listCmd "github.com/CanastaWiki/Canasta-CLI-Go/cmd/list" @@ -57,5 +58,6 @@ func init() { rootCmd.AddCommand(startCmd.NewCmdCreate()) rootCmd.AddCommand(stopCmd.NewCmdCreate()) rootCmd.AddCommand(versionCmd.NewCmdCreate()) + rootCmd.AddCommand(elasticCmd.NewCmdCreate()) rootCmd.CompletionOptions.DisableDefaultCmd = true }