Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "canasta elasticsearch index" command #76

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions cmd/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
@@ -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
}
34 changes: 34 additions & 0 deletions cmd/elasticsearch/index.go
Original file line number Diff line number Diff line change
@@ -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")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CirrusSearch README states that before running the scripts, it's necessary to enable $wgDisableSearchUpdate flag and then disable it back once all the operations are completed

Frankly, I did not notice any issues running the scripts with the flag kept disabled, but it still may worth to be considered

orchestrators.Exec(instance.Path, instance.Orchestrator, "web", "php extensions/CirrusSearch/maintenance/ForceSearchIndex.php --skipParse")
fmt.Println("Search index initialization completed")
}
2 changes: 2 additions & 0 deletions cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}