fipamo/app/Http/Controllers/SettingsController.php
ro 743d7c4d90
routing overhaul
previously all the of the page routing was handlede through controller
organized by CRUD methods. it worked, but organizing by CRUD and not
purpose resulted in more time spent looking for a specific task through
controllers, so it turned out not to an effecient way of organizing.

so routing has been completely reorganized into laravel's web routing
section and methods have been moved to their appropriate controller so
tasks are much easier to find

front facing page routing turned out to be a bit more tricky that
anticipated do the overap of routing paths, but it only affects dynamic
page rendering and there's a patch in place that handles that issue
until a better solution is found. Rendered HTML pages works fine.

whew!
2025-05-16 17:37:53 -06:00

113 lines
3.6 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Interfaces\MemberRepositoryInterface;
use App\Services\Data\SettingsService;
use App\Services\Data\SortingService;
use App\Services\Assets\AssetService;
use App\Services\Assets\RenderService;
use App\Services\Upkeep\MaintenanceService;
use App\Services\Upkeep\ResetService;
use Illuminate\Http\Request;
class SettingsController extends Controller
{
protected $theme;
protected $member;
protected $settings;
protected $sort;
protected $assets;
protected $render;
protected $maintenance;
protected $reset;
public function __construct(
ThemeController $themeController,
MemberRepositoryInterface $memberRepo,
SettingsService $settingsService,
SortingService $sortingService,
AssetService $assetsService,
RenderService $renderService,
MaintenanceService $maintenanceService,
ResetService $resetService,
) {
$this->theme = $themeController;
$this->member = $memberRepo;
$this->settings = $settingsService;
$this->sort = $sortingService;
$this->assets = $assetsService;
$this->render = $renderService;
$this->maintenance = $maintenanceService;
$this->reset = $resetService;
}
public function start()
{
return view('back.settings', ['settings' => $this->sort->settings(), 'nav' => $this->sort->navigation()]);
}
public function tasks(Request $request)
{
$result = [];
switch (explode("/", $request->getURI())[5]) {
case 'publish':
$this->assets->moveToTheme(true);
$result = $this->render->publishAll();
break;
case 'sync':
$body = json_decode($request->getContent());
//update member if needed
$this->member->update($body->member);
//sync settings
$result = $this->settings->sync($body);
break;
case 'nav-sync':
$body = json_decode($request->getContent());
$result = $this->settings->navSync($body);
break;
}
return response()->json($result)->header('Content-Type', 'application/json');
}
public function createBackup(Request $request)
{
$body = json_decode($request->getContent());
if ($body->task == 'content_backup') {
return response()->json(
$this->maintenance->createContentBackUp()
)->header('Content-Type', 'application/json');
} else {
return response()->json(
$this->maintenance->createFileBackUp()
)->header('Content-Type', 'application/json');
}
}
public function downloadBackup($type)
{
if ($this->member::status()) {
$latest = '';
$file = '';
if ($type == 'content-download') {
$latest = $this->settings->getGlobal()['last_content_backup'];
$file = 'backup-content-' . $latest . '.zip';
} else {
$latest = $this->settings->getGlobal()['last_files_backup'];
$file = 'backup-files-' . $latest . '.zip';
}
return response()->download(
'../content/backups/' . $file,
$file,
['Content-Type: application/zip']
);
}
}
public function reset(Request $request)
{
$result = $this->reset->site($request);
return response()->json($result)->header('Content-Type', 'application/json');
}
}