mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-10-31 05:46:51 +01:00 
			
		
		
		
	Fix redis connection check (#698)
This commit is contained in:
		
							parent
							
								
									f793b49a81
								
							
						
					
					
						commit
						382dcb3868
					
				| @ -10,7 +10,8 @@ use Filament\Forms\Components\Wizard\Step; | |||||||
| use Filament\Forms\Get; | use Filament\Forms\Get; | ||||||
| use Filament\Notifications\Notification; | use Filament\Notifications\Notification; | ||||||
| use Filament\Support\Exceptions\Halt; | use Filament\Support\Exceptions\Halt; | ||||||
| use Illuminate\Support\Facades\Redis; | use Illuminate\Foundation\Application; | ||||||
|  | use Illuminate\Redis\RedisManager; | ||||||
| 
 | 
 | ||||||
| class RedisStep | class RedisStep | ||||||
| { | { | ||||||
| @ -47,8 +48,8 @@ class RedisStep | |||||||
|                     ->revealable() |                     ->revealable() | ||||||
|                     ->default(config('database.redis.default.password')), |                     ->default(config('database.redis.default.password')), | ||||||
|             ]) |             ]) | ||||||
|             ->afterValidation(function (Get $get) use ($installer) { |             ->afterValidation(function (Get $get, Application $app) use ($installer) { | ||||||
|                 if (!self::testConnection($get('env_redis.REDIS_HOST'), $get('env_redis.REDIS_PORT'), $get('env_redis.REDIS_USERNAME'), $get('env_redis.REDIS_PASSWORD'))) { |                 if (!self::testConnection($app, $get('env_redis.REDIS_HOST'), $get('env_redis.REDIS_PORT'), $get('env_redis.REDIS_USERNAME'), $get('env_redis.REDIS_PASSWORD'))) { | ||||||
|                     throw new Halt('Redis connection failed'); |                     throw new Halt('Redis connection failed'); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
| @ -56,17 +57,19 @@ class RedisStep | |||||||
|             }); |             }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private static function testConnection(string $host, null|string|int $port, ?string $username, ?string $password): bool |     private static function testConnection(Application $app, string $host, null|string|int $port, ?string $username, ?string $password): bool | ||||||
|     { |     { | ||||||
|         try { |         try { | ||||||
|             config()->set('database.redis._panel_install_test', [ |             $redis = new RedisManager($app, 'predis', [ | ||||||
|  |                 'default' => [ | ||||||
|                     'host' => $host, |                     'host' => $host, | ||||||
|                     'port' => $port, |                     'port' => $port, | ||||||
|                     'username' => $username, |                     'username' => $username, | ||||||
|                     'password' => $password, |                     'password' => $password, | ||||||
|  |                 ], | ||||||
|             ]); |             ]); | ||||||
| 
 | 
 | ||||||
|             Redis::connection('_panel_install_test')->command('ping'); |             $redis->connection()->command('ping'); | ||||||
|         } catch (Exception $exception) { |         } catch (Exception $exception) { | ||||||
|             Notification::make() |             Notification::make() | ||||||
|                 ->title('Redis connection failed') |                 ->title('Redis connection failed') | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Boy132
						Boy132