Path: blob/master/src/applications/metamta/management/PhabricatorMailManagementResendWorkflow.php
12256 views
<?php12final class PhabricatorMailManagementResendWorkflow3extends PhabricatorMailManagementWorkflow {45protected function didConstruct() {6$this7->setName('resend')8->setSynopsis(pht('Send mail again.'))9->setExamples(10'**resend** --id 1 --id 2')11->setArguments(12array(13array(14'name' => 'id',15'param' => 'id',16'help' => pht('Send mail with a given ID again.'),17'repeat' => true,18),19));20}2122public function execute(PhutilArgumentParser $args) {23$console = PhutilConsole::getConsole();2425$ids = $args->getArg('id');26if (!$ids) {27throw new PhutilArgumentUsageException(28pht(29"Use the '%s' flag to specify one or more messages to resend.",30'--id'));31}3233$messages = id(new PhabricatorMetaMTAMail())->loadAllWhere(34'id IN (%Ld)',35$ids);3637if ($ids) {38$ids = array_fuse($ids);39$missing = array_diff_key($ids, $messages);40if ($missing) {41throw new PhutilArgumentUsageException(42pht(43'Some specified messages do not exist: %s',44implode(', ', array_keys($missing))));45}46}4748foreach ($messages as $message) {49$message->setStatus(PhabricatorMailOutboundStatus::STATUS_QUEUE);50$message->save();5152$mailer_task = PhabricatorWorker::scheduleTask(53'PhabricatorMetaMTAWorker',54$message->getID(),55array(56'priority' => PhabricatorWorker::PRIORITY_ALERTS,57));5859$console->writeOut(60"%s\n",61pht(62'Queued message #%d for resend.',63$message->getID()));64}65}6667}686970