fipamo/app/Http/Controllers/API/SettingsAPIController.php
ro 1d206b927d
navigation sync bug fix, api & settings cleanup
there was an error when reordering menu items due to a missing variable
to a service class, so that was patched

also removed unecessary code from api url definitions and settings
service class
2024-07-26 12:43:45 -06:00

94 lines
3 KiB
PHP

<?php
namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Services\Data\SettingsService;
use App\Services\Assets\RenderService;
use App\Services\Upkeep\MaintenanceService;
use App\Interfaces\MemberRepositoryInterface;
use App\Services\Assets\AssetService;
class SettingsAPIController extends Controller
{
protected $settings;
protected $render;
protected $mainteance;
protected $member;
protected $assets;
public function __construct(
SettingsService $settingsService,
RenderService $renderService,
MaintenanceService $maintenanceService,
MemberRepositoryInterface $memberRepo,
AssetService $assetService
) {
$this->settings = $settingsService;
$this->render = $renderService;
$this->maintenance = $maintenanceService;
$this->member = $memberRepo;
$this->assets = $assetService;
}
public function publish(Request $request)
{
$this->assets->moveToTheme(true);
$result = $this->render->publishAll();
return response()->json($result)->header('Content-Type', 'application/json');
}
public function sync(Request $request)
{
$body = json_decode($request->getContent());
//update member if needed
$this->member->update($body->member);
//sync settings
$result = $this->settings->sync($body);
return response()->json($result)->header('Content-Type', 'application/json');
}
public function navSync(Request $request)
{
$body = json_decode($request->getContent());
$result = $this->settings->navSync($body);
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(Request $request)
{
if ($this->member::status()) {
$latest = '';
$file = '';
if (explode('/', $request->getRequestUri())[4] == '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']
);
}
}
}