Path: blob/master/src/applications/config/editor/PhabricatorConfigEditor.php
12256 views
<?php12final class PhabricatorConfigEditor3extends PhabricatorApplicationTransactionEditor {45public function getEditorApplicationClass() {6return 'PhabricatorConfigApplication';7}89public function getEditorObjectsDescription() {10return pht('Configuration');11}1213public function getTransactionTypes() {14$types = parent::getTransactionTypes();1516$types[] = PhabricatorConfigTransaction::TYPE_EDIT;1718return $types;19}2021protected function getCustomTransactionOldValue(22PhabricatorLiskDAO $object,23PhabricatorApplicationTransaction $xaction) {2425switch ($xaction->getTransactionType()) {26case PhabricatorConfigTransaction::TYPE_EDIT:27return array(28'deleted' => (int)$object->getIsDeleted(),29'value' => $object->getValue(),30);31}32}3334protected function getCustomTransactionNewValue(35PhabricatorLiskDAO $object,36PhabricatorApplicationTransaction $xaction) {3738switch ($xaction->getTransactionType()) {39case PhabricatorConfigTransaction::TYPE_EDIT:40return $xaction->getNewValue();41}42}4344protected function applyCustomInternalTransaction(45PhabricatorLiskDAO $object,46PhabricatorApplicationTransaction $xaction) {4748switch ($xaction->getTransactionType()) {49case PhabricatorConfigTransaction::TYPE_EDIT:50$v = $xaction->getNewValue();5152// If this is a defined configuration option (vs a straggler from an53// old version of Phabricator or a configuration file misspelling)54// submit it to the validation gauntlet.55$key = $object->getConfigKey();56$all_options = PhabricatorApplicationConfigOptions::loadAllOptions();57$option = idx($all_options, $key);58if ($option) {59$option->getGroup()->validateOption(60$option,61$v['value']);62}6364$object->setIsDeleted((int)$v['deleted']);65$object->setValue($v['value']);66break;67}68}6970protected function applyCustomExternalTransaction(71PhabricatorLiskDAO $object,72PhabricatorApplicationTransaction $xaction) {73return;74}7576protected function mergeTransactions(77PhabricatorApplicationTransaction $u,78PhabricatorApplicationTransaction $v) {7980$type = $u->getTransactionType();81switch ($type) {82case PhabricatorConfigTransaction::TYPE_EDIT:83return $v;84}8586return parent::mergeTransactions($u, $v);87}8889protected function transactionHasEffect(90PhabricatorLiskDAO $object,91PhabricatorApplicationTransaction $xaction) {9293$old = $xaction->getOldValue();94$new = $xaction->getNewValue();9596$type = $xaction->getTransactionType();97switch ($type) {98case PhabricatorConfigTransaction::TYPE_EDIT:99// If an edit deletes an already-deleted entry, no-op it.100if (idx($old, 'deleted') && idx($new, 'deleted')) {101return false;102}103break;104}105106return parent::transactionHasEffect($object, $xaction);107}108109protected function didApplyTransactions($object, array $xactions) {110// Force all the setup checks to run on the next page load.111PhabricatorSetupCheck::deleteSetupCheckCache();112113return $xactions;114}115116public static function storeNewValue(117PhabricatorUser $user,118PhabricatorConfigEntry $config_entry,119$value,120PhabricatorContentSource $source,121$acting_as_phid = null) {122123$xaction = id(new PhabricatorConfigTransaction())124->setTransactionType(PhabricatorConfigTransaction::TYPE_EDIT)125->setNewValue(126array(127'deleted' => false,128'value' => $value,129));130131$editor = id(new PhabricatorConfigEditor())132->setActor($user)133->setContinueOnNoEffect(true)134->setContentSource($source);135136if ($acting_as_phid) {137$editor->setActingAsPHID($acting_as_phid);138}139140$editor->applyTransactions($config_entry, array($xaction));141}142143public static function deleteConfig(144PhabricatorUser $user,145PhabricatorConfigEntry $config_entry,146PhabricatorContentSource $source) {147148$xaction = id(new PhabricatorConfigTransaction())149->setTransactionType(PhabricatorConfigTransaction::TYPE_EDIT)150->setNewValue(151array(152'deleted' => true,153'value' => null,154));155156$editor = id(new PhabricatorConfigEditor())157->setActor($user)158->setContinueOnNoEffect(true)159->setContentSource($source);160161$editor->applyTransactions($config_entry, array($xaction));162}163164}165166167