Skip to content

Commit fae400f

Browse files
authored
Merge pull request #43 from middleDuckAi/middleDuck/installer-41-extras-hub
Add bundled and legacy sources to installer extras flow
2 parents ec635ab + 0686372 commit fae400f

16 files changed

Lines changed: 2111 additions & 68 deletions

internal/domain/extras.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,37 @@ const (
1818
)
1919

2020
type ExtrasPackage struct {
21+
ID string `json:"id,omitempty"`
2122
Name string `json:"name"`
2223
Version string `json:"version"`
2324
Versions []string `json:"versions,omitempty"`
2425
Description string `json:"description"`
2526
DefaultInstallMode string `json:"defaultInstallMode"`
2627
DefaultBranch string `json:"defaultBranch,omitempty"`
28+
Source string `json:"source,omitempty"`
29+
Section string `json:"section,omitempty"`
30+
Kind string `json:"kind,omitempty"`
31+
InstallMode string `json:"installMode,omitempty"`
32+
Preselected bool `json:"preselected,omitempty"`
33+
Path string `json:"path,omitempty"`
34+
Properties string `json:"properties,omitempty"`
35+
Events string `json:"events,omitempty"`
36+
GUID string `json:"guid,omitempty"`
37+
Category string `json:"category,omitempty"`
38+
LegacyNames string `json:"legacyNames,omitempty"`
39+
Disabled bool `json:"disabled,omitempty"`
40+
ShareParams int `json:"shareParams,omitempty"`
41+
Icon string `json:"icon,omitempty"`
42+
DownloadURL string `json:"downloadUrl,omitempty"`
43+
Dependencies string `json:"dependencies,omitempty"`
44+
Deprecated bool `json:"deprecated,omitempty"`
45+
Method string `json:"method,omitempty"`
2746
}
2847

2948
type ExtrasSelection struct {
49+
ID string
3050
Name string
51+
Source string
3152
Version string
3253
}
3354

@@ -45,6 +66,7 @@ type ExtrasItemDetail struct {
4566
type ExtrasState struct {
4667
Active bool
4768
Stage ExtrasStage
69+
ProjectPath string
4870
Packages []ExtrasPackage
4971
Selections []ExtrasSelection
5072
Results []ExtrasItemResult

internal/engine/install/engine.go

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,9 +991,43 @@ func (e *Engine) Run(ctx context.Context, ch chan<- domain.Event, actions <-chan
991991
}
992992

993993
e.maybeRunExtras(ctx, emit, actions, workDir)
994+
e.cleanupExtrasRuntimeArtifacts(emit, workDir)
994995
}()
995996
}
996997

998+
func (e *Engine) cleanupExtrasRuntimeArtifacts(emit func(domain.Event) bool, workDir string) {
999+
cacheDir := filepath.Join(absDir(workDir), extrasRuntimeCacheDir)
1000+
if _, err := os.Stat(cacheDir); err != nil {
1001+
return
1002+
}
1003+
if err := os.RemoveAll(cacheDir); err != nil {
1004+
if emit != nil {
1005+
_ = emit(domain.Event{
1006+
Type: domain.EventWarning,
1007+
StepID: extrasStepID,
1008+
Source: "extras",
1009+
Severity: domain.SeverityWarn,
1010+
Payload: domain.LogPayload{
1011+
Message: "Failed to remove installer extras runtime cache.",
1012+
Fields: map[string]string{"error": err.Error()},
1013+
},
1014+
})
1015+
}
1016+
return
1017+
}
1018+
if emit != nil {
1019+
_ = emit(domain.Event{
1020+
Type: domain.EventLog,
1021+
StepID: extrasStepID,
1022+
Source: "extras",
1023+
Severity: domain.SeverityInfo,
1024+
Payload: domain.LogPayload{
1025+
Message: "Removed installer extras runtime cache.",
1026+
},
1027+
})
1028+
}
1029+
}
1030+
9971031
type phpNewOptions struct {
9981032
DBType string
9991033
DBHost string
@@ -1796,9 +1830,9 @@ func dbDriverQuestionOptions(status domain.SystemStatus) []domain.QuestionOption
17961830
// If we don't have system status yet, don't block the user.
17971831
if len(status.Items) == 0 {
17981832
return []domain.QuestionOption{
1833+
{ID: "sqlite", Label: "SQLite", Enabled: true},
17991834
{ID: "mysql", Label: "MySQL or MariaDB", Enabled: true},
18001835
{ID: "pgsql", Label: "PostgreSQL", Enabled: true},
1801-
{ID: "sqlite", Label: "SQLite", Enabled: true},
18021836
{ID: "sqlsrv", Label: "SQL Server", Enabled: true},
18031837
}
18041838
}
@@ -1807,9 +1841,9 @@ func dbDriverQuestionOptions(status domain.SystemStatus) []domain.QuestionOption
18071841
pdoOK := ok && pdoLevel == domain.StatusOK
18081842

18091843
return []domain.QuestionOption{
1844+
dbDriverOption(status, pdoOK, "sqlite", "SQLite", "pdo_sqlite"),
18101845
dbDriverOption(status, pdoOK, "mysql", "MySQL or MariaDB", "pdo_mysql"),
18111846
dbDriverOption(status, pdoOK, "pgsql", "PostgreSQL", "pdo_pgsql"),
1812-
dbDriverOption(status, pdoOK, "sqlite", "SQLite", "pdo_sqlite"),
18131847
dbDriverOption(status, pdoOK, "sqlsrv", "SQL Server", "pdo_sqlsrv"),
18141848
}
18151849
}
@@ -1858,6 +1892,15 @@ try {
18581892
if ($name !== ":memory:" && !str_starts_with($name, "file:") && !preg_match('/^(\/|[A-Za-z]:[\\\\\\/])/', $name)) {
18591893
$name = "core/database/" . basename(str_replace("\\", "/", $name));
18601894
}
1895+
if ($name !== ":memory:" && !str_starts_with($name, "file:")) {
1896+
$dir = dirname($name);
1897+
if ($dir !== "" && $dir !== "." && !is_dir($dir)) {
1898+
@mkdir($dir, 0755, true);
1899+
}
1900+
if (!file_exists($name)) {
1901+
@touch($name);
1902+
}
1903+
}
18611904
new \PDO("sqlite:".$name, null, null, $timeout);
18621905
echo json_encode(["ok"=>true]); exit(0);
18631906
}

internal/engine/install/extras.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ func sanitizeExtrasPackages(pkgs []domain.ExtrasPackage) []domain.ExtrasPackage
6161
p.Description = strings.TrimSpace(p.Description)
6262
p.DefaultInstallMode = strings.TrimSpace(p.DefaultInstallMode)
6363
p.DefaultBranch = strings.TrimSpace(p.DefaultBranch)
64+
p.Source = strings.TrimSpace(p.Source)
65+
p.Section = strings.TrimSpace(p.Section)
66+
p.Kind = strings.TrimSpace(p.Kind)
67+
p.InstallMode = strings.TrimSpace(p.InstallMode)
68+
p.Path = strings.TrimSpace(p.Path)
69+
p.Properties = strings.TrimSpace(p.Properties)
70+
p.Events = strings.TrimSpace(p.Events)
71+
p.GUID = strings.TrimSpace(p.GUID)
72+
p.Category = strings.TrimSpace(p.Category)
73+
p.LegacyNames = strings.TrimSpace(p.LegacyNames)
74+
p.Icon = strings.TrimSpace(p.Icon)
75+
p.DownloadURL = strings.TrimSpace(p.DownloadURL)
76+
p.Dependencies = strings.TrimSpace(p.Dependencies)
77+
p.Method = strings.TrimSpace(p.Method)
6478
if len(p.Versions) > 0 {
6579
seen := map[string]struct{}{}
6680
clean := make([]string, 0, len(p.Versions))
@@ -77,6 +91,18 @@ func sanitizeExtrasPackages(pkgs []domain.ExtrasPackage) []domain.ExtrasPackage
7791
}
7892
p.Versions = clean
7993
}
94+
if p.Source == "" {
95+
p.Source = "managed"
96+
}
97+
if p.Section == "" {
98+
p.Section = "Managed extras"
99+
}
100+
if p.InstallMode == "" {
101+
p.InstallMode = "managed-artisan"
102+
}
103+
if p.ID == "" {
104+
p.ID = p.Source + ":" + p.Name
105+
}
80106
out = append(out, p)
81107
}
82108
return out

0 commit comments

Comments
 (0)