[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/metamta/management/ -> PhabricatorMailManagementListInboundWorkflow.php (source)

   1  <?php
   2  
   3  final class PhabricatorMailManagementListInboundWorkflow
   4    extends PhabricatorMailManagementWorkflow {
   5  
   6    protected function didConstruct() {
   7      $this
   8        ->setName('list-inbound')
   9        ->setSynopsis('List inbound messages received by Phabricator.')
  10        ->setExamples(
  11          '**list-inbound**')
  12        ->setArguments(
  13          array(
  14            array(
  15              'name'    => 'limit',
  16              'param'   => 'N',
  17              'default' => 100,
  18              'help'    => 'Show a specific number of messages (default 100).',
  19            ),
  20          ));
  21    }
  22  
  23    public function execute(PhutilArgumentParser $args) {
  24      $console = PhutilConsole::getConsole();
  25      $viewer = $this->getViewer();
  26  
  27      $mails = id(new PhabricatorMetaMTAReceivedMail())->loadAllWhere(
  28        '1 = 1 ORDER BY id DESC LIMIT %d',
  29        $args->getArg('limit'));
  30  
  31      if (!$mails) {
  32        $console->writeErr("%s\n", pht('No received mail.'));
  33        return 0;
  34      }
  35  
  36      $phids = array_merge(
  37        mpull($mails, 'getRelatedPHID'),
  38        mpull($mails, 'getAuthorPHID'));
  39      $handles = id(new PhabricatorHandleQuery())
  40        ->setViewer($viewer)
  41        ->withPHIDs($phids)
  42        ->execute();
  43  
  44      $table = id(new PhutilConsoleTable())
  45        ->setShowHeader(false)
  46        ->addColumn('id',      array('title' => 'ID'))
  47        ->addColumn('author',  array('title' => 'Author'))
  48        ->addColumn('phid',    array('title' => 'Related PHID'))
  49        ->addColumn('subject', array('title' => 'Subject'));
  50  
  51      foreach (array_reverse($mails) as $mail) {
  52        $table->addRow(array(
  53          'id'      => $mail->getID(),
  54          'author'  => $mail->getAuthorPHID()
  55                         ? $handles[$mail->getAuthorPHID()]->getName()
  56                         : '-',
  57          'phid'    => $mail->getRelatedPHID()
  58                         ? $handles[$mail->getRelatedPHID()]->getName()
  59                         : '-',
  60          'subject' => $mail->getSubject()
  61                         ? $mail->getSubject()
  62                         : pht('(No subject.)'),
  63        ));
  64      }
  65  
  66      $table->draw();
  67      return 0;
  68    }
  69  
  70  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1