MCPcopy Index your code
hub / github.com/ddev/ddev / createBackdropSettingsFile

Function createBackdropSettingsFile

pkg/ddevapp/backdrop.go:59–89  ·  view source on GitHub ↗

createBackdropSettingsFile manages creation and modification of settings.php and settings.ddev.php. If a settings.php file already exists, it will be modified to ensure that it includes settings.ddev.php, which contains ddev-specific configuration.

(app *DdevApp)

Source from the content-addressed store, hash-verified

57// If a settings.php file already exists, it will be modified to ensure that it includes
58// settings.ddev.php, which contains ddev-specific configuration.
59func createBackdropSettingsFile(app *DdevApp) (string, error) {
60 settings := NewBackdropSettings(app)
61
62 if !fileutil.FileExists(app.SiteSettingsPath) {
63 output.UserOut.Printf("No %s file exists, creating one", settings.SiteSettings)
64 if err := writeDrupalSettingsPHP(app); err != nil {
65 return "", err
66 }
67 }
68
69 included, err := fileutil.FgrepStringInFile(app.SiteSettingsPath, settings.SiteSettingsDdev)
70 if err != nil {
71 return "", err
72 }
73
74 if included {
75 output.UserOut.Printf("Existing %s includes %s", settings.SiteSettings, settings.SiteSettingsDdev)
76 } else {
77 output.UserOut.Printf("Existing %s file does not include %s, modifying to include ddev settings", settings.SiteSettings, settings.SiteSettingsDdev)
78
79 if err = appendIncludeToDrupalSettingsFile(app); err != nil {
80 return "", fmt.Errorf("failed to include %s in %s: %v", settings.SiteSettingsDdev, settings.SiteSettings, err)
81 }
82 }
83
84 if err = writeBackdropSettingsDdevPHP(settings, app.SiteDdevSettingsFile, app); err != nil {
85 return "", fmt.Errorf("failed to write Drupal settings file %s: %v", app.SiteDdevSettingsFile, err)
86 }
87
88 return app.SiteDdevSettingsFile, nil
89}
90
91// writeBackdropSettingsDdevPHP dynamically produces a valid settings.ddev.php file
92// by combining a configuration object with a data-driven template.

Callers

nothing calls this directly

Calls 7

FileExistsFunction · 0.92
FgrepStringInFileFunction · 0.92
NewBackdropSettingsFunction · 0.85
writeDrupalSettingsPHPFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected