Skip to content

Commit

Permalink
docs: added sql:sanitize to Drupal hook examples. (#5737) [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
karenmurky committed Feb 2, 2024
1 parent da7bb23 commit 6e4997f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
32 changes: 19 additions & 13 deletions docs/content/users/configuration/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ DDEV currently supports these tasks:

Value: string providing the command to run. Commands requiring user interaction are not supported. You can also add a “service” key to the command, specifying to run it on the `db` container or any other container you use.

Example: _Use Drush to clear the Drupal cache and get a user login link after database import_.
Example: _Use Drush to rebuild all caches and get a user login link after database import_.

```yaml
hooks:
post-import-db:
- exec: drush cr
- exec: drush uli
- exec: drush cache:rebuild
- exec: drush user:login
```

Example: _Use wp-cli to replace the production URL with development URL in a WordPress project’s database_.
Expand All @@ -60,6 +60,14 @@ hooks:
- exec: wp search-replace https://www.myproductionsite.com http://mydevsite.ddev.site
```

Example: _Use Drush to sanitize a database by removing or obfuscating user data_.

```yaml
hooks:
post-import-db:
- exec: drush sql:sanitize
```

Example: _Add an extra database before `import-db`, executing in `db` container_.

```yaml
Expand Down Expand Up @@ -143,24 +151,22 @@ hooks:
- exec: "drush cc all"
```

## Drupal 8 Example
## Drupal 10 Example

```yaml
hooks:
post-start:
# Install Composer dependencies from the web container
- composer: install
# Install Drupal after start if not installed already
- exec: "(drush status bootstrap | grep -q Successful) || drush site-install -y --db-url=mysql://db:db@db/db"
# Generate a one-time login link for the admin account
- exec: "drush uli 1"
- exec: "drush user:login"
post-import-db:
# Set the site name
- exec: "drush config-set system.site name MyDevSite"
# Enable the environment indicator module
- exec: "drush en -y environment_indicator"
# Clear the cache
- exec: "drush cr"
# Sanitize the database
- exec: "drush sql:sanitize"
# Apply any database updates
- exec: "drush updatedb"
# Rebuild all caches
- exec: "drush cache:rebuild"
```

## TYPO3 Example
Expand Down
4 changes: 2 additions & 2 deletions pkg/ddevapp/apptypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func init() {
nodeps.AppTypeDrupal9: {
settingsCreator: createDrupalSettingsPHP,
uploadDirs: getDrupalUploadDirs,
hookDefaultComments: getDrupal8Hooks,
hookDefaultComments: getDrupal10Hooks,
appTypeSettingsPaths: setDrupalSiteSettingsPaths,
appTypeDetect: isDrupal9App,
postStartAction: drupalPostStartAction,
Expand All @@ -156,7 +156,7 @@ func init() {
nodeps.AppTypeDrupal10: {
settingsCreator: createDrupalSettingsPHP,
uploadDirs: getDrupalUploadDirs,
hookDefaultComments: getDrupal8Hooks,
hookDefaultComments: getDrupal10Hooks,
appTypeSettingsPaths: setDrupalSiteSettingsPaths,
appTypeDetect: isDrupal10App,
configOverrideAction: drupal10ConfigOverrideAction,
Expand Down
12 changes: 12 additions & 0 deletions pkg/ddevapp/drupal.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ func getDrupalUploadDirs(_ *DdevApp) []string {
return uploadDirs
}

// Drupal10Hooks adds a d10-specific hooks example for post-import-db
const Drupal10Hooks = `# post-import-db:
# - exec: drush sql:sanitize
# - exec: drush updatedb
# - exec: drush cache:rebuild
`

// Drupal8Hooks adds a d8-specific hooks example for post-import-db
const Drupal8Hooks = `# post-import-db:
# - exec: drush cr
Expand Down Expand Up @@ -283,6 +290,11 @@ func getDrupal8Hooks() []byte {
return []byte(Drupal8Hooks)
}

// getDrupal10Hooks for appending as byte array
func getDrupal10Hooks() []byte {
return []byte(Drupal10Hooks)
}

// setDrupalSiteSettingsPaths sets the paths to settings.php/settings.ddev.php
// for templating.
func setDrupalSiteSettingsPaths(app *DdevApp) {
Expand Down

0 comments on commit 6e4997f

Please sign in to comment.