bug fixes

This commit is contained in:
Dennis Eichhorn 2021-09-28 10:19:37 +02:00
parent 0df18d08e1
commit d7e89a4a31
11 changed files with 130 additions and 37 deletions

View File

@ -113,7 +113,9 @@ final class ApplicationManager
$this->installFiles($source, $destination);
$this->replacePlaceholder($destination);
$class = '\\Web\\' . $info->getInternalName() . '\\Admin\\Installer';
$classPath = \substr(\realpath($destination) . '/Admin/Installer', \strlen(\realpath(__DIR__ . '/../../')));
$class = \str_replace('/', '\\', $classPath);
$class::install($this->app->dbPool, $info, $this->app->appSettings);
return true;
@ -149,22 +151,23 @@ final class ApplicationManager
* Get all installed modules.
*
* @param bool $useCache Use Cache
* @param string $basePath Base path for the applications
*
* @return array<string, ModuleInfo>
*
* @since 1.0.0
*/
public function getInstalledApplications(bool $useCache = true) : array
public function getInstalledApplications(bool $useCache = true, string $basePath = __DIR__ . '/../../Web') : array
{
if (empty($this->installed) || !$useCache) {
$apps = \scandir(__DIR__ . '/../../Web');
$apps = \scandir($basePath);
foreach ($apps as $app) {
if ($app === '.' || $app === '..' || !\is_file(__DIR__ . '/../../Web/' . $app . '/info.json')) {
if ($app === '.' || $app === '..' || !\is_file($basePath . '/' . $app . '/info.json')) {
continue;
}
$this->installed[$app] = $this->loadInfo(__DIR__ . '/../../Web/' . $app . '/info.json');
$this->installed[$app] = $this->loadInfo($basePath . '/' . $app . '/info.json');
}
}

View File

@ -30,6 +30,8 @@ use phpOMS\System\File\Local\Directory;
*/
abstract class InstallerAbstract
{
public const PATH = '';
/**
* Install app.
*
@ -46,7 +48,7 @@ abstract class InstallerAbstract
self::createTables($dbPool, $info);
self::installSettings($dbPool, $info, $cfgHandler);
self::activate($dbPool, $info);
self::installTheme(__DIR__ . '/../../Web/' . $info->getInternalName(), 'Default');
self::installTheme(static::PATH . '/..', 'Default');
}
/**
@ -96,7 +98,7 @@ abstract class InstallerAbstract
*/
public static function installSettings(DatabasePool $dbPool, ApplicationInfo $info, SettingsInterface $cfgHandler) : void
{
$path = __DIR__ . '/../../Web/' . $info->getInternalName() . '/Admin/Install/Settings.install.php';
$path = static::PATH . '/Install/Settings.install.php';
if (!\is_file($path)) {
return;
}
@ -120,7 +122,7 @@ abstract class InstallerAbstract
*/
protected static function createTables(DatabasePool $dbPool, ApplicationInfo $info) : void
{
$path = __DIR__ . '/../../Web/' . $info->getInternalName() . '/Admin/Install/db.json';
$path = static::PATH . '/Install/db.json';
if (!\is_file($path)) {
return;
}
@ -148,8 +150,9 @@ abstract class InstallerAbstract
*/
protected static function activate(DatabasePool $dbPool, ApplicationInfo $info) : void
{
/** @var StatusAbstract $class */
$class = '\\Web\\' . $info->getInternalName() . '\\Admin\\Status';
$classPath = \substr(\realpath(static::PATH) . '/Status', \strlen(\realpath(__DIR__ . '/../../')));
$class = \str_replace('/', '\\', $classPath);
$class::activate($dbPool, $info);
}
@ -164,7 +167,9 @@ abstract class InstallerAbstract
*/
public static function reInit(ApplicationInfo $info) : void
{
$class = '\\Web\\' . $info->getInternalName() . '\\Admin\\Status';
$classPath = \substr(\realpath(static::PATH) . '/Status', \strlen(\realpath(__DIR__ . '/../../')));
$class = \str_replace('/', '\\', $classPath);
$class::activateRoutes($info);
$class::activateHooks($info);
}

View File

@ -33,6 +33,7 @@ use phpOMS\Utils\ArrayUtils;
*/
abstract class StatusAbstract
{
public const PATH = '';
/**
* Deactivate app.
*
@ -62,7 +63,7 @@ abstract class StatusAbstract
*/
public static function activateRoutes(ApplicationInfo $appInfo = null) : void
{
self::installRoutes(__DIR__ . '/../../Web/' . $appInfo->getInternalName() . '/Routes.php', __DIR__ . '/../../Web/' . $appInfo->getInternalName() . '/Admin/Install/Application/Routes.php');
self::installRoutes(static::PATH . '/../Routes.php', static::PATH . '/../Admin/Install/Application/Routes.php');
}
/**
@ -78,7 +79,7 @@ abstract class StatusAbstract
*/
public static function activateHooks(ApplicationInfo $appInfo = null) : void
{
self::installRoutes(__DIR__ . '/../../Web/' . $appInfo->getInternalName() . '/Hooks.php', __DIR__ . '/../../Web/' . $appInfo->getInternalName() . '/Admin/Install/Application/Hooks.php');
self::installRoutes(static::PATH . '/../Hooks.php', static::PATH . '/../Admin/Install/Application/Hooks.php');
}
/**
@ -175,7 +176,7 @@ abstract class StatusAbstract
*/
public static function deactivateRoutes(ApplicationInfo $appInfo) : void
{
self::installRoutes(__DIR__ . '/../../Web/' . $appInfo->getInternalName() . '/Routes.php', __DIR__ . '/../../Web/' . $appInfo->getInternalName() . '/Admin/Install/Application/Routes.php');
self::installRoutes(static::PATH . '/../Routes.php', static::PATH . '/../Admin/Install/Application/Routes.php');
}
/**
@ -191,7 +192,7 @@ abstract class StatusAbstract
*/
public static function deactivateHooks(ApplicationInfo $appInfo) : void
{
self::installRoutes(__DIR__ . '/../../Web/' . $appInfo->getInternalName() . '/Hooks.php', __DIR__ . '/../../Web/' . $appInfo->getInternalName() . '/Admin/Install/Application/Hooks.php');
self::installRoutes(static::PATH . '/../Hooks.php', static::PATH . '/../Admin/Install/Application/Hooks.php');
}
/**

View File

@ -336,7 +336,7 @@ final class ModuleManager
*
* @since 1.0.0
*/
private function loadInfo(string $module) : ?ModuleInfo
public function loadInfo(string $module) : ?ModuleInfo
{
$path = \realpath($oldPath = $this->modulePath . $module . '/info.json');
if ($path === false) {

View File

@ -60,8 +60,8 @@ class ApplicationInfoTest extends \PHPUnit\Framework\TestCase
$info = new ApplicationInfo(__DIR__ . '/info-test.json');
$info->load();
$info->set('/name/internal', 'ABC');
self::assertEquals('ABC', $info->getInternalName());
$info->set('/name/internal', 'Testapp');
self::assertEquals('Testapp', $info->getInternalName());
$info->update();
$info2 = new ApplicationInfo(__DIR__ . '/info-test.json');

View File

@ -101,9 +101,7 @@ class ApplicationManagerTest extends \PHPUnit\Framework\TestCase
*/
public function testMissingApplicationInfoFile() : void
{
$this->expectException(\phpOMS\System\File\PathException::class);
self::assertFalse($this->appManager->install(__DIR__, __DIR__ . '/newapp'));
self::assertFalse($this->appManager->install(__DIR__, __DIR__ . '/newapp', __DIR__ . '/Apps/newapp'));
}
/**

View File

@ -0,0 +1,30 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Web\Api\Admin
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace phpOMS\tests\Application\Apps\{APPNAME}\Admin;
use phpOMS\Application\InstallerAbstract;
/**
* Installer class.
*
* @package Web\Api\Admin
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class Installer extends InstallerAbstract
{
public const PATH = __DIR__;
}

View File

@ -0,0 +1,30 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Web\Api\Admin
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace phpOMS\tests\Application\Apps\{APPNAME}\Admin;
use phpOMS\Application\StatusAbstract;
/**
* Status class.
*
* @package Web\Api\Admin
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
final class Status extends StatusAbstract
{
public const PATH = __DIR__;
}

View File

@ -1,8 +1,8 @@
{
"name": {
"id": 1000100000,
"internal": "ABC",
"external": "ABC"
"internal": "Testapp",
"external": "Testapp"
},
"version": "1.0.0",
"category": "Test",

View File

@ -112,11 +112,11 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->orderBy('a.test', 'ASC')->toSql());
$query = new Builder($this->con);
$sql = 'SELECT `a`.`test` FROM `a` WHERE `a`.`test` = 1 ORDER BY `a`.`test`, `a`.`test2` DESC;';
$sql = 'SELECT `a`.`test` FROM `a` WHERE `a`.`test` = 1 ORDER BY `a`.`test` DESC, `a`.`test2` DESC;';
self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->orderBy(['a.test', 'a.test2'], ['DESC', 'DESC'])->toSql());
$query = new Builder($this->con);
$sql = 'SELECT `a`.`test` FROM `a` WHERE `a`.`test` = 1 ORDER BY `a`.`test`, `a`.`test2` ASC;';
$sql = 'SELECT `a`.`test` FROM `a` WHERE `a`.`test` = 1 ORDER BY `a`.`test` ASC, `a`.`test2` ASC;';
self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->orderBy(['a.test', 'a.test2'], 'ASC')->toSql());
}
@ -508,16 +508,4 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
$query = new Builder($this->con, true);
$query->join('b')->on('a', 'invalid', 'b');
}
/**
* @testdox Invalid order column types throw a InvalidArgumentException
* @group framework
*/
public function testInvalidOrderColumnType() : void
{
$this->expectException(\InvalidArgumentException::class);
$query = new Builder($this->con, true);
$query->orderBy('valid', ['invalid']);
}
}

View File

@ -15,12 +15,16 @@ declare(strict_types=1);
namespace phpOMS\tests\Module;
use Model\CoreSettings;
use Modules\Admin\Models\ModuleMapper;
use phpOMS\Application\ApplicationAbstract;
use phpOMS\Dispatcher\Dispatcher;
use phpOMS\Message\Http\HttpRequest;
use phpOMS\Module\ModuleManager;
use phpOMS\Router\WebRouter;
use phpOMS\Uri\HttpUri;
use Modules\Admin\Models\Module;
use phpOMS\Module\ModuleStatus;
use phpOMS\DataStorage\Database\Query\Builder;
require_once __DIR__ . '/../Autoloader.php';
@ -163,10 +167,44 @@ class ModuleManagerTest extends \PHPUnit\Framework\TestCase
{
$this->moduleManager->install('TestModule');
$module = new Module();
$module->id = 'TestModule';
$module->name = 'TestModule';
$module->path = 'TestModule';
ModuleMapper::create($module);
self::assertTrue($this->moduleManager->deactivate('TestModule'));
self::assertFalse($this->moduleManager->isActive('TestModule'));
self::assertTrue($this->moduleManager->activate('TestModule'));
// this is normally done in the ApiController
$module->setStatus(ModuleStatus::ACTIVE);
ModuleMapper::update($module);
$queryLoad = new Builder($this->app->dbPool->get('insert'));
$queryLoad->insert('module_load_pid', 'module_load_type', 'module_load_from', 'module_load_for', 'module_load_file')
->into('module_load');
$moduleInfo = $this->moduleManager->loadInfo('TestModule');
$load = $moduleInfo->getLoad();
foreach ($load as $val) {
foreach ($val['pid'] as $pid) {
$queryLoad->values(
\sha1(\str_replace('/', '', $pid)),
(int) $val['type'],
$val['from'],
$val['for'],
$val['file']
);
}
}
if (!empty($queryLoad->getValues())) {
$queryLoad->execute();
}
self::assertTrue($this->moduleManager->isActive('TestModule'));
}