From 86029bc54f01a089ce97f64b4a15a86e123876e4 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 27 Sep 2021 23:14:01 +0200 Subject: [PATCH] impl. todos or move to Project.md --- Ai/Ocr/BasicOcr.php | 1 - Algorithm/Clustering/Kmeans.php | 8 +-- Algorithm/JobScheduling/Weighted.php | 4 -- Application/ApplicationManager.php | 59 +++++++++++++++++-- Autoloader.php | 3 +- .../Database/Connection/MysqlConnection.php | 1 - DataStorage/Database/DataMapperAbstract.php | 37 +----------- DataStorage/Database/Schema/Builder.php | 18 +++--- Localization/L11nManager.php | 23 ++++++++ Message/Http/Rest.php | 11 +--- Module/InstallerAbstract.php | 27 --------- README.md | 2 +- tests/Application/ApplicationManagerTest.php | 3 +- 13 files changed, 94 insertions(+), 103 deletions(-) diff --git a/Ai/Ocr/BasicOcr.php b/Ai/Ocr/BasicOcr.php index d15b19e63..77caef568 100644 --- a/Ai/Ocr/BasicOcr.php +++ b/Ai/Ocr/BasicOcr.php @@ -189,7 +189,6 @@ final class BasicOcr { $predictedLabels = []; foreach ($Xtest as $sample) { - // @todo: consider to path the k-limit to the getDistances function for earlier filtering $distances = $this->getDistances($Xtrain, $sample); \asort($distances); diff --git a/Algorithm/Clustering/Kmeans.php b/Algorithm/Clustering/Kmeans.php index 0e708ae25..47191af89 100644 --- a/Algorithm/Clustering/Kmeans.php +++ b/Algorithm/Clustering/Kmeans.php @@ -148,13 +148,7 @@ final class Kmeans foreach ($clusterCenters as $center) { for ($i = 0; $i < $coordinates; ++$i) { - /** - * @todo Orange-Management/phpOMS#229 - * Invalid center coodinate value - * In some cases the center point of a cluster belongs to the group 0 in this case the coordinate value is not working correctly. - * As a quick fix the value is set to `1` in such a case but probably has multiple side effects. - * Maybe it makes sense to just use `$center->group + 1` or set the value to `0`. - */ + // @todo Invalid center coodinate value in like 5 % of the runs $center->setCoordinate($i, $center->getCoordinate($i) / ($center->group === 0 ? 1 : $center->group)); } } diff --git a/Algorithm/JobScheduling/Weighted.php b/Algorithm/JobScheduling/Weighted.php index 6e224da41..03cb5d5b0 100644 --- a/Algorithm/JobScheduling/Weighted.php +++ b/Algorithm/JobScheduling/Weighted.php @@ -104,10 +104,6 @@ final class Weighted * * @return JobInterface[] * - * @todo Orange-Management/phpOMS#244 - * [JobScheduling] Implement test for Jobs with same value. - * There is no test case for the else clause in the `solve` function. Implement it. - * * @since 1.0.0 */ public static function solve(array $jobs) : array diff --git a/Application/ApplicationManager.php b/Application/ApplicationManager.php index a43c08e8f..4e3ecab84 100644 --- a/Application/ApplicationManager.php +++ b/Application/ApplicationManager.php @@ -40,12 +40,12 @@ final class ApplicationManager private ApplicationAbstract $app; /** - * Applications + * Installed modules. * - * @var ApplicationInfo[] + * @var array * @since 1.0.0 */ - private array $applications = []; + private array $installed = []; /** * Constructor. @@ -107,8 +107,8 @@ final class ApplicationManager } try { - $info = $this->loadInfo($source . '/info.json'); - $this->applications[$info->getInternalName()] = $info; + $info = $this->loadInfo($source . '/info.json'); + $this->installed[$info->getInternalName()] = $info; $this->installFiles($source, $destination); $this->replacePlaceholder($destination); @@ -122,6 +122,55 @@ final class ApplicationManager } } + public function getProvidingForModule(string $module) : array + { + $providing = []; + $installed = $this->getInstalledApplications(); + + foreach ($installed as $app => $info) { + if (!isset($providing[$app])) { + $providing[$app] = []; + } + + $appProviding = $info->getProviding(); + foreach ($appProviding as $for => $version) { + if ($for !== $module) { + continue; + } + + $providing[$app][] = $for; + } + } + + return $providing; + } + + /** + * Get all installed modules. + * + * @param bool $useCache Use Cache + * + * @return array + * + * @since 1.0.0 + */ + public function getInstalledApplications(bool $useCache = true) : array + { + if (empty($this->installed) || !$useCache) { + $apps = \scandir(__DIR__ . '/../../Web'); + + foreach ($apps as $app) { + if ($app === '.' || $app === '..' || !\is_file(__DIR__ . '/../../Web/' . $app . '/info.json')) { + continue; + } + + $this->installed[$app] = $this->loadInfo(__DIR__ . '/../../Web/' . $app . '/info.json'); + } + } + + return $this->installed; + } + /** * Install the files to the destination * diff --git a/Autoloader.php b/Autoloader.php index 1c0536832..d740f5399 100644 --- a/Autoloader.php +++ b/Autoloader.php @@ -139,14 +139,13 @@ final class Autoloader /** * Invalidate a already loaded file * - * IMPORTANT: This does not reload an already loaded file + * IMPORTANT: This does not reload an already loaded file, this is not possible. * * @param string $class Class to invalidate * * @return bool * * @since 1.0.0 - * @todo Find a way to re-load aready loaded files. This can be important for changed scripts */ public static function invalidate(string $class) : bool { diff --git a/DataStorage/Database/Connection/MysqlConnection.php b/DataStorage/Database/Connection/MysqlConnection.php index 520aadcc6..7576a1ef2 100644 --- a/DataStorage/Database/Connection/MysqlConnection.php +++ b/DataStorage/Database/Connection/MysqlConnection.php @@ -16,7 +16,6 @@ namespace phpOMS\DataStorage\Database\Connection; use phpOMS\DataStorage\Database\DatabaseStatus; use phpOMS\DataStorage\Database\DatabaseType; -use phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException; use phpOMS\DataStorage\Database\Query\Grammar\MysqlGrammar; use phpOMS\DataStorage\Database\Schema\Grammar\MysqlGrammar as MysqlSchemaGrammar; diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index 805056a07..0d3c4547e 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -32,52 +32,17 @@ use phpOMS\Utils\ArrayUtils; * @link https://orange-management.org * @since 1.0.0 * - * @todo Orange-Management/phpOMS#122 - * Split/Refactor. - * Child extends parent. Parent creates GetMapper, CreateMapper etc. - * Example: - * ```User::get(...)``` - * The get() function (defined in an abstract class) creates internally an instance of GetMapper. - * The GetMapper receives all information such as primaryField, columns etc internally from the get(). - * This transfer of knowledge to the GetMapper could be done in the abstract class as a setup() function. - * Now all mappers are split. The overhead is one additional function call and the setup() function. - * Alternatively, think about using traits in the beginning. - * - * @todo Orange-Management/Modules#99 - * Use binds - * Currently databinds are not used. Currently injections are possible. - * - * @todo Orange-Management/phpOMS#241 - * [DataMapper] Consider global conditionals - * In some cases conditionals in the mapper are typed again and again - * e.g. language conditional for localization purposes - * This is very annoying and maybe could be defined once in a `$conditionalsGlobal = [];` array. - * This array then populates the `$conditionals` array in the mapper. - * Overwriting the global conditionals could be possible by defining a conditional as `null`. - * * @todo Orange-Management/phpOMS#242 * [DataMapper] Conditional queries bugs/problems * Corrupted conditional relations are not shown and therefor cannot be fixed by the user e.g. * * Tag is created * * No l11n is created - * -> The tags without l11n are not shown in the list and therefor the user doesn't know about them and cannot fix them. + * -> The tags without l11n are not shown in the list and therefor the user doesn't know about them and cannot fix them. (wrong join type?) * If the defined conditional doesn't exist (e.g. language) the element is not shown at all. * This can be a problem if the user wants the conditional as preferred result * but also accepts alternatives if nothing exists for this conditional but for other conditionals. E.g. * * News article doesn't exist in the defined l11n * * However if the article exists in english language it should at least show in that language. - * - * @todo Orange-Management/phpOMS#??? - * Use more column/field names instead of model variable names - * Consider to replace the model member variable name in the `column` definition of hasMany etc. definitions with the actual column name. This could be faster. - * This could make it faster since we don't need to do a reverse look up. - * Maybe this will require us to do a different lookup however which costs a similar amount of time? - * - * @todo Orange-Management/phpOMS#??? - * Concise usage of runtime evaluations vs hard-coded definitions - * Most of the time we are using Mapper::class etc. but there are still places where we use 'table' => 'table_name' instead of Mapper::$table. - * The Mapper::$table approach is probably better for future code changes but makes it probably also slower. - * We really need to decide to follow one path and implement this everywhere. */ class DataMapperAbstract implements DataMapperInterface { diff --git a/DataStorage/Database/Schema/Builder.php b/DataStorage/Database/Schema/Builder.php index 4d1c13b8e..0cd6f0016 100644 --- a/DataStorage/Database/Schema/Builder.php +++ b/DataStorage/Database/Schema/Builder.php @@ -67,6 +67,16 @@ class Builder extends QueryBuilder */ public array $selectTables = ['*']; + /** + * Always calls compileCreateTableSettings in the Grammar + * + * This is important to set the correct table settings (e.g. utf8mb4 instead of utf8) + * + * @var bool + * @since 1.0.0 + */ + public bool $createTableSettings = true; + /** * Select fields. * @@ -75,14 +85,6 @@ class Builder extends QueryBuilder */ public string $selectFields = ''; - /** - * @todo: ?????. - * - * @var bool - * @since 1.0.0 - */ - public bool $createTableSettings = true; - /** * Table to alter. * diff --git a/Localization/L11nManager.php b/Localization/L11nManager.php index c94e55868..037341682 100644 --- a/Localization/L11nManager.php +++ b/Localization/L11nManager.php @@ -95,6 +95,29 @@ final class L11nManager : $translation[$from] + $this->language[$language][$from]; } + /** + * Load language file which contains multiple languages. + * + * @param string $from Module name + * @param string $file File to import language from + * + * @return void + * + * @since 1.0.0 + */ + public function loadLanguageFile(string $from, string $file) : void + { + if (!\is_file($file)) { + return; + } + + /** @noinspection PhpIncludeInspection */ + $lang = include $file; + + foreach ($lang as $code => $translation) + $this->loadLanguage($code, $from, $translation); + } + /** * Load language from file. * diff --git a/Message/Http/Rest.php b/Message/Http/Rest.php index 3c8ff227b..5091dd081 100644 --- a/Message/Http/Rest.php +++ b/Message/Http/Rest.php @@ -89,16 +89,7 @@ final class Rest $boundary = '----' . \uniqid(); $data = self::createMultipartData($boundary, $request->getData()); - /** - * @todo: - * there is a very weird bug where boundary= fails to create the correct request - * while removing the = or putting it at a different location works (e.g. bound=ary). - * Maybe boundary= is a reserved keyword? - * - * according to the verbose output of curl the request is correct. this means the server must have a problem with it - * - * the php webserver and apache2 both seem to be unable to populate the php://input correctly -> not a server issue but a php issue? - */ + // @todo: replace boundary/ with the correct boundary= in the future. Currently this cannot be done due to a bug. If we do it now the server cannot correclty populate php://input $headers['content-type'] = 'Content-Type: multipart/form-data; boundary/' . $boundary; $headers['content-length'] = 'Content-Length: ' . \strlen($data); diff --git a/Module/InstallerAbstract.php b/Module/InstallerAbstract.php index a2dcf439c..14b32f833 100644 --- a/Module/InstallerAbstract.php +++ b/Module/InstallerAbstract.php @@ -44,36 +44,9 @@ abstract class InstallerAbstract public static function install(DatabasePool $dbPool, ModuleInfo $info, SettingsInterface $cfgHandler) : void { self::createTables($dbPool, $info); - self::installSettings($dbPool, $info, $cfgHandler); self::activate($dbPool, $info); } - /** - * Install module settings. - * - * @param DatabasePool $dbPool Database instance - * @param ModuleInfo $info Module info - * @param SettingsInterface $cfgHandler Settings/Configuration handler - * - * @return void - * - * @since 1.0.0 - * @todo move to admin module as providing option (like media providing `Admin.install.php` instead of Settings.install.php) - */ - public static function installSettings(DatabasePool $dbPool, ModuleInfo $info, SettingsInterface $cfgHandler) : void - { - $path = \dirname($info->getPath()) . '/Admin/Install/Settings.install.php'; - if (!\is_file($path)) { - return; - } - - $settings = include $path; - - foreach ($settings as $setting) { - $cfgHandler->create($setting); - } - } - /** * Create tables for module. * diff --git a/README.md b/README.md index 9cea1707b..ba2cf2b04 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ For more detailed information please checkout the [Installation Guide](https://o #### Developer -https://github.com/Orange-Management/Developer-Guide/blob/master/setup/installation.md +https://github.com/Orange-Management/Developer-Guide/blob/develop/general/setup.md ## Philosophy diff --git a/tests/Application/ApplicationManagerTest.php b/tests/Application/ApplicationManagerTest.php index b048971db..688fd6a27 100644 --- a/tests/Application/ApplicationManagerTest.php +++ b/tests/Application/ApplicationManagerTest.php @@ -53,6 +53,7 @@ class ApplicationManagerTest extends \PHPUnit\Framework\TestCase public function get( mixed $ids = null, string | array $names = null, + int $app = null, string $module = null, int $group = null, int $account = null @@ -69,7 +70,7 @@ class ApplicationManagerTest extends \PHPUnit\Framework\TestCase $app->moduleManager = new ModuleManager($app, __DIR__ . '/../../../Modules/'); - $this->appManager = new ApplicationManager(); + $this->appManager = new ApplicationManager($app); } /**