aboutsummaryrefslogtreecommitdiff
path: root/cli/import-sqlite-for-user.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2019-10-31 18:15:47 +0100
committerGravatar GitHub <noreply@github.com> 2019-10-31 18:15:47 +0100
commit3aa66f317b496ccd9a2df914bbc747c52081a7ad (patch)
tree6a3f3f74899801abdca00546e213dfdc141c53cf /cli/import-sqlite-for-user.php
parent82611c9622ed23b0e9fcf5f9f651ddffa1fd7706 (diff)
parentfcae48f313d399050cb15f37a8a73ae52fc67796 (diff)
Merge pull request #2599 from FreshRSS/dev1.15.0
FreshRSS 1.15
Diffstat (limited to 'cli/import-sqlite-for-user.php')
-rwxr-xr-xcli/import-sqlite-for-user.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/cli/import-sqlite-for-user.php b/cli/import-sqlite-for-user.php
new file mode 100755
index 000000000..f0e54e2fa
--- /dev/null
+++ b/cli/import-sqlite-for-user.php
@@ -0,0 +1,34 @@
+#!/usr/bin/php
+<?php
+require(__DIR__ . '/_cli.php');
+
+$params = [
+ 'user:',
+ 'filename:',
+ 'force-overwrite',
+];
+
+$options = getopt('', $params);
+
+if (!validateOptions($argv, $params) || empty($options['user']) || empty($options['filename'])) {
+ fail('Usage: ' . basename(__FILE__) . ' --user username --force-overwrite --filename /path/to/db.sqlite');
+}
+
+$username = cliInitUser($options['user']);
+$filename = $options['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);
+$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);