Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/management/PhabricatorAuthManagementUnlimitWorkflow.php
12256 views
1
<?php
2
3
final class PhabricatorAuthManagementUnlimitWorkflow
4
extends PhabricatorAuthManagementWorkflow {
5
6
protected function didConstruct() {
7
$this
8
->setName('unlimit')
9
->setExamples('**unlimit** --user __username__ --all')
10
->setSynopsis(
11
pht(
12
'Reset action counters so a user can continue taking '.
13
'rate-limited actions.'))
14
->setArguments(
15
array(
16
array(
17
'name' => 'user',
18
'param' => 'username',
19
'help' => pht('Reset action counters for this user.'),
20
),
21
array(
22
'name' => 'all',
23
'help' => pht('Reset all counters.'),
24
),
25
));
26
}
27
28
public function execute(PhutilArgumentParser $args) {
29
$username = $args->getArg('user');
30
if (!strlen($username)) {
31
throw new PhutilArgumentUsageException(
32
pht(
33
'Use %s to choose a user to reset actions for.', '--user'));
34
}
35
36
$user = id(new PhabricatorPeopleQuery())
37
->setViewer($this->getViewer())
38
->withUsernames(array($username))
39
->executeOne();
40
if (!$user) {
41
throw new PhutilArgumentUsageException(
42
pht(
43
'No user exists with username "%s".',
44
$username));
45
}
46
47
$all = $args->getArg('all');
48
if (!$all) {
49
// TODO: Eventually, let users reset specific actions. For now, we
50
// require `--all` so that usage won't change when you can reset in a
51
// more tailored way.
52
throw new PhutilArgumentUsageException(
53
pht(
54
'Specify %s to reset all action counters.', '--all'));
55
}
56
57
$count = PhabricatorSystemActionEngine::resetActions(
58
array(
59
$user->getPHID(),
60
));
61
62
echo pht('Reset %s action(s).', new PhutilNumber($count))."\n";
63
64
return 0;
65
}
66
67
}
68
69