fix search

This commit is contained in:
Dennis Eichhorn 2023-09-29 16:42:41 +00:00
parent 0c48aa50f8
commit 6056f44884
4 changed files with 20 additions and 81 deletions

View File

@ -45,11 +45,15 @@ final class Installer extends InstallerAbstract
*/
public static function install(ApplicationAbstract $app, ModuleInfo $info, SettingsInterface $cfgHandler) : void
{
if (\file_exists(__DIR__ . '/../SearchCommands.php')) {
\unlink(__DIR__ . '/../SearchCommands.php');
if (!\is_writable(__DIR__ . '/SearchCommands.php')) {
throw new PermissionException(__DIR__ . '/SearchCommands.php');
}
\file_put_contents(__DIR__ . '/../SearchCommands.php', '<?php return [];');
if (\is_file(__DIR__ . '/SearchCommands.php')) {
\unlink(__DIR__ . '/SearchCommands.php');
}
\file_put_contents(__DIR__ . '/SearchCommands.php', '<?php return [];');
parent::install($app, $info, $cfgHandler);
}
@ -68,30 +72,31 @@ final class Installer extends InstallerAbstract
*/
public static function installExternal(ApplicationAbstract $app, array $data) : array
{
if (!\file_exists(__DIR__ . '/../SearchCommands.php')) {
\file_put_contents(__DIR__ . '/../SearchCommands.php', '<?php return [];');
if (!\is_file(__DIR__ . '/SearchCommands.php')) {
\file_put_contents(__DIR__ . '/SearchCommands.php', '<?php return [];');
}
if (!\file_exists($data['path'] ?? '')) {
if (!\is_file($data['path'] ?? '')) {
return [];
}
if (!\file_exists(__DIR__ . '/../SearchCommands.php')) {
throw new PathException(__DIR__ . '/../SearchCommands.php');
if (!\is_file(__DIR__ . '/SearchCommands.php')) {
throw new PathException(__DIR__ . '/SearchCommands.php');
}
if (!\is_writable(__DIR__ . '/../SearchCommands.php')) {
throw new PermissionException(__DIR__ . '/../SearchCommands.php');
if (!\is_writable(__DIR__ . '/SearchCommands.php')) {
throw new PermissionException(__DIR__ . '/SearchCommands.php');
}
/** @noinspection PhpIncludeInspection */
$appRoutes = include __DIR__ . '/../SearchCommands.php';
$appRoutes = include __DIR__ . '/SearchCommands.php';
/** @noinspection PhpIncludeInspection */
$moduleRoutes = include $data['path'];
$appRoutes = \array_merge_recursive($appRoutes, $moduleRoutes);
\file_put_contents(__DIR__ . '/../SearchCommands.php', '<?php return ' . ArrayParser::serializeArray($appRoutes) . ';', \LOCK_EX);
\file_put_contents(__DIR__ . '/SearchCommands.php', '<?php return ' . ArrayParser::serializeArray($appRoutes) . ';', \LOCK_EX);
return [];
}

View File

@ -39,7 +39,7 @@ final class ApiController extends Controller
parent::__construct($app);
$this->router = new WebRouter();
$this->router->importFromFile(__DIR__ . '/../SearchCommands.php');
$this->router->importFromFile(__DIR__ . '/../Admin/SearchCommands.php');
}
/**
@ -70,7 +70,7 @@ final class ApiController extends Controller
$response
);
if (empty($response->{$data})) {
if (empty($response->data)) {
$this->fillJsonRawResponse($request, $response, []);
}
}

View File

@ -1,66 +0,0 @@
<?php return [
'^:help .*$' => [
0 => [
'dest' => '\Modules\Help\Controller\SearchController:searchHelp',
'verb' => 16,
'permission' => [
'module' => 'Help',
'type' => 2,
'state' => 2,
],
],
],
'^:help :user .*$' => [
0 => [
'dest' => '\Modules\Help\Controller\SearchController:searchHelp',
'verb' => 16,
'permission' => [
'module' => 'Help',
'type' => 2,
'state' => 2,
],
],
],
'^:help :dev .*$' => [
0 => [
'dest' => '\Modules\Help\Controller\SearchController:searchHelp',
'verb' => 16,
'permission' => [
'module' => 'Help',
'type' => 2,
'state' => 3,
],
],
],
'^:help :module .*$' => [
0 => [
'dest' => '\Modules\Help\Controller\SearchController:searchHelp',
'verb' => 16,
'permission' => [
'module' => 'Help',
'type' => 2,
'state' => 2,
],
],
],
'^:goto .*$' => [
0 => [
'dest' => '\Modules\Navigation\Controller\SearchController:searchGoto',
'verb' => 16,
'permission' => [
'module' => 'Navigation',
'type' => 2,
],
],
],
'^:tag .*$' => [
0 => [
'dest' => '\Modules\Tasks\Controller\SearchController:searchTag',
'verb' => 16,
'permission' => [
'module' => 'Tasks',
'type' => 2,
],
],
],
];

View File

@ -102,7 +102,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
$request = new HttpRequest(new HttpUri(''));
$request->header->account = 1;
$request->setData('search', ':help file');
$request->setData('search', ':help introduction');
$this->module->routeSearch($request, $response);
self::assertGreaterThan(0, \count($response->get('')));