Add initial HTML template for MojeGS1 application with Cookiebot and Google Analytics integration

This commit is contained in:
2026-02-24 23:32:19 +01:00
parent 18d0019c28
commit 12f0c262c8
67 changed files with 50193 additions and 230 deletions

View File

@@ -13,6 +13,16 @@ use App\Core\Support\Logger;
use App\Core\Support\Session;
use App\Core\View\Template;
use App\Modules\Auth\AuthService;
use App\Modules\Cron\CronJobProcessor;
use App\Modules\Cron\CronJobRepository;
use App\Modules\Cron\CronJobType;
use App\Modules\Cron\ProductLinksHealthCheckHandler;
use App\Modules\ProductLinks\ChannelOffersRepository;
use App\Modules\ProductLinks\OfferImportService;
use App\Modules\ProductLinks\ProductLinksRepository;
use App\Modules\Settings\AppSettingsRepository;
use App\Modules\Settings\IntegrationRepository;
use App\Modules\Settings\ShopProClient;
use App\Modules\Users\UserRepository;
use PDO;
use Throwable;
@@ -64,6 +74,7 @@ final class Application
public function run(): void
{
$request = Request::capture();
$this->maybeRunCronOnWeb($request);
$response = $this->router->dispatch($request);
$response->send();
}
@@ -196,4 +207,98 @@ final class Application
return false;
});
}
private function maybeRunCronOnWeb(Request $request): void
{
if ($request->method() !== 'GET') {
return;
}
if ($request->path() === '/health') {
return;
}
$enabled = (bool) $this->config('app.cron.run_on_web_default', false);
$limit = max(1, min(100, (int) $this->config('app.cron.web_limit_default', 5)));
try {
$appSettings = new AppSettingsRepository($this->db);
$enabled = $appSettings->getBool('cron_run_on_web', $enabled);
$limit = max(1, min(100, $appSettings->getInt('cron_web_limit', $limit)));
} catch (Throwable $exception) {
$this->logger->error('Cron web settings load failed', [
'message' => $exception->getMessage(),
]);
}
if (!$enabled) {
return;
}
if ($this->isWebCronThrottled(20)) {
return;
}
if (!$this->acquireWebCronLock()) {
return;
}
try {
$cronJobs = new CronJobRepository($this->db);
$processor = new CronJobProcessor($cronJobs);
$integrationRepository = new IntegrationRepository(
$this->db,
(string) $this->config('app.integrations.secret', '')
);
$offersRepository = new ChannelOffersRepository($this->db);
$linksRepository = new ProductLinksRepository($this->db);
$shopProClient = new ShopProClient();
$offerImportService = new OfferImportService($shopProClient, $offersRepository, $this->db);
$linksHealthCheckHandler = new ProductLinksHealthCheckHandler(
$integrationRepository,
$offerImportService,
$linksRepository,
$offersRepository
);
$processor->registerHandler(CronJobType::PRODUCT_LINKS_HEALTH_CHECK, $linksHealthCheckHandler);
$result = $processor->run($limit);
$this->logger->info('Cron web run completed', $result);
} catch (Throwable $exception) {
$this->logger->error('Cron web run failed', [
'message' => $exception->getMessage(),
]);
} finally {
$this->releaseWebCronLock();
}
}
private function isWebCronThrottled(int $minIntervalSeconds): bool
{
$safeInterval = max(1, $minIntervalSeconds);
$now = time();
$lastRunAt = isset($_SESSION['cron_web_last_run_at']) ? (int) $_SESSION['cron_web_last_run_at'] : 0;
if ($lastRunAt > 0 && ($now - $lastRunAt) < $safeInterval) {
return true;
}
$_SESSION['cron_web_last_run_at'] = $now;
return false;
}
private function acquireWebCronLock(): bool
{
$statement = $this->db->query("SELECT GET_LOCK('orderpro_web_cron_lock', 0)");
$value = $statement !== false ? $statement->fetchColumn() : false;
return (string) $value === '1';
}
private function releaseWebCronLock(): void
{
$this->db->query("DO RELEASE_LOCK('orderpro_web_cron_lock')");
}
}