_update-or-create-user.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. require(__DIR__ . '/_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. 'max_posts_per_rss:',
  15. );
  16. if (!$isUpdate) {
  17. $params[] = 'no_default_feeds'; //Only for creating new users
  18. }
  19. $options = getopt('', $params);
  20. if (!validateOptions($argv, $params) || empty($options['user'])) {
  21. fail('Usage: ' . basename($_SERVER['SCRIPT_FILENAME']) .
  22. " --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 --max_posts_per_rss 400 )");
  27. }
  28. function strParam($name) {
  29. global $options;
  30. return isset($options[$name]) ? strval($options[$name]) : null;
  31. }
  32. function intParam($name) {
  33. global $options;
  34. return isset($options[$name]) && ctype_digit($options[$name]) ? intval($options[$name]) : null;
  35. }
  36. $values = array(
  37. 'language' => strParam('language'),
  38. 'mail_login' => strParam('email'),
  39. 'token' => strParam('token'),
  40. 'old_entries' => intParam('purge_after_months'), //TODO: Update with new mechanism
  41. 'keep_history_default' => intParam('feed_min_articles_default'), //TODO: Update with new mechanism
  42. 'ttl_default' => intParam('feed_ttl_default'),
  43. 'since_hours_posts_per_rss' => intParam('since_hours_posts_per_rss'),
  44. 'max_posts_per_rss' => intParam('max_posts_per_rss'),
  45. );
  46. $values = array_filter($values);