[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/config/editor/ -> PhabricatorConfigEditor.php (source)

   1  <?php
   2  
   3  final class PhabricatorConfigEditor
   4    extends PhabricatorApplicationTransactionEditor {
   5  
   6    public function getEditorApplicationClass() {
   7      return 'PhabricatorConfigApplication';
   8    }
   9  
  10    public function getEditorObjectsDescription() {
  11      return pht('Phabricator Configuration');
  12    }
  13  
  14    public function getTransactionTypes() {
  15      $types = parent::getTransactionTypes();
  16  
  17      $types[] = PhabricatorConfigTransaction::TYPE_EDIT;
  18  
  19      return $types;
  20    }
  21  
  22    protected function getCustomTransactionOldValue(
  23      PhabricatorLiskDAO $object,
  24      PhabricatorApplicationTransaction $xaction) {
  25  
  26      switch ($xaction->getTransactionType()) {
  27        case PhabricatorConfigTransaction::TYPE_EDIT:
  28          return array(
  29            'deleted' => (int)$object->getIsDeleted(),
  30            'value'   => $object->getValue(),
  31          );
  32      }
  33    }
  34  
  35    protected function getCustomTransactionNewValue(
  36      PhabricatorLiskDAO $object,
  37      PhabricatorApplicationTransaction $xaction) {
  38  
  39      switch ($xaction->getTransactionType()) {
  40        case PhabricatorConfigTransaction::TYPE_EDIT:
  41          return $xaction->getNewValue();
  42      }
  43    }
  44  
  45    protected function applyCustomInternalTransaction(
  46      PhabricatorLiskDAO $object,
  47      PhabricatorApplicationTransaction $xaction) {
  48  
  49      switch ($xaction->getTransactionType()) {
  50        case PhabricatorConfigTransaction::TYPE_EDIT:
  51          $v = $xaction->getNewValue();
  52  
  53          // If this is a defined configuration option (vs a straggler from an
  54          // old version of Phabricator or a configuration file misspelling)
  55          // submit it to the validation gauntlet.
  56          $key = $object->getConfigKey();
  57          $all_options = PhabricatorApplicationConfigOptions::loadAllOptions();
  58          $option = idx($all_options, $key);
  59          if ($option) {
  60            $option->getGroup()->validateOption(
  61              $option,
  62              $v['value']);
  63          }
  64  
  65          $object->setIsDeleted((int)$v['deleted']);
  66          $object->setValue($v['value']);
  67          break;
  68      }
  69    }
  70  
  71    protected function applyCustomExternalTransaction(
  72      PhabricatorLiskDAO $object,
  73      PhabricatorApplicationTransaction $xaction) {
  74      return;
  75    }
  76  
  77    protected function mergeTransactions(
  78      PhabricatorApplicationTransaction $u,
  79      PhabricatorApplicationTransaction $v) {
  80  
  81      $type = $u->getTransactionType();
  82      switch ($type) {
  83        case PhabricatorConfigTransaction::TYPE_EDIT:
  84          return $v;
  85      }
  86  
  87      return parent::mergeTransactions($u, $v);
  88    }
  89  
  90    protected function transactionHasEffect(
  91      PhabricatorLiskDAO $object,
  92      PhabricatorApplicationTransaction $xaction) {
  93  
  94      $old = $xaction->getOldValue();
  95      $new = $xaction->getNewValue();
  96  
  97      $type = $xaction->getTransactionType();
  98      switch ($type) {
  99        case PhabricatorConfigTransaction::TYPE_EDIT:
 100          // If an edit deletes an already-deleted entry, no-op it.
 101          if (idx($old, 'deleted') && idx($new, 'deleted')) {
 102            return false;
 103          }
 104          break;
 105      }
 106  
 107      return parent::transactionHasEffect($object, $xaction);
 108    }
 109  
 110    protected function didApplyTransactions(array $xactions) {
 111      // Force all the setup checks to run on the next page load.
 112      PhabricatorSetupCheck::deleteSetupCheckCache();
 113    }
 114  
 115    public static function storeNewValue(
 116      PhabricatorUser $user,
 117      PhabricatorConfigEntry $config_entry,
 118      $value,
 119      PhabricatorContentSource $source) {
 120  
 121      $xaction = id(new PhabricatorConfigTransaction())
 122        ->setTransactionType(PhabricatorConfigTransaction::TYPE_EDIT)
 123        ->setNewValue(
 124          array(
 125             'deleted' => false,
 126             'value' => $value,
 127          ));
 128  
 129      $editor = id(new PhabricatorConfigEditor())
 130        ->setActor($user)
 131        ->setContinueOnNoEffect(true)
 132        ->setContentSource($source);
 133  
 134      $editor->applyTransactions($config_entry, array($xaction));
 135    }
 136  
 137    public static function deleteConfig(
 138      PhabricatorUser $user,
 139      PhabricatorConfigEntry $config_entry,
 140      PhabricatorContentSource $source) {
 141  
 142      $xaction = id(new PhabricatorConfigTransaction())
 143        ->setTransactionType(PhabricatorConfigTransaction::TYPE_EDIT)
 144        ->setNewValue(
 145          array(
 146            'deleted' => true,
 147            'value' => null,
 148          ));
 149  
 150      $editor = id(new PhabricatorConfigEditor())
 151        ->setActor($user)
 152        ->setContinueOnNoEffect(true)
 153        ->setContentSource($source);
 154  
 155      $editor->applyTransactions($config_entry, array($xaction));
 156    }
 157  
 158  }


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