Differential D9431 Diff 22523 src/applications/audit/management/PhabricatorAuditManagementDeleteWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/audit/management/PhabricatorAuditManagementDeleteWorkflow.php
| Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | public function execute(PhutilArgumentParser $args) { | ||||
| if (!$status) { | if (!$status) { | ||||
| $status = DiffusionCommitQuery::AUDIT_STATUS_OPEN; | $status = DiffusionCommitQuery::AUDIT_STATUS_OPEN; | ||||
| } | } | ||||
| $min_date = $this->loadDate($args->getArg('min-commit-date')); | $min_date = $this->loadDate($args->getArg('min-commit-date')); | ||||
| $max_date = $this->loadDate($args->getArg('max-commit-date')); | $max_date = $this->loadDate($args->getArg('max-commit-date')); | ||||
| if ($min_date && $max_date && ($min_date > $max_date)) { | if ($min_date && $max_date && ($min_date > $max_date)) { | ||||
| throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
| "Specified max date must come after specified min date."); | 'Specified max date must come after specified min date.'); | ||||
| } | } | ||||
| $is_dry_run = $args->getArg('dry-run'); | $is_dry_run = $args->getArg('dry-run'); | ||||
| $query = id(new DiffusionCommitQuery()) | $query = id(new DiffusionCommitQuery()) | ||||
| ->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
| ->needAuditRequests(true); | ->needAuditRequests(true); | ||||
| Show All 35 Lines | foreach ($commits as $commit) { | ||||
| } | } | ||||
| $audits[] = $curr_audits; | $audits[] = $curr_audits; | ||||
| } | } | ||||
| $audits = array_mergev($audits); | $audits = array_mergev($audits); | ||||
| $console = PhutilConsole::getConsole(); | $console = PhutilConsole::getConsole(); | ||||
| if (!$audits) { | if (!$audits) { | ||||
| $console->writeErr("%s\n", pht("No audits match the query.")); | $console->writeErr("%s\n", pht('No audits match the query.')); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| $handles = id(new PhabricatorHandleQuery()) | $handles = id(new PhabricatorHandleQuery()) | ||||
| ->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
| ->withPHIDs(mpull($audits, 'getAuditorPHID')) | ->withPHIDs(mpull($audits, 'getAuditorPHID')) | ||||
| ->execute(); | ->execute(); | ||||
| foreach ($audits as $audit) { | foreach ($audits as $audit) { | ||||
| $commit = $commits[$audit->getCommitPHID()]; | $commit = $commits[$audit->getCommitPHID()]; | ||||
| $console->writeOut( | $console->writeOut( | ||||
| "%s\n", | "%s\n", | ||||
| sprintf( | sprintf( | ||||
| "%10d %-16s %-16s %s: %s", | '%10d %-16s %-16s %s: %s', | ||||
| $audit->getID(), | $audit->getID(), | ||||
| $handles[$audit->getAuditorPHID()]->getName(), | $handles[$audit->getAuditorPHID()]->getName(), | ||||
| PhabricatorAuditStatusConstants::getStatusName( | PhabricatorAuditStatusConstants::getStatusName( | ||||
| $audit->getAuditStatus()), | $audit->getAuditStatus()), | ||||
| $commit->getRepository()->formatCommitName( | $commit->getRepository()->formatCommitName( | ||||
| $commit->getCommitIdentifier()), | $commit->getCommitIdentifier()), | ||||
| trim($commit->getSummary()))); | trim($commit->getSummary()))); | ||||
| } | } | ||||
| if (!$is_dry_run) { | if (!$is_dry_run) { | ||||
| $message = pht( | $message = pht( | ||||
| 'Really delete these %d audit(s)? They will be permanently deleted '. | 'Really delete these %d audit(s)? They will be permanently deleted '. | ||||
| 'and can not be recovered.', | 'and can not be recovered.', | ||||
| count($audits)); | count($audits)); | ||||
| if ($console->confirm($message)) { | if ($console->confirm($message)) { | ||||
| foreach ($audits as $audit) { | foreach ($audits as $audit) { | ||||
| $id = $audit->getID(); | $id = $audit->getID(); | ||||
| $console->writeOut("%s\n", pht("Deleting audit %d...", $id)); | $console->writeOut("%s\n", pht('Deleting audit %d...', $id)); | ||||
| $audit->delete(); | $audit->delete(); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 100 Lines • Show Last 20 Lines | |||||