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

Method CreateSettingsFile

pkg/ddevapp/apptypes.go:302–371  ·  view source on GitHub ↗

CreateSettingsFile creates the settings file (like settings.php) for the provided app is the apptype has a settingsCreator function. It also preps the ddev directory, including setting up the .ddev gitignore

()

Source from the content-addressed store, hash-verified

300// provided app is the apptype has a settingsCreator function.
301// It also preps the ddev directory, including setting up the .ddev gitignore
302func (app *DdevApp) CreateSettingsFile() (string, error) {
303 err := PrepDdevDirectory(app)
304 if err != nil {
305 util.Warning("Unable to PrepDdevDirectory: %v", err)
306 }
307
308 app.SetApptypeSettingsPaths()
309
310 if app.DisableSettingsManagement && app.Type != nodeps.AppTypePHP && app.Type != nodeps.AppTypeGeneric {
311 util.Warning("Not creating CMS settings files because disable_settings_management=true or project type doesn't require settings")
312 return "", nil
313 }
314
315 // Drupal and WordPress love to change settings files to be unwriteable.
316 // Chmod them to something we can work with in the event that they already
317 // exist.
318 if app.SiteSettingsPath != "" {
319 chmodTargets := []string{filepath.Dir(app.SiteSettingsPath), app.SiteDdevSettingsFile}
320 for _, fp := range chmodTargets {
321 fileInfo, err := os.Stat(fp)
322 if err != nil {
323 // We're not doing anything about this error other than warning,
324 // and will have to deal with the same check in settingsCreator.
325 if !os.IsNotExist(err) {
326 util.Warning("Unable to ensure write permissions: %v", err)
327 }
328
329 continue
330 }
331
332 perms := 0644
333 if fileInfo.IsDir() {
334 perms = 0755
335 }
336
337 err = util.Chmod(fp, os.FileMode(perms))
338 if err != nil {
339 return "", fmt.Errorf("could not change permissions on file %s to make it writeable: %v", fp, err)
340 }
341 }
342 }
343
344 // If we have a function to do the settings creation, do it, otherwise
345 // ignore it.
346 if appFuncs, ok := appTypeMatrix[app.GetType()]; ok && appFuncs.settingsCreator != nil {
347 settingsPath, err := appFuncs.settingsCreator(app)
348 if err != nil {
349 util.Warning("Unable to create settings file '%s': %v", app.SiteSettingsPath, err)
350 }
351
352 // Don't create settings-directory .gitignore if it would be in top-level directory, where
353 // there is almost certainly already a gitignore (like Backdrop)
354 // Don't accidentally override the existing .ddev/.gitignore as well
355 // TODO: we may want to append to .ddev/.gitignore if needed.
356 if path.Dir(app.SiteSettingsPath) != app.AppRoot && path.Dir(app.SiteSettingsPath) != app.GetConfigPath("") && app.SiteDdevSettingsFile != "" {
357 if err = CreateGitIgnore(filepath.Dir(app.SiteSettingsPath), filepath.Base(app.SiteDdevSettingsFile), "drushrc.php"); err != nil {
358 util.Warning("Failed to write .gitignore in %s: %v", filepath.Dir(app.SiteDdevSettingsFile), err)
359 }

Calls 10

GetTypeMethod · 0.95
GetConfigPathMethod · 0.95
SiteStatusMethod · 0.95
MutagenSyncFlushMethod · 0.95
WarningFunction · 0.92
ChmodFunction · 0.92
PrepDdevDirectoryFunction · 0.85
CreateGitIgnoreFunction · 0.85
ErrorfMethod · 0.80