_update-or-create-user.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. require('_cli.php');
  3. $params = array(
  4. 'user:',
  5. 'password:',
  6. 'api_password:',
  7. 'language:',
  8. 'email:',
  9. 'token:',
  10. 'purge_after_months:',
  11. 'feed_min_articles_default:',
  12. 'feed_ttl_default:',
  13. 'since_hours_posts_per_rss:',
  14. 'min_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 (empty($options['user'])) {
  22. fail('Usage: ' . basename($_SERVER['SCRIPT_FILENAME']) . " --user username ( --password 'password' --api_password 'api_password'" .
  23. " --language en --email user@example.net --token 'longRandomString'" .
  24. ($isUpdate ? '' : '--no_default_feeds') .
  25. " --purge_after_months 3 --feed_min_articles_default 50 --feed_ttl_default 3600" .
  26. " --since_hours_posts_per_rss 168 --min_posts_per_rss 2 --max_posts_per_rss 400 )");
  27. }
  28. function strParam($name) {
  29. return isset($options[$name]) ? strval($options[$name]) : null;
  30. }
  31. function intParam($name) {
  32. return isset($options[$name]) && ctype_digit($options[$name]) ? intval($options[$name]) : null;
  33. }
  34. $values = array(
  35. 'language' => strParam('language'),
  36. 'mail_login' => strParam('email'),
  37. 'token' => strParam('token'),
  38. 'old_entries' => intParam('purge_after_months'),
  39. 'keep_history_default' => intParam('feed_min_articles_default'),
  40. 'ttl_default' => intParam('feed_ttl_default'),
  41. 'since_hours_posts_per_rss' => intParam('since_hours_posts_per_rss'),
  42. 'min_posts_per_rss' => intParam('min_posts_per_rss'),
  43. 'max_posts_per_rss' => intParam('max_posts_per_rss'),
  44. );