createWordpressSettingsFile creates a Wordpress settings file from a template. Returns full path to location of file + err
(app *DdevApp)
| 91 | // createWordpressSettingsFile creates a Wordpress settings file from a |
| 92 | // template. Returns full path to location of file + err |
| 93 | func createWordpressSettingsFile(app *DdevApp) (string, error) { |
| 94 | absPath, err := wordpressGetRelativeAbsPath(app) |
| 95 | if err != nil { |
| 96 | if strings.Contains(err.Error(), "multiple") { |
| 97 | util.Warning("Unable to determine ABSPATH: %v", err) |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | config := NewWordpressConfig(absPath) |
| 102 | |
| 103 | // Write DDEV settings file |
| 104 | if err := writeWordpressDdevSettingsFile(app.SiteDdevSettingsFile); err != nil { |
| 105 | return "", err |
| 106 | } |
| 107 | |
| 108 | // Check if an existing WordPress settings file exists |
| 109 | if fileutil.FileExists(app.SiteSettingsPath) { |
| 110 | // Check if existing WordPress settings file is ddev-managed |
| 111 | sigExists, err := fileutil.FgrepStringInFile(app.SiteSettingsPath, nodeps.DdevFileSignature) |
| 112 | if err != nil { |
| 113 | return "", err |
| 114 | } |
| 115 | |
| 116 | if sigExists { |
| 117 | // Settings file is ddev-managed, overwriting is safe |
| 118 | if err := writeWordpressSettingsFile(config, app.SiteSettingsPath); err != nil { |
| 119 | return "", err |
| 120 | } |
| 121 | } else { |
| 122 | // Settings file exists and is not ddev-managed, alert the user to the location |
| 123 | // of the generated DDEV settings file |
| 124 | includeExists, err := fileutil.FgrepStringInFile(app.SiteSettingsPath, "wp-config-ddev.php") |
| 125 | if err != nil { |
| 126 | util.Warning("Unable to check that the DDEV settings file has been included: %v", err) |
| 127 | } |
| 128 | |
| 129 | if includeExists { |
| 130 | util.Success("Include of %s found in %s", app.SiteDdevSettingsFile, app.SiteSettingsPath) |
| 131 | } else { |
| 132 | util.Warning(wordpressConfigInstructions, app.SiteDdevSettingsFile) |
| 133 | } |
| 134 | } |
| 135 | } else { |
| 136 | // If settings file does not exist, write basic settings file including it |
| 137 | if err := writeWordpressSettingsFile(config, app.SiteSettingsPath); err != nil { |
| 138 | return "", err |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | return app.SiteDdevSettingsFile, nil |
| 143 | } |
| 144 | |
| 145 | // writeWordpressSettingsFile dynamically produces valid wp-config.php file by combining a configuration |
| 146 | // object with a data-driven template. |
nothing calls this directly
no test coverage detected