Files
FreshRSS/cli/delete-user.php
Alexis Degrugillier 71b4226dc7 Add an option validation on cli commands (#2278)
If an option used on cli is not recognized, the command
aborts and displays an error message.
If the typed option is similar to one of the recognized
options, a hint is displayed.

At the moment, there is a limitation on long options.
Short options are not validated at the moment.

See #2046
2019-03-19 20:27:06 +01:00

35 lines
914 B
PHP
Executable File

#!/usr/bin/php
<?php
require(__DIR__ . '/_cli.php');
$params = array(
'user:',
);
$options = getopt('', $params);
if (!validateOptions($argv, $params) || empty($options['user'])) {
fail('Usage: ' . basename(__FILE__) . " --user username");
}
$username = $options['user'];
if (!FreshRSS_user_Controller::checkUsername($username)) {
fail('FreshRSS error: invalid username “' . $username . '”');
}
$usernames = listUsers();
if (!preg_grep("/^$username$/i", $usernames)) {
fail('FreshRSS error: username not found “' . $username . '”');
}
if (strcasecmp($username, FreshRSS_Context::$system_conf->default_user) === 0) {
fail('FreshRSS error: default user must not be deleted: “' . $username . '”');
}
echo 'FreshRSS deleting user “', $username, "”…\n";
$ok = FreshRSS_user_Controller::deleteUser($username);
invalidateHttpCache(FreshRSS_Context::$system_conf->default_user);
done($ok);