Commit 322fa243 authored by Erick Hitter's avatar Erick Hitter
Browse files

Begin switching to JSON results and sane data structures

CSV is too hacky, and it was only used because #113 disguised why JSON didn't work.
parent 042e9f78
...@@ -70,7 +70,7 @@ class Orchestrate extends \WP_CLI_Command { ...@@ -70,7 +70,7 @@ class Orchestrate extends \WP_CLI_Command {
public function get_info( $args, $assoc_args ) { public function get_info( $args, $assoc_args ) {
$info = array( $info = array(
array( array(
'multisite' => is_multisite() ? "true" : "false", 'multisite' => is_multisite() ? 1 : 0,
'siteurl' => site_url(), 'siteurl' => site_url(),
), ),
); );
......
...@@ -2,6 +2,7 @@ package main ...@@ -2,6 +2,7 @@ package main
import ( import (
"encoding/csv" "encoding/csv"
"encoding/json"
"flag" "flag"
"fmt" "fmt"
"log" "log"
...@@ -12,6 +13,11 @@ import ( ...@@ -12,6 +13,11 @@ import (
"time" "time"
) )
type SiteInfo struct {
Multisite int
Siteurl string
}
type Event struct { type Event struct {
url string url string
timestamp string timestamp string
...@@ -124,14 +130,12 @@ func keepAlive() { ...@@ -124,14 +130,12 @@ func keepAlive() {
} }
func getSites() ([][]string, error) { func getSites() ([][]string, error) {
siteInfo, err := getWpCliOutput([]string{"cron-control", "orchestrate", "get-info"}) siteInfo, err := getInstanceInfo()
if err != nil { if err != nil {
return make([][]string,0), err return make([][]string,0), err
} }
isMultisite, siteUrl := siteInfo[1][0], siteInfo[1][1] if siteInfo.Multisite == 1 {
if isMultisite == "true" {
sites, err := getWpCliOutput([]string{"site", "list", "--fields=url", "--archived=false", "--deleted=false", "--spam=false"}) sites, err := getWpCliOutput([]string{"site", "list", "--fields=url", "--archived=false", "--deleted=false", "--spam=false"})
if err != nil { if err != nil {
...@@ -145,7 +149,7 @@ func getSites() ([][]string, error) { ...@@ -145,7 +149,7 @@ func getSites() ([][]string, error) {
sites[0] = make([]string,0) sites[0] = make([]string,0)
sites[0] = append(sites[0], "url") sites[0] = append(sites[0], "url")
sites[1] = make([]string,0) sites[1] = make([]string,0)
sites[1] = append(sites[1], siteUrl) sites[1] = append(sites[1], siteInfo.Siteurl)
return sites, nil return sites, nil
} }
...@@ -194,6 +198,20 @@ func runEvents(workerId int, events <-chan Event) { ...@@ -194,6 +198,20 @@ func runEvents(workerId int, events <-chan Event) {
} }
} }
func getInstanceInfo() (SiteInfo, error) {
raw, err := runWpCliCmd([]string{"cron-control", "orchestrate", "get-info","--format=json"})
if err != nil {
return SiteInfo{}, err
}
jsonRes := make([]SiteInfo,0)
if err = json.Unmarshal([]byte(raw), &jsonRes); err != nil {
return SiteInfo{}, err
}
return jsonRes[0], nil
}
func getWpCliOutput(subcommand []string) ([][]string, error) { func getWpCliOutput(subcommand []string) ([][]string, error) {
subcommand = append(subcommand, "--format=csv") subcommand = append(subcommand, "--format=csv")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment