aboutsummaryrefslogtreecommitdiff
path: root/cli/import-sqlite-for-user.php
blob: 29b7c1b0c31676662df14c21c9fbd9807e1a04b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/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);