Files
FreshRSS/cli/user-info.php
Alexis Degrugillier f2925594c7 Add header to cli (#2296)
* Add header to cli

Now there is a switch to display the header on user info.
While doing that, I've changed how the command is working to display
all users by default and to accept more than one user at once.
I also changed the display to make it more pleasing.

As this command displays all users by default. I wonder if we still
need the list user command.

See #2294

* Minor format
2019-03-23 23:17:22 +01:00

75 lines
1.8 KiB
PHP
Executable File

#!/usr/bin/php
<?php
require(__DIR__ . '/_cli.php');
const DATA_FORMAT = "%-7s | %-20s | %-25s | %-15s | %-10s | %-10s | %-10s | %-10s | %-10s | %-10s\n";
$params = array(
'user:',
'header',
);
$options = getopt('h', $params);
if (!validateOptions($argv, $params)) {
fail('Usage: ' . basename(__FILE__) . ' (-h --header --user username --user username …)');
}
if (empty($options['user'])) {
$users = listUsers();
} elseif (is_array($options['user'])) {
$users = $options['user'];
} else {
$users = array($options['user']);
}
sort($users);
if (array_key_exists('header', $options)) {
printf(
DATA_FORMAT,
'default',
'user',
'last update',
'space used',
'categories',
'feeds',
'reads',
'unreads',
'favourites',
'tags'
);
}
foreach ($users as $username) {
$username = cliInitUser($username);
$catDAO = FreshRSS_Factory::createCategoryDao();
$feedDAO = FreshRSS_Factory::createFeedDao($username);
$entryDAO = FreshRSS_Factory::createEntryDao($username);
$tagDAO = FreshRSS_Factory::createTagDao($username);
$databaseDAO = FreshRSS_Factory::createDatabaseDAO($username);
$nbEntries = $entryDAO->countUnreadRead();
$nbFavorites = $entryDAO->countUnreadReadFavorites();
$data = array(
'default' => $username === FreshRSS_Context::$system_conf->default_user ? '*' : '',
'user' => $username,
'lastUpdate' => FreshRSS_UserDAO::mtime($username),
'spaceUsed' => $databaseDAO->size(),
'categories' => $catDAO->count(),
'feeds' => count($feedDAO->listFeedsIds()),
'reads' => $nbEntries['read'],
'unreads' => $nbEntries['unread'],
'favourites' => $nbFavorites['all'],
'tags' => $tagDAO->count(),
);
if (isset($options['h'])) { //Human format
$data['lastUpdate'] = date('c', $data['lastUpdate']);
$data['spaceUsed'] = format_bytes($data['spaceUsed']);
}
vprintf(DATA_FORMAT, $data);
}
done();