From e0e5d760fd9f246655dbe3e41c545ddc5e66faaa Mon Sep 17 00:00:00 2001 From: Andrew French Date: Mon, 1 Oct 2018 17:35:09 -0600 Subject: [PATCH] Respect an existing user-managed AdditionalConfiguration.php, fixes #1053 (#1140) --- pkg/ddevapp/ddevapp.go | 19 ++++++++++--------- pkg/ddevapp/typo3.go | 30 +++++++++++++++++++----------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/pkg/ddevapp/ddevapp.go b/pkg/ddevapp/ddevapp.go index a8a1003c309..8915c4d92cb 100644 --- a/pkg/ddevapp/ddevapp.go +++ b/pkg/ddevapp/ddevapp.go @@ -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 } } diff --git a/pkg/ddevapp/typo3.go b/pkg/ddevapp/typo3.go index f8e48f45fd5..096f0a01d51 100644 --- a/pkg/ddevapp/typo3.go +++ b/pkg/ddevapp/typo3.go @@ -40,23 +40,32 @@ $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 @@ -64,7 +73,6 @@ func createTypo3SettingsFile(app *DdevApp) (string, error) { // 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.