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

docs: added sql:sanitize to Drupal hook examples. #5737

Merged
merged 5 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure, but isn't "Drupal 8 Example" still relevant for Drupal 8, and "Drupal 10 Example" might have its own section?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was command differences between Drupal 7 and Drupal 8 (eg: drush cc all to drush cr) but D8 onwards the commands are the same.

Drupal.org doesn't list Drupal 8 or 9 as current versions (D8 was end of life in 2021 and D9 was November 2023)
so it was just to keep with consistency with the Project.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, that sounds good.


```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
karenmurky marked this conversation as resolved.
Show resolved Hide resolved
`

// 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