Add Status Report to Info page
This commit is contained in:
parent
cda68d3454
commit
f5c5999f44
11 changed files with 361 additions and 20 deletions
66
internal/wisski/ingredient/php/extras/requirements.go
Normal file
66
internal/wisski/ingredient/php/extras/requirements.go
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
package extras
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/phpx"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/status"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/php"
|
||||
"golang.org/x/exp/slices"
|
||||
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
type Requirements struct {
|
||||
ingredient.Base
|
||||
Dependencies struct {
|
||||
PHP *php.PHP
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
_ ingredient.WissKIFetcher = (*Requirements)(nil)
|
||||
)
|
||||
|
||||
//go:embed requirements.php
|
||||
var requirementsPHP string
|
||||
|
||||
// Create creates a new block with the given title and html content
|
||||
func (requirements *Requirements) Get(ctx context.Context, server *phpx.Server) (data []status.Requirement, err error) {
|
||||
err = requirements.Dependencies.PHP.ExecScript(ctx, server, &data, requirementsPHP, "get_requirements", requirements.URL().String())
|
||||
if err == nil {
|
||||
// sort first by weight, then by id!
|
||||
slices.SortFunc(data, func(a, b status.Requirement) bool {
|
||||
// compare first by weight
|
||||
if a.Weight < b.Weight {
|
||||
return true
|
||||
}
|
||||
if a.Weight > b.Weight {
|
||||
return false
|
||||
}
|
||||
|
||||
// then by severity
|
||||
if a.Severity < b.Severity {
|
||||
return true
|
||||
}
|
||||
if a.Severity > b.Severity {
|
||||
return false
|
||||
}
|
||||
|
||||
// and finally by id
|
||||
return a.ID < b.ID
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Fetch fetches information
|
||||
func (requirements *Requirements) Fetch(flags ingredient.FetcherFlags, target *status.WissKI) error {
|
||||
if flags.Quick {
|
||||
return nil
|
||||
}
|
||||
|
||||
target.Requirements, _ = requirements.Get(flags.Context, flags.Server)
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue