39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Controller\Api;
|
|
|
|
use League\Flysystem\FilesystemOperator;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
|
|
|
#[Route('/api')]
|
|
#[IsGranted('ROLE_OAUTH2_API')]
|
|
class LastUpdateController extends AbstractController
|
|
{
|
|
public function __construct(private readonly FilesystemOperator $xmlExport)
|
|
{
|
|
}
|
|
|
|
#[Route(path: '/last-update', name: 'api_last_update', methods: ['GET'])]
|
|
public function index(): JsonResponse
|
|
{
|
|
if (false === $this->xmlExport->has('uebertragung.info')) {
|
|
$lastUploadAt = null;
|
|
} else {
|
|
$file = $this->xmlExport->read('uebertragung.info');
|
|
$lines = explode("\n", $file);
|
|
$line = trim($lines[0]);
|
|
|
|
if (true === empty($line)) {
|
|
$lastUploadAt = null;
|
|
} else {
|
|
$lastUploadAt = \DateTime::createFromFormat('d.m.Y H:i:s', $line);
|
|
}
|
|
}
|
|
|
|
return $this->json(['timestamp' => $lastUploadAt->format('Y-m-d H:i:s')]);
|
|
}
|
|
}
|