[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/almanac/storage/ -> AlmanacDeviceTransaction.php (source)

   1  <?php
   2  
   3  final class AlmanacDeviceTransaction
   4    extends PhabricatorApplicationTransaction {
   5  
   6    const TYPE_NAME = 'almanac:device:name';
   7    const TYPE_INTERFACE = 'almanac:device:interface';
   8  
   9    public function getApplicationName() {
  10      return 'almanac';
  11    }
  12  
  13    public function getApplicationTransactionType() {
  14      return AlmanacDevicePHIDType::TYPECONST;
  15    }
  16  
  17    public function getApplicationTransactionCommentObject() {
  18      return null;
  19    }
  20  
  21    public function getRequiredHandlePHIDs() {
  22      $phids = parent::getRequiredHandlePHIDs();
  23  
  24      $old = $this->getOldValue();
  25      $new = $this->getNewValue();
  26  
  27      switch ($this->getTransactionType()) {
  28        case self::TYPE_INTERFACE:
  29          if ($old) {
  30            $phids[] = $old['networkPHID'];
  31          }
  32          if ($new) {
  33            $phids[] = $new['networkPHID'];
  34          }
  35          break;
  36      }
  37  
  38      return $phids;
  39    }
  40  
  41    public function getTitle() {
  42      $author_phid = $this->getAuthorPHID();
  43  
  44      $old = $this->getOldValue();
  45      $new = $this->getNewValue();
  46  
  47      switch ($this->getTransactionType()) {
  48        case self::TYPE_NAME:
  49          if ($old === null) {
  50            return pht(
  51              '%s created this device.',
  52              $this->renderHandleLink($author_phid));
  53          } else {
  54            return pht(
  55              '%s renamed this device from "%s" to "%s".',
  56              $this->renderHandleLink($author_phid),
  57              $old,
  58              $new);
  59          }
  60          break;
  61        case self::TYPE_INTERFACE:
  62          if ($old && $new) {
  63            return pht(
  64              '%s changed interface %s on this device to %s.',
  65              $this->renderHandleLink($author_phid),
  66              $this->describeInterface($old),
  67              $this->describeInterface($new));
  68          } else if ($old) {
  69            return pht(
  70              '%s removed the interface %s from this device.',
  71              $this->renderHandleLink($author_phid),
  72              $this->describeInterface($new));
  73          } else if ($new) {
  74            return pht(
  75              '%s added the interface %s to this device.',
  76              $this->renderHandleLink($author_phid),
  77              $this->describeInterface($new));
  78          }
  79      }
  80  
  81      return parent::getTitle();
  82    }
  83  
  84    public function shouldGenerateOldValue() {
  85      switch ($this->getTransactionType()) {
  86        case self::TYPE_INTERFACE:
  87          return false;
  88      }
  89      return parent::shouldGenerateOldValue();
  90    }
  91  
  92    private function describeInterface(array $info) {
  93      return pht(
  94        '%s:%s (%s)',
  95        $info['address'],
  96        $info['port'],
  97        $this->renderHandleLink($info['networkPHID']));
  98    }
  99  
 100  }


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