github.com/drud/ddev@v1.21.5-alpha1.0.20230226034409-94fcc4b94453/pkg/ddevapp/shopware6.go (about) 1 package ddevapp 2 3 import ( 4 "fmt" 5 "github.com/drud/ddev/pkg/archive" 6 "github.com/drud/ddev/pkg/fileutil" 7 "os" 8 "path/filepath" 9 ) 10 11 // isShopware6App returns true if the app is of type shopware6 12 func isShopware6App(app *DdevApp) bool { 13 isShopware6, err := fileutil.FgrepStringInFile(filepath.Join(app.AppRoot, "config", "README.md"), "packages/shopware.yaml") 14 if err == nil && isShopware6 { 15 return true 16 } 17 return false 18 } 19 20 // setShopware6SiteSettingsPaths sets the paths to .env file. 21 func setShopware6SiteSettingsPaths(app *DdevApp) { 22 app.SiteSettingsPath = filepath.Join(app.AppRoot, ".env") 23 } 24 25 // shopware6ImportFilesAction defines the shopware6 workflow for importing user-generated files. 26 func shopware6ImportFilesAction(app *DdevApp, importPath, extPath string) error { 27 destPath := app.GetHostUploadDirFullPath() 28 29 // parent of destination dir should exist 30 if !fileutil.FileExists(filepath.Dir(destPath)) { 31 return fmt.Errorf("unable to import to %s: parent directory does not exist", destPath) 32 } 33 34 // parent of destination dir should be writable. 35 if err := os.Chmod(filepath.Dir(destPath), 0755); err != nil { 36 return err 37 } 38 39 // If the destination path exists, remove it as was warned 40 if fileutil.FileExists(destPath) { 41 if err := os.RemoveAll(destPath); err != nil { 42 return fmt.Errorf("failed to cleanup %s before import: %v", destPath, err) 43 } 44 } 45 46 if isTar(importPath) { 47 if err := archive.Untar(importPath, destPath, extPath); err != nil { 48 return fmt.Errorf("failed to extract provided archive: %v", err) 49 } 50 51 return nil 52 } 53 54 if isZip(importPath) { 55 if err := archive.Unzip(importPath, destPath, extPath); err != nil { 56 return fmt.Errorf("failed to extract provided archive: %v", err) 57 } 58 59 return nil 60 } 61 62 //nolint: revive 63 if err := fileutil.CopyDir(importPath, destPath); err != nil { 64 return err 65 } 66 67 return nil 68 } 69 70 // getShopwareUploadDir will return a custom upload dir if defined, 71 // returning a default path if not; this is relative to the docroot 72 func getShopwareUploadDir(app *DdevApp) string { 73 if app.UploadDir == "" { 74 return "media" 75 } 76 77 return app.UploadDir 78 } 79 80 // shopware6PostStartAction checks to see if the .env file is set up 81 func shopware6PostStartAction(app *DdevApp) error { 82 if app.DisableSettingsManagement { 83 return nil 84 } 85 envFilePath := filepath.Join(app.AppRoot, ".env") 86 _, envText, err := ReadProjectEnvFile(envFilePath) 87 var envMap = map[string]string{ 88 "DATABASE_URL": `mysql://db:db@db:3306/db`, 89 "APP_URL": app.GetPrimaryURL(), 90 "MAILER_URL": `smtp://127.0.0.1:1025?encryption=&auth_mode=`, 91 } 92 // Shopware 6 refuses to do bin/console system:setup if the env file exists, 93 // so if it doesn't exist, wait for it to be created 94 if err == nil { 95 err := WriteProjectEnvFile(envFilePath, envMap, envText) 96 if err != nil { 97 return err 98 } 99 } 100 101 return nil 102 }