aboutsummaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2016-11-05 20:48:46 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2016-11-05 20:48:46 +0100
commitaeda49a7d271c2196fcba0d3b2b15d31ad0b33b5 (patch)
tree5913bdb716f5e3025963bcc9dc93c34c4d521601 /cli
parent28bb2813f3121a7c992eba279d0c566269d619aa (diff)
Add CLI for user information + Fix last user activity
https://github.com/FreshRSS/FreshRSS/issues/1345
Diffstat (limited to 'cli')
-rw-r--r--cli/README.md16
-rw-r--r--cli/user-info.php43
2 files changed, 59 insertions, 0 deletions
diff --git a/cli/README.md b/cli/README.md
index 444606b50..09dcbd27e 100644
--- a/cli/README.md
+++ b/cli/README.md
@@ -55,4 +55,20 @@ cd /usr/share/FreshRSS
./cli/export-opml-for-user.php --user username > /path/to/file.opml.xml
./cli/export-zip-for-user.php --user username ( --max-feed-entries 100 ) > /path/to/file.zip
+
+./cli/user-info.php -h --user username
+# -h is to use a human-readable format
+# --user can be a username, or '*' to loop on all users
+# Returns a * if the user is admin, the name of the user, the date/time of last action, and the size occupied
+```
+
+
+## Unix piping
+
+It is possible to invoke a command multiple times, e.g. with different usernames, thanks to the `xargs -n1` command.
+
+Example showing user information for all users which username starts with 'a':
+
+```sh
+./cli/list-users.php | grep '^a' | xargs -n1 ./cli/user-info.php -h --user
```
diff --git a/cli/user-info.php b/cli/user-info.php
new file mode 100644
index 000000000..5b26ecb15
--- /dev/null
+++ b/cli/user-info.php
@@ -0,0 +1,43 @@
+#!/usr/bin/php
+<?php
+require('_cli.php');
+
+function formatSize($bytes)
+{//http://www.php.net/manual/function.disk-free-space.php#103382
+ $si_prefix = array('', 'k', 'M', 'G', 'T', 'P');
+ $i = min((int)log($bytes, 1024), count($si_prefix) - 1);
+ return ($i <= 0) ? $bytes.'B' :
+ round($bytes / pow(1024, $i), 2).' '.$si_prefix[$i].'B';
+}
+
+$options = getopt('h', array(
+ 'user:',
+ ));
+
+if (empty($options['user'])) {
+ fail('Usage: ' . basename(__FILE__) . " -h --user username");
+}
+
+$users = $options['user'] === '*' ? listUsers() : array($options['user']);
+
+foreach ($users as $username) {
+ $username = cliInitUser($username);
+
+ $entryDAO = FreshRSS_Factory::createEntryDao($username);
+
+ echo $username === FreshRSS_Context::$system_conf->default_user ? '*' : ' ', "\t";
+
+ if (isset($options['h'])) { //Human format
+ echo
+ $username, "\t",
+ date('c', FreshRSS_UserDAO::mtime($username)), "\t",
+ formatSize($entryDAO->size()), "\t",
+ "\n";
+ } else {
+ echo
+ $username, "\t",
+ FreshRSS_UserDAO::mtime($username), "\t",
+ $entryDAO->size(), "\t",
+ "\n";
+ }
+}