-
-
Notifications
You must be signed in to change notification settings - Fork 580
/
typo3.go
213 lines (177 loc) · 6.76 KB
/
typo3.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
package ddevapp
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/drud/ddev/pkg/archive"
"github.com/drud/ddev/pkg/fileutil"
"github.com/drud/ddev/pkg/output"
"github.com/drud/ddev/pkg/util"
)
const typo3AdditionalConfigTemplate = `<?php
/** ` + DdevFileSignature + `: Automatically generated TYPO3 AdditionalConfiguration.php file.
ddev manages this file and may delete or overwrite the file unless this comment is removed.
*/
$GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] = '.*';
$GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default'] = array_merge(
// on first install, this could be not set yet
isset($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default'])
? $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']
: [],
[
'dbname' => 'db',
'host' => 'db',
'password' => 'db',
'port' => '3306',
'user' => 'db',
]
);
// This mail configuration sends all emails to mailhog
$GLOBALS['TYPO3_CONF_VARS']['MAIL']['transport'] = 'smtp';
$GLOBALS['TYPO3_CONF_VARS']['MAIL']['transport_smtp_server'] = 'localhost:1025';
$GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'] = '*';
$GLOBALS['TYPO3_CONF_VARS']['SYS']['displayErrors'] = 1;
// This GFX configuration allows processing by installed ImageMagick 6
$GLOBALS['TYPO3_CONF_VARS']['GFX']['processor'] = 'ImageMagick';
$GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_path'] = '/usr/bin/';
$GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_path_lzw'] = '/usr/bin/';
`
// createTypo3SettingsFile creates the app's LocalConfiguration.php and
// 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 %s (%s)", filepath.Base(app.SiteSettingsPath), app.SiteSettingsPath)
}
// TYPO3 ddev settings file will be AdditionalConfiguration.php (app.SiteDdevSettingsFile).
// Check if the file already exists.
if fileutil.FileExists(app.SiteDdevSettingsFile) {
// Check if the file is managed by ddev.
signatureFound, err := fileutil.FgrepStringInFile(app.SiteDdevSettingsFile, 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.SiteDdevSettingsFile))
return app.SiteDdevSettingsFile, nil
}
}
output.UserOut.Printf("Generating %s file for database connection.", filepath.Base(app.SiteDdevSettingsFile))
if err := writeTypo3SettingsFile(app); err != nil {
return "", fmt.Errorf("failed to write TYPO3 AdditionalConfiguration.php file: %v", err.Error())
}
return app.SiteDdevSettingsFile, 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.SiteDdevSettingsFile
// Ensure target directory is writable.
dir := filepath.Dir(filePath)
var perms os.FileMode = 0755
if err := os.Chmod(dir, perms); err != nil {
if !os.IsNotExist(err) {
// The directory exists, but chmod failed.
return err
}
// The directory doesn't exist, create it with the appropriate permissions.
if err := os.Mkdir(dir, perms); err != nil {
return err
}
}
file, err := os.Create(filePath)
if err != nil {
return err
}
contents := []byte(typo3AdditionalConfigTemplate)
err = ioutil.WriteFile(filePath, contents, 0644)
if err != nil {
return err
}
util.CheckClose(file)
return nil
}
// getTypo3UploadDir will return a custom upload dir if defined, returning a default path if not.
func getTypo3UploadDir(app *DdevApp) string {
if app.UploadDir == "" {
return "fileadmin"
}
return app.UploadDir
}
// Typo3Hooks adds a TYPO3-specific hooks example for post-import-db
const Typo3Hooks = `# post-start:
# - exec: composer install -d /var/www/html
`
// getTypo3Hooks for appending as byte array
func getTypo3Hooks() []byte {
// We don't have anything new to add yet.
return []byte(Typo3Hooks)
}
// setTypo3SiteSettingsPaths sets the paths to settings.php/settings.local.php
// for templating.
func setTypo3SiteSettingsPaths(app *DdevApp) {
settingsFileBasePath := filepath.Join(app.AppRoot, app.Docroot)
var settingsFilePath, localSettingsFilePath string
settingsFilePath = filepath.Join(settingsFileBasePath, "typo3conf", "LocalConfiguration.php")
localSettingsFilePath = filepath.Join(settingsFileBasePath, "typo3conf", "AdditionalConfiguration.php")
app.SiteSettingsPath = settingsFilePath
app.SiteDdevSettingsFile = localSettingsFilePath
}
// isTypoApp returns true if the app is of type typo3
func isTypo3App(app *DdevApp) bool {
if _, err := os.Stat(filepath.Join(app.AppRoot, app.Docroot, "typo3")); err == nil {
return true
}
return false
}
// typo3ConfigOverrideAction sets a safe php_version for TYPO3
func typo3ConfigOverrideAction(app *DdevApp) error {
app.PHPVersion = PHP72
return nil
}
// typo3ImportFilesAction defines the TYPO3 workflow for importing project files.
// The TYPO3 import-files workflow is currently identical to the Drupal workflow.
func typo3ImportFilesAction(app *DdevApp, importPath, extPath string) error {
destPath := filepath.Join(app.GetAppRoot(), app.GetDocroot(), app.GetUploadDir())
// parent of destination dir should exist
if !fileutil.FileExists(filepath.Dir(destPath)) {
return fmt.Errorf("unable to import to %s: parent directory does not exist", destPath)
}
// parent of destination dir should be writable.
if err := os.Chmod(filepath.Dir(destPath), 0755); err != nil {
return err
}
// If the destination path exists, remove it as was warned
if fileutil.FileExists(destPath) {
if err := os.RemoveAll(destPath); err != nil {
return fmt.Errorf("failed to cleanup %s before import: %v", destPath, err)
}
}
if isTar(importPath) {
if err := archive.Untar(importPath, destPath, extPath); err != nil {
return fmt.Errorf("failed to extract provided archive: %v", err)
}
return nil
}
if isZip(importPath) {
if err := archive.Unzip(importPath, destPath, extPath); err != nil {
return fmt.Errorf("failed to extract provided archive: %v", err)
}
return nil
}
if err := fileutil.CopyDir(importPath, destPath); err != nil {
return err
}
return nil
}
// typo3PostStartAction handles default post-start actions
func typo3PostStartAction(app *DdevApp) error {
if _, err := app.CreateSettingsFile(); err != nil {
return fmt.Errorf("failed to write settings file %s: %v", app.SiteDdevSettingsFile, err)
}
return nil
}