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

Function cakephpPostStartAction

pkg/ddevapp/cakephp.go:19–78  ·  view source on GitHub ↗
(app *DdevApp)

Source from the content-addressed store, hash-verified

17}
18
19func cakephpPostStartAction(app *DdevApp) error {
20 // We won't touch env if disable_settings_management: true
21 if app.DisableSettingsManagement {
22 return nil
23 }
24 envFileName := "config/.env"
25 envFilePath := filepath.Join(app.AppRoot, app.ComposerRoot, envFileName)
26 _, _, err := ReadProjectEnvFile(envFilePath)
27 if err != nil && !os.IsNotExist(err) {
28 return fmt.Errorf("unable to read .env file in config folder: %v", err)
29 }
30 if err == nil {
31 envFileName = "config/.env.ddev"
32 envFilePath = filepath.Join(app.AppRoot, app.ComposerRoot, envFileName)
33 _, _, err = ReadProjectEnvFile(envFilePath)
34 if err == nil {
35 util.Warning("CakePHP: .env.ddev file exists already. Replacing it. You can rename it or copy settings to your .env file.")
36 } else {
37 util.Warning("CakePHP: .env file exists already. Creating .env.ddev. You can rename it or copy settings to your .env file.")
38 }
39 } else {
40 util.Success("CakePHP: Creating .env file to store your config settings.")
41 }
42 err = fileutil.CopyFile(filepath.Join(app.AppRoot, app.ComposerRoot, "config/.env.example"), envFilePath)
43 if err != nil {
44 util.Debug("CakePHP: .env.example does not exist yet in config folder, not trying to process it")
45 return nil
46 }
47 _, envText, err := ReadProjectEnvFile(envFilePath)
48 if err != nil {
49 return err
50 }
51 port := "3306"
52 dbConnection := "mysql"
53 dbParams := ""
54 if app.Database.Type == nodeps.Postgres {
55 dbConnection = "postgres"
56 port = "5432"
57 dbParams = "?encoding=utf8"
58 }
59 envMap := map[string]string{
60 "export APP_NAME": app.GetName(),
61 "export DEBUG": "true",
62 "export APP_ENCODING": "UTF-8",
63 "export DATABASE_URL": dbConnection + "://db:db@db:" + port + "/db" + dbParams,
64 "export EMAIL_TRANSPORT_DEFAULT_URL": "smtp://localhost:1025",
65 "export SECURITY_SALT": util.HashSalt(app.GetName()),
66 "export DEBUG_KIT_SAFE_TLD": "site",
67 "export APP_FULL_BASE_URL": app.GetPrimaryURL(),
68 }
69 err = WriteProjectEnvFile(envFilePath, envMap, envText)
70 if err != nil {
71 return err
72 }
73 err = enableDotEnvLoading(app)
74 if err != nil {
75 return err
76 }

Callers

nothing calls this directly

Calls 11

WarningFunction · 0.92
SuccessFunction · 0.92
CopyFileFunction · 0.92
DebugFunction · 0.92
HashSaltFunction · 0.92
ReadProjectEnvFileFunction · 0.85
WriteProjectEnvFileFunction · 0.85
enableDotEnvLoadingFunction · 0.85
ErrorfMethod · 0.80
GetNameMethod · 0.80
GetPrimaryURLMethod · 0.80

Tested by

no test coverage detected