Skip to content

Commit

Permalink
[fix] EventCache Management for plugins + add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelfolaron committed Sep 19, 2024
1 parent 59d5c56 commit cfe4539
Show file tree
Hide file tree
Showing 22 changed files with 316 additions and 1,917 deletions.
133 changes: 0 additions & 133 deletions .dev/.env

This file was deleted.

8 changes: 8 additions & 0 deletions .dev/docker-compose.tests.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# This docker compose file is used to build the environment for our testing framework in codeception
# It is not to be used for development
#

version: "3.9"

services:
Expand All @@ -7,6 +12,9 @@ services:
- "./xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
- "./error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini"
- "./test.env:/var/www/html/config/.env"
ports:
- "8002:8080" #Using different ports for testing, so we don't have to worry about collision
- "44302:443" #Using different ports for testing, so we don't have to worry about collision (available range is 44300–44399)
environment:
LEAN_DB_HOST: 'db'
LEAN_DB_USER: 'leantime'
Expand Down
5 changes: 2 additions & 3 deletions .dev/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ services:
leantime-dev:
build: .
ports:
- "8888:8080"
- "8443:443"
- "8001:8080" #Using ports that are hopefully available. format is: 80XX
- "44301:443" #Using ports that are hopefully available. format is: 443XX (available range is 44300–44399)
volumes:
- "../:/var/www/html"
- "./xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
- "./error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini"
# - ".env:/var/www/html/config/.env"
environment:
LEAN_DB_HOST: 'db'
LEAN_DB_USER: 'leantime'
Expand Down
10 changes: 6 additions & 4 deletions .dev/test.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This is a sample configuration file with all possible configuration options.
# If you don't want to maintain a file like this you can pass in all variables via Server Variabels
#
# This environment file is used for our testing framework
# It is not to be used for development
#

## Minimum Configuration, these are required for installation

Expand Down Expand Up @@ -42,8 +44,8 @@ LEAN_DB_BACKUP_PATH = 'backupdb/' # Local relative path to stor
# S3 File Uploads
LEAN_USE_S3 = false # Set to true if you want to use S3 instead of local files
LEAN_S3_KEY = 'AKIAIOSFODNN7EXAMPLE' # S3 Key, hardcoded in s3ninja
LEAN_S3_SECRET = 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY' # S3 Secret, hardcoded in s3ninja
LEAN_S3_BUCKET = 'leantime' # Your S3 bucket
LEAN_S3_SECRET = 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY' # S3 Secret, hardcoded in s3ninja
LEAN_S3_BUCKET = 'leantime' # Your S3 bucket
LEAN_S3_USE_PATH_STYLE_ENDPOINT = true # Sets the endpoint style: false => https://[bucket].[endpoint] ; true => https://[endpoint]/[bucket]
LEAN_S3_REGION = 'eu-west-1' # S3 region
LEAN_S3_FOLDER_NAME = '' # Foldername within S3 (can be emtpy)
Expand Down
2 changes: 0 additions & 2 deletions .idea/leantime-oss.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions .idea/php-test-framework.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":1,"defects":{"Unit\\app\\Domain\\Menu\\Repositories\\MenuRepositoryTests::testGetMenuTypes":4,"Unit\\app\\Domain\\Menu\\Repositories\\MenuRepositoryTests::testGetDefaultMenuStructure":4,"Unit\\app\\Domain\\Menu\\Repositories\\MenuRepositoryTests::testGetFullMenuStructure":4,"Unit\\app\\Domain\\Menu\\Repositories\\MenuRepositoryTests::testGetInvalidMenuStructure":4,"Unit\\app\\Domain\\Menu\\Repositories\\MenuRepositoryTests::testUnsetMenuStructure":4,"Unit\\app\\Domain\\Menu\\Repositories\\MenuRepositoryTests::testGetFilteredMenuStructure":4},"times":{"Unit\\app\\Domain\\Menu\\Repositories\\MenuRepositoryTests::testGetMenuTypes":0.004,"Unit\\app\\Domain\\Menu\\Repositories\\MenuRepositoryTests::testGetDefaultMenuStructure":0,"Unit\\app\\Domain\\Menu\\Repositories\\MenuRepositoryTests::testGetFullMenuStructure":0,"Unit\\app\\Domain\\Menu\\Repositories\\MenuRepositoryTests::testGetInvalidMenuStructure":0,"Unit\\app\\Domain\\Menu\\Repositories\\MenuRepositoryTests::testUnsetMenuStructure":0,"Unit\\app\\Domain\\Menu\\Repositories\\MenuRepositoryTests::testGetFilteredMenuStructure":0}}
9 changes: 5 additions & 4 deletions app/Core/Console/ConsoleKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Contracts\Console\Kernel as ConsoleKernelContract;
use Illuminate\Foundation\Bus;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\ProcessUtils;
use Illuminate\Support\Str;
use Leantime\Core\Events\DispatchesEvents;
Expand Down Expand Up @@ -127,16 +128,16 @@ protected function commands()
$customCommands = $customPluginCommands = null;


session(["commands.core" => collect(glob(APP_ROOT . '/app/Command/*.php') ?? [])
Cache::store('installation')->set("commands.core", collect(glob(APP_ROOT . '/app/Command/*.php') ?? [])
->filter(function ($command) use (&$customCommands) {
return ! Arr::has(
$customCommands ??= collect(glob(APP_ROOT . '/custom/Command/*.php') ?? []),
str_replace(APP_ROOT . '/app', APP_ROOT . '/custom', $command)
);
})
->concat($customCommands ?? [])]);
->concat($customCommands ?? []));

session(["commands.plugins" => collect(glob(APP_ROOT . '/app/Plugins/*/Command/*.php') ?? [])
Cache::store('installation')->set("commands.plugins", collect(glob(APP_ROOT . '/app/Plugins/*/Command/*.php') ?? [])
->filter(function ($command) use (&$customPluginCommands) {
return ! in_array(
str_replace(APP_ROOT . '/app', APP_ROOT . '/custom', $command),
Expand All @@ -148,7 +149,7 @@ protected function commands()
->filter(fn ($command) => in_array(
Str::of($command)->after('Plugins/')->before('/Command')->toString(),
array_map(fn ($plugin) => $plugin->foldername, $this->getApplication()->make(PluginsService::class)->getAllPlugins(enabledOnly: true)),
))]);
)));

$commands = collect(Arr::flatten(session("commands")))
->map(fn ($path) => $this->getApplication()->getNamespace() . Str::of($path)->remove([APP_ROOT . '/app/', APP_ROOT . '/custom/'])->replace(['/', '.php'], ['\\', ''])->toString());
Expand Down
4 changes: 3 additions & 1 deletion app/Core/Events/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ public static function discover_listeners(): void
return;
}

if(!config('debug')) {
if((bool)config('debug') === false) {

$modules = Cache::store('installation')->rememberForever('domainEvents', function () {
return EventDispatcher::getDomainPaths();
});
Expand All @@ -199,6 +200,7 @@ public static function discover_listeners(): void
}
}

//Call system plugins (defined via config)
if (
isset(app(Environment::class)->plugins)
&& $configplugins = explode(',', app(Environment::class)->plugins)
Expand Down
2 changes: 1 addition & 1 deletion app/Core/Middleware/InitialHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function handle(IncomingRequest $request, Closure $next): Response
"base-uri 'self';",
"script-src 'self' 'unsafe-inline' unpkg.com",
"font-src 'self' data:",
"img-src 'self' *.leantime.io *.amazonaws.com data: blob:",
"img-src 'self' *.leantime.io *.amazonaws.com data: blob: marketplace.localhost",
"frame-src 'self' *.google.com *.microsoft.com *.live.com",
"frame-ancestors 'self' *.google.com *.microsoft.com *.live.com",
];
Expand Down
Loading

0 comments on commit cfe4539

Please sign in to comment.