4
0

import-sqlite-for-user.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. $cliOptions = new class extends CliOptionsParser {
  7. public string $user;
  8. public string $filename;
  9. public bool $forceOverwrite;
  10. public function __construct() {
  11. $this->addRequiredOption('user', (new CliOption('user')));
  12. $this->addRequiredOption('filename', (new CliOption('filename')));
  13. $this->addOption('forceOverwrite', (new CliOption('force-overwrite'))->withValueNone());
  14. parent::__construct();
  15. }
  16. };
  17. if (!empty($cliOptions->errors)) {
  18. fail('FreshRSS error: ' . array_shift($cliOptions->errors) . "\n" . $cliOptions->usage);
  19. }
  20. $username = cliInitUser($cliOptions->user);
  21. $filename = $cliOptions->filename;
  22. if (pathinfo($filename, PATHINFO_EXTENSION) !== 'sqlite') {
  23. fail('Only *.sqlite files are supported!');
  24. }
  25. echo 'FreshRSS importing database from SQLite for user “', $username, "”…\n";
  26. $databaseDAO = FreshRSS_Factory::createDatabaseDAO($username);
  27. $ok = $databaseDAO->dbCopy($filename, FreshRSS_DatabaseDAO::SQLITE_IMPORT, clearFirst: $cliOptions->forceOverwrite);
  28. if (!$ok) {
  29. echo 'If you would like to clear the user database first, use the option --force-overwrite', "\n";
  30. }
  31. invalidateHttpCache($username);
  32. done($ok);