aboutsummaryrefslogtreecommitdiff
path: root/cli/_cli.php
blob: 1b26ea738ade8825b649c572940c844f0ded667c (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
<?php
if (php_sapi_name() !== 'cli') {
	die('FreshRSS error: This PHP script may only be invoked from command line!');
}

require(dirname(__FILE__) . '/../constants.php');
require(LIB_PATH . '/lib_rss.php');

Minz_Configuration::register('system',
	DATA_PATH . '/config.php',
	FRESHRSS_PATH . '/config.default.php');
FreshRSS_Context::$system_conf = Minz_Configuration::get('system');
Minz_Translate::init('en');

FreshRSS_Context::$isCli = true;

function fail($message) {
	fwrite(STDERR, $message . "\n");
	die(1);
}

function cliInitUser($username) {
	if (!FreshRSS_user_Controller::checkUsername($username)) {
		fail('FreshRSS error: invalid username: ' . $username . "\n");
	}

	$usernames = listUsers();
	if (!in_array($username, $usernames)) {
		fail('FreshRSS error: user not found: ' . $username . "\n");
	}

	FreshRSS_Context::$user_conf = get_user_configuration($username);
	if (FreshRSS_Context::$user_conf == null) {
		fail('FreshRSS error: invalid configuration for user: ' . $username . "\n");
	}
	new Minz_ModelPdo($username);

	return $username;
}

function accessRights() {
	echo '• Remember to re-apply the appropriate access rights, such as:' , "\n",
		"\t", 'sudo chown -R :www-data . && sudo chmod -R g+r . && sudo chmod -R g+w ./data/', "\n";
}

function done($ok = true) {
	fwrite(STDERR, 'Result: ' . ($ok ? 'success' : 'fail') . "\n");
	exit($ok ? 0 : 1);
}