dis: Display initial statistics

This commit is contained in:
Tom Wiesing 2022-11-16 16:44:24 +01:00
parent 6d30a42e56
commit 964e74a9f4
No known key found for this signature in database
12 changed files with 252 additions and 7 deletions

View file

@ -1,12 +1,15 @@
#!/bin/bash
set -e
# This script is used to start a user shell inside the docker container.
# if the user is not www-data, re-invoke self as www-data
if [ "$USER" != "www-data" ]; then
sudo -u www-data /bin/bash /user_shell.sh "$@"
exit $?
fi
# Now start a shell in the proper path
cd "/var/www/data/project"
export "PATH=/var/www/data/project/vendor/bin:$PATH"
if [ "$USER" = "www-data" ]; then
/bin/bash "$@"
else
sudo -u www-data /bin/bash "$@"
fi;
# Re-invoke the actual command
/bin/bash "$@"

View file

@ -38,6 +38,9 @@ type Information struct {
LastUpdate time.Time
LastCron time.Time
// Statistics of the wisski (TODO: fix me)
Statistics Statistics
// List of backups made
Snapshots []models.Export
@ -49,3 +52,39 @@ type Information struct {
Prefixes []string // list of prefixes
Pathbuilders map[string]string // all the pathbuilders
}
type Statistics struct {
Activity struct {
MostVisited string `json:"mostVisited"`
PageVisits []struct {
URL string `json:"url"`
Visits int `json:"visits"`
} `json:"pageVisits"`
TotalEditsLastWeek int `json:"totalEditsLastWeek"`
} `json:"activity"`
Bundles struct {
Bundles []struct {
Label string `json:"label"`
MachineName string `json:"machineName"`
Count int `json:"entities"`
LastEdit int `json:"lastEdit"`
MainBundle phpx.BooleanIsh `json:"mainBundle"`
} `json:"bundleStatistics"`
TotalBundles int `json:"totalBundles"`
TotalMainBundles int `json:"totalMainBundles"`
} `json:"bundles"`
Triplestore struct {
Graphs []struct {
URI string `json:"uri"`
Count int `json:"triples"`
} `json:"graphStatistics"`
Total int `json:"totalTriples"`
} `json:"triplestore"`
Users struct {
LastLogin string `json:"lastLogin"`
TotalUsers int `json:"totalUsers"`
} `json:"users"`
}

View file

@ -0,0 +1,37 @@
package extras
import (
_ "embed"
"log"
"github.com/FAU-CDI/wisski-distillery/internal/phpx"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/php"
)
type Stats struct {
ingredient.Base
PHP *php.PHP
}
//go:embed stats.php
var statsPHP string
// Get fetches all statistics from the server
func (stats *Stats) Get(server *phpx.Server) (data ingredient.Statistics, err error) {
err = stats.PHP.ExecScript(server, &data, statsPHP, "export_statistics")
if err != nil {
log.Println(err)
}
return
}
func (stats *Stats) Fetch(flags ingredient.FetchFlags, info *ingredient.Information) (err error) {
if flags.Quick {
return
}
info.Statistics, _ = stats.Get(flags.Server)
return
}

View file

@ -0,0 +1,8 @@
<?php
function export_statistics() {
$service = 'wisski_statistics.statistics';
if (empty(\Drupal::hasService($service))) return (object)[];
$statistics = \Drupal::service($service);
return $statistics->update();
}

View file

@ -99,6 +99,7 @@ func (wisski *WissKI) allIngredients() []initFunc {
auto[*extras.Prefixes],
auto[*extras.Settings],
auto[*extras.Pathbuilder],
auto[*extras.Stats],
// info
manual(func(info *info.Info) {