Skip to content

Commit

Permalink
Respect an existing user-managed AdditionalConfiguration.php, fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewfrench committed Oct 1, 2018
1 parent 66a6eae commit e0e5d76
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
19 changes: 10 additions & 9 deletions pkg/ddevapp/ddevapp.go
Expand Up @@ -821,16 +821,17 @@ func (app *DdevApp) Wait(containerTypes ...string) error {
func (app *DdevApp) DetermineSettingsPathLocation() (string, error) {
possibleLocations := []string{app.SiteSettingsPath, app.SiteLocalSettingsPath}
for _, loc := range possibleLocations {
// If the file is found we need to check for a signature to determine if it's safe to use.
if fileutil.FileExists(loc) {
signatureFound, err := fileutil.FgrepStringInFile(loc, DdevFileSignature)
util.CheckErr(err) // Really can't happen as we already checked for the file existence
// If the file doesn't exist, it's safe to use
if !fileutil.FileExists(loc) {
return loc, nil
}

if signatureFound {
return loc, nil
}
} else {
// If the file is not found it's safe to use.
// If the file does exist, check for a signature indicating it's managed by ddev.
signatureFound, err := fileutil.FgrepStringInFile(loc, DdevFileSignature)
util.CheckErr(err) // Really can't happen as we already checked for the file existence

// If the signature was found, it's safe to use.
if signatureFound {
return loc, nil
}
}
Expand Down
30 changes: 19 additions & 11 deletions pkg/ddevapp/typo3.go
Expand Up @@ -40,31 +40,39 @@ $GLOBALS['TYPO3_CONF_VARS']['SYS']['displayErrors'] = 1;
// AdditionalConfiguration.php, adding things like database host, name, and
// password. Returns the fullpath to settings file and error
func createTypo3SettingsFile(app *DdevApp) (string, error) {

if !fileutil.FileExists(app.SiteSettingsPath) {
util.Warning("TYPO3 does not seem to have been set up yet, missing LocalConfiguration.php (%s)", app.SiteLocalSettingsPath)
util.Warning("TYPO3 does not seem to have been set up yet, missing %s (%s)", filepath.Base(app.SiteSettingsPath), app.SiteSettingsPath)
}

settingsFilePath, err := app.DetermineSettingsPathLocation()
if err != nil {
return "", fmt.Errorf("Failed to get TYPO3 AdditionalConfiguration.php file path: %v", err.Error())
// TYPO3 ddev settings file will be AdditionalConfiguration.php (app.SiteLocalSettingsPath).
// Check if the file already exists.
if fileutil.FileExists(app.SiteLocalSettingsPath) {
// Check if the file is managed by ddev.
signatureFound, err := fileutil.FgrepStringInFile(app.SiteLocalSettingsPath, DdevFileSignature)
if err != nil {
return "", err
}

// If the signature wasn't found, warn the user and return.
if !signatureFound {
util.Warning("%s already exists and is managed by the user.", filepath.Base(app.SiteLocalSettingsPath))
return app.SiteLocalSettingsPath, nil
}
}
output.UserOut.Printf("Generating %s file for database connection.", filepath.Base(settingsFilePath))

err = writeTypo3SettingsFile(app)
if err != nil {
return settingsFilePath, fmt.Errorf("Failed to write TYPO3 AdditionalConfiguration.php file: %v", err.Error())
output.UserOut.Printf("Generating %s file for database connection.", filepath.Base(app.SiteLocalSettingsPath))
if err := writeTypo3SettingsFile(app); err != nil {
return "", fmt.Errorf("failed to write TYPO3 AdditionalConfiguration.php file: %v", err.Error())
}

return settingsFilePath, nil
return app.SiteLocalSettingsPath, nil
}

// writeTypo3SettingsFile produces AdditionalConfiguration.php file
// It's assumed that the LocalConfiguration.php already exists, and we're
// overriding the db config values in it. The typo3conf/ directory will
// be created if it does not yet exist.
func writeTypo3SettingsFile(app *DdevApp) error {

filePath := app.SiteLocalSettingsPath

// Ensure target directory is writable.
Expand Down

0 comments on commit e0e5d76

Please sign in to comment.