aboutsummaryrefslogtreecommitdiff
path: root/cli/update-user.php
blob: f8ed26c8f82ae95fe466b63cb98f257d704c3190 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/php
<?php
require('_cli.php');

$options = getopt('', array(
		'user:',
		'password:',
		'api-password:',
		'language:',
		'email:',
		'token:',
		'purge_after_months:',
		'feed_min_articles_default:',
		'feed_ttl_default:',
		'since_hours_posts_per_rss:',
		'min_posts_per_rss:',
		'max_posts_per_rss:',
	));

if (empty($options['user'])) {
	fail('Usage: ' . basename(__FILE__) . " --user username ( --password 'password' --api-password 'api_password'" .
		" --language en --email user@example.net --token 'longRandomString' --purge_after_months 3 " .
		" --feed_min_articles_default 50 --feed_ttl_default 3600 --since_hours_posts_per_rss 168 --min_posts_per_rss 2 --max_posts_per_rss 400 )");
}

$username = cliInitUser($options['user']);

echo 'FreshRSS updating user “', $username, "”…\n";

function intParam($name) {
	return isset($options[$name]) && ctype_digit($options[$name]) ? intval($options[$name]) : null;
}

$ok = FreshRSS_user_Controller::updateContextUser(
	empty($options['password']) ? '' : $options['password'],
	empty($options['api-password']) ? '' : $options['api-password'],
	array(
		'language' => isset($options['language']) ? $options['language'] : null,
		'mail_login' => isset($options['email']) ? $options['email'] : null,
		'token' => isset($options['token']) ? $options['token'] : null,
		'old_entries' => intParam('purge_after_months'),
		'keep_history_default' => intParam('feed_min_articles_default'),
		'ttl_default' => intParam('feed_ttl_default'),
		'since_hours_posts_per_rss' => intParam('since_hours_posts_per_rss'),
		'min_posts_per_rss' => intParam('min_posts_per_rss'),
		'max_posts_per_rss' => intParam('max_posts_per_rss'),
	));

if (!$ok) {
	fail('FreshRSS could not update user!');
}

invalidateHttpCache($username);

accessRights();

done($ok);