writeBackdropSettingsDdevPHP dynamically produces a valid settings.ddev.php file by combining a configuration object with a data-driven template.
(settings *BackdropSettings, filePath string, _ *DdevApp)
| 91 | // writeBackdropSettingsDdevPHP dynamically produces a valid settings.ddev.php file |
| 92 | // by combining a configuration object with a data-driven template. |
| 93 | func writeBackdropSettingsDdevPHP(settings *BackdropSettings, filePath string, _ *DdevApp) error { |
| 94 | if fileutil.FileExists(filePath) { |
| 95 | // Check if the file is managed by ddev. |
| 96 | signatureFound, err := fileutil.FgrepStringInFile(filePath, nodeps.DdevFileSignature) |
| 97 | if err != nil { |
| 98 | return err |
| 99 | } |
| 100 | |
| 101 | // If the signature wasn't found, warn the user and return. |
| 102 | if !signatureFound { |
| 103 | util.Warning("%s already exists and is managed by the user.", filepath.Base(filePath)) |
| 104 | return nil |
| 105 | } |
| 106 | } |
| 107 | t, err := template.New("settings.ddev.php").ParseFS(bundledAssets, path.Join("drupal/backdrop/settings.ddev.php")) |
| 108 | if err != nil { |
| 109 | return err |
| 110 | } |
| 111 | |
| 112 | // Ensure target directory exists and is writable |
| 113 | dir := filepath.Dir(filePath) |
| 114 | if err = util.Chmod(dir, 0755); os.IsNotExist(err) { |
| 115 | if err = os.MkdirAll(dir, 0755); err != nil { |
| 116 | return err |
| 117 | } |
| 118 | } else if err != nil { |
| 119 | return err |
| 120 | } |
| 121 | |
| 122 | file, err := os.Create(filePath) |
| 123 | if err != nil { |
| 124 | return err |
| 125 | } |
| 126 | defer util.CheckClose(file) |
| 127 | |
| 128 | err = t.Execute(file, settings) |
| 129 | return err |
| 130 | } |
| 131 | |
| 132 | // getBackdropUploadDirs will return the default paths. |
| 133 | func getBackdropUploadDirs(_ *DdevApp) []string { |
no test coverage detected