_update-or-create-user.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 (!isset($isUpdate)) {
  18. $isUpdate = false;
  19. } elseif (!$isUpdate) {
  20. $params[] = 'no_default_feeds'; //Only for creating new users
  21. }
  22. $GLOBALS['options'] = getopt('', $params);
  23. if (!validateOptions($argv, $params) || empty($options['user'])) {
  24. fail('Usage: ' . basename($_SERVER['SCRIPT_FILENAME']) .
  25. " --user username ( --password 'password' --api_password 'api_password'" .
  26. " --language en --email user@example.net --token 'longRandomString'" .
  27. ($isUpdate ? '' : ' --no_default_feeds') .
  28. " --purge_after_months 3 --feed_min_articles_default 50 --feed_ttl_default 3600" .
  29. " --since_hours_posts_per_rss 168 --max_posts_per_rss 400 )");
  30. }
  31. function strParam($name) {
  32. global $options;
  33. return isset($options[$name]) ? strval($options[$name]) : null;
  34. }
  35. function intParam($name) {
  36. global $options;
  37. return isset($options[$name]) && ctype_digit($options[$name]) ? intval($options[$name]) : null;
  38. }
  39. $values = array(
  40. 'language' => strParam('language'),
  41. 'mail_login' => strParam('email'),
  42. 'token' => strParam('token'),
  43. 'old_entries' => intParam('purge_after_months'), //TODO: Update with new mechanism
  44. 'keep_history_default' => intParam('feed_min_articles_default'), //TODO: Update with new mechanism
  45. 'ttl_default' => intParam('feed_ttl_default'),
  46. 'since_hours_posts_per_rss' => intParam('since_hours_posts_per_rss'),
  47. 'max_posts_per_rss' => intParam('max_posts_per_rss'),
  48. );
  49. $values = array_filter($values);