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

Function writeDrupalSettingsDdevPhp

pkg/ddevapp/drupal.go:176–220  ·  view source on GitHub ↗

writeDrupalSettingsDdevPhp dynamically produces valid settings.ddev.php file by combining a configuration object with a data-driven template.

(settings *DrupalSettings, filePath string, app *DdevApp)

Source from the content-addressed store, hash-verified

174// writeDrupalSettingsDdevPhp dynamically produces valid settings.ddev.php file by combining a configuration
175// object with a data-driven template.
176func writeDrupalSettingsDdevPhp(settings *DrupalSettings, filePath string, app *DdevApp) error {
177 if fileutil.FileExists(filePath) {
178 // Check if the file is managed by ddev.
179 signatureFound, err := fileutil.FgrepStringInFile(filePath, nodeps.DdevFileSignature)
180 if err != nil {
181 return err
182 }
183
184 // If the signature wasn't found, warn the user and return.
185 if !signatureFound {
186 util.Warning("%s already exists and is managed by the user.", filepath.Base(filePath))
187 return nil
188 }
189 }
190
191 drupalVersion, err := GetDrupalVersion(app)
192 if err != nil || drupalVersion == "" {
193 drupalVersion = DefaultDrupalSettingsVersion
194 }
195 t, err := template.New("settings.ddev.php").ParseFS(bundledAssets, path.Join("drupal", "drupal"+drupalVersion, "settings.ddev.php"))
196 if err != nil {
197 return err
198 }
199
200 // Ensure target directory exists and is writable
201 dir := filepath.Dir(filePath)
202 if err = util.Chmod(dir, 0755); os.IsNotExist(err) {
203 if err = os.MkdirAll(dir, 0755); err != nil {
204 return err
205 }
206 } else if err != nil {
207 return err
208 }
209
210 file, err := os.Create(filePath)
211 if err != nil {
212 return err
213 }
214 err = t.Execute(file, settings)
215 if err != nil {
216 return err
217 }
218 util.CheckClose(file)
219 return nil
220}
221
222// WriteDrushrc writes out drushrc.php based on passed-in values.
223// This works on Drupal 6 and Drupal 7 or with drush8 and older

Callers 1

createDrupalSettingsPHPFunction · 0.85

Calls 7

FileExistsFunction · 0.92
FgrepStringInFileFunction · 0.92
WarningFunction · 0.92
ChmodFunction · 0.92
CheckCloseFunction · 0.92
GetDrupalVersionFunction · 0.85
ExecuteMethod · 0.65

Tested by

no test coverage detected