54 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
use JetBrains\PhpStorm\NoReturn;
 | 
						|
 | 
						|
require __DIR__ . '/../cli-start.php';
 | 
						|
 | 
						|
cli_title('FEED REFRESH');
 | 
						|
 | 
						|
if ($argc < 2) display_help();
 | 
						|
 | 
						|
switch ($argv[1]) {
 | 
						|
    case 'all':
 | 
						|
        refresh_all();
 | 
						|
        break;
 | 
						|
    default:
 | 
						|
        printfn('Unrecognized option "%s"', $argv[1]);
 | 
						|
        display_help();
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
 * Display the options for this utility and exit
 | 
						|
 */
 | 
						|
#[NoReturn]
 | 
						|
function display_help(): void {
 | 
						|
    printfn('Options:');
 | 
						|
    printfn(' - all');
 | 
						|
    printfn('     Refreshes all feeds');
 | 
						|
    exit(0);
 | 
						|
}
 | 
						|
 | 
						|
function refresh_all(): void {
 | 
						|
    $db = Data::getConnection();
 | 
						|
 | 
						|
    try {
 | 
						|
        $feeds = Feed::retrieveAll($db);
 | 
						|
        if (array_key_exists('error', $feeds)) {
 | 
						|
            printfn('SQLite error: %s', $feeds['error']);
 | 
						|
            return;
 | 
						|
        }
 | 
						|
        array_walk($feeds, function ($feed) use ($db) {
 | 
						|
            $result = Feed::refreshFeed($feed['id'], $feed['url'], $db);
 | 
						|
            if (array_key_exists('error', $result)) {
 | 
						|
                printfn('ERR (%s) %s', $feed['email'], $feed['url']);
 | 
						|
                printfn('         %s', $result['error']);
 | 
						|
            } else {
 | 
						|
                printfn('OK  (%s) %s', $feed['email'], $feed['url']);
 | 
						|
            }
 | 
						|
        });
 | 
						|
        printfn(PHP_EOL . 'All feeds refreshed');
 | 
						|
    } finally {
 | 
						|
        $db->close();
 | 
						|
    }
 | 
						|
}
 |