64 lines
2.1 KiB
PHP
64 lines
2.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Gemeinsames Bootstrap fuer den Telegram-Cron.
|
|
*
|
|
* Diese Datei laedt Konfigurationen, bindet die Hilfsbibliotheken ein,
|
|
* erstellt die PDO-Datenbankverbindung, initialisiert Zeitzonen und stellt
|
|
* alle benoetigten Objekte und Pfade gesammelt fuer den Cron bereit.
|
|
*/
|
|
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', '1');
|
|
set_time_limit(0);
|
|
|
|
$rootDir = dirname(__DIR__, 2);
|
|
$stateFile = __DIR__ . DIRECTORY_SEPARATOR . 'telegram_cron_state.json';
|
|
$dbConfig = require $rootDir . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'database.php';
|
|
$telegramConfig = require $rootDir . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'telegram.php';
|
|
require_once $rootDir . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'telegram_message_footer.php';
|
|
|
|
$GLOBALS['filterColorConfigPath'] = $rootDir . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'filter_colors.json';
|
|
|
|
require_once __DIR__ . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'cron_helpers.php';
|
|
require_once __DIR__ . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'telegram_api.php';
|
|
require_once __DIR__ . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'tcrb_helpers.php';
|
|
|
|
$dsn = sprintf(
|
|
'mysql:host=%s;port=%d;dbname=%s;charset=%s',
|
|
$dbConfig['host'],
|
|
(int) ($dbConfig['port'] ?? 3306),
|
|
$dbConfig['dbname'],
|
|
$dbConfig['charset'] ?? 'utf8mb4'
|
|
);
|
|
|
|
$pdo = new PDO(
|
|
$dsn,
|
|
$dbConfig['user'],
|
|
$dbConfig['pass'],
|
|
[
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
|
]
|
|
);
|
|
|
|
ensureImportRunsTableExists($pdo);
|
|
|
|
$timezoneBerlin = new DateTimeZone('Europe/Berlin');
|
|
$timezoneUtc = new DateTimeZone('UTC');
|
|
$nowBerlin = new DateTimeImmutable('now', $timezoneBerlin);
|
|
$nowUtc = $nowBerlin->setTimezone($timezoneUtc);
|
|
|
|
return [
|
|
'rootDir' => $rootDir,
|
|
'stateFile' => $stateFile,
|
|
'dbConfig' => $dbConfig,
|
|
'telegramConfig' => $telegramConfig,
|
|
'pdo' => $pdo,
|
|
'timezoneBerlin' => $timezoneBerlin,
|
|
'timezoneUtc' => $timezoneUtc,
|
|
'nowBerlin' => $nowBerlin,
|
|
'nowUtc' => $nowUtc,
|
|
];
|