| Server IP : 202.61.199.114 / Your IP : 216.73.217.139 Web Server : nginx/1.22.1 System : Linux de.arni-solutions.de 6.1.0-49-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.174-1 (2026-05-26) x86_64 User : web20 ( 1018) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/clients/client2/web20/web/wp-content/plugins/dgt-verkehrsmonitor/cli/ |
Upload File : |
<?php
/**
* CLI-Einstiegspunkt für System-Crontab.
*
* Aufruf:
* /usr/bin/php8.4 /var/www/clients/client2/web20/web/wp-content/plugins/dgt-verkehrsmonitor/cli/cron.php <action> [--bundesland=slug] [--full]
*
* Aktionen:
* fetch – RSS-Quellen abrufen (alle 2 Stunden)
* scrape – Blaulicht-Listenseiten scrapen (alle 4 Stunden)
* regions – Presseportal Regional-Seiten scrapen (alle Bundesländer)
* mvnet – polizei.mvnet.de scrapen (Mecklenburg-Vorpommern)
* analyze – Ausstehende Entwürfe per KI analysieren (alle 30 Min)
* aggregate – Tagesstatistiken + Report generieren (täglich 06:00)
* search – Presseportal-Suche nach DUI-Keywords (Deep-Import)
* all – fetch + scrape + regions + mvnet + analyze + aggregate nacheinander
*
* Optionen:
* --bundesland=slug – Nur ein Bundesland scrapen (z.B. --bundesland=mecklenburg-vorpommern)
* --full – Deep-Import: alle Seiten bis 01.01.2026 durchlaufen
*
* @package dgt-verkehrsmonitor
*/
// Keine Ausgabe-Buffer im CLI.
if ( PHP_SAPI !== 'cli' ) {
http_response_code( 403 );
exit( 'Nur per CLI aufrufbar.' );
}
// WordPress laden.
$wp_load = dirname( __DIR__, 4 ) . '/wp-load.php';
if ( ! file_exists( $wp_load ) ) {
fwrite( STDERR, "wp-load.php nicht gefunden: {$wp_load}\n" );
exit( 1 );
}
require_once $wp_load;
// Action aus Argument.
$action = isset( $argv[1] ) ? $argv[1] : '';
// --bundesland=slug parsen.
$bundesland = '';
$full_import = false;
foreach ( $argv as $arg ) {
if ( 0 === strpos( $arg, '--bundesland=' ) ) {
$bundesland = substr( $arg, 13 );
}
if ( '--full' === $arg ) {
$full_import = true;
}
}
$valid_actions = array( 'fetch', 'scrape', 'regions', 'search', 'mvnet', 'analyze', 'aggregate', 'all' );
if ( ! in_array( $action, $valid_actions, true ) ) {
fwrite( STDERR, "Verwendung: php cron.php <" . implode( '|', $valid_actions ) . "> [--bundesland=slug] [--full]\n" );
exit( 1 );
}
$start = microtime( true );
if ( 'fetch' === $action || 'all' === $action ) {
echo "[" . date( 'Y-m-d H:i:s' ) . "] Fetch starten ...\n";
dgt_vm_do_fetch_sources();
$count = get_option( 'dgt_vm_last_fetch_count', 0 );
echo " -> {$count} neue Meldungen\n";
}
if ( 'scrape' === $action || 'all' === $action ) {
$scrape_pages = $full_import ? 30 : 5;
if ( $bundesland ) {
echo "[" . date( 'Y-m-d H:i:s' ) . "] Listing-Scrape für {$bundesland} starten ...\n";
$count = dgt_vm_do_scrape_listings_bl( $bundesland, $scrape_pages );
echo " -> {$count} neue Meldungen per Listing-Scrape ({$bundesland})\n";
} else {
echo "[" . date( 'Y-m-d H:i:s' ) . "] Listing-Scrape starten ...\n";
$count = dgt_vm_do_scrape_listings( $scrape_pages );
echo " -> {$count} neue Meldungen per Listing-Scrape\n";
}
echo "[" . date( 'Y-m-d H:i:s' ) . "] Kategorie-Scrape starten ...\n";
$count2 = dgt_vm_do_scrape_categories( $full_import ? 10 : 3 );
echo " -> {$count2} neue Meldungen per Kategorie-Scrape\n";
}
if ( 'regions' === $action || 'all' === $action ) {
$region_pages = $full_import ? 200 : 5;
$min_date = $full_import ? '2026-01-01' : '';
echo "[" . date( 'Y-m-d H:i:s' ) . "] Regional-Scrape starten" . ( $full_import ? ' (Full-Import ab 2026-01-01)' : '' ) . " ...\n";
$count = dgt_vm_do_scrape_regions( $region_pages, $bundesland, $min_date );
echo " -> {$count} neue Meldungen per Regional-Scrape\n";
}
if ( 'search' === $action || 'all' === $action ) {
$search_pages = $full_import ? 300 : 10;
$min_date = $full_import ? '2026-01-01' : '';
echo "[" . date( 'Y-m-d H:i:s' ) . "] Presseportal-Suche starten" . ( $full_import ? ' (Full-Import ab 2026-01-01)' : '' ) . " ...\n";
$count = dgt_vm_do_search_import( $search_pages, $min_date );
echo " -> {$count} neue Meldungen per Suche\n";
}
if ( 'mvnet' === $action || 'all' === $action ) {
echo "[" . date( 'Y-m-d H:i:s' ) . "] MV-Net Scrape starten ...\n";
$count = dgt_vm_scrape_mvnet( $full_import ? 30 : 5 );
echo " -> {$count} neue Meldungen per MV-Net-Scrape\n";
}
if ( 'analyze' === $action || 'all' === $action ) {
echo "[" . date( 'Y-m-d H:i:s' ) . "] Analyse starten ...\n";
dgt_vm_do_analyze_pending();
$count = get_option( 'dgt_vm_last_analyze_count', 0 );
echo " -> {$count} Meldungen analysiert\n";
}
if ( 'aggregate' === $action || 'all' === $action ) {
echo "[" . date( 'Y-m-d H:i:s' ) . "] Aggregation starten ...\n";
dgt_vm_do_aggregate_daily();
echo " -> Tagesstatistik und Report generiert\n";
}
$elapsed = round( microtime( true ) - $start, 2 );
echo "[" . date( 'Y-m-d H:i:s' ) . "] Fertig ({$elapsed}s)\n";