folder restructuring, namespace adjustments
parent
0d3a7c871b
commit
c4596ace03
|
@ -1,6 +1,6 @@
|
||||||
composer.lock
|
composer.lock
|
||||||
vendor
|
vendor
|
||||||
php/version.php
|
php/federator/version.php
|
||||||
php-docs
|
php-docs
|
||||||
.phpdoc
|
.phpdoc
|
||||||
phpdoc
|
phpdoc
|
||||||
|
|
|
@ -367,7 +367,5 @@ return [
|
||||||
// A list of individual files to include in analysis
|
// A list of individual files to include in analysis
|
||||||
// with a path relative to the root directory of the
|
// with a path relative to the root directory of the
|
||||||
// project.
|
// project.
|
||||||
'file_list' => [
|
'file_list' => [],
|
||||||
'maintenance.php'
|
|
||||||
],
|
|
||||||
];
|
];
|
||||||
|
|
|
@ -9,8 +9,8 @@ path = '../templates/'
|
||||||
compiledir = '../cache'
|
compiledir = '../cache'
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
rediscache = '../plugins/rediscache.php'
|
rediscache = 'rediscache.php'
|
||||||
dummy = '../plugins/dummyconnector.php'
|
dummy = 'dummyconnector.php'
|
||||||
|
|
||||||
[maintenance]
|
[maintenance]
|
||||||
username = 'federatoradmin'
|
username = 'federatoradmin'
|
||||||
|
|
|
@ -12,8 +12,6 @@ if (! array_key_exists('_call', $_REQUEST)) {
|
||||||
}
|
}
|
||||||
date_default_timezone_set("Europe/Berlin");
|
date_default_timezone_set("Europe/Berlin");
|
||||||
spl_autoload_register(static function (string $className) {
|
spl_autoload_register(static function (string $className) {
|
||||||
// strip Federator from class path
|
|
||||||
$className = str_replace('Federator\\', '', $className);
|
|
||||||
include '../php/' . str_replace("\\", "/", strtolower($className)) . '.php';
|
include '../php/' . str_replace("\\", "/", strtolower($className)) . '.php';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,95 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* SPDX-FileCopyrightText: 2024 Sascha Nitsch (grumpydeveloper) https://contentnation.net/@grumpydevelop
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*
|
|
||||||
* @author Sascha Nitsch (grumpydeveloper)
|
|
||||||
**/
|
|
||||||
|
|
||||||
function dbupgrade(\Federator\Main $main)
|
|
||||||
{
|
|
||||||
$config = $main->getConfig();
|
|
||||||
$maintenance = $config['maintenance'];
|
|
||||||
$main->openDatabase($maintenance['username'], $maintenance['password']);
|
|
||||||
$dbh = $main->getDatabase();
|
|
||||||
if ($dbh === false) {
|
|
||||||
die();
|
|
||||||
}
|
|
||||||
$sql = 'select `value` from settings where `key`="database_version"';
|
|
||||||
try {
|
|
||||||
$sth = $dbh->query($sql);
|
|
||||||
} catch (mysqli_sql_exception) {
|
|
||||||
$sth = false;
|
|
||||||
}
|
|
||||||
$version = '0';
|
|
||||||
if ($sth instanceof mysqli_result) {
|
|
||||||
$row = $sth->fetch_row();
|
|
||||||
if (is_array($row)) {
|
|
||||||
$version = $row[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
echo "current version: $version\n";
|
|
||||||
$updateFolder = opendir("sql");
|
|
||||||
if ($updateFolder === false) {
|
|
||||||
die();
|
|
||||||
}
|
|
||||||
$updates = [];
|
|
||||||
while (($file = readdir($updateFolder)) !== false) {
|
|
||||||
$matches = [];
|
|
||||||
if (preg_match('/^(\d{4}-\d{2}-\d{2}).sql$/', $file, $matches) == 1) {
|
|
||||||
if (strcmp($matches[1], $version) > 0) { // file is newer than our version
|
|
||||||
$updates[] = $file;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir($updateFolder);
|
|
||||||
sort($updates);
|
|
||||||
foreach ($updates as $update) {
|
|
||||||
echo "applying update $update\n";
|
|
||||||
$u = fopen('sql/' . $update, 'r');
|
|
||||||
if ($u !== false) {
|
|
||||||
try {
|
|
||||||
$dbh->begin_transaction();
|
|
||||||
// apply updates line by line
|
|
||||||
while (($line = fgets($u)) !== false) {
|
|
||||||
$line = trim($line);
|
|
||||||
$dbh->query($line);
|
|
||||||
}
|
|
||||||
$dbh->commit();
|
|
||||||
} catch (mysqli_sql_exception $e) {
|
|
||||||
//print_r($e);
|
|
||||||
echo "error while applying update $update: " . $e->getMessage() . "\n";
|
|
||||||
}
|
|
||||||
fclose($u);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function printUsage()
|
|
||||||
{
|
|
||||||
echo "usage php maintenance.php <command>\n";
|
|
||||||
echo "command can be one of:\n";
|
|
||||||
echo " dbupgrade - this upgrades the db to the most recent version. Run this after you updated the program files\n";
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
date_default_timezone_set("Europe/Berlin");
|
|
||||||
spl_autoload_register(static function (string $className) {
|
|
||||||
$root = array_key_exists('DOCUMENT_ROOT', $_SERVER) ? $_SERVER['DOCUMENT_ROOT'] : '';
|
|
||||||
// strip Federator from class path
|
|
||||||
$className = str_replace('Federator\\', '', $className);
|
|
||||||
include $root . 'php/' . str_replace("\\", "/", strtolower($className)) . '.php';
|
|
||||||
});
|
|
||||||
|
|
||||||
if ($argc < 2) {
|
|
||||||
printUsage();
|
|
||||||
}
|
|
||||||
|
|
||||||
$main = new \Federator\Main('');
|
|
||||||
switch ($argv[1]) {
|
|
||||||
case 'dbupgrade':
|
|
||||||
dbupgrade($main);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
printUsage();
|
|
||||||
}
|
|
|
@ -67,7 +67,7 @@ class User
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if use has asked permission
|
* check if use has asked permission
|
||||||
* @param string $p @unused-param
|
* @param string $p
|
||||||
* permission to check
|
* permission to check
|
||||||
*
|
*
|
||||||
* @return bool true if user has permission, false if not
|
* @return bool true if user has permission, false if not
|
|
@ -79,11 +79,11 @@ class Main
|
||||||
/**
|
/**
|
||||||
* constructor
|
* constructor
|
||||||
*
|
*
|
||||||
* @param string $rootDir root directory
|
|
||||||
*/
|
*/
|
||||||
public function __construct($rootDir = '../')
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->responseCode = 200;
|
$this->responseCode = 200;
|
||||||
|
$rootDir = $_SERVER['DOCUMENT_ROOT'] . '../';
|
||||||
$config = parse_ini_file($rootDir . 'config.ini', true);
|
$config = parse_ini_file($rootDir . 'config.ini', true);
|
||||||
if ($config !== false) {
|
if ($config !== false) {
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
@ -141,9 +141,10 @@ class Main
|
||||||
public function loadPlugins() : void
|
public function loadPlugins() : void
|
||||||
{
|
{
|
||||||
if (array_key_exists('plugins', $this->config)) {
|
if (array_key_exists('plugins', $this->config)) {
|
||||||
|
$basepath = $_SERVER['DOCUMENT_ROOT'] . '../plugins/federator/';
|
||||||
$plugins = $this->config['plugins'];
|
$plugins = $this->config['plugins'];
|
||||||
foreach ($plugins as $name => $file) {
|
foreach ($plugins as $name => $file) {
|
||||||
require_once($file);
|
require_once($basepath . $file);
|
||||||
$fktn = 'Federator\\' . $name . '_load';
|
$fktn = 'Federator\\' . $name . '_load';
|
||||||
if (function_exists($fktn)) {
|
if (function_exists($fktn)) {
|
||||||
$fktn($this);
|
$fktn($this);
|
|
@ -0,0 +1,121 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* SPDX-FileCopyrightText: 2024 Sascha Nitsch (grumpydeveloper) https://contentnation.net/@grumpydevelop
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
* @author Sascha Nitsch (grumpydeveloper)
|
||||||
|
**/
|
||||||
|
namespace Federator;
|
||||||
|
|
||||||
|
class Maintenance
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* run maintenance
|
||||||
|
*
|
||||||
|
* @param int $argc number of arguments
|
||||||
|
* @param string[] $argv arguments
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function run($argc, $argv)
|
||||||
|
{
|
||||||
|
date_default_timezone_set("Europe/Berlin");
|
||||||
|
spl_autoload_register(static function (string $className) {
|
||||||
|
$root = $_SERVER['DOCUMENT_ROOT'];
|
||||||
|
include $root . '../php/' . str_replace("\\", "/", strtolower($className)) . '.php';
|
||||||
|
});
|
||||||
|
if ($argc < 2) {
|
||||||
|
self::printUsage();
|
||||||
|
}
|
||||||
|
// pretend that we are running from web directory
|
||||||
|
$_SERVER['DOCUMENT_ROOT'] = realpath('../../htdocs') . '/';
|
||||||
|
$main = new \Federator\Main();
|
||||||
|
switch ($argv[1]) {
|
||||||
|
case 'dbupgrade':
|
||||||
|
self::dbupgrade($main);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
self::printUsage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* upgrade database to newest version
|
||||||
|
*
|
||||||
|
* @param \Federator\Main $main main instance
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function dbupgrade($main)
|
||||||
|
{
|
||||||
|
$config = $main->getConfig();
|
||||||
|
$maintenance = $config['maintenance'];
|
||||||
|
$main->openDatabase($maintenance['username'], $maintenance['password']);
|
||||||
|
$dbh = $main->getDatabase();
|
||||||
|
if ($dbh === false) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
$sql = 'select `value` from settings where `key`="database_version"';
|
||||||
|
try {
|
||||||
|
$sth = $dbh->query($sql);
|
||||||
|
} catch (\mysqli_sql_exception) {
|
||||||
|
$sth = false;
|
||||||
|
}
|
||||||
|
$version = '0';
|
||||||
|
if ($sth instanceof \mysqli_result) {
|
||||||
|
$row = $sth->fetch_row();
|
||||||
|
if (is_array($row)) {
|
||||||
|
$version = $row[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo "current version: $version\n";
|
||||||
|
$root = $_SERVER['DOCUMENT_ROOT'] . '../';
|
||||||
|
$updateFolder = opendir($root . 'sql');
|
||||||
|
if ($updateFolder === false) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
$updates = [];
|
||||||
|
while (($file = readdir($updateFolder)) !== false) {
|
||||||
|
$matches = [];
|
||||||
|
if (preg_match('/^(\d{4}-\d{2}-\d{2}).sql$/', $file, $matches) == 1) {
|
||||||
|
if (strcmp($matches[1], $version) > 0) { // file is newer than our version
|
||||||
|
$updates[] = $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir($updateFolder);
|
||||||
|
sort($updates);
|
||||||
|
foreach ($updates as $update) {
|
||||||
|
echo "applying update $update\n";
|
||||||
|
$u = fopen($root . 'sql/' . $update, 'r');
|
||||||
|
if ($u !== false) {
|
||||||
|
try {
|
||||||
|
$dbh->begin_transaction();
|
||||||
|
// apply updates line by line
|
||||||
|
while (($line = fgets($u)) !== false) {
|
||||||
|
$line = trim($line);
|
||||||
|
$dbh->query($line);
|
||||||
|
}
|
||||||
|
$dbh->commit();
|
||||||
|
} catch (\mysqli_sql_exception $e) {
|
||||||
|
echo "error while applying update $update: " . $e->getMessage() . "\n";
|
||||||
|
}
|
||||||
|
fclose($u);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* print usage of maintenance tool
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function printUsage()
|
||||||
|
{
|
||||||
|
echo "usage php maintenance.php <command>\n";
|
||||||
|
echo "command can be one of:\n";
|
||||||
|
echo " dbupgrade - this upgrades the db to the most recent version. Run this after you updated the program files\n";
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Maintenance::run($argc, $argv);
|
|
@ -35,9 +35,9 @@ class RedisCache implements Cache
|
||||||
private $redis;
|
private $redis;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* user cache time to life
|
* user cache time to live in secods
|
||||||
*
|
*
|
||||||
* @var int time to life in secons
|
* @var int $userTTL
|
||||||
*/
|
*/
|
||||||
private $userTTL;
|
private $userTTL;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
git log | head -n1 | awk '{print "<?php\nglobal $version;\n$version=\"" $2 "\";\n"}' > php/version.php
|
git log | head -n1 | awk '{print "<?php\nglobal $version;\n$version=\"" $2 "\";\n"}' > php/federator/version.php
|
||||||
vendor/phan/phan/phan
|
vendor/bin/phan
|
||||||
./phpdoc
|
./phpdoc
|
||||||
|
|
Loading…
Reference in New Issue