_update-or-create-user.php 1.7 KB

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