protected function loadPage()
 {
     $table = new PhabricatorConfigEntry();
     $conn_r = $table->establishConnection('r');
     $data = queryfx_all($conn_r, 'SELECT * FROM %T %Q %Q %Q', $table->getTableName(), $this->buildWhereClause($conn_r), $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r));
     return $table->loadAllFromArray($data);
 }
 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 delete.'));
     }
     $key = $argv[0];
     if (count($argv) > 1) {
         throw new PhutilArgumentUsageException(pht('Too many arguments: expected one key.'));
     }
     $use_database = $args->getArg('database');
     if ($use_database) {
         $config = new PhabricatorConfigDatabaseSource('default');
         $config_type = 'database';
     } else {
         $config = new PhabricatorConfigLocalSource();
         $config_type = 'local';
     }
     $values = $config->getKeys(array($key));
     if (!$values) {
         throw new PhutilArgumentUsageException(pht("Configuration key '%s' is not set in %s configuration!", $key, $config_type));
     }
     if ($use_database) {
         $config_entry = PhabricatorConfigEntry::loadConfigEntry($key);
         $config_entry->setIsDeleted(1);
         $config_entry->save();
     } else {
         $config->deleteKeys(array($key));
     }
     $console->writeOut("%s\n", pht("Deleted '%s' from %s configuration.", $key, $config_type));
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $xactions = id(new PhabricatorConfigTransactionQuery())->setViewer($viewer)->needComments(true)->execute();
     $object = new PhabricatorConfigEntry();
     $xaction = $object->getApplicationTransactionTemplate();
     $view = $xaction->getApplicationTransactionViewObject();
     $timeline = $view->setUser($viewer)->setTransactions($xactions)->setRenderAsFeed(true)->setObjectPHID(PhabricatorPHIDConstants::PHID_VOID);
     $timeline->setShouldTerminate(true);
     $object->willRenderTimeline($timeline, $this->getRequest());
     $title = pht('Settings History');
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb('Config', $this->getApplicationURI());
     $crumbs->addTextCrumb($title, '/config/history/');
     $nav = $this->buildSideNavView();
     $nav->selectFilter('history/');
     $view = id(new PHUITwoColumnView())->setNavigation($nav)->setMainColumn(array($timeline));
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $xactions = id(new PhabricatorConfigTransactionQuery())->setViewer($viewer)->needComments(true)->execute();
     $object = new PhabricatorConfigEntry();
     $xaction = $object->getApplicationTransactionTemplate();
     $view = $xaction->getApplicationTransactionViewObject();
     $timeline = $view->setUser($viewer)->setTransactions($xactions)->setRenderAsFeed(true)->setObjectPHID(PhabricatorPHIDConstants::PHID_VOID);
     $timeline->setShouldTerminate(true);
     $object->willRenderTimeline($timeline, $this->getRequest());
     $title = pht('Settings History');
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb($title);
     $crumbs->setBorder(true);
     $nav = $this->buildSideNavView();
     $nav->selectFilter('history/');
     $header = id(new PHUIHeaderView())->setHeader($title)->setProfileHeader(true);
     $content = id(new PhabricatorConfigPageView())->setHeader($header)->setContent($timeline);
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->setNavigation($nav)->appendChild($content)->addClass('white-background');
 }
 public function manageApplication($issue)
 {
     $key = 'config.ignore-issues';
     $config_entry = PhabricatorConfigEntry::loadConfigEntry($key);
     $list = $config_entry->getValue();
     if (isset($list[$issue])) {
         unset($list[$issue]);
     } else {
         $list[$issue] = true;
     }
     PhabricatorConfigEditor::storeNewValue($this->getRequest()->getUser(), $config_entry, $list, PhabricatorContentSource::newFromRequest($this->getRequest()));
 }
 public function manageApplication()
 {
     $key = 'config.ignore-issues';
     $config_entry = PhabricatorConfigEntry::loadConfigEntry($key);
     $list = $config_entry->getValue();
     if (isset($list[$this->issue])) {
         unset($list[$this->issue]);
     } else {
         $list[$this->issue] = true;
     }
     PhabricatorConfigEditor::storeNewValue($config_entry, $list, $this->getRequest());
 }
 public function manageApplication()
 {
     $key = 'phabricator.uninstalled-applications';
     $config_entry = PhabricatorConfigEntry::loadConfigEntry($key);
     $list = $config_entry->getValue();
     $uninstalled = PhabricatorEnv::getEnvConfig($key);
     if (isset($uninstalled[$this->application])) {
         unset($list[$this->application]);
     } else {
         $list[$this->application] = true;
     }
     PhabricatorConfigEditor::storeNewValue($this->getViewer(), $config_entry, $list, PhabricatorContentSource::newFromRequest($this->getRequest()));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $xactions = id(new PhabricatorConfigTransactionQuery())->setViewer($user)->needComments(true)->execute();
     $object = new PhabricatorConfigEntry();
     $xaction = $object->getApplicationTransactionTemplate();
     $view = $xaction->getApplicationTransactionViewObject();
     $timeline = $view->setUser($user)->setTransactions($xactions)->setRenderAsFeed(true)->setObjectPHID(PhabricatorPHIDConstants::PHID_VOID);
     $timeline->setShouldTerminate(true);
     $object->willRenderTimeline($timeline, $this->getRequest());
     $title = pht('Settings History');
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->setBorder(true);
     $crumbs->addTextCrumb('Config', $this->getApplicationURI());
     $crumbs->addTextCrumb($title, '/config/history/');
     $nav = $this->buildSideNavView();
     $nav->selectFilter('history/');
     $nav->setCrumbs($crumbs);
     $nav->appendChild($timeline);
     return $this->buildApplicationPage(array($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;
 }
Пример #10
0
$table = new PhabricatorDashboardInstall();
$conn_w = $table->establishConnection('w');
foreach (new LiskMigrationIterator($table) as $dashboard_install) {
    $application = $dashboard_install->getApplicationClass();
    queryfx($conn_w, 'UPDATE %T SET applicationClass = %s WHERE id = %d', $table->getTableName(), idx($map, $application, $application), $dashboard_install->getID());
}
/* -(  Phabricator configuration  )------------------------------------------ */
$config_key = 'phabricator.uninstalled-applications';
echo "Migrating `{$config_key}` config...\n";
$config = PhabricatorConfigEntry::loadConfigEntry($config_key);
$old_config = $config->getValue();
$new_config = array();
if ($old_config) {
    foreach ($old_config as $application => $uninstalled) {
        $new_config[idx($map, $application, $application)] = $uninstalled;
    }
    $config->setIsDeleted(0)->setValue($new_config)->save();
}
/* -(  phabricator.application-settings  )----------------------------------- */
$config_key = 'phabricator.application-settings';
echo "Migrating `{$config_key}` config...\n";
$config = PhabricatorConfigEntry::loadConfigEntry($config_key);
$old_config = $config->getValue();
$new_config = array();
if ($old_config) {
    foreach ($old_config as $application => $settings) {
        $application = preg_replace('/^PHID-APPS-/', '', $application);
        $new_config['PHID-APPS-' . idx($map, $application, $application)] = $settings;
    }
    $config->setIsDeleted(0)->setValue($new_config)->save();
}
 public function handleRequest(AphrontRequest $request)
 {
     $user = $request->getUser();
     $application = $request->getURIData('application');
     $application = id(new PhabricatorApplicationQuery())->setViewer($user)->withClasses(array($application))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
     if (!$application) {
         return new Aphront404Response();
     }
     $title = $application->getName();
     $view_uri = $this->getApplicationURI('view/' . get_class($application) . '/');
     $policies = id(new PhabricatorPolicyQuery())->setViewer($user)->setObject($application)->execute();
     if ($request->isFormPost()) {
         $result = array();
         foreach ($application->getCapabilities() as $capability) {
             $old = $application->getPolicy($capability);
             $new = $request->getStr('policy:' . $capability);
             if ($old == $new) {
                 // No change to the setting.
                 continue;
             }
             if (empty($policies[$new])) {
                 // Not a standard policy, check for a custom policy.
                 $policy = id(new PhabricatorPolicyQuery())->setViewer($user)->withPHIDs(array($new))->executeOne();
                 if (!$policy) {
                     // Not a custom policy either. Can't set the policy to something
                     // invalid, so skip this.
                     continue;
                 }
             }
             if ($new == PhabricatorPolicies::POLICY_PUBLIC) {
                 $capobj = PhabricatorPolicyCapability::getCapabilityByKey($capability);
                 if (!$capobj || !$capobj->shouldAllowPublicPolicySetting()) {
                     // Can't set non-public policies to public.
                     continue;
                 }
             }
             $result[$capability] = $new;
         }
         if ($result) {
             $key = 'phabricator.application-settings';
             $config_entry = PhabricatorConfigEntry::loadConfigEntry($key);
             $value = $config_entry->getValue();
             $phid = $application->getPHID();
             if (empty($value[$phid])) {
                 $value[$application->getPHID()] = array();
             }
             if (empty($value[$phid]['policy'])) {
                 $value[$phid]['policy'] = array();
             }
             $value[$phid]['policy'] = $result + $value[$phid]['policy'];
             // Don't allow users to make policy edits which would lock them out of
             // applications, since they would be unable to undo those actions.
             PhabricatorEnv::overrideConfig($key, $value);
             PhabricatorPolicyFilter::mustRetainCapability($user, $application, PhabricatorPolicyCapability::CAN_VIEW);
             PhabricatorPolicyFilter::mustRetainCapability($user, $application, PhabricatorPolicyCapability::CAN_EDIT);
             PhabricatorConfigEditor::storeNewValue($user, $config_entry, $value, PhabricatorContentSource::newFromRequest($request));
         }
         return id(new AphrontRedirectResponse())->setURI($view_uri);
     }
     $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions($user, $application);
     $form = id(new AphrontFormView())->setUser($user);
     $locked_policies = PhabricatorEnv::getEnvConfig('policy.locked');
     foreach ($application->getCapabilities() as $capability) {
         $label = $application->getCapabilityLabel($capability);
         $can_edit = $application->isCapabilityEditable($capability);
         $locked = idx($locked_policies, $capability);
         $caption = $application->getCapabilityCaption($capability);
         if (!$can_edit || $locked) {
             $form->appendChild(id(new AphrontFormStaticControl())->setLabel($label)->setValue(idx($descriptions, $capability))->setCaption($caption));
         } else {
             $control = id(new AphrontFormPolicyControl())->setUser($user)->setDisabled($locked)->setCapability($capability)->setPolicyObject($application)->setPolicies($policies)->setLabel($label)->setName('policy:' . $capability)->setCaption($caption);
             $template = $application->getCapabilityTemplatePHIDType($capability);
             if ($template) {
                 $phid_types = PhabricatorPHIDType::getAllTypes();
                 $phid_type = idx($phid_types, $template);
                 if ($phid_type) {
                     $template_object = $phid_type->newObject();
                     if ($template_object) {
                         $template_policies = id(new PhabricatorPolicyQuery())->setViewer($user)->setObject($template_object)->execute();
                         // NOTE: We want to expose both any object template policies
                         // (like "Subscribers") and any custom policy.
                         $all_policies = $template_policies + $policies;
                         $control->setPolicies($all_policies);
                         $control->setTemplateObject($template_object);
                     }
                 }
                 $control->setTemplatePHIDType($template);
             }
             $form->appendControl($control);
         }
     }
     $form->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Save Policies'))->addCancelButton($view_uri));
     $crumbs = $this->buildApplicationCrumbs();
     $crumbs->addTextCrumb($application->getName(), $view_uri);
     $crumbs->addTextCrumb(pht('Edit Policies'));
     $header = id(new PHUIHeaderView())->setHeader(pht('Edit Policies: %s', $application->getName()));
     $object_box = id(new PHUIObjectBoxView())->setHeader($header)->setForm($form);
     return $this->buildApplicationPage(array($crumbs, $object_box), array('title' => $title));
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $viewer = $this->getViewer();
     $obj_names = $args->getArg('objects');
     if (!$obj_names) {
         throw new PhutilArgumentUsageException(pht('Specify the name of an object to unlock.'));
     } else {
         if (count($obj_names) > 1) {
             throw new PhutilArgumentUsageException(pht('Specify the name of exactly one object to unlock.'));
         }
     }
     $object = id(new PhabricatorObjectQuery())->setViewer($viewer)->withNames($obj_names)->executeOne();
     if (!$object) {
         $name = head($obj_names);
         throw new PhutilArgumentUsageException(pht("No such object '%s'!", $name));
     }
     $handle = id(new PhabricatorHandleQuery())->setViewer($viewer)->withPHIDs(array($object->getPHID()))->executeOne();
     if ($object instanceof PhabricatorApplication) {
         $application = $object;
         $console->writeOut("%s\n", pht('Unlocking Application: %s', $handle->getFullName()));
         // For applications, we can't unlock them in a normal way and don't want
         // to unlock every capability, just view and edit.
         $capabilities = array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT);
         $key = 'phabricator.application-settings';
         $config_entry = PhabricatorConfigEntry::loadConfigEntry($key);
         $value = $config_entry->getValue();
         foreach ($capabilities as $capability) {
             if ($application->isCapabilityEditable($capability)) {
                 unset($value[$application->getPHID()]['policy'][$capability]);
             }
         }
         $config_entry->setValue($value);
         $config_entry->save();
         $console->writeOut("%s\n", pht('Saved application.'));
         return 0;
     }
     $console->writeOut("%s\n", pht('Unlocking: %s', $handle->getFullName()));
     $updated = false;
     foreach ($object->getCapabilities() as $capability) {
         switch ($capability) {
             case PhabricatorPolicyCapability::CAN_VIEW:
                 try {
                     $object->setViewPolicy(PhabricatorPolicies::POLICY_USER);
                     $console->writeOut("%s\n", pht('Unlocked view policy.'));
                     $updated = true;
                 } catch (Exception $ex) {
                     $console->writeOut("%s\n", pht('View policy is not mutable.'));
                 }
                 break;
             case PhabricatorPolicyCapability::CAN_EDIT:
                 try {
                     $object->setEditPolicy(PhabricatorPolicies::POLICY_USER);
                     $console->writeOut("%s\n", pht('Unlocked edit policy.'));
                     $updated = true;
                 } catch (Exception $ex) {
                     $console->writeOut("%s\n", pht('Edit policy is not mutable.'));
                 }
                 break;
             case PhabricatorPolicyCapability::CAN_JOIN:
                 try {
                     $object->setJoinPolicy(PhabricatorPolicies::POLICY_USER);
                     $console->writeOut("%s\n", pht('Unlocked join policy.'));
                     $updated = true;
                 } catch (Exception $ex) {
                     $console->writeOut("%s\n", pht('Join policy is not mutable.'));
                 }
                 break;
         }
     }
     if ($updated) {
         $object->save();
         $console->writeOut("%s\n", pht('Saved object.'));
     } else {
         $console->writeOut("%s\n", pht('Object has no mutable policies. Try unlocking parent/container ' . 'object instead. For example, to gain access to a commit, unlock ' . 'the repository it belongs to.'));
     }
 }
 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));
 }
Пример #14
0
            case 'caption':
            case 'options':
                $new_spec[$key] = $value;
                break;
            case 'checkbox-label':
                $new_spec['strings']['edit.checkbox'] = $value;
                break;
            case 'checkbox-value':
                $new_spec['strings']['view.yes'] = $value;
                break;
            case 'type':
                switch ($value) {
                    case 'string':
                        $value = 'text';
                        break;
                    case 'user':
                        $value = 'users';
                        $new_spec['limit'] = 1;
                        break;
                }
                $new_spec['type'] = $value;
                break;
            case 'copy':
                $new_spec['copy'] = $value;
                break;
        }
    }
    $new[$field_key] = $new_spec;
}
PhabricatorConfigEntry::loadConfigEntry($new_key)->setIsDeleted(0)->setValue($new)->save();
echo "Done.\n";