Move wisski instance code to separate package
This commit is contained in:
parent
7c3c84e116
commit
063f3f9b7d
67 changed files with 533 additions and 409 deletions
77
internal/wisski/php/export_pathbuilder.php
Normal file
77
internal/wisski/php/export_pathbuilder.php
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
use Drupal\wisski_pathbuilder\Entity\WisskiPathEntity;
|
||||
|
||||
/** all_xml lists all pathbuilders, and returns the corresponding xml */
|
||||
function all_xml(): object {
|
||||
$all = \Drupal::entityTypeManager()->getStorage('wisski_pathbuilder')->loadMultiple();
|
||||
return (object)array_map("entity_to_xml", $all);
|
||||
}
|
||||
|
||||
|
||||
/** all_list lists the ids of all pathbuilders */
|
||||
function all_list(): Array {
|
||||
return array_keys(\Drupal::entityQuery('wisski_pathbuilder')->execute());
|
||||
}
|
||||
|
||||
/** one_xml serializes a single pathbuilder as xml */
|
||||
function one_xml(string $id): string {
|
||||
$pb = \Drupal::entityTypeManager()->getStorage('wisski_pathbuilder')->load($id);
|
||||
if ($pb === NULL) {
|
||||
return "";
|
||||
}
|
||||
return entity_to_xml($pb);
|
||||
}
|
||||
|
||||
// =================================================================================
|
||||
// =================================================================================
|
||||
|
||||
|
||||
function entity_to_xml($pb) {
|
||||
$xml = new \SimpleXMLElement("<pathbuilderinterface></pathbuilderinterface>");
|
||||
|
||||
$paths = $pb->getAllPaths();
|
||||
foreach ($paths as $key => $path) {
|
||||
$id = $path->getID();
|
||||
|
||||
$path = $pb->getPbPath($id);
|
||||
|
||||
$pathChild = $xml->addChild("path");
|
||||
$pathObject = WisskiPathEntity::load($id);
|
||||
|
||||
foreach ($path as $subkey => $value) {
|
||||
|
||||
if (in_array($subkey, ['relativepath'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($subkey == "parent") {
|
||||
$subkey = "group_id";
|
||||
}
|
||||
|
||||
$pathChild->addChild($subkey, htmlspecialchars($value));
|
||||
}
|
||||
|
||||
$pathArray = $pathChild->addChild('path_array');
|
||||
foreach ($pathObject->getPathArray() as $subkey => $value) {
|
||||
$pathArray->addChild($subkey % 2 == 0 ? 'x' : 'y', $value);
|
||||
}
|
||||
|
||||
$pathChild->addChild('datatype_property', htmlspecialchars($pathObject->getDatatypeProperty()));
|
||||
$pathChild->addChild('short_name', htmlspecialchars($pathObject->getShortName()));
|
||||
$pathChild->addChild('disamb', htmlspecialchars($pathObject->getDisamb()));
|
||||
$pathChild->addChild('description', htmlspecialchars($pathObject->getDescription()));
|
||||
$pathChild->addChild('uuid', htmlspecialchars($pathObject->uuid()));
|
||||
if ($pathObject->getType() == "Group" || $pathObject->getType() == "Smartgroup") {
|
||||
$pathChild->addChild('is_group', "1");
|
||||
} else {
|
||||
$pathChild->addChild('is_group', "0");
|
||||
}
|
||||
$pathChild->addChild('name', htmlspecialchars($pathObject->getName()));
|
||||
}
|
||||
|
||||
// turn it into XML
|
||||
$dom = dom_import_simplexml($xml)->ownerDocument;
|
||||
$dom->formatOutput = TRUE;
|
||||
return $dom->saveXML();
|
||||
}
|
||||
51
internal/wisski/php/list_uri_prefixes.php
Normal file
51
internal/wisski/php/list_uri_prefixes.php
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* list_prefixes lists all content prefixes known to this WissKI.
|
||||
* Prefixes are not filtered, and may contain duplicates.
|
||||
*/
|
||||
function list_prefixes() {
|
||||
$prefixes = [];
|
||||
$storage = \Drupal::entityTypeManager()->getStorage('wisski_salz_adapter');
|
||||
foreach ($storage->loadMultiple() as $adapter) {
|
||||
// load all the prefixes from the triplestore
|
||||
$engine = $adapter->getEngine();
|
||||
getTriplestorePrefixes($adapter->getEngine(), $prefixes);
|
||||
|
||||
// read the configuration to check if we have a default graph
|
||||
$conf = $engine->getConfiguration();
|
||||
if(!array_key_exists('default_graph', $conf)) {
|
||||
continue;
|
||||
}
|
||||
$prefixes[] = $conf['default_graph'];
|
||||
}
|
||||
return $prefixes;
|
||||
}
|
||||
|
||||
function getTriplestorePrefixes($engine, &$prefixes) {
|
||||
// some adapters don't support a query method!
|
||||
if (!method_exists($engine, 'directQuery')) return NULL;
|
||||
|
||||
$results = $engine->directQuery('
|
||||
select distinct ?base where {
|
||||
{
|
||||
select distinct ?iri where {
|
||||
{
|
||||
select distinct (?s as ?iri) { ?s ?p ?o }
|
||||
} union {
|
||||
select distinct (?o as ?iri) { ?s ?p ?o FILTER(isiri(?o)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
BIND(replace(str(?iri), "/[^/]*/?$", "/") as ?base)
|
||||
FILTER(!REGEX(?base, "/wisski/navigate/[\\\\d]+/$"))
|
||||
} ORDER BY ?base');
|
||||
if (!$results) return FALSE;
|
||||
|
||||
foreach($results as $result) {
|
||||
$prefixes[] = $result->base->getValue();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
34
internal/wisski/php/server.php
Normal file
34
internal/wisski/php/server.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
// This file contains code to execute a php execution server.
|
||||
// It is passed as a *command line literal * directly to 'drush:script'.
|
||||
//
|
||||
// As such it is preprocessed and shortened.
|
||||
// It should only contain comments at the beginning of each line, and only starting with '//'.
|
||||
// See wisski_php_server.go.
|
||||
|
||||
// don't buffer stdin!
|
||||
stream_set_read_buffer(STDIN,0);
|
||||
|
||||
// stop all other output
|
||||
ob_start(null,0,PHP_OUTPUT_HANDLER_CLEANABLE);
|
||||
|
||||
while($line = fgets(STDIN)){
|
||||
// decode the command to run
|
||||
$code=@json_decode($line);
|
||||
|
||||
// execute it
|
||||
try{
|
||||
$json = json_encode([eval($code),""]);
|
||||
}catch(Throwable $t){
|
||||
$json = json_encode([null,(string)$t]);
|
||||
}
|
||||
if($json===false) {
|
||||
$json = '[null,"Error encoding result"]';
|
||||
}
|
||||
|
||||
// and write out the result
|
||||
ob_end_clean();
|
||||
fwrite(STDOUT,"$json\n");
|
||||
ob_start(null,0,PHP_OUTPUT_HANDLER_CLEANABLE);
|
||||
}
|
||||
29
internal/wisski/php/settings.php
Normal file
29
internal/wisski/php/settings.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
/** gets a setting from 'settings.php' */
|
||||
function get_setting($name) {
|
||||
use \Drupal\Core\Site\Settings;
|
||||
return Settings::get($name);
|
||||
}
|
||||
|
||||
/** sets a setting in 'settings.php' */
|
||||
function set_setting($name, $value) {
|
||||
// load install.inc
|
||||
if(is_file(DRUPAL_ROOT . "/internal/")) {
|
||||
include_once DRUPAL_ROOT . "/internal/core/includes/install.inc";
|
||||
} else {
|
||||
include_once DRUPAL_ROOT . "/core/includes/install.inc";
|
||||
}
|
||||
|
||||
// update the provided setting
|
||||
$settings["settings"][$name] = (object)[
|
||||
"value" => $value,
|
||||
"required" => TRUE,
|
||||
];
|
||||
|
||||
// find the filename
|
||||
$filename = DRUPAL_ROOT . "/" . \Drupal::service("site.path") . "/settings.php";
|
||||
drupal_rewrite_settings($settings, $filename);
|
||||
|
||||
return True;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue