controller refactoring part 12

This commit is contained in:
Peter Papp
2021-07-20 17:27:18 +02:00
parent b0859f71cd
commit 2333b52d68
10 changed files with 123 additions and 105 deletions
@@ -1,83 +0,0 @@
<?php
namespace Domain\Maintenance\Controllers;
use Gate;
use Artisan;
use Illuminate\Http\Response;
use App\Http\Controllers\Controller;
use Illuminate\Contracts\Foundation\Application;
use Domain\Localization\Services\LanguageService;
use Illuminate\Contracts\Routing\ResponseFactory;
class MaintenanceController extends Controller
{
/**
* Start maintenance mode
*/
public function up()
{
// Check admin permission
Gate::authorize('maintenance');
$command = Artisan::call('up');
if ($command === 0) {
echo 'System is in production mode';
}
}
/**
* End maintenance mode
*/
public function down()
{
// Check admin permission
Gate::authorize('maintenance');
$command = Artisan::call('down');
if ($command === 0) {
echo 'System is in maintenance mode';
}
}
/**
* Get new language translations from default translations
* and insert it into database
*
* @return Application|ResponseFactory|Response
*/
public function upgrade_translations()
{
// Check admin permission
Gate::authorize('maintenance');
resolve(LanguageService::class)
->upgrade_language_translations();
return response('Done.', 201);
}
/**
* @return int|mixed
*/
public function upgrade_database()
{
// Check admin permission
Gate::authorize('maintenance');
$command = Artisan::call('migrate', [
'--force' => true,
]);
if ($command === 0) {
echo 'Operation was successful.';
}
if ($command === 1) {
echo 'Operation failed.';
}
return $command;
}
}
@@ -0,0 +1,42 @@
<?php
namespace Domain\Maintenance\Controllers;
use App\Http\Controllers\Controller;
use Artisan;
use Gate;
class MaintenanceModeController extends Controller
{
/**
* Start maintenance mode
*/
public function up()
{
// Check admin permission
Gate::authorize('maintenance');
$command = Artisan::call('up');
if ($command === 0) {
echo 'System is in production mode';
}
}
/**
* End maintenance mode
*/
public function down()
{
// Check admin permission
Gate::authorize('maintenance');
$command = Artisan::call('down');
if ($command === 0) {
echo 'System is in maintenance mode';
}
}
}
@@ -0,0 +1,32 @@
<?php
namespace Domain\Maintenance\Controllers;
use App\Http\Controllers\Controller;
use Artisan;
use Gate;
class UpgradeDatabaseController extends Controller
{
public function __invoke(): mixed
{
// Check admin permission
Gate::authorize('maintenance');
$command = Artisan::call('migrate', [
'--force' => true,
]);
if ($command === 0) {
echo 'Operation was successful.';
}
if ($command === 1) {
echo 'Operation failed.';
}
return $command;
}
}
@@ -0,0 +1,25 @@
<?php
namespace Domain\Maintenance\Controllers;
use Gate;
use Illuminate\Http\Response;
use App\Http\Controllers\Controller;
use Domain\Localization\Services\LanguageService;
class UpgradeTranslationsController extends Controller
{
/**
* Get new language translations from default translations
* and insert it into database
*/
public function __invoke(): Response
{
// Check admin permission
Gate::authorize('maintenance');
resolve(LanguageService::class)
->upgrade_language_translations();
return response('Done.', 201);
}
}