Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelfolaron committed Nov 27, 2024
2 parents 3619037 + 3f93fcf commit f5717e6
Show file tree
Hide file tree
Showing 34 changed files with 409 additions and 575 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ body:
- type: textarea
id: context
attributes:
label: Additional Notes
description: "Please add any additional context you can share"
label: Error Logs (LEANTIMEFOLDER/storage/logs)
description: "Please past the contents of your error logs and any other logs you may have."
validations:
required: false
4 changes: 4 additions & 0 deletions .idea/php.xml

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

3 changes: 2 additions & 1 deletion .pint/pint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"exclude": [
"storage/",
"userfiles/"
"userfiles/",
"tests/Support/_generated"
]
}
4 changes: 3 additions & 1 deletion app/Command/AddUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
#[AsCommand(
name: 'user:add',
description: 'Add a new user',
description: 'Add a new user (email, password, role required options)',
)]
class AddUserCommand extends Command
{
Expand Down Expand Up @@ -139,6 +139,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return Command::FAILURE;
}

$io->success('User created successfully');

return Command::SUCCESS;
}
}
2 changes: 1 addition & 1 deletion app/Command/BackupDbCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$output = [];
$cmd = sprintf(
'mysqldump --column-statistics=0 --user=%s --password=%s --host=%s %s --port=%s --result-file=%s 2>&1',
'mysqldump --column-statistics=0 --user=\'%s\' --password=\'%s\' --host=%s %s --port=%s --result-file=%s 2>&1',
$config->dbUser,
$config->dbPassword,
$config->dbHost == 'localhost' ? '127.0.0.1' : $config->dbHost,
Expand Down
2 changes: 1 addition & 1 deletion app/Command/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
#[AsCommand(
name: 'db:migrate',
description: 'Runs and pending Database Migrations',
description: 'Runs and pending Leantime Database Migrations',
)]
class MigrateCommand extends Command
{
Expand Down
4 changes: 2 additions & 2 deletions app/Command/UpdateLeantime.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
#[AsCommand(
name: 'system:update',
description: 'Updates the system',
description: 'Updates Leantime to the latest version from Github',
)]
class UpdateLeantime extends Command
{
Expand Down Expand Up @@ -103,7 +103,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$zip = new \ZipArchive;
$zip->open($zipFile);
$zip->extractTo(storage_path('/framework/cache'));
$zip->extractTo(storage_path('/framework/cache/leantime'));
$zip->close();

//Disable Plugins + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
Expand Down
31 changes: 27 additions & 4 deletions app/Core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Leantime\Core;

use Illuminate\Log\LogServiceProvider;
use Illuminate\Routing\Router;
use Illuminate\Routing\RoutingServiceProvider;
use Leantime\Core\Configuration\Environment;
use Leantime\Core\Events\DispatchesEvents;
Expand Down Expand Up @@ -98,21 +97,45 @@ protected function registerBaseServiceProviders()

public function registerLeantimeAliases()
{

foreach ([
'app' => [self::class, \Illuminate\Foundation\Application::class, \Illuminate\Contracts\Container\Container::class, \Illuminate\Contracts\Foundation\Application::class, \Psr\Container\ContainerInterface::class],
'auth' => [\Illuminate\Auth\AuthManager::class, \Illuminate\Contracts\Auth\Factory::class],
'auth.driver' => [\Illuminate\Contracts\Auth\Guard::class],
'blade.compiler' => [\Illuminate\View\Compilers\BladeCompiler::class],
'cache' => [\Illuminate\Cache\CacheManager::class, \Illuminate\Contracts\Cache\Factory::class],
'cache.store' => [\Illuminate\Cache\Repository::class, \Illuminate\Contracts\Cache\Repository::class, \Psr\SimpleCache\CacheInterface::class],
'cache.psr6' => [\Symfony\Component\Cache\Adapter\Psr16Adapter::class, \Symfony\Component\Cache\Adapter\AdapterInterface::class, \Psr\Cache\CacheItemPoolInterface::class],
'config' => [Environment::class, \Illuminate\Config\Repository::class, \Illuminate\Contracts\Config\Repository::class],
'cookie' => [\Illuminate\Cookie\CookieJar::class, \Illuminate\Contracts\Cookie\Factory::class, \Illuminate\Contracts\Cookie\QueueingFactory::class],
'db' => [\Illuminate\Database\DatabaseManager::class, \Illuminate\Database\ConnectionResolverInterface::class],
'db.connection' => [\Illuminate\Database\Connection::class, \Illuminate\Database\ConnectionInterface::class],
'db.schema' => [\Illuminate\Database\Schema\Builder::class],
'encrypter' => [\Illuminate\Encryption\Encrypter::class, \Illuminate\Contracts\Encryption\Encrypter::class, \Illuminate\Contracts\Encryption\StringEncrypter::class],
'events' => [\Leantime\Core\Events\EventDispatcher::class, \Illuminate\Events\Dispatcher::class, \Illuminate\Contracts\Events\Dispatcher::class],
'request' => [IncomingRequest::class, ApiRequest::class, Console\CliRequest::class, \Illuminate\Http\Request::class, \Symfony\Component\HttpFoundation\Request::class],
'files' => [\Illuminate\Filesystem\Filesystem::class],
'filesystem' => [\Illuminate\Filesystem\FilesystemManager::class, \Illuminate\Contracts\Filesystem\Factory::class],
'filesystem.disk' => [\Illuminate\Contracts\Filesystem\Filesystem::class],
'filesystem.cloud' => [\Illuminate\Contracts\Filesystem\Cloud::class],
'hash' => [\Illuminate\Hashing\HashManager::class],
'hash.driver' => [\Illuminate\Contracts\Hashing\Hasher::class],
//'translator' => [\Illuminate\Translation\Translator::class, \Illuminate\Contracts\Translation\Translator::class],
'log' => [\Illuminate\Log\LogManager::class, \Psr\Log\LoggerInterface::class],
//'mail.manager' => [\Illuminate\Mail\MailManager::class, \Illuminate\Contracts\Mail\Factory::class],
//'mailer' => [\Illuminate\Mail\Mailer::class, \Illuminate\Contracts\Mail\Mailer::class, \Illuminate\Contracts\Mail\MailQueue::class],
//'auth.password' => [\Illuminate\Auth\Passwords\PasswordBrokerManager::class, \Illuminate\Contracts\Auth\PasswordBrokerFactory::class],
//'auth.password.broker' => [\Illuminate\Auth\Passwords\PasswordBroker::class, \Illuminate\Contracts\Auth\PasswordBroker::class],
//'queue' => [\Illuminate\Queue\QueueManager::class, \Illuminate\Contracts\Queue\Factory::class, \Illuminate\Contracts\Queue\Monitor::class],
//'queue.connection' => [\Illuminate\Contracts\Queue\Queue::class],
//'queue.failer' => [\Illuminate\Queue\Failed\FailedJobProviderInterface::class],
'redirect' => [\Illuminate\Routing\Redirector::class],
'redis' => [\Illuminate\Redis\RedisManager::class, \Illuminate\Contracts\Redis\Factory::class],
'redis.connection' => [\Illuminate\Redis\Connections\Connection::class, \Illuminate\Contracts\Redis\Connection::class],
'request' => [IncomingRequest::class, ApiRequest::class, Console\CliRequest::class, \Illuminate\Http\Request::class, \Symfony\Component\HttpFoundation\Request::class],
'router' => [\Illuminate\Routing\Router::class, \Illuminate\Contracts\Routing\Registrar::class, \Illuminate\Contracts\Routing\BindingRegistrar::class],
'session' => [\Illuminate\Session\SessionManager::class],
'session.store' => [\Illuminate\Session\Store::class, \Illuminate\Contracts\Session\Session::class],
'router' => [Router::class, \Illuminate\Contracts\Routing\Registrar::class, \Illuminate\Contracts\Routing\BindingRegistrar::class],
'url' => [\Illuminate\Routing\UrlGenerator::class, \Illuminate\Contracts\Routing\UrlGenerator::class],
'validator' => [\Illuminate\Validation\Factory::class, \Illuminate\Contracts\Validation\Factory::class],
'view' => [\Illuminate\View\Factory::class, \Illuminate\Contracts\View\Factory::class],
] as $key => $aliases) {
foreach ($aliases as $alias) {
Expand Down
7 changes: 5 additions & 2 deletions app/Core/Bootstrap/LoadConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public function bootstrap(Application $app)
});
}

//Need to run this in case config is coming from cache
$this->setBaseConstants($app['config']->get('appUrl'), $app);

$config = $app['config'];

self::dispatchEvent('config_initialized');
Expand Down Expand Up @@ -121,9 +124,9 @@ public function setBaseConstants($appUrl, $app)
if (! defined('BASE_URL')) {
if (isset($appUrl) && ! empty($appUrl)) {
define('BASE_URL', $appUrl);

} else {
define('BASE_URL', ! empty($app['request']) ? $app['request']->getSchemeAndHttpHost() : 'http://localhost');
$appUrl = ! empty($app['request']) ? $app['request']->getSchemeAndHttpHost() : 'http://localhost';
define('BASE_URL', $appUrl);
}
}

Expand Down
59 changes: 43 additions & 16 deletions app/Core/Events/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class EventDispatcher implements Dispatcher
use Macroable;
use ReflectsClosures;

/**
* Cache for pattern matching results
*/
private static array $patternMatchCache = [];

/**
* Registry of all events added to a hook
*/
Expand Down Expand Up @@ -115,34 +120,56 @@ public function dispatch(
*/
public static function findEventListeners(string $eventName, array $registry): array
{
// Check cache first
$cacheKey = $eventName.'_'.md5(serialize(array_keys($registry)));
if (isset(self::$patternMatchCache[$cacheKey])) {
return self::$patternMatchCache[$cacheKey];
}

$matches = [];
$patterns = [];

foreach ($registry as $key => $value) {
preg_match_all('/\{RGX:(.*?):RGX\}/', $key, $regexMatches);

$key = strtr($key, [
...collect($regexMatches[0] ?? [])->mapWithKeys(fn ($match, $i) => [$match => "REGEX_MATCH_$i"])->toArray(),
'*' => 'RANDOM_STRING',
'?' => 'RANDOM_CHARACTER',
]);

// escape the non regex characters
$pattern = preg_quote($key, '/');

$pattern = strtr($pattern, [
'RANDOM_STRING' => '.*?', // 0 or more (lazy) - asterisk (*)
'RANDOM_CHARACTER' => '.', // 1 character - question mark (?)
...collect($regexMatches[1] ?? [])->mapWithKeys(fn ($match, $i) => ["REGEX_MATCH_$i" => $match])->toArray(),
]);
// Skip if we've already compiled this pattern
if (! isset($patterns[$key])) {
preg_match_all('/\{RGX:(.*?):RGX\}/', $key, $regexMatches);
$pattern = self::compilePattern($key, $regexMatches);
$patterns[$key] = $pattern;
} else {
$pattern = $patterns[$key];
}

if (preg_match("/^$pattern$/", $eventName)) {
$matches = array_merge($matches, $value);
}
}

// Cache the result
self::$patternMatchCache[$cacheKey] = $matches;

return $matches;
}

/**
* Compiles a pattern for matching
*/
private static function compilePattern(string $key, array $regexMatches): string
{
$key = strtr($key, [
...collect($regexMatches[0] ?? [])->mapWithKeys(fn ($match, $i) => [$match => "REGEX_MATCH_$i"])->toArray(),
'*' => 'RANDOM_STRING',
'?' => 'RANDOM_CHARACTER',
]);

$pattern = preg_quote($key, '/');

return strtr($pattern, [
'RANDOM_STRING' => '.*?',
'RANDOM_CHARACTER' => '.',
...collect($regexMatches[1] ?? [])->mapWithKeys(fn ($match, $i) => ["REGEX_MATCH_$i" => $match])->toArray(),
]);
}

/**
* Dispatches a filter to manipulate a variable somewhere
*
Expand Down
9 changes: 9 additions & 0 deletions app/Core/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,15 @@ public function __(string $index, string $default = ''): string
return (string) $returnValue;
}

public function mergeLanguageArray($newLanguageArray)
{

if (is_array($newLanguageArray)) {
$this->ini_array = array_merge($this->ini_array, $newLanguageArray);
}

}

public function get(string $index, $default = '', $locale = '')
{
$contentReplacement = '';
Expand Down
8 changes: 7 additions & 1 deletion app/Core/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Leantime\Core\Providers;

use Illuminate\Foundation\Console\AboutCommand;
use Illuminate\Support\ServiceProvider;
use Leantime\Core\Configuration\AppSettings;

class AppServiceProvider extends ServiceProvider
{
Expand All @@ -19,6 +21,10 @@ public function register(): void
*/
public function boot(): void
{
//
AboutCommand::add('Environment', [
'Leantime App Version' => fn () => $this->app->make(AppSettings::class)->appVersion,
'Leantime Db Version' => fn () => $this->app->make(AppSettings::class)->dbVersion,
]);

}
}
6 changes: 3 additions & 3 deletions app/Core/Providers/CliServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ class CliServices extends ServiceProvider implements DeferrableProvider
'ConfigCache' => ConfigCacheCommand::class,
'ConfigClear' => ConfigClearCommand::class,
'ConfigShow' => ConfigShowCommand::class,
//'Db' => DbCommand::class,
//'DbMonitor' => DatabaseMonitorCommand::class,
'Db' => DbCommand::class,
'DbMonitor' => DatabaseMonitorCommand::class,
//'DbPrune' => PruneCommand::class,
//'DbShow' => ShowCommand::class,
'DbShow' => ShowCommand::class,
//'DbTable' => DatabaseTableCommand::class,
//'DbWipe' => WipeCommand::class,
'Down' => DownCommand::class,
Expand Down
8 changes: 0 additions & 8 deletions app/Core/Providers/FileSystemServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ public function register()

$this->registerFlysystem();

$this->app->alias(\Illuminate\Filesystem\Filesystem::class, 'files');

$this->app->alias(\Illuminate\Filesystem\FilesystemManager::class, 'filesystem');
$this->app->alias(\Illuminate\Filesystem\FilesystemManager::class, \Illuminate\Contracts\Filesystem\Factory::class);

$this->app->alias(\Illuminate\Contracts\Filesystem\Filesystem::class, 'filesystem.disk');
$this->app->alias(\Illuminate\Contracts\Filesystem\Cloud::class, 'filesystem.cloud');

}

public function prepareConfig()
Expand Down
6 changes: 5 additions & 1 deletion app/Domain/Connector/Controllers/Integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ public function run()
$fields = unserialize(session('serFields'));

//confirm and store in DB
$this->connectorService->importValues($fields, $values, session('currentImportEntity'));
$result = $this->connectorService->importValues($fields, $values, session('currentImportEntity'));

if ($result !== true) {
$this->tpl->setNotification('There was a problem with the import '.$result, 'error');
}

//display stored successfully message
return $this->tpl->display('connector.integrationConfirm');
Expand Down
Loading

0 comments on commit f5717e6

Please sign in to comment.