2024-03-19 22:34:01 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Http\Request;
|
2024-05-13 21:36:06 +02:00
|
|
|
use App\Services\Data\SettingsService;
|
|
|
|
use App\Services\Assets\RenderService;
|
|
|
|
use App\Services\Upkeep\MaintenanceService;
|
2024-05-13 20:06:05 +02:00
|
|
|
use App\Interfaces\MemberRepositoryInterface;
|
2024-05-13 21:36:06 +02:00
|
|
|
use App\Services\Assets\AssetService;
|
2024-03-19 22:34:01 +01:00
|
|
|
|
|
|
|
class SettingsAPIController extends Controller
|
|
|
|
{
|
|
|
|
protected $settings;
|
|
|
|
protected $render;
|
2024-04-05 20:29:38 +02:00
|
|
|
protected $mainteance;
|
2024-05-13 20:06:05 +02:00
|
|
|
protected $member;
|
2024-04-25 21:17:24 +02:00
|
|
|
protected $assets;
|
2024-03-19 22:34:01 +01:00
|
|
|
|
2024-04-05 20:29:38 +02:00
|
|
|
public function __construct(
|
|
|
|
SettingsService $settingsService,
|
|
|
|
RenderService $renderService,
|
|
|
|
MaintenanceService $maintenanceService,
|
2024-05-13 20:06:05 +02:00
|
|
|
MemberRepositoryInterface $memberRepo,
|
2024-04-25 21:17:24 +02:00
|
|
|
AssetService $assetService
|
2024-04-05 20:29:38 +02:00
|
|
|
) {
|
|
|
|
$this->settings = $settingsService;
|
|
|
|
$this->render = $renderService;
|
|
|
|
$this->maintenance = $maintenanceService;
|
2024-05-13 20:06:05 +02:00
|
|
|
$this->member = $memberRepo;
|
2024-04-25 21:17:24 +02:00
|
|
|
$this->assets = $assetService;
|
2024-03-19 22:34:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function publish(Request $request)
|
|
|
|
{
|
2024-04-25 21:17:24 +02:00
|
|
|
$this->assets->moveToTheme(true);
|
2024-03-19 22:34:01 +01:00
|
|
|
$result = $this->render->publishAll();
|
|
|
|
return response()->json($result)->header('Content-Type', 'application/json');
|
|
|
|
}
|
2024-03-19 23:35:02 +01:00
|
|
|
|
|
|
|
public function sync(Request $request)
|
|
|
|
{
|
2024-05-13 21:36:06 +02:00
|
|
|
$body = json_decode($request->getContent());
|
|
|
|
//update member if needed
|
|
|
|
$this->member->update($body->member);
|
|
|
|
//sync settings
|
2024-03-19 23:35:02 +01:00
|
|
|
$result = $this->settings->sync($body);
|
|
|
|
return response()->json($result)->header('Content-Type', 'application/json');
|
|
|
|
}
|
2024-03-22 21:35:44 +01:00
|
|
|
|
|
|
|
public function navSync(Request $request)
|
|
|
|
{
|
|
|
|
$body = json_decode($request->getContent());
|
|
|
|
$result = $this->settings->navSync($body);
|
|
|
|
return response()->json($result)->header('Content-Type', 'application/json');
|
|
|
|
}
|
2024-04-05 20:29:38 +02:00
|
|
|
|
|
|
|
public function createBackup(Request $request)
|
|
|
|
{
|
2024-07-03 22:30:32 +02:00
|
|
|
$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-04-05 20:29:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function downloadBackup(Request $request)
|
|
|
|
{
|
2024-05-13 20:06:05 +02:00
|
|
|
if ($this->member::status()) {
|
2024-07-03 22:30:32 +02:00
|
|
|
$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']
|
|
|
|
);
|
2024-04-05 20:29:38 +02:00
|
|
|
}
|
|
|
|
}
|
2024-03-19 22:34:01 +01:00
|
|
|
}
|