summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/_cli.php5
-rwxr-xr-xcli/create-user.php17
-rwxr-xr-xcli/delete-user.php3
-rw-r--r--cli/import-for-user.php36
-rwxr-xr-xcli/list-users.php4
5 files changed, 52 insertions, 13 deletions
diff --git a/cli/_cli.php b/cli/_cli.php
index cb6d8ec32..d81d83d66 100644
--- a/cli/_cli.php
+++ b/cli/_cli.php
@@ -37,3 +37,8 @@ function cliInitUser($username) {
return $username;
}
+
+function done($ok) {
+ echo 'Result: ', ($ok ? 'success' : 'fail'), ".\n";
+ exit($ok ? 0 : 1);
+}
diff --git a/cli/create-user.php b/cli/create-user.php
index 08c057af8..387b503b6 100755
--- a/cli/create-user.php
+++ b/cli/create-user.php
@@ -15,19 +15,19 @@ if (empty($options['user'])) {
fail('Usage: ' . basename(__FILE__) . " --user=username --password='password' --api-password='api_password'" .
" --language=en --email=user@example.net --token='longRandomString'");
}
-$new_user_name = $options['user'];
-if (!ctype_alnum($new_user_name)) {
- fail('FreshRSS error: invalid username “' . $new_user_name . '”');
+$username = $options['user'];
+if (!ctype_alnum($username)) {
+ fail('FreshRSS error: invalid username “' . $username . '”');
}
$usernames = listUsers();
-if (preg_grep("/^$new_user_name$/i", $usernames)) {
- fail('FreshRSS error: username already taken “' . $new_user_name . '”');
+if (preg_grep("/^$username$/i", $usernames)) {
+ fail('FreshRSS error: username already taken “' . $username . '”');
}
-echo 'FreshRSS creating user “', $new_user_name, "”…\n";
+echo 'FreshRSS creating user “', $username, "”…\n";
-$ok = FreshRSS_user_Controller::createUser($new_user_name,
+$ok = FreshRSS_user_Controller::createUser($username,
empty($options['password']) ? '' : $options['password'],
empty($options['api-password']) ? '' : $options['api-password'],
array(
@@ -37,5 +37,4 @@ $ok = FreshRSS_user_Controller::createUser($new_user_name,
invalidateHttpCache(FreshRSS_Context::$system_conf->default_user);
-echo 'Result: ', ($ok ? 'success' : 'fail'), ".\n";
-exit($ok ? 0 : 1);
+done($ok);
diff --git a/cli/delete-user.php b/cli/delete-user.php
index 46332fe34..da48103f7 100755
--- a/cli/delete-user.php
+++ b/cli/delete-user.php
@@ -29,5 +29,4 @@ $ok = FreshRSS_user_Controller::deleteUser($username);
invalidateHttpCache(FreshRSS_Context::$system_conf->default_user);
-echo 'Result: ', ($ok ? 'success' : 'fail'), ".\n";
-exit($ok ? 0 : 1);
+done($ok);
diff --git a/cli/import-for-user.php b/cli/import-for-user.php
new file mode 100644
index 000000000..308786599
--- /dev/null
+++ b/cli/import-for-user.php
@@ -0,0 +1,36 @@
+#!/usr/bin/php
+<?php
+require('_cli.php');
+
+$options = getopt('', array(
+ 'user:',
+ 'filename:',
+ 'clear-existing',
+ ));
+
+if (empty($options['user']) || empty($options['filename'])) {
+ fail('Usage: ' . basename(__FILE__) . " --user=username --filename='/path/to/file.ext' --clear-existing");
+}
+
+$username = cliInitUser($options['user']);
+
+$filename = $options['filename'];
+if (!is_readable($filename)) {
+ fail('FreshRSS error: file is not readable “' . $filename . '”');
+}
+
+echo 'FreshRSS importing ZIP/OPML/JSON for user “', $username, "”…\n";
+
+$importController = new FreshRSS_importExport_Controller();
+
+$ok = false;
+try {
+ $ok = $importController->importFile($filename, $filename, $username);
+} catch (FreshRSS_ZipMissing_Exception $zme) {
+ fail('FreshRSS error: Lacking php-zip extension!');
+} catch (FreshRSS_Zip_Exception $ze) {
+ fail('FreshRSS error: ZIP archive cannot be imported! Error code: ' . $ze->zipErrorCode());
+}
+invalidateHttpCache($username);
+
+done($ok);
diff --git a/cli/list-users.php b/cli/list-users.php
index cc1cf5269..e690ff451 100755
--- a/cli/list-users.php
+++ b/cli/list-users.php
@@ -4,8 +4,8 @@ require('_cli.php');
$users = listUsers();
sort($users);
-if ($system_conf->default_user !== '') {
- array_unshift($users, $system_conf->default_user);
+if (FreshRSS_Context::$system_conf->default_user !== '') {
+ array_unshift($users, FreshRSS_Context::$system_conf->default_user);
$users = array_unique($users);
}