4
0

import-sqlite-for-user.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env php
  2. <?php
  3. declare(strict_types=1);
  4. require(__DIR__ . '/_cli.php');
  5. performRequirementCheck(FreshRSS_Context::systemConf()->db['type'] ?? '');
  6. $parameters = [
  7. 'long' => [
  8. 'user' => ':',
  9. 'filename' => ':',
  10. 'force-overwrite' => '',
  11. ],
  12. 'short' => [],
  13. 'deprecated' => [],
  14. ];
  15. $options = parseCliParams($parameters);
  16. if (!empty($options['invalid'])
  17. || empty($options['valid']['user']) || empty($options['valid']['filename'])
  18. || !is_string($options['valid']['user']) || !is_string($options['valid']['filename'])
  19. ) {
  20. fail('Usage: ' . basename(__FILE__) . ' --user username --force-overwrite --filename /path/to/db.sqlite');
  21. }
  22. $username = cliInitUser($options['valid']['user']);
  23. $filename = $options['valid']['filename'];
  24. if (pathinfo($filename, PATHINFO_EXTENSION) !== 'sqlite') {
  25. fail('Only *.sqlite files are supported!');
  26. }
  27. echo 'FreshRSS importing database from SQLite for user “', $username, "”…\n";
  28. $databaseDAO = FreshRSS_Factory::createDatabaseDAO($username);
  29. $clearFirst = array_key_exists('force-overwrite', $options['valid']);
  30. $ok = $databaseDAO->dbCopy($filename, FreshRSS_DatabaseDAO::SQLITE_IMPORT, $clearFirst);
  31. if (!$ok) {
  32. echo 'If you would like to clear the user database first, use the option --force-overwrite', "\n";
  33. }
  34. invalidateHttpCache($username);
  35. done($ok);