Initial status page
This commit is contained in:
parent
a3511b1bfc
commit
a1f35b97d3
17 changed files with 618 additions and 83 deletions
|
|
@ -1,34 +1,45 @@
|
|||
package instances
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
_ "embed"
|
||||
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
"golang.org/x/exp/maps"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
var errPathbuildersExecFailed = errors.New("ExportPathbuilders: Failed to call export_pathbuilder")
|
||||
//go:embed php/export_pathbuilder.php
|
||||
var exportPathbuilderPHP string
|
||||
|
||||
// Pathbuilders returns the ids of all pathbuilders in consistent order.
|
||||
func (wisski *WissKI) Pathbuilders() (ids []string, err error) {
|
||||
err = wisski.ExecPHPScript(stream.FromNil(), &ids, exportPathbuilderPHP, "all_list")
|
||||
slices.Sort(ids)
|
||||
return
|
||||
}
|
||||
|
||||
// Pathbuilder returns a single pathbuilder as xml.
|
||||
// If it does not exist, it returns the empty string and nil error.
|
||||
func (wisski *WissKI) Pathbuilder(id string) (xml string, err error) {
|
||||
err = wisski.ExecPHPScript(stream.FromNil(), &xml, exportPathbuilderPHP, "one_xml", id)
|
||||
return
|
||||
}
|
||||
|
||||
// AllPathbuilders returns all pathbuilders serialized as xml
|
||||
func (wisski *WissKI) AllPathbuilders() (pathbuilders map[string]string, err error) {
|
||||
err = wisski.ExecPHPScript(stream.FromNil(), &pathbuilders, exportPathbuilderPHP, "all_xml")
|
||||
return
|
||||
}
|
||||
|
||||
// ExportPathbuilders writes pathbuilders into the directory dest
|
||||
func (wisski *WissKI) ExportPathbuilders(dest string) error {
|
||||
// export all the pathbuilders into the buffer
|
||||
var buffer bytes.Buffer
|
||||
wu := stream.NewIOStream(&buffer, nil, nil, 0)
|
||||
code, err := wisski.Barrel().Exec(wu, "barrel", "/bin/bash", "/user_shell.sh", "-c", "drush php:script /wisskiutils/export_pathbuilder.php")
|
||||
if err != nil || code != 0 {
|
||||
return errPathbuildersExecFailed
|
||||
}
|
||||
|
||||
// decode them as a json array
|
||||
var pathbuilders map[string]string
|
||||
if err := json.NewDecoder(&buffer).Decode(&pathbuilders); err != nil {
|
||||
pathbuilders, err := wisski.AllPathbuilders()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue