4
0

_update-or-create-user.php 1.6 KB

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