public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $argv = $args->getArg('args');
     if (count($argv) == 0) {
         throw new PhutilArgumentUsageException('Specify a configuration key to get.');
     }
     $key = $argv[0];
     if (count($argv) > 1) {
         throw new PhutilArgumentUsageException('Too many arguments: expected one key.');
     }
     $options = PhabricatorApplicationConfigOptions::loadAllOptions();
     if (empty($options[$key])) {
         throw new PhutilArgumentUsageException("No such configuration key '{$key}'! Use `config list` to list all " . "keys.");
     }
     $config = new PhabricatorConfigLocalSource();
     $values = $config->getKeys(array($key));
     $result = array();
     foreach ($values as $key => $value) {
         $result[] = array('key' => $key, 'source' => 'local', 'value' => $value);
     }
     $result = array('config' => $result);
     $json = new PhutilJSON();
     $console->writeOut($json->encodeFormatted($result));
 }
 protected function executeChecks()
 {
     $adapter = PhabricatorEnv::getEnvConfig('metamta.mail-adapter');
     switch ($adapter) {
         case 'PhabricatorMailImplementationPHPMailerLiteAdapter':
             if (!Filesystem::pathExists('/usr/bin/sendmail') && !Filesystem::pathExists('/usr/sbin/sendmail')) {
                 $message = pht('Mail is configured to send via sendmail, but this system has ' . 'no sendmail binary. Install sendmail or choose a different ' . 'mail adapter.');
                 $this->newIssue('config.metamta.mail-adapter')->setShortName(pht('Missing Sendmail'))->setName(pht('No Sendmail Binary Found'))->setMessage($message)->addRelatedPhabricatorConfig('metamta.mail-adapter');
             }
             break;
         case 'PhabricatorMailImplementationAmazonSESAdapter':
             if (PhabricatorEnv::getEnvConfig('metamta.can-send-as-user')) {
                 $message = pht('Amazon SES does not support sending email as users. Disable ' . 'send as user, or choose a different mail adapter.');
                 $this->newIssue('config.can-send-as-user')->setName(pht("SES Can't Send As User"))->setMessage($message)->addRelatedPhabricatorConfig('metamta.mail-adapter')->addPhabricatorConfig('metamta.can-send-as-user');
             }
             if (!PhabricatorEnv::getEnvConfig('amazon-ses.access-key')) {
                 $message = pht('Amazon SES is selected as the mail adapter, but no SES access ' . 'key is configured. Provide an SES access key, or choose a ' . 'different mail adapter.');
                 $this->newIssue('config.amazon-ses.access-key')->setName(pht('Amazon SES Access Key Not Set'))->setMessage($message)->addRelatedPhabricatorConfig('metamta.mail-adapter')->addPhabricatorConfig('amazon-ses.access-key');
             }
             if (!PhabricatorEnv::getEnvConfig('amazon-ses.secret-key')) {
                 $message = pht('Amazon SES is selected as the mail adapter, but no SES secret ' . 'key is configured. Provide an SES secret key, or choose a ' . 'different mail adapter.');
                 $this->newIssue('config.amazon-ses.secret-key')->setName(pht('Amazon SES Secret Key Not Set'))->setMessage($message)->addRelatedPhabricatorConfig('metamta.mail-adapter')->addPhabricatorConfig('amazon-ses.secret-key');
             }
             $address_key = 'metamta.default-address';
             $options = PhabricatorApplicationConfigOptions::loadAllOptions();
             $default = $options[$address_key]->getDefault();
             $value = PhabricatorEnv::getEnvConfig($address_key);
             if ($default === $value) {
                 $message = pht('Amazon SES requires verification of the "From" address, but ' . 'you have not configured a "From" address. Configure and verify ' . 'a "From" address, or choose a different mail adapter.');
                 $this->newIssue('config.metamta.default-address')->setName(pht('No SES From Address Configured'))->setMessage($message)->addRelatedPhabricatorConfig('metamta.mail-adapter')->addPhabricatorConfig('metamta.default-address');
             }
             break;
     }
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $db_values = id(new PhabricatorConfigEntry())->loadAllWhere('namespace = %s', 'default');
     $db_values = mpull($db_values, null, 'getConfigKey');
     $rows = array();
     $options = PhabricatorApplicationConfigOptions::loadAllOptions();
     ksort($options);
     foreach ($options as $option) {
         $key = $option->getKey();
         if ($option->getHidden()) {
             $value = phutil_tag('em', array(), pht('Hidden'));
         } else {
             $value = PhabricatorEnv::getEnvConfig($key);
             $value = PhabricatorConfigJSON::prettyPrintJSON($value);
         }
         $db_value = idx($db_values, $key);
         $rows[] = array(phutil_tag('a', array('href' => $this->getApplicationURI('edit/' . $key . '/')), $key), $value, $db_value && !$db_value->getIsDeleted() ? pht('Customized') : '');
     }
     $table = id(new AphrontTableView($rows))->setColumnClasses(array('', 'wide'))->setHeaders(array(pht('Key'), pht('Value'), pht('Customized')));
     $title = pht('Current Settings');
     $crumbs = $this->buildApplicationCrumbs()->addTextCrumb($title);
     $panel = new PHUIObjectBoxView();
     $panel->setHeaderText(pht('Current Settings'));
     $panel->setTable($table);
     $nav = $this->buildSideNavView();
     $nav->selectFilter('all/');
     $view = id(new PHUITwoColumnView())->setNavigation($nav)->setMainColumn(array($panel));
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
 }
 public function execute(PhutilArgumentParser $args)
 {
     $options = PhabricatorApplicationConfigOptions::loadAllOptions();
     ksort($options);
     $console = PhutilConsole::getConsole();
     foreach ($options as $option) {
         $console->writeOut($option->getKey() . "\n");
     }
     return 0;
 }
 private function renderPhabricatorConfig(array $configs, $related = false)
 {
     $issue = $this->getIssue();
     $table_info = phutil_tag('p', array(), pht('The current Phabricator configuration has these %d value(s):', count($configs)));
     $options = PhabricatorApplicationConfigOptions::loadAllOptions();
     $hidden = array();
     foreach ($options as $key => $option) {
         if ($option->getHidden()) {
             $hidden[$key] = true;
         }
     }
     $table = null;
     $dict = array();
     foreach ($configs as $key) {
         if (isset($hidden[$key])) {
             $dict[$key] = null;
         } else {
             $dict[$key] = PhabricatorEnv::getUnrepairedEnvConfig($key);
         }
     }
     $table = $this->renderValueTable($dict, $hidden);
     if ($this->getIssue()->getIsFatal()) {
         $update_info = phutil_tag('p', array(), pht('To update these %d value(s), run these command(s) from the command ' . 'line:', count($configs)));
         $update = array();
         foreach ($configs as $key) {
             $update[] = hsprintf('<tt>phabricator/ $</tt> ./bin/config set %s <em>value</em>', $key);
         }
         $update = phutil_tag('pre', array(), phutil_implode_html("\n", $update));
     } else {
         $update = array();
         foreach ($configs as $config) {
             if (idx($options, $config) && $options[$config]->getLocked()) {
                 $name = pht('View "%s"', $config);
             } else {
                 $name = pht('Edit "%s"', $config);
             }
             $link = phutil_tag('a', array('href' => '/config/edit/' . $config . '/?issue=' . $issue->getIssueKey()), $name);
             $update[] = phutil_tag('li', array(), $link);
         }
         if ($update) {
             $update = phutil_tag('ul', array(), $update);
             if (!$related) {
                 $update_info = phutil_tag('p', array(), pht('You can update these %d value(s) here:', count($configs)));
             } else {
                 $update_info = phutil_tag('p', array(), pht('These %d configuration value(s) are related:', count($configs)));
             }
         } else {
             $update = null;
             $update_info = null;
         }
     }
     return phutil_tag('div', array('class' => 'setup-issue-config'), array($table_info, $table, $update_info, $update));
 }
 protected function executeChecks()
 {
     $ancient_config = self::getAncientConfig();
     $all_keys = PhabricatorEnv::getAllConfigKeys();
     $all_keys = array_keys($all_keys);
     sort($all_keys);
     $defined_keys = PhabricatorApplicationConfigOptions::loadAllOptions();
     foreach ($all_keys as $key) {
         if (isset($defined_keys[$key])) {
             continue;
         }
         if (isset($ancient_config[$key])) {
             $summary = pht('This option has been removed. You may delete it at your ' . 'convenience.');
             $message = pht("The configuration option '%s' has been removed. You may delete " . "it at your convenience." . "\n\n%s", $key, $ancient_config[$key]);
             $short = pht('Obsolete Config');
             $name = pht('Obsolete Configuration Option "%s"', $key);
         } else {
             $summary = pht('This option is not recognized. It may be misspelled.');
             $message = pht("The configuration option '%s' is not recognized. It may be " . "misspelled, or it might have existed in an older version of " . "Phabricator. It has no effect, and should be corrected or deleted.", $key);
             $short = pht('Unknown Config');
             $name = pht('Unknown Configuration Option "%s"', $key);
         }
         $issue = $this->newIssue('config.unknown.' . $key)->setShortName($short)->setName($name)->setSummary($summary);
         $stack = PhabricatorEnv::getConfigSourceStack();
         $stack = $stack->getStack();
         $found = array();
         $found_local = false;
         $found_database = false;
         foreach ($stack as $source_key => $source) {
             $value = $source->getKeys(array($key));
             if ($value) {
                 $found[] = $source->getName();
                 if ($source instanceof PhabricatorConfigDatabaseSource) {
                     $found_database = true;
                 }
                 if ($source instanceof PhabricatorConfigLocalSource) {
                     $found_local = true;
                 }
             }
         }
         $message = $message . "\n\n" . pht('This configuration value is defined in these %d ' . 'configuration source(s): %s.', count($found), implode(', ', $found));
         $issue->setMessage($message);
         if ($found_local) {
             $command = csprintf('phabricator/ $ ./bin/config delete %s', $key);
             $issue->addCommand($command);
         }
         if ($found_database) {
             $issue->addPhabricatorConfig($key);
         }
     }
     $this->executeManiphestFieldChecks();
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $nav = $this->buildSideNavView();
     $nav->selectFilter('application/');
     $groups = PhabricatorApplicationConfigOptions::loadAll();
     $apps_list = $this->buildConfigOptionsList($groups, 'apps');
     $title = pht('Application Settings');
     $header = id(new PHUIHeaderView())->setHeader($title)->setProfileHeader(true);
     $crumbs = $this->buildApplicationCrumbs()->addTextCrumb(pht('Applications'))->setBorder(true);
     $content = id(new PhabricatorConfigPageView())->setHeader($header)->setContent($apps_list);
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->setNavigation($nav)->appendChild($content)->addClass('white-background');
 }
 protected function executeChecks()
 {
     $groups = PhabricatorApplicationConfigOptions::loadAll();
     foreach ($groups as $group) {
         $options = $group->getOptions();
         foreach ($options as $option) {
             try {
                 $group->validateOption($option, PhabricatorEnv::getUnrepairedEnvConfig($option->getKey()));
             } catch (PhabricatorConfigValidationException $ex) {
                 $this->newIssue('config.invalid.' . $option->getKey())->setName(pht("Config '%s' Invalid", $option->getKey()))->setMessage(pht("Configuration option '%s' has invalid value and " . "was restored to the default: %s", $option->getKey(), $ex->getMessage()))->addPhabricatorConfig($option->getKey());
             }
         }
     }
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $db_values = id(new PhabricatorConfigEntry())->loadAllWhere('namespace = %s', 'default');
     $db_values = mpull($db_values, null, 'getConfigKey');
     $rows = array();
     $options = PhabricatorApplicationConfigOptions::loadAllOptions();
     ksort($options);
     foreach ($options as $option) {
         $key = $option->getKey();
         if ($option->getMasked()) {
             $value = phutil_tag('em', array(), pht('Masked'));
         } else {
             if ($option->getHidden()) {
                 $value = phutil_tag('em', array(), pht('Hidden'));
             } else {
                 $value = PhabricatorEnv::getEnvConfig($key);
                 $value = PhabricatorConfigJSON::prettyPrintJSON($value);
             }
         }
         $db_value = idx($db_values, $key);
         $rows[] = array(phutil_tag('a', array('href' => $this->getApplicationURI('edit/' . $key . '/')), $key), $value, $db_value && !$db_value->getIsDeleted() ? pht('Customized') : '');
     }
     $table = id(new AphrontTableView($rows))->setColumnClasses(array('', 'wide'))->setHeaders(array(pht('Key'), pht('Value'), pht('Customized')));
     $title = pht('Current Settings');
     $crumbs = $this->buildApplicationCrumbs()->addTextCrumb($title);
     $panel = new PHUIObjectBoxView();
     $panel->setHeaderText(pht('Current Settings'));
     $panel->appendChild($table);
     $versions = $this->loadVersions();
     $version_property_list = id(new PHUIPropertyListView());
     foreach ($versions as $version) {
         list($name, $hash) = $version;
         $version_property_list->addProperty($name, $hash);
     }
     $object_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Current Version'))->addPropertyList($version_property_list);
     $phabricator_root = dirname(phutil_get_library_root('phabricator'));
     $version_path = $phabricator_root . '/conf/local/VERSION';
     if (Filesystem::pathExists($version_path)) {
         $version_from_file = Filesystem::readFile($version_path);
         $version_property_list->addProperty(pht('Local Version'), $version_from_file);
     }
     $nav = $this->buildSideNavView();
     $nav->selectFilter('all/');
     $nav->setCrumbs($crumbs);
     $nav->appendChild($object_box);
     $nav->appendChild($panel);
     return $this->buildApplicationPage($nav, array('title' => $title));
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $key_count = 0;
     $options = PhabricatorApplicationConfigOptions::loadAllOptions();
     $local_config = new PhabricatorConfigLocalSource();
     $database_config = new PhabricatorConfigDatabaseSource('default');
     $config_sources = PhabricatorEnv::getConfigSourceStack()->getStack();
     $console->writeOut("%s\n", pht('Migrating file-based config to more modern config...'));
     foreach ($config_sources as $config_source) {
         if (!$config_source instanceof PhabricatorConfigFileSource) {
             $console->writeOut("%s\n", pht('Skipping config of source type %s...', get_class($config_source)));
             continue;
         }
         $console->writeOut("%s\n", pht('Migrating file source...'));
         $all_keys = $config_source->getAllKeys();
         foreach ($all_keys as $key => $value) {
             $option = idx($options, $key);
             if (!$option) {
                 $console->writeOut("%s\n", pht('Skipping obsolete option: %s', $key));
                 continue;
             }
             $in_local = $local_config->getKeys(array($option->getKey()));
             if ($in_local) {
                 $console->writeOut("%s\n", pht('Skipping option "%s"; already in local config.', $key));
                 continue;
             }
             $is_locked = $option->getLocked();
             if ($is_locked) {
                 $local_config->setKeys(array($option->getKey() => $value));
                 $key_count++;
                 $console->writeOut("%s\n", pht('Migrated option "%s" from file to local config.', $key));
             } else {
                 $in_database = $database_config->getKeys(array($option->getKey()));
                 if ($in_database) {
                     $console->writeOut("%s\n", pht('Skipping option "%s"; already in database config.', $key));
                     continue;
                 } else {
                     $config_entry = PhabricatorConfigEntry::loadConfigEntry($key);
                     $config_entry->setValue($value);
                     $config_entry->save();
                     $key_count++;
                     $console->writeOut("%s\n", pht('Migrated option "%s" from file to database config.', $key));
                 }
             }
         }
     }
     $console->writeOut("%s\n", pht('Done. Migrated %d keys.', $key_count));
     return 0;
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $nav = $this->buildSideNavView();
     $nav->selectFilter('/');
     $groups = PhabricatorApplicationConfigOptions::loadAll();
     $core_list = $this->buildConfigOptionsList($groups, 'core');
     $apps_list = $this->buildConfigOptionsList($groups, 'apps');
     $title = pht('Phabricator Configuration');
     $core = id(new PHUIObjectBoxView())->setHeaderText($title)->setObjectList($core_list);
     $apps = id(new PHUIObjectBoxView())->setHeaderText(pht('Applications Configuration'))->setObjectList($apps_list);
     $crumbs = $this->buildApplicationCrumbs()->addTextCrumb(pht('Config'), $this->getApplicationURI());
     $view = id(new PHUITwoColumnView())->setNavigation($nav)->setMainColumn(array($core, $apps));
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $nav = $this->buildSideNavView();
     $nav->selectFilter('/');
     $groups = PhabricatorApplicationConfigOptions::loadAll();
     $list = $this->buildConfigOptionsList($groups);
     $title = pht('Phabricator Configuration');
     $box = id(new PHUIObjectBoxView())->setHeaderText($title)->appendChild($list);
     $nav->appendChild(array($box));
     $crumbs = $this->buildApplicationCrumbs()->addTextCrumb(pht('Config'), $this->getApplicationURI());
     $nav->setCrumbs($crumbs);
     return $this->buildApplicationPage($nav, array('title' => $title));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $groups = PhabricatorApplicationConfigOptions::loadAll();
     $options = idx($groups, $this->groupKey);
     if (!$options) {
         return new Aphront404Response();
     }
     $title = pht('%s Configuration', $options->getName());
     $list = $this->buildOptionList($options->getOptions());
     $box = id(new PHUIObjectBoxView())->setHeaderText($title)->setObjectList($list);
     $crumbs = $this->buildApplicationCrumbs()->addTextCrumb(pht('Config'), $this->getApplicationURI())->addTextCrumb($options->getName(), $this->getApplicationURI());
     return $this->buildApplicationPage(array($crumbs, $box), array('title' => $title));
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $group_key = $request->getURIData('key');
     $groups = PhabricatorApplicationConfigOptions::loadAll();
     $options = idx($groups, $group_key);
     if (!$options) {
         return new Aphront404Response();
     }
     $title = pht('%s Configuration', $options->getName());
     $list = $this->buildOptionList($options->getOptions());
     $box = id(new PHUIObjectBoxView())->setObjectList($list);
     $crumbs = $this->buildApplicationCrumbs()->addTextCrumb(pht('Config'), $this->getApplicationURI())->addTextCrumb($options->getName(), $this->getApplicationURI())->setBorder(true);
     $header = id(new PHUIHeaderView())->setHeader($title)->setHeaderIcon('fa-sliders');
     $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter($box);
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
 }
예제 #15
0
 protected function applyCustomInternalTransaction(PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction)
 {
     switch ($xaction->getTransactionType()) {
         case PhabricatorConfigTransaction::TYPE_EDIT:
             $v = $xaction->getNewValue();
             // If this is a defined configuration option (vs a straggler from an
             // old version of Phabricator or a configuration file misspelling)
             // submit it to the validation gauntlet.
             $key = $object->getConfigKey();
             $all_options = PhabricatorApplicationConfigOptions::loadAllOptions();
             $option = idx($all_options, $key);
             if ($option) {
                 $option->getGroup()->validateOption($option, $v['value']);
             }
             $object->setIsDeleted((int) $v['deleted']);
             $object->setValue($v['value']);
             break;
     }
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $argv = $args->getArg('args');
     if (count($argv) == 0) {
         throw new PhutilArgumentUsageException(pht('Specify a configuration key to get.'));
     }
     $key = $argv[0];
     if (count($argv) > 1) {
         throw new PhutilArgumentUsageException(pht('Too many arguments: expected one key.'));
     }
     $options = PhabricatorApplicationConfigOptions::loadAllOptions();
     if (empty($options[$key])) {
         throw new PhutilArgumentUsageException(pht("No such configuration key '%s'! Use `%s` to list all keys.", $key, 'config list'));
     }
     $values = array();
     $config = new PhabricatorConfigLocalSource();
     $local_value = $config->getKeys(array($key));
     if (empty($local_value)) {
         $values['local'] = array('key' => $key, 'value' => null, 'status' => 'unset', 'errorInfo' => null);
     } else {
         $values['local'] = array('key' => $key, 'value' => reset($local_value), 'status' => 'set', 'errorInfo' => null);
     }
     try {
         $database_config = new PhabricatorConfigDatabaseSource('default');
         $database_value = $database_config->getKeys(array($key));
         if (empty($database_value)) {
             $values['database'] = array('key' => $key, 'value' => null, 'status' => 'unset', 'errorInfo' => null);
         } else {
             $values['database'] = array('key' => $key, 'value' => reset($database_value), 'status' => 'set', 'errorInfo' => null);
         }
     } catch (Exception $e) {
         $values['database'] = array('key' => $key, 'value' => null, 'status' => 'error', 'errorInfo' => pht('Database source is not configured properly'));
     }
     $result = array();
     foreach ($values as $source => $value) {
         $result[] = array('key' => $value['key'], 'source' => $source, 'value' => $value['value'], 'status' => $value['status'], 'errorInfo' => $value['errorInfo']);
     }
     $result = array('config' => $result);
     $json = new PhutilJSON();
     $console->writeOut($json->encodeFormatted($result));
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $group_key = $request->getURIData('key');
     $groups = PhabricatorApplicationConfigOptions::loadAll();
     $options = idx($groups, $group_key);
     if (!$options) {
         return new Aphront404Response();
     }
     $group_uri = PhabricatorConfigGroupConstants::getGroupURI($options->getGroup());
     $group_name = PhabricatorConfigGroupConstants::getGroupShortName($options->getGroup());
     $nav = $this->buildSideNavView();
     $nav->selectFilter($group_uri);
     $title = pht('%s Configuration', $options->getName());
     $list = $this->buildOptionList($options->getOptions());
     $crumbs = $this->buildApplicationCrumbs()->addTextCrumb($group_name, $this->getApplicationURI($group_uri))->addTextCrumb($options->getName())->setBorder(true);
     $header = id(new PHUIHeaderView())->setHeader($title)->setProfileHeader(true);
     $content = id(new PhabricatorConfigPageView())->setHeader($header)->setContent($list);
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->setNavigation($nav)->appendChild($content)->addClass('white-background');
 }
 public function renderContextualDescription(PhabricatorConfigOption $option, AphrontRequest $request)
 {
     switch ($option->getKey()) {
         case 'asana.workspace-id':
             break;
         case 'asana.project-ids':
             return $this->renderContextualProjectDescription($option, $request);
         default:
             return parent::renderContextualDescription($option, $request);
     }
     $viewer = $request->getUser();
     $provider = PhabricatorAsanaAuthProvider::getAsanaProvider();
     if (!$provider) {
         return null;
     }
     $account = id(new PhabricatorExternalAccountQuery())->setViewer($viewer)->withUserPHIDs(array($viewer->getPHID()))->withAccountTypes(array($provider->getProviderType()))->withAccountDomains(array($provider->getProviderDomain()))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$account) {
         return null;
     }
     $token = $provider->getOAuthAccessToken($account);
     if (!$token) {
         return null;
     }
     try {
         $workspaces = id(new PhutilAsanaFuture())->setAccessToken($token)->setRawAsanaQuery('workspaces')->resolve();
     } catch (Exception $ex) {
         return null;
     }
     if (!$workspaces) {
         return null;
     }
     $out = array();
     $out[] = pht('| Workspace ID | Workspace Name |');
     $out[] = '| ------------ | -------------- |';
     foreach ($workspaces as $workspace) {
         $out[] = sprintf('| `%s` | `%s` |', $workspace['id'], $workspace['name']);
     }
     $out = implode("\n", $out);
     $out = pht("The Asana Workspaces your linked account has access to are:\n\n%s", $out);
     return PhabricatorMarkupEngine::renderOneObject(id(new PhabricatorMarkupOneOff())->setContent($out), 'default', $viewer);
 }
 public function loadExternalOptions()
 {
     $options = PhabricatorApplicationConfigOptions::loadAllOptions(true);
     $options = mpull($options, 'getDefault');
     $this->setKeys($options);
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $argv = $args->getArg('args');
     if (count($argv) == 0) {
         throw new PhutilArgumentUsageException(pht('Specify a configuration key and a value to set it to.'));
     }
     $key = $argv[0];
     if (count($argv) == 1) {
         throw new PhutilArgumentUsageException(pht("Specify a value to set the key '%s' to.", $key));
     }
     $value = $argv[1];
     if (count($argv) > 2) {
         throw new PhutilArgumentUsageException(pht('Too many arguments: expected one key and one value.'));
     }
     $options = PhabricatorApplicationConfigOptions::loadAllOptions();
     if (empty($options[$key])) {
         throw new PhutilArgumentUsageException(pht("No such configuration key '%s'! Use `%s` to list all keys.", $key, 'config list'));
     }
     $option = $options[$key];
     $type = $option->getType();
     switch ($type) {
         case 'string':
         case 'class':
         case 'enum':
             $value = (string) $value;
             break;
         case 'int':
             if (!ctype_digit($value)) {
                 throw new PhutilArgumentUsageException(pht("Config key '%s' is of type '%s'. Specify an integer.", $key, $type));
             }
             $value = (int) $value;
             break;
         case 'bool':
             if ($value == 'true') {
                 $value = true;
             } else {
                 if ($value == 'false') {
                     $value = false;
                 } else {
                     throw new PhutilArgumentUsageException(pht("Config key '%s' is of type '%s'. Specify '%s' or '%s'.", $key, $type, 'true', 'false'));
                 }
             }
             break;
         default:
             $value = json_decode($value, true);
             if (!is_array($value)) {
                 switch ($type) {
                     case 'set':
                         $command = csprintf('./bin/config set %R %s', $key, '{"value1": true, "value2": true}');
                         $message = sprintf("%s\n\n    %s\n", pht('Config key "%s" is of type "%s". Specify it in JSON. ' . 'For example:', $key, $type), $command);
                         break;
                     default:
                         if (preg_match('/^list</', $type)) {
                             $command = csprintf('./bin/config set %R %s', $key, '["a", "b", "c"]');
                             $message = sprintf("%s\n\n    %s\n", pht('Config key "%s" is of type "%s". Specify it in JSON. ' . 'For example:', $key, $type), $command);
                         } else {
                             $message = pht('Config key "%s" is of type "%s". Specify it in JSON.', $key, $type);
                         }
                         break;
                 }
                 throw new PhutilArgumentUsageException($message);
             }
             break;
     }
     $use_database = $args->getArg('database');
     if ($option->getLocked() && $use_database) {
         throw new PhutilArgumentUsageException(pht('Config key "%s" is locked and can only be set in local ' . 'configuration. To learn more, see "%s" in the documentation.', $key, pht('Configuration Guide: Locked and Hidden Configuration')));
     }
     try {
         $option->getGroup()->validateOption($option, $value);
     } catch (PhabricatorConfigValidationException $validation) {
         // Convert this into a usage exception so we don't dump a stack trace.
         throw new PhutilArgumentUsageException($validation->getMessage());
     }
     if ($use_database) {
         $config_type = 'database';
         $config_entry = PhabricatorConfigEntry::loadConfigEntry($key);
         $config_entry->setValue($value);
         $config_entry->save();
     } else {
         $config_type = 'local';
         id(new PhabricatorConfigLocalSource())->setKeys(array($key => $value));
     }
     $console->writeOut("%s\n", pht("Set '%s' in %s configuration.", $key, $config_type));
 }
예제 #21
0
 public static final function repairConfig()
 {
     $needs_repair = false;
     $options = PhabricatorApplicationConfigOptions::loadAllOptions();
     foreach ($options as $option) {
         try {
             $option->getGroup()->validateOption($option, PhabricatorEnv::getEnvConfig($option->getKey()));
         } catch (PhabricatorConfigValidationException $ex) {
             PhabricatorEnv::repairConfig($option->getKey(), $option->getDefault());
             $needs_repair = true;
         }
     }
     return $needs_repair;
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $argv = $args->getArg('args');
     if (count($argv) == 0) {
         throw new PhutilArgumentUsageException('Specify a configuration key and a value to set it to.');
     }
     $key = $argv[0];
     if (count($argv) == 1) {
         throw new PhutilArgumentUsageException("Specify a value to set the key '{$key}' to.");
     }
     $value = $argv[1];
     if (count($argv) > 2) {
         throw new PhutilArgumentUsageException('Too many arguments: expected one key and one value.');
     }
     $options = PhabricatorApplicationConfigOptions::loadAllOptions();
     if (empty($options[$key])) {
         throw new PhutilArgumentUsageException("No such configuration key '{$key}'! Use `config list` to list all " . "keys.");
     }
     $option = $options[$key];
     $type = $option->getType();
     switch ($type) {
         case 'string':
         case 'class':
         case 'enum':
             $value = (string) $value;
             break;
         case 'int':
             if (!ctype_digit($value)) {
                 throw new PhutilArgumentUsageException("Config key '{$key}' is of type '{$type}'. Specify an integer.");
             }
             $value = (int) $value;
             break;
         case 'bool':
             if ($value == 'true') {
                 $value = true;
             } else {
                 if ($value == 'false') {
                     $value = false;
                 } else {
                     throw new PhutilArgumentUsageException("Config key '{$key}' is of type '{$type}'. " . "Specify 'true' or 'false'.");
                 }
             }
             break;
         default:
             $value = json_decode($value, true);
             if (!is_array($value)) {
                 throw new PhutilArgumentUsageException("Config key '{$key}' is of type '{$type}'. Specify it in JSON.");
             }
             break;
     }
     try {
         $option->getGroup()->validateOption($option, $value);
     } catch (PhabricatorConfigValidationException $validation) {
         // Convert this into a usage exception so we don't dump a stack trace.
         throw new PhutilArgumentUsageException($validation->getMessage());
     }
     $config = new PhabricatorConfigLocalSource();
     $config->setKeys(array($key => $value));
     $console->writeOut(pht("Set '%s' in local configuration.", $key) . "\n");
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $key = $request->getURIData('key');
     $options = PhabricatorApplicationConfigOptions::loadAllOptions();
     if (empty($options[$key])) {
         $ancient = PhabricatorExtraConfigSetupCheck::getAncientConfig();
         if (isset($ancient[$key])) {
             $desc = pht("This configuration has been removed. You can safely delete " . "it.\n\n%s", $ancient[$key]);
         } else {
             $desc = pht('This configuration option is unknown. It may be misspelled, ' . 'or have existed in a previous version of Phabricator.');
         }
         // This may be a dead config entry, which existed in the past but no
         // longer exists. Allow it to be edited so it can be reviewed and
         // deleted.
         $option = id(new PhabricatorConfigOption())->setKey($key)->setType('wild')->setDefault(null)->setDescription($desc);
         $group = null;
         $group_uri = $this->getApplicationURI();
     } else {
         $option = $options[$key];
         $group = $option->getGroup();
         $group_uri = $this->getApplicationURI('group/' . $group->getKey() . '/');
     }
     $issue = $request->getStr('issue');
     if ($issue) {
         // If the user came here from an open setup issue, send them back.
         $done_uri = $this->getApplicationURI('issue/' . $issue . '/');
     } else {
         $done_uri = $group_uri;
     }
     // Check if the config key is already stored in the database.
     // Grab the value if it is.
     $config_entry = id(new PhabricatorConfigEntry())->loadOneWhere('configKey = %s AND namespace = %s', $key, 'default');
     if (!$config_entry) {
         $config_entry = id(new PhabricatorConfigEntry())->setConfigKey($key)->setNamespace('default')->setIsDeleted(true);
         $config_entry->setPHID($config_entry->generatePHID());
     }
     $e_value = null;
     $errors = array();
     if ($request->isFormPost() && !$option->getLocked()) {
         $result = $this->readRequest($option, $request);
         list($e_value, $value_errors, $display_value, $xaction) = $result;
         $errors = array_merge($errors, $value_errors);
         if (!$errors) {
             $editor = id(new PhabricatorConfigEditor())->setActor($viewer)->setContinueOnNoEffect(true)->setContentSourceFromRequest($request);
             try {
                 $editor->applyTransactions($config_entry, array($xaction));
                 return id(new AphrontRedirectResponse())->setURI($done_uri);
             } catch (PhabricatorConfigValidationException $ex) {
                 $e_value = pht('Invalid');
                 $errors[] = $ex->getMessage();
             }
         }
     } else {
         if ($config_entry->getIsDeleted()) {
             $display_value = null;
         } else {
             $display_value = $this->getDisplayValue($option, $config_entry, $config_entry->getValue());
         }
     }
     $form = id(new AphrontFormView())->setEncType('multipart/form-data');
     $error_view = null;
     if ($errors) {
         $error_view = id(new PHUIInfoView())->setErrors($errors);
     }
     $status_items = array();
     if ($option->getHidden()) {
         $message = pht('This configuration is hidden and can not be edited or viewed from ' . 'the web interface.');
         $status_items[] = id(new PHUIStatusItemView())->setIcon('fa-eye-slash red')->setTarget(phutil_tag('strong', array(), pht('Configuration Hidden')))->setNote($message);
     } else {
         if ($option->getLocked()) {
             $message = $option->getLockedMessage();
             $status_items[] = id(new PHUIStatusItemView())->setIcon('fa-lock red')->setTarget(phutil_tag('strong', array(), pht('Configuration Locked')))->setNote($message);
         }
     }
     if ($status_items) {
         $doc_href = PhabricatorEnv::getDoclink('Configuration Guide: Locked and Hidden Configuration');
         $doc_link = phutil_tag('a', array('href' => $doc_href, 'target' => '_blank'), pht('Configuration Guide: Locked and Hidden Configuration'));
         $status_items[] = id(new PHUIStatusItemView())->setIcon('fa-book')->setTarget(phutil_tag('strong', array(), pht('Learn More')))->setNote($doc_link);
     }
     if ($option->getHidden() || $option->getLocked()) {
         $controls = array();
     } else {
         $controls = $this->renderControls($option, $display_value, $e_value);
     }
     $engine = new PhabricatorMarkupEngine();
     $engine->setViewer($viewer);
     $engine->addObject($option, 'description');
     $engine->process();
     $description = phutil_tag('div', array('class' => 'phabricator-remarkup'), $engine->getOutput($option, 'description'));
     $form->setUser($viewer)->addHiddenInput('issue', $request->getStr('issue'));
     if ($status_items) {
         $status_view = id(new PHUIStatusListView());
         foreach ($status_items as $status_item) {
             $status_view->addItem($status_item);
         }
         $form->appendControl(id(new AphrontFormMarkupControl())->setValue($status_view));
     }
     $description = $option->getDescription();
     if (strlen($description)) {
         $description_view = new PHUIRemarkupView($viewer, $description);
         $form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Description'))->setValue($description_view));
     }
     if ($group) {
         $extra = $group->renderContextualDescription($option, $request);
         if ($extra !== null) {
             $form->appendChild(id(new AphrontFormMarkupControl())->setValue($extra));
         }
     }
     foreach ($controls as $control) {
         $form->appendControl($control);
     }
     if (!$option->getLocked()) {
         $form->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($done_uri)->setValue(pht('Save Config Entry')));
     }
     if (!$option->getHidden()) {
         $form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Current Configuration'))->setValue($this->renderDefaults($option, $config_entry)));
     }
     $examples = $this->renderExamples($option);
     if ($examples) {
         $form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Examples'))->setValue($examples));
     }
     $title = pht('Edit Option: %s', $key);
     $header_icon = 'fa-pencil';
     $short = pht('Edit');
     $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Config Option'))->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setForm($form);
     if ($error_view) {
         $form_box->setInfoView($error_view);
     }
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Config'), $this->getApplicationURI());
     if ($group) {
         $crumbs->addTextCrumb($group->getName(), $group_uri);
     }
     $crumbs->addTextCrumb($key, '/config/edit/' . $key);
     $crumbs->setBorder(true);
     $timeline = $this->buildTransactionTimeline($config_entry, new PhabricatorConfigTransactionQuery());
     $timeline->setShouldTerminate(true);
     $header = id(new PHUIHeaderView())->setHeader($title)->setHeaderIcon($header_icon);
     $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter($form_box);
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $options = PhabricatorApplicationConfigOptions::loadAllOptions();
     if (empty($options[$this->key])) {
         $ancient = PhabricatorExtraConfigSetupCheck::getAncientConfig();
         if (isset($ancient[$this->key])) {
             $desc = pht("This configuration has been removed. You can safely delete " . "it.\n\n%s", $ancient[$this->key]);
         } else {
             $desc = pht('This configuration option is unknown. It may be misspelled, ' . 'or have existed in a previous version of Phabricator.');
         }
         // This may be a dead config entry, which existed in the past but no
         // longer exists. Allow it to be edited so it can be reviewed and
         // deleted.
         $option = id(new PhabricatorConfigOption())->setKey($this->key)->setType('wild')->setDefault(null)->setDescription($desc);
         $group = null;
         $group_uri = $this->getApplicationURI();
     } else {
         $option = $options[$this->key];
         $group = $option->getGroup();
         $group_uri = $this->getApplicationURI('group/' . $group->getKey() . '/');
     }
     $issue = $request->getStr('issue');
     if ($issue) {
         // If the user came here from an open setup issue, send them back.
         $done_uri = $this->getApplicationURI('issue/' . $issue . '/');
     } else {
         $done_uri = $group_uri;
     }
     // Check if the config key is already stored in the database.
     // Grab the value if it is.
     $config_entry = id(new PhabricatorConfigEntry())->loadOneWhere('configKey = %s AND namespace = %s', $this->key, 'default');
     if (!$config_entry) {
         $config_entry = id(new PhabricatorConfigEntry())->setConfigKey($this->key)->setNamespace('default')->setIsDeleted(true);
         $config_entry->setPHID($config_entry->generatePHID());
     }
     $e_value = null;
     $errors = array();
     if ($request->isFormPost() && !$option->getLocked()) {
         $result = $this->readRequest($option, $request);
         list($e_value, $value_errors, $display_value, $xaction) = $result;
         $errors = array_merge($errors, $value_errors);
         if (!$errors) {
             $editor = id(new PhabricatorConfigEditor())->setActor($user)->setContinueOnNoEffect(true)->setContentSourceFromRequest($request);
             try {
                 $editor->applyTransactions($config_entry, array($xaction));
                 return id(new AphrontRedirectResponse())->setURI($done_uri);
             } catch (PhabricatorConfigValidationException $ex) {
                 $e_value = pht('Invalid');
                 $errors[] = $ex->getMessage();
             }
         }
     } else {
         if ($config_entry->getIsDeleted()) {
             $display_value = null;
         } else {
             $display_value = $this->getDisplayValue($option, $config_entry, $config_entry->getValue());
         }
     }
     $form = new AphrontFormView();
     $error_view = null;
     if ($errors) {
         $error_view = id(new PHUIInfoView())->setErrors($errors);
     } else {
         if ($option->getHidden()) {
             $msg = pht('This configuration is hidden and can not be edited or viewed from ' . 'the web interface.');
             $error_view = id(new PHUIInfoView())->setTitle(pht('Configuration Hidden'))->setSeverity(PHUIInfoView::SEVERITY_WARNING)->appendChild(phutil_tag('p', array(), $msg));
         } else {
             if ($option->getLocked()) {
                 $msg = $option->getLockedMessage();
                 $error_view = id(new PHUIInfoView())->setTitle(pht('Configuration Locked'))->setSeverity(PHUIInfoView::SEVERITY_NOTICE)->appendChild(phutil_tag('p', array(), $msg));
             }
         }
     }
     if ($option->getHidden()) {
         $control = null;
     } else {
         $control = $this->renderControl($option, $display_value, $e_value);
     }
     $engine = new PhabricatorMarkupEngine();
     $engine->setViewer($user);
     $engine->addObject($option, 'description');
     $engine->process();
     $description = phutil_tag('div', array('class' => 'phabricator-remarkup'), $engine->getOutput($option, 'description'));
     $form->setUser($user)->addHiddenInput('issue', $request->getStr('issue'))->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Description'))->setValue($description));
     if ($group) {
         $extra = $group->renderContextualDescription($option, $request);
         if ($extra !== null) {
             $form->appendChild(id(new AphrontFormMarkupControl())->setValue($extra));
         }
     }
     $form->appendChild($control);
     $submit_control = id(new AphrontFormSubmitControl())->addCancelButton($done_uri);
     if (!$option->getLocked()) {
         $submit_control->setValue(pht('Save Config Entry'));
     }
     $form->appendChild($submit_control);
     $examples = $this->renderExamples($option);
     if ($examples) {
         $form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Examples'))->setValue($examples));
     }
     if (!$option->getHidden()) {
         $form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Default'))->setValue($this->renderDefaults($option, $config_entry)));
     }
     $title = pht('Edit %s', $this->key);
     $short = pht('Edit');
     $form_box = id(new PHUIObjectBoxView())->setHeaderText($title)->setForm($form);
     if ($error_view) {
         $form_box->setInfoView($error_view);
     }
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb(pht('Config'), $this->getApplicationURI());
     if ($group) {
         $crumbs->addTextCrumb($group->getName(), $group_uri);
     }
     $crumbs->addTextCrumb($this->key, '/config/edit/' . $this->key);
     $timeline = $this->buildTransactionTimeline($config_entry, new PhabricatorConfigTransactionQuery());
     $timeline->setShouldTerminate(true);
     return $this->buildApplicationPage(array($crumbs, $form_box, $timeline), array('title' => $title));
 }