Files
FreshRSS/cli/import-sqlite-for-user.php
Kasimir Cash 6d14813840 Standardise command line option parsing (#6036)
* Separates long & short options for parsing

* Adds parsing for short options + doc rewrites

* Fixes undefined constant in check.translation

* Standardises CL option parsing

* Refactors option parsing

* Renames getLongOptions -> getOptions

* Removes unused code

* Converges on string typing for options

* Updates docs & help files

* Updates array syntax array( ) -> [ ]
2024-01-17 08:42:43 +01:00

45 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'] ?? '');
$parameters = [
'long' => [
'user' => ':',
'filename' => ':',
'force-overwrite' => '',
],
'short' => [],
'deprecated' => [],
];
$options = parseCliParams($parameters);
if (!empty($options['invalid'])
|| empty($options['valid']['user']) || empty($options['valid']['filename'])
|| !is_string($options['valid']['user']) || !is_string($options['valid']['filename'])
) {
fail('Usage: ' . basename(__FILE__) . ' --user username --force-overwrite --filename /path/to/db.sqlite');
}
$username = cliInitUser($options['valid']['user']);
$filename = $options['valid']['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);
$clearFirst = array_key_exists('force-overwrite', $options['valid']);
$ok = $databaseDAO->dbCopy($filename, FreshRSS_DatabaseDAO::SQLITE_IMPORT, $clearFirst);
if (!$ok) {
echo 'If you would like to clear the user database first, use the option --force-overwrite', "\n";
}
invalidateHttpCache($username);
done($ok);