_update-or-create-user.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. declare(strict_types=1);
  3. require(__DIR__ . '/_cli.php');
  4. performRequirementCheck(FreshRSS_Context::systemConf()->db['type'] ?? '');
  5. $params = array(
  6. 'user:',
  7. 'password:',
  8. 'api_password:',
  9. 'language:',
  10. 'email:',
  11. 'token:',
  12. 'purge_after_months:',
  13. 'feed_min_articles_default:',
  14. 'feed_ttl_default:',
  15. 'since_hours_posts_per_rss:',
  16. 'max_posts_per_rss:',
  17. );
  18. if (!isset($isUpdate)) {
  19. $isUpdate = false;
  20. } elseif (!$isUpdate) {
  21. $params[] = 'no_default_feeds'; //Only for creating new users
  22. }
  23. $GLOBALS['options'] = getopt('', $params);
  24. if (!validateOptions($argv, $params) || empty($options['user'])) {
  25. fail('Usage: ' . basename($_SERVER['SCRIPT_FILENAME']) .
  26. " --user username ( --password 'password' --api_password 'api_password'" .
  27. " --language en --email user@example.net --token 'longRandomString'" .
  28. ($isUpdate ? '' : ' --no_default_feeds') .
  29. " --purge_after_months 3 --feed_min_articles_default 50 --feed_ttl_default 3600" .
  30. " --since_hours_posts_per_rss 168 --max_posts_per_rss 400 )");
  31. }
  32. function strParam(string $name): ?string {
  33. global $options;
  34. return isset($options[$name]) ? strval($options[$name]) : null;
  35. }
  36. function intParam(string $name): ?int {
  37. global $options;
  38. return isset($options[$name]) && ctype_digit($options[$name]) ? intval($options[$name]) : null;
  39. }
  40. $values = array(
  41. 'language' => strParam('language'),
  42. 'mail_login' => strParam('email'),
  43. 'token' => strParam('token'),
  44. 'old_entries' => intParam('purge_after_months'), //TODO: Update with new mechanism
  45. 'keep_history_default' => intParam('feed_min_articles_default'), //TODO: Update with new mechanism
  46. 'ttl_default' => intParam('feed_ttl_default'),
  47. 'since_hours_posts_per_rss' => intParam('since_hours_posts_per_rss'),
  48. 'max_posts_per_rss' => intParam('max_posts_per_rss'),
  49. );
  50. $values = array_filter($values);