Merge pull request #5144 from devansh-webkul/maintainence-mode-enhacement
Maintainence Mode Enhanced
This commit is contained in:
commit
e9a39ce76f
|
|
@ -14,10 +14,12 @@ class ChannelSettingsChange
|
|||
*/
|
||||
public function checkForMaintenaceMode($channel)
|
||||
{
|
||||
if ((bool) $channel->is_maintenance_on) {
|
||||
Artisan::call('down');
|
||||
$channels = core()->getAllChannels();
|
||||
|
||||
if ($channels->contains('is_maintenance_on', 1)) {
|
||||
Artisan::call('channel:down');
|
||||
} else {
|
||||
Artisan::call('up');
|
||||
Artisan::call('channel:up');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Core\Console\Commands;
|
||||
|
||||
use Illuminate\Foundation\Console\DownCommand as OriginalCommand;
|
||||
|
||||
class DownChannelCommand extends OriginalCommand
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'channel:down {--redirect= : The path that users should be redirected to}
|
||||
{--render= : The view that should be prerendered for display during maintenance mode}
|
||||
{--retry= : The number of seconds after which the request may be retried}
|
||||
{--secret= : The secret phrase that may be used to bypass maintenance mode}
|
||||
{--status=503 : The status code that should be used when returning the maintenance mode response}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Down channel command. Same as parent but database will not update.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
parent::handle();
|
||||
}
|
||||
}
|
||||
|
|
@ -7,16 +7,27 @@ use Webkul\Core\Models\Channel;
|
|||
|
||||
class DownCommand extends OriginalCommand
|
||||
{
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->downAllChannel();
|
||||
|
||||
$this->downAllChannels();
|
||||
|
||||
parent::handle();
|
||||
}
|
||||
|
||||
protected function downAllChannel()
|
||||
/**
|
||||
* Update all channels.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function downAllChannels()
|
||||
{
|
||||
$this->comment('All channels are down.');
|
||||
|
||||
return Channel::query()->update(['is_maintenance_on' => 1]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Core\Console\Commands;
|
||||
|
||||
use Illuminate\Foundation\Console\UpCommand as OriginalCommand;
|
||||
|
||||
class UpChannelCommand extends OriginalCommand
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'channel:up';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Up channel command. Same as parent but database will not update.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
parent::handle();
|
||||
}
|
||||
}
|
||||
|
|
@ -7,16 +7,27 @@ use Webkul\Core\Models\Channel;
|
|||
|
||||
class UpCommand extends OriginalCommand
|
||||
{
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->upAllChannel();
|
||||
|
||||
$this->upAllChannels();
|
||||
|
||||
parent::handle();
|
||||
}
|
||||
|
||||
protected function upAllChannel()
|
||||
/**
|
||||
* Update all channels.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function upAllChannels()
|
||||
{
|
||||
$this->comment('Activating all channels.');
|
||||
|
||||
return Channel::query()->update(['is_maintenance_on' => 0]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
namespace Webkul\Core\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Original;
|
||||
use Illuminate\Routing\Route;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class CheckForMaintenanceMode extends Original
|
||||
{
|
||||
|
|
@ -49,6 +49,9 @@ class CheckForMaintenanceMode extends Original
|
|||
/* application */
|
||||
$this->app = $app;
|
||||
|
||||
/* current channel */
|
||||
$this->channel = core()->getCurrentChannel();
|
||||
|
||||
/* adding exception for admin routes */
|
||||
$this->except[] = env('APP_ADMIN_URL', 'admin') . '*';
|
||||
|
||||
|
|
@ -56,27 +59,6 @@ class CheckForMaintenanceMode extends Original
|
|||
$this->setAllowedIps();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for the except routes.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return boolean
|
||||
*/
|
||||
protected function shouldPassThrough($request)
|
||||
{
|
||||
foreach ($this->except as $except) {
|
||||
if ($except !== '/') {
|
||||
$except = trim($except, '/');
|
||||
}
|
||||
|
||||
if ($request->is($except)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
|
|
@ -103,8 +85,11 @@ class CheckForMaintenanceMode extends Original
|
|||
}
|
||||
}
|
||||
|
||||
if ($this->shouldPassThrough($request))
|
||||
{
|
||||
if ($this->shouldPassThrough($request)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
if (! (bool) $this->channel->is_maintenance_on) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
|
@ -121,10 +106,29 @@ class CheckForMaintenanceMode extends Original
|
|||
*/
|
||||
protected function setAllowedIps()
|
||||
{
|
||||
$this->channel = core()->getCurrentChannel();
|
||||
|
||||
if ($this->channel) {
|
||||
$this->excludedIPs = array_map('trim', explode(',', $this->channel->allowed_ips));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for the except routes.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return boolean
|
||||
*/
|
||||
protected function shouldPassThrough($request)
|
||||
{
|
||||
foreach ($this->except as $except) {
|
||||
if ($except !== '/') {
|
||||
$except = trim($except, '/');
|
||||
}
|
||||
|
||||
if ($request->is($except)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,25 +2,19 @@
|
|||
|
||||
namespace Webkul\Core\Providers;
|
||||
|
||||
use Illuminate\Contracts\Debug\ExceptionHandler;
|
||||
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
|
||||
use Illuminate\Foundation\AliasLoader;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Webkul\Core\Core;
|
||||
use Webkul\Core\Exceptions\Handler;
|
||||
use Webkul\Core\Models\SliderProxy;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Foundation\AliasLoader;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Webkul\Theme\ViewRenderEventManager;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Webkul\Core\Console\Commands\Install;
|
||||
use Webkul\Core\Observers\SliderObserver;
|
||||
use Webkul\Core\Console\Commands\UpCommand;
|
||||
use Webkul\Core\Facades\Core as CoreFacade;
|
||||
use Webkul\Core\Console\Commands\BookingCron;
|
||||
use Webkul\Core\Console\Commands\DownCommand;
|
||||
use Webkul\Core\Models\SliderProxy;
|
||||
use Webkul\Core\Observers\SliderObserver;
|
||||
use Webkul\Core\View\Compilers\BladeCompiler;
|
||||
use Illuminate\Contracts\Debug\ExceptionHandler;
|
||||
use Webkul\Core\Console\Commands\BagistoVersion;
|
||||
use Webkul\Core\Console\Commands\ExchangeRateUpdate;
|
||||
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
|
||||
use Webkul\Theme\ViewRenderEventManager;
|
||||
|
||||
class CoreServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
|
@ -60,20 +54,20 @@ class CoreServiceProvider extends ServiceProvider
|
|||
|
||||
$this->loadViewsFrom(__DIR__ . '/../Resources/views', 'core');
|
||||
|
||||
Event::listen('bagisto.shop.layout.body.after', static function(ViewRenderEventManager $viewRenderEventManager) {
|
||||
Event::listen('bagisto.shop.layout.body.after', static function (ViewRenderEventManager $viewRenderEventManager) {
|
||||
$viewRenderEventManager->addTemplate('core::blade.tracer.style');
|
||||
});
|
||||
|
||||
Event::listen('bagisto.admin.layout.head', static function(ViewRenderEventManager $viewRenderEventManager) {
|
||||
Event::listen('bagisto.admin.layout.head', static function (ViewRenderEventManager $viewRenderEventManager) {
|
||||
$viewRenderEventManager->addTemplate('core::blade.tracer.style');
|
||||
});
|
||||
|
||||
$this->app->extend('command.down', function () {
|
||||
return new DownCommand;
|
||||
return new \Webkul\Core\Console\Commands\DownCommand;
|
||||
});
|
||||
|
||||
$this->app->extend('command.up', function () {
|
||||
return new UpCommand;
|
||||
return new \Webkul\Core\Console\Commands\UpCommand;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -107,7 +101,7 @@ class CoreServiceProvider extends ServiceProvider
|
|||
}
|
||||
|
||||
/**
|
||||
* Register the console commands of this package
|
||||
* Register the console commands of this package.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
|
@ -115,19 +109,23 @@ class CoreServiceProvider extends ServiceProvider
|
|||
{
|
||||
if ($this->app->runningInConsole()) {
|
||||
$this->commands([
|
||||
BagistoVersion::class,
|
||||
Install::class,
|
||||
ExchangeRateUpdate::class,
|
||||
BookingCron::class
|
||||
\Webkul\Core\Console\Commands\BagistoVersion::class,
|
||||
\Webkul\Core\Console\Commands\Install::class,
|
||||
\Webkul\Core\Console\Commands\ExchangeRateUpdate::class,
|
||||
\Webkul\Core\Console\Commands\BookingCron::class,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->commands([
|
||||
\Webkul\Core\Console\Commands\DownChannelCommand::class,
|
||||
\Webkul\Core\Console\Commands\UpChannelCommand::class,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register factories.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return void
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue