fix: PHP versions fallback and auto-migrate on panel start
This commit is contained in:
+12
-15
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/panelhosting/panel/internal/models"
|
||||
"github.com/panelhosting/panel/internal/phpversions"
|
||||
)
|
||||
|
||||
type SiteRepository struct {
|
||||
@@ -121,10 +122,7 @@ func (r *PHPVersionRepository) ListActive(ctx context.Context) ([]string, error)
|
||||
SELECT version FROM php_versions WHERE is_active = true ORDER BY sort_order
|
||||
`)
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return defaultPHPVersions(), nil
|
||||
}
|
||||
return nil, err
|
||||
return phpversions.Defaults, nil
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
@@ -132,25 +130,24 @@ func (r *PHPVersionRepository) ListActive(ctx context.Context) ([]string, error)
|
||||
for rows.Next() {
|
||||
var v string
|
||||
if err := rows.Scan(&v); err != nil {
|
||||
return nil, err
|
||||
return phpversions.Defaults, nil
|
||||
}
|
||||
versions = append(versions, v)
|
||||
}
|
||||
if len(versions) == 0 {
|
||||
return defaultPHPVersions(), nil
|
||||
if err := rows.Err(); err != nil || len(versions) == 0 {
|
||||
return phpversions.Defaults, nil
|
||||
}
|
||||
return versions, rows.Err()
|
||||
return versions, nil
|
||||
}
|
||||
|
||||
func (r *PHPVersionRepository) IsActive(ctx context.Context, version string) (bool, error) {
|
||||
var active bool
|
||||
err := r.pool.QueryRow(ctx, `SELECT is_active FROM php_versions WHERE version = $1`, version).Scan(&active)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return false, nil
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return phpversions.Contains(version), nil
|
||||
}
|
||||
return phpversions.Contains(version), nil
|
||||
}
|
||||
return active, err
|
||||
}
|
||||
|
||||
func defaultPHPVersions() []string {
|
||||
return []string{"8.1", "8.2", "8.3", "8.4"}
|
||||
return active, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user