diff --git a/.gitignore b/.gitignore index 4f14251..d222587 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ composer.lock vendor -php/version.php +php/federator/version.php php-docs .phpdoc phpdoc diff --git a/.phan/config.php b/.phan/config.php index 467e60d..8c7f84a 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -367,7 +367,5 @@ return [ // A list of individual files to include in analysis // with a path relative to the root directory of the // project. - 'file_list' => [ - 'maintenance.php' - ], + 'file_list' => [], ]; diff --git a/config.ini b/config.ini index a14e900..d2f0e56 100644 --- a/config.ini +++ b/config.ini @@ -9,8 +9,8 @@ path = '../templates/' compiledir = '../cache' [plugins] -rediscache = '../plugins/rediscache.php' -dummy = '../plugins/dummyconnector.php' +rediscache = 'rediscache.php' +dummy = 'dummyconnector.php' [maintenance] username = 'federatoradmin' diff --git a/htdocs/api.php b/htdocs/api.php index 2a14e74..5bf4f65 100644 --- a/htdocs/api.php +++ b/htdocs/api.php @@ -12,8 +12,6 @@ if (! array_key_exists('_call', $_REQUEST)) { } date_default_timezone_set("Europe/Berlin"); spl_autoload_register(static function (string $className) { - // strip Federator from class path - $className = str_replace('Federator\\', '', $className); include '../php/' . str_replace("\\", "/", strtolower($className)) . '.php'; }); diff --git a/maintenance.php b/maintenance.php deleted file mode 100644 index 5f42688..0000000 --- a/maintenance.php +++ /dev/null @@ -1,95 +0,0 @@ -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 \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(); -} diff --git a/php/api.php b/php/federator/api.php similarity index 100% rename from php/api.php rename to php/federator/api.php diff --git a/php/api/v1.php b/php/federator/api/v1.php similarity index 100% rename from php/api/v1.php rename to php/federator/api/v1.php diff --git a/php/api/v1/dummy.php b/php/federator/api/v1/dummy.php similarity index 100% rename from php/api/v1/dummy.php rename to php/federator/api/v1/dummy.php diff --git a/php/cache/cache.php b/php/federator/cache/cache.php similarity index 100% rename from php/cache/cache.php rename to php/federator/cache/cache.php diff --git a/php/connector/connector.php b/php/federator/connector/connector.php similarity index 100% rename from php/connector/connector.php rename to php/federator/connector/connector.php diff --git a/php/data/user.php b/php/federator/data/user.php similarity index 98% rename from php/data/user.php rename to php/federator/data/user.php index 92e9362..bbc7015 100644 --- a/php/data/user.php +++ b/php/federator/data/user.php @@ -67,7 +67,7 @@ class User /** * check if use has asked permission - * @param string $p @unused-param + * @param string $p * permission to check * * @return bool true if user has permission, false if not diff --git a/php/dio/user.php b/php/federator/dio/user.php similarity index 100% rename from php/dio/user.php rename to php/federator/dio/user.php diff --git a/php/exceptions/exception.php b/php/federator/exceptions/exception.php similarity index 100% rename from php/exceptions/exception.php rename to php/federator/exceptions/exception.php diff --git a/php/exceptions/filenotfound.php b/php/federator/exceptions/filenotfound.php similarity index 100% rename from php/exceptions/filenotfound.php rename to php/federator/exceptions/filenotfound.php diff --git a/php/exceptions/invalidargument.php b/php/federator/exceptions/invalidargument.php similarity index 100% rename from php/exceptions/invalidargument.php rename to php/federator/exceptions/invalidargument.php diff --git a/php/exceptions/permissiondenied.php b/php/federator/exceptions/permissiondenied.php similarity index 100% rename from php/exceptions/permissiondenied.php rename to php/federator/exceptions/permissiondenied.php diff --git a/php/exceptions/servererror.php b/php/federator/exceptions/servererror.php similarity index 100% rename from php/exceptions/servererror.php rename to php/federator/exceptions/servererror.php diff --git a/php/exceptions/unauthorized.php b/php/federator/exceptions/unauthorized.php similarity index 100% rename from php/exceptions/unauthorized.php rename to php/federator/exceptions/unauthorized.php diff --git a/php/language.php b/php/federator/language.php similarity index 100% rename from php/language.php rename to php/federator/language.php diff --git a/php/main.php b/php/federator/main.php similarity index 96% rename from php/main.php rename to php/federator/main.php index 36aec45..3c52abe 100644 --- a/php/main.php +++ b/php/federator/main.php @@ -79,11 +79,11 @@ class Main /** * constructor * - * @param string $rootDir root directory */ - public function __construct($rootDir = '../') + public function __construct() { $this->responseCode = 200; + $rootDir = $_SERVER['DOCUMENT_ROOT'] . '../'; $config = parse_ini_file($rootDir . 'config.ini', true); if ($config !== false) { $this->config = $config; @@ -141,9 +141,10 @@ class Main public function loadPlugins() : void { if (array_key_exists('plugins', $this->config)) { + $basepath = $_SERVER['DOCUMENT_ROOT'] . '../plugins/federator/'; $plugins = $this->config['plugins']; foreach ($plugins as $name => $file) { - require_once($file); + require_once($basepath . $file); $fktn = 'Federator\\' . $name . '_load'; if (function_exists($fktn)) { $fktn($this); diff --git a/php/federator/maintenance.php b/php/federator/maintenance.php new file mode 100644 index 0000000..e518f2c --- /dev/null +++ b/php/federator/maintenance.php @@ -0,0 +1,121 @@ +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 \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); diff --git a/plugins/dummyconnector.php b/plugins/federator/dummyconnector.php similarity index 100% rename from plugins/dummyconnector.php rename to plugins/federator/dummyconnector.php diff --git a/plugins/rediscache.php b/plugins/federator/rediscache.php similarity index 97% rename from plugins/rediscache.php rename to plugins/federator/rediscache.php index cf9b47a..fccdc75 100644 --- a/plugins/rediscache.php +++ b/plugins/federator/rediscache.php @@ -35,9 +35,9 @@ class RedisCache implements Cache 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; diff --git a/release.sh b/release.sh index 75af5b6..3b07dbd 100644 --- a/release.sh +++ b/release.sh @@ -1,4 +1,4 @@ #!/bin/bash -git log | head -n1 | awk '{print " php/version.php -vendor/phan/phan/phan +git log | head -n1 | awk '{print " php/federator/version.php +vendor/bin/phan ./phpdoc