Refactor test mode article fetching logic in index.php and wiki.php. Unified article filtering for both test and live modes, enhancing code clarity and reducing redundancy.

This commit is contained in:
smueller
2026-07-07 11:11:10 +02:00
parent ec13c9680d
commit b536712ea7
2 changed files with 4 additions and 7 deletions

View File

@@ -634,11 +634,10 @@ function newsletterData(array $config, bool $testMode = false): array
[$start, $end, $periodLabel, $periodKey] = newsletterPeriod($config['period_mode']); [$start, $end, $periodLabel, $periodKey] = newsletterPeriod($config['period_mode']);
$allArticles = fetchLatestArticles($config['wiki_url'], (int)$config['article_fetch_limit']); $allArticles = fetchLatestArticles($config['wiki_url'], (int)$config['article_fetch_limit']);
// Testversand nutzt denselben Zeitraum wie der Liveversand.
$articles = filterArticlesForPeriod($allArticles, $start, $end, (int)$config['article_limit']);
if ($testMode) { if ($testMode) {
$articles = array_slice($allArticles, 0, (int)$config['article_limit']);
$periodKey = 'test-' . date('Y-m-d-H-i-s'); $periodKey = 'test-' . date('Y-m-d-H-i-s');
} else {
$articles = filterArticlesForPeriod($allArticles, $start, $end, (int)$config['article_limit']);
} }
return [$articles, $periodLabel, $periodKey]; return [$articles, $periodLabel, $periodKey];

View File

@@ -635,12 +635,10 @@ function newsletterData(array $config, bool $testMode = false): array
[$start, $end, $periodLabel, $periodKey] = newsletterPeriod($config['period_mode']); [$start, $end, $periodLabel, $periodKey] = newsletterPeriod($config['period_mode']);
$allArticles = fetchLatestArticles($config['wiki_url'], (int)$config['article_fetch_limit']); $allArticles = fetchLatestArticles($config['wiki_url'], (int)$config['article_fetch_limit']);
// Testversand nutzt denselben Zeitraum wie der Liveversand.
$articles = filterArticlesForPeriod($allArticles, $start, $end, (int)$config['article_limit']);
if ($testMode) { if ($testMode) {
$articles = array_slice($allArticles, 0, (int)$config['article_limit']);
$periodLabel = 'aktuelle Übersicht';
$periodKey = 'test-' . date('Y-m-d-H-i-s'); $periodKey = 'test-' . date('Y-m-d-H-i-s');
} else {
$articles = filterArticlesForPeriod($allArticles, $start, $end, (int)$config['article_limit']);
} }
return [$articles, $periodLabel, $periodKey]; return [$articles, $periodLabel, $periodKey];