_update-or-create-user.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. declare(strict_types=1);
  3. require(__DIR__ . '/_cli.php');
  4. performRequirementCheck(FreshRSS_Context::systemConf()->db['type'] ?? '');
  5. $parameters = array(
  6. 'valid' => array(
  7. 'user' => ':',
  8. 'password' => ':',
  9. 'api-password' => ':',
  10. 'language' => ':',
  11. 'email' => ':',
  12. 'token' => ':',
  13. 'purge-after-months' => ':',
  14. 'feed-min-articles-default' => ':',
  15. 'feed-ttl-default' => ':',
  16. 'since-hours-posts-per-rss' => ':',
  17. 'max-posts-per-rss' => ':',
  18. ),
  19. 'deprecated' => array(
  20. 'api-password' => 'api_password',
  21. 'purge-after-months' => 'purge_after_months',
  22. 'feed-min-articles-default' => 'feed_min_articles_default',
  23. 'feed-ttl-default' => 'feed_ttl_default',
  24. 'since-hours-posts-per-rss' => 'since_hours_posts_per_rss',
  25. 'max-posts-per-rss' => 'max_posts_per_rss',
  26. ),
  27. );
  28. if (!isset($isUpdate)) {
  29. $isUpdate = false;
  30. } elseif (!$isUpdate) {
  31. $parameters['valid']['no-default-feeds'] = ''; //Only for creating new users
  32. $parameters['deprecated']['no-default-feeds'] = 'no_default_feeds';
  33. }
  34. $GLOBALS['options'] = parseCliParams($parameters);
  35. if (!empty($options['invalid']) || empty($options['valid']['user'])) {
  36. fail('Usage: ' . basename($_SERVER['SCRIPT_FILENAME']) .
  37. " --user username ( --password 'password' --api-password 'api_password'" .
  38. " --language en --email user@example.net --token 'longRandomString'" .
  39. ($isUpdate ? '' : ' --no-default-feeds') .
  40. " --purge-after-months 3 --feed-min-articles-default 50 --feed-ttl-default 3600" .
  41. " --since-hours-posts-per-rss 168 --max-posts-per-rss 400 )");
  42. }
  43. function strParam(string $name): ?string {
  44. global $options;
  45. return isset($options['valid'][$name]) ? strval($options['valid'][$name]) : null;
  46. }
  47. function intParam(string $name): ?int {
  48. global $options;
  49. return isset($options['valid'][$name]) && ctype_digit($options['valid'][$name]) ? intval($options['valid'][$name]) : null;
  50. }
  51. $values = array(
  52. 'language' => strParam('language'),
  53. 'mail_login' => strParam('email'),
  54. 'token' => strParam('token'),
  55. 'old_entries' => intParam('purge-after-months'), //TODO: Update with new mechanism
  56. 'keep_history_default' => intParam('feed-min-articles-default'), //TODO: Update with new mechanism
  57. 'ttl_default' => intParam('feed-ttl-default'),
  58. 'since_hours_posts_per_rss' => intParam('since-hours-posts-per-rss'),
  59. 'max_posts_per_rss' => intParam('max-posts-per-rss'),
  60. );
  61. $values = array_filter($values);