Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / metamta / management / PhabricatorMailManagementUnverifyWorkflow.php
blob64f4976ebe5d92ee9249c6e58e8d3ffa107ef989
1 <?php
3 final class PhabricatorMailManagementUnverifyWorkflow
4 extends PhabricatorMailManagementWorkflow {
6 protected function didConstruct() {
7 $this
8 ->setName('unverify')
9 ->setSynopsis(
10 pht('Unverify an email address so it no longer receives mail.'))
11 ->setExamples('**unverify** __address__ ...')
12 ->setArguments(
13 array(
14 array(
15 'name' => 'addresses',
16 'wildcard' => true,
17 'help' => pht('Address (or addresses) to unverify.'),
19 ));
22 public function execute(PhutilArgumentParser $args) {
23 $console = PhutilConsole::getConsole();
24 $viewer = $this->getViewer();
26 $addresses = $args->getArg('addresses');
27 if (!$addresses) {
28 throw new PhutilArgumentUsageException(
29 pht('Specify one or more email addresses to unverify.'));
32 foreach ($addresses as $address) {
33 $email = id(new PhabricatorUserEmail())->loadOneWhere(
34 'address = %s',
35 $address);
36 if (!$email) {
37 echo tsprintf(
38 "%s\n",
39 pht(
40 'Address "%s" is unknown.',
41 $address));
42 continue;
45 $user_phid = $email->getUserPHID();
47 $user = id(new PhabricatorPeopleQuery())
48 ->setViewer($viewer)
49 ->withPHIDs(array($user_phid))
50 ->executeOne();
52 if (!$user) {
53 echo tsprintf(
54 "%s\n",
55 pht(
56 'Address "%s" belongs to invalid user "%s".',
57 $address,
58 $user_phid));
59 continue;
62 if (!$email->getIsVerified()) {
63 echo tsprintf(
64 "%s\n",
65 pht(
66 'Address "%s" (owned by "%s") is already unverified.',
67 $address,
68 $user->getUsername()));
69 continue;
72 $email->openTransaction();
74 $email
75 ->setIsVerified(0)
76 ->save();
78 if ($email->getIsPrimary()) {
79 $user
80 ->setIsEmailVerified(0)
81 ->save();
84 $email->saveTransaction();
86 if ($email->getIsPrimary()) {
87 echo tsprintf(
88 "%s\n",
89 pht(
90 'Unverified "%s", the primary address for "%s".',
91 $address,
92 $user->getUsername()));
93 } else {
94 echo tsprintf(
95 "%s\n",
96 pht(
97 'Unverified "%s", an address for "%s".',
98 $address,
99 $user->getUsername()));
103 echo tsprintf(
104 "%s\n",
105 pht('Done.'));
107 return 0;