Files
FreshRSS/cli/import-sqlite-for-user.php
Alexandre Alapetite 64bbb42553 Fix CLI flag parsing (#7430)
* Fix CLI flag parsing
fix https://github.com/FreshRSS/FreshRSS/issues/7428

* Fix other places

* Forgotten debugging
2025-03-22 23:17:52 +01:00

42 lines
1.3 KiB
PHP
Executable File

#!/usr/bin/env php
<?php
declare(strict_types=1);
require(__DIR__ . '/_cli.php');
performRequirementCheck(FreshRSS_Context::systemConf()->db['type'] ?? '');
$cliOptions = new class extends CliOptionsParser {
public string $user;
public string $filename;
public bool $forceOverwrite;
public function __construct() {
$this->addRequiredOption('user', (new CliOption('user')));
$this->addRequiredOption('filename', (new CliOption('filename')));
$this->addOption('forceOverwrite', (new CliOption('force-overwrite'))->withValueNone());
parent::__construct();
}
};
if (!empty($cliOptions->errors)) {
fail('FreshRSS error: ' . array_shift($cliOptions->errors) . "\n" . $cliOptions->usage);
}
$username = cliInitUser($cliOptions->user);
$filename = $cliOptions->filename;
if (pathinfo($filename, PATHINFO_EXTENSION) !== 'sqlite') {
fail('Only *.sqlite files are supported!');
}
echo 'FreshRSS importing database from SQLite for user “', $username, "”…\n";
$databaseDAO = FreshRSS_Factory::createDatabaseDAO($username);
$ok = $databaseDAO->dbCopy($filename, FreshRSS_DatabaseDAO::SQLITE_IMPORT, clearFirst: $cliOptions->forceOverwrite);
if (!$ok) {
echo 'If you would like to clear the user database first, use the option --force-overwrite', "\n";
}
invalidateHttpCache($username);
done($ok);