Skip to content

Commit

Permalink
Merge pull request #16 from szike/main
Browse files Browse the repository at this point in the history
add db-prefix option to magento2 and to wordpress bootstrap
  • Loading branch information
janosmiko authored Mar 4, 2022
2 parents ae3e8b8 + 3c2d3c5 commit 36b12cb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,13 @@ func addFlags() {
)

_ = viper.BindPFlag(core.AppName+"_reset_admin_url", Cmd.Flags().Lookup("reset-admin-url"))

// --db-prefix
Cmd.Flags().String(
"db-prefix",
"",
"database table prefix",
)

_ = viper.BindPFlag(core.AppName+"_db_prefix", Cmd.Flags().Lookup("db-prefix"))
}
7 changes: 7 additions & 0 deletions docs/environments/initializing-magento2.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ It's pretty easy to bootstrap a Magento 2 project using Reward.
$ reward bootstrap --with-sampledata
```

It is possible to change the DB prefix with the following command.

``` shell
$ reward bootstrap --db-prefix=<somestring>
```


#### Importing a Magento 2 Project and initializing with bootstrap command

1. Clone your project and initialize Reward.
Expand Down
6 changes: 6 additions & 0 deletions docs/environments/initializing-wordpress.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ It's pretty easy to bootstrap a WordPress project using Reward.
This is going to create a new WordPress installation by downloading WordPress and configuring wp-config.php.
It is possible to change the DB prefix with the following command.
``` shell
$ reward bootstrap --db-prefix=<somestring>
```
#### Importing a WordPress Project and initializing with bootstrap command
1. Clone your project and initialize Reward.
Expand Down
20 changes: 20 additions & 0 deletions internal/commands/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ func bootstrapMagento2() error {
"--db-password=magento",
}

if getDBPrefix() != "" {
magentoCmdParams = append(
magentoCmdParams,
fmt.Sprintf("--db-prefix=%s",
getDBPrefix()),
)
}

if core.IsServiceEnabled("redis") {
magentoCmdParams = append(
magentoCmdParams,
Expand Down Expand Up @@ -788,6 +796,10 @@ func bootstrapWordpress() error {
return err
}

if getDBPrefix() != "" {
viper.Set("wordpress_table_prefix", getDBPrefix())
}

for e := wptmpList.Front(); e != nil; e = e.Next() {
tplName := fmt.Sprint(e.Value)

Expand Down Expand Up @@ -893,3 +905,11 @@ func getMagentoMode() string {

return "developer"
}

// getDBPrefix returns db-prefix
func getDBPrefix() string {
if viper.IsSet(core.AppName + "_db_prefix") {
return viper.GetString(core.AppName + "_db_prefix")
}
return ""
}

0 comments on commit 36b12cb

Please sign in to comment.