import-for-user.php 959 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/php
  2. <?php
  3. require(__DIR__ . '/_cli.php');
  4. $options = getopt('', array(
  5. 'user:',
  6. 'filename:',
  7. ));
  8. if (empty($options['user']) || empty($options['filename'])) {
  9. fail('Usage: ' . basename(__FILE__) . " --user username --filename /path/to/file.ext");
  10. }
  11. $username = cliInitUser($options['user']);
  12. $filename = $options['filename'];
  13. if (!is_readable($filename)) {
  14. fail('FreshRSS error: file is not readable “' . $filename . '”');
  15. }
  16. echo 'FreshRSS importing ZIP/OPML/JSON for user “', $username, "”…\n";
  17. $importController = new FreshRSS_importExport_Controller();
  18. $ok = false;
  19. try {
  20. $ok = $importController->importFile($filename, $filename, $username);
  21. } catch (FreshRSS_ZipMissing_Exception $zme) {
  22. fail('FreshRSS error: Lacking php-zip extension!');
  23. } catch (FreshRSS_Zip_Exception $ze) {
  24. fail('FreshRSS error: ZIP archive cannot be imported! Error code: ' . $ze->zipErrorCode());
  25. }
  26. invalidateHttpCache($username);
  27. done($ok);