2024-07-13 22:23:01 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Interfaces\PageRepositoryInterface;
|
|
|
|
use App\Services\Assets\AssetService;
|
|
|
|
use App\Services\Assets\RenderService;
|
|
|
|
use App\Interfaces\MemberRepositoryInterface;
|
|
|
|
use App\Services\Data\SettingsService;
|
2024-07-17 23:08:10 +02:00
|
|
|
use App\Services\Upkeep\MaintenanceService;
|
2024-07-13 22:23:01 +02:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class RoutePutController extends Controller
|
|
|
|
{
|
|
|
|
protected $page;
|
|
|
|
protected $assets;
|
|
|
|
protected $render;
|
|
|
|
protected $settings;
|
|
|
|
protected $member;
|
2024-07-17 23:08:10 +02:00
|
|
|
protected $maintenance;
|
2024-07-13 22:23:01 +02:00
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
PageRepositoryInterface $pageRepo,
|
|
|
|
AssetService $assetService,
|
|
|
|
RenderService $renderService,
|
|
|
|
SettingsService $settingsService,
|
|
|
|
MemberRepositoryInterface $memberRepo,
|
2024-07-17 23:08:10 +02:00
|
|
|
MaintenanceService $maintenanceService,
|
2024-07-13 22:23:01 +02:00
|
|
|
) {
|
2024-07-17 23:08:10 +02:00
|
|
|
$this->page = $pageRepo;
|
|
|
|
$this->assets = $assetService;
|
|
|
|
$this->render = $renderService;
|
|
|
|
$this->settings = $settingsService;
|
|
|
|
$this->member = $memberRepo;
|
|
|
|
$this->maintenance = $maintenanceService;
|
2024-07-13 22:23:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function handleRequest(Request $request)
|
|
|
|
{
|
|
|
|
$path = explode('/', $request->path());
|
|
|
|
switch ($path[0]) {
|
|
|
|
case 'page':
|
|
|
|
$body = json_decode($request->getContent());
|
|
|
|
$result = $this->page->update($body);
|
|
|
|
return response()->json($result)->header('Content-Type', 'application/json');
|
|
|
|
break;
|
|
|
|
case 'settings':
|
|
|
|
return $this->settingsTasks($request, $path[1]);
|
|
|
|
break;
|
2024-07-17 23:08:10 +02:00
|
|
|
case 'backup':
|
|
|
|
return $this->createBackup($request);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function createBackup($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');
|
2024-07-13 22:23:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function settingsTasks($request, $task)
|
|
|
|
{
|
|
|
|
$result = [];
|
|
|
|
switch ($task) {
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|