public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $ids = $args->getArg('id');
     if (!$ids) {
         throw new PhutilArgumentUsageException(pht("Use the '%s' flag to specify one or more SMS messages to show.", '--id'));
     }
     $messages = id(new PhabricatorSMS())->loadAllWhere('id IN (%Ld)', $ids);
     if ($ids) {
         $ids = array_fuse($ids);
         $missing = array_diff_key($ids, $messages);
         if ($missing) {
             throw new PhutilArgumentUsageException(pht('Some specified SMS messages do not exist: %s', implode(', ', array_keys($missing))));
         }
     }
     $last_key = last_key($messages);
     foreach ($messages as $message_key => $message) {
         $info = array();
         $info[] = pht('PROPERTIES');
         $info[] = pht('ID: %d', $message->getID());
         $info[] = pht('Status: %s', $message->getSendStatus());
         $info[] = pht('To: %s', $message->getToNumber());
         $info[] = pht('From: %s', $message->getFromNumber());
         $info[] = null;
         $info[] = pht('BODY');
         $info[] = $message->getBody();
         $info[] = null;
         $console->writeOut('%s', implode("\n", $info));
         if ($message_key != $last_key) {
             $console->writeOut("\n%s\n\n", str_repeat('-', 80));
         }
     }
 }
 public function execute(PhutilArgumentParser $args)
 {
     $commits = $this->loadCommits($args, 'commits');
     if (!$commits) {
         throw new PhutilArgumentUsageException('Specify one or more commits to resolve users for.');
     }
     $console = PhutilConsole::getConsole();
     foreach ($commits as $commit) {
         $repo = $commit->getRepository();
         $name = $repo->formatCommitName($commit->getCommitIdentifier());
         $console->writeOut("%s\n", pht('Examining commit %s...', $name));
         $ref = id(new DiffusionLowLevelCommitQuery())->setRepository($repo)->withIdentifier($commit->getCommitIdentifier())->execute();
         $author = $ref->getAuthor();
         $console->writeOut("%s\n", pht('Raw author string: %s', coalesce($author, 'null')));
         if ($author !== null) {
             $handle = $this->resolveUser($commit, $author);
             if ($handle) {
                 $console->writeOut("%s\n", pht('Phabricator user: %s', $handle->getFullName()));
             } else {
                 $console->writeOut("%s\n", pht('Unable to resolve a corresponding Phabricator user.'));
             }
         }
         $committer = $ref->getCommitter();
         $console->writeOut("%s\n", pht('Raw committer string: %s', coalesce($committer, 'null')));
         if ($committer !== null) {
             $handle = $this->resolveUser($commit, $committer);
             if ($handle) {
                 $console->writeOut("%s\n", pht('Phabricator user: %s', $handle->getFullName()));
             } else {
                 $console->writeOut("%s\n", pht('Unable to resolve a corresponding Phabricator user.'));
             }
         }
     }
     return 0;
 }
 public function execute(PhutilArgumentParser $args)
 {
     $can_recover = id(new PhabricatorPeopleQuery())->setViewer($this->getViewer())->withIsAdmin(true)->execute();
     if (!$can_recover) {
         throw new PhutilArgumentUsageException(pht('This Phabricator installation has no recoverable administrator ' . 'accounts. You can use `bin/accountadmin` to create a new ' . 'administrator account or make an existing user an administrator.'));
     }
     $can_recover = mpull($can_recover, 'getUsername');
     sort($can_recover);
     $can_recover = implode(', ', $can_recover);
     $usernames = $args->getArg('username');
     if (!$usernames) {
         throw new PhutilArgumentUsageException(pht('You must specify the username of the account to recover.'));
     } else {
         if (count($usernames) > 1) {
             throw new PhutilArgumentUsageException(pht('You can only recover the username for one account.'));
         }
     }
     $username = head($usernames);
     $user = id(new PhabricatorPeopleQuery())->setViewer($this->getViewer())->withUsernames(array($username))->executeOne();
     if (!$user) {
         throw new PhutilArgumentUsageException(pht('No such user "%s". Recoverable administrator accounts are: %s.', $username, $can_recover));
     }
     if (!$user->getIsAdmin()) {
         throw new PhutilArgumentUsageException(pht('You can only recover administrator accounts, but %s is not an ' . 'administrator. Recoverable administrator accounts are: %s.', $username, $can_recover));
     }
     $engine = new PhabricatorAuthSessionEngine();
     $onetime_uri = $engine->getOneTimeLoginURI($user, null, PhabricatorAuthSessionEngine::ONETIME_RECOVER);
     $console = PhutilConsole::getConsole();
     $console->writeOut(pht('Use this link to recover access to the "%s" account from the web ' . 'interface:', $username));
     $console->writeOut("\n\n");
     $console->writeOut('    %s', $onetime_uri);
     $console->writeOut("\n\n");
     $console->writeOut(pht('After logging in, you can use the "Auth" application to add or ' . 'restore authentication providers and allow normal logins to ' . 'succeed.') . "\n");
     return 0;
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $resource_type = $args->getArg('type');
     if (!$resource_type) {
         throw new PhutilArgumentUsageException(pht('Specify a resource type with `%s`.', '--type'));
     }
     $until = $args->getArg('until');
     if (strlen($until)) {
         $until = strtotime($until);
         if ($until <= 0) {
             throw new PhutilArgumentUsageException(pht('Unable to parse argument to "%s".', '--until'));
         }
     }
     $attributes = $args->getArg('attributes');
     if ($attributes) {
         $options = new PhutilSimpleOptions();
         $options->setCaseSensitive(true);
         $attributes = $options->parse($attributes);
     }
     $lease = id(new DrydockLease())->setResourceType($resource_type);
     if ($attributes) {
         $lease->setAttributes($attributes);
     }
     if ($until) {
         $lease->setUntil($until);
     }
     $lease->queueForActivation();
     echo tsprintf("%s\n", pht('Waiting for daemons to activate lease...'));
     $lease->waitUntilActive();
     echo tsprintf("%s\n", pht('Activated lease "%s".', $lease->getID()));
     return 0;
 }
 public function execute(PhutilArgumentParser $args)
 {
     $emails = $args->getArg('email');
     if (!$emails) {
         throw new PhutilArgumentUsageException(pht('You must specify the email to verify.'));
     } else {
         if (count($emails) > 1) {
             throw new PhutilArgumentUsageException(pht('You can only verify one address at a time.'));
         }
     }
     $address = head($emails);
     $email = id(new PhabricatorUserEmail())->loadOneWhere('address = %s', $address);
     if (!$email) {
         throw new PhutilArgumentUsageException(pht('No email exists with address "%s"!', $address));
     }
     $viewer = $this->getViewer();
     $user = id(new PhabricatorPeopleQuery())->setViewer($viewer)->withPHIDs(array($email->getUserPHID()))->executeOne();
     if (!$user) {
         throw new Exception(pht('Email record has invalid user PHID!'));
     }
     $editor = id(new PhabricatorUserEditor())->setActor($viewer)->verifyEmail($user, $email);
     $console = PhutilConsole::getConsole();
     $console->writeOut("%s\n", pht('Done.'));
     return 0;
 }
示例#6
0
 protected function getConsole()
 {
     if ($this->console) {
         return $this->console;
     }
     return PhutilConsole::getConsole();
 }
 public function execute(PhutilArgumentParser $args)
 {
     $repos = $this->loadRepositories($args, 'repos');
     if (!$repos) {
         throw new PhutilArgumentUsageException(pht('Specify one or more repositories to mark imported.'));
     }
     $new_importing_value = (bool) $args->getArg('mark-not-imported');
     $console = PhutilConsole::getConsole();
     foreach ($repos as $repo) {
         $name = $repo->getDisplayName();
         if ($repo->isImporting() && $new_importing_value) {
             $console->writeOut("%s\n", pht('Repository "%s" is already importing.', $name));
         } else {
             if (!$repo->isImporting() && !$new_importing_value) {
                 $console->writeOut("%s\n", pht('Repository "%s" is already imported.', $name));
             } else {
                 if ($new_importing_value) {
                     $console->writeOut("%s\n", pht('Marking repository "%s" as importing.', $name));
                 } else {
                     $console->writeOut("%s\n", pht('Marking repository "%s" as imported.', $name));
                 }
                 $repo->setDetail('importing', $new_importing_value);
                 $repo->save();
             }
         }
     }
     $console->writeOut("%s\n", pht('Done.'));
     return 0;
 }
 private function getConsole()
 {
     if ($this->console) {
         return $this->console;
     }
     return PhutilConsole::getConsole();
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $ids = $args->getArg('ids');
     if (!$ids) {
         throw new PhutilArgumentUsageException('Specify one or more lease IDs to release.');
     }
     $viewer = $this->getViewer();
     $leases = id(new DrydockLeaseQuery())->setViewer($viewer)->withIDs($ids)->execute();
     foreach ($ids as $id) {
         $lease = idx($leases, $id);
         if (!$lease) {
             $console->writeErr("Lease %d does not exist!\n", $id);
         } else {
             if ($lease->getStatus() != DrydockLeaseStatus::STATUS_ACTIVE) {
                 $console->writeErr("Lease %d is not 'active'!\n", $id);
             } else {
                 $resource = $lease->getResource();
                 $blueprint = $resource->getBlueprint();
                 $blueprint->releaseLease($resource, $lease);
                 $console->writeErr("Released lease %d.\n", $id);
             }
         }
     }
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $iterator = $this->buildIterator($args);
     if (!$iterator) {
         throw new PhutilArgumentUsageException('Either specify a list of files to purge, or use `--all` ' . 'to purge all files.');
     }
     $is_dry_run = $args->getArg('dry-run');
     foreach ($iterator as $file) {
         $fid = 'F' . $file->getID();
         try {
             $file->loadFileData();
             $okay = true;
         } catch (Exception $ex) {
             $okay = false;
         }
         if ($okay) {
             $console->writeOut("%s: File data is OK, not purging.\n", $fid);
         } else {
             if ($is_dry_run) {
                 $console->writeOut("%s: Would purge (dry run).\n", $fid);
             } else {
                 $console->writeOut("%s: Purging.\n", $fid);
                 $file->delete();
             }
         }
     }
     return 0;
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $resource_name = $args->getArg('name');
     if (!$resource_name) {
         throw new PhutilArgumentUsageException('Specify a resource name with `--name`.');
     }
     $blueprint_id = $args->getArg('blueprint');
     if (!$blueprint_id) {
         throw new PhutilArgumentUsageException('Specify a blueprint ID with `--blueprint`.');
     }
     $attributes = $args->getArg('attributes');
     if ($attributes) {
         $options = new PhutilSimpleOptions();
         $options->setCaseSensitive(true);
         $attributes = $options->parse($attributes);
     }
     $viewer = $this->getViewer();
     $blueprint = id(new DrydockBlueprintQuery())->setViewer($viewer)->withIDs(array($blueprint_id))->executeOne();
     if (!$blueprint) {
         throw new PhutilArgumentUsageException('Specified blueprint does not exist.');
     }
     $resource = id(new DrydockResource())->setBlueprintPHID($blueprint->getPHID())->setType($blueprint->getImplementation()->getType())->setName($resource_name)->setStatus(DrydockResourceStatus::STATUS_OPEN);
     if ($attributes) {
         $resource->setAttributes($attributes);
     }
     $resource->save();
     $console->writeOut("Created Resource %s\n", $resource->getID());
     return 0;
 }
示例#12
0
 private function log($pattern)
 {
     $console = PhutilConsole::getConsole();
     $argv = func_get_args();
     $argv[0] .= "\n";
     call_user_func_array(array($console, 'writeErr'), $argv);
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $public_keyfile = $args->getArg('public');
     if (!strlen($public_keyfile)) {
         throw new PhutilArgumentUsageException(pht('You must specify the path to a public keyfile with %s.', '--public'));
     }
     if (!Filesystem::pathExists($public_keyfile)) {
         throw new PhutilArgumentUsageException(pht('Specified public keyfile "%s" does not exist!', $public_keyfile));
     }
     $public_key = Filesystem::readFile($public_keyfile);
     $pkcs8_keyfile = $args->getArg('pkcs8');
     if (!strlen($pkcs8_keyfile)) {
         throw new PhutilArgumentUsageException(pht('You must specify the path to a pkcs8 keyfile with %s.', '--pkc8s'));
     }
     if (!Filesystem::pathExists($pkcs8_keyfile)) {
         throw new PhutilArgumentUsageException(pht('Specified pkcs8 keyfile "%s" does not exist!', $pkcs8_keyfile));
     }
     $pkcs8_key = Filesystem::readFile($pkcs8_keyfile);
     $warning = pht('Adding a PKCS8 keyfile to the cache can be very dangerous. If the ' . 'PKCS8 file really encodes a different public key than the one ' . 'specified, an attacker could use it to gain unauthorized access.' . "\n\n" . 'Generally, you should use this option only in a development ' . 'environment where ssh-keygen is broken and it is inconvenient to ' . 'fix it, and only if you are certain you understand the risks. You ' . 'should never cache a PKCS8 file you did not generate yourself.');
     $console->writeOut("%s\n", phutil_console_wrap($warning));
     $prompt = pht('Really trust this PKCS8 keyfile?');
     if (!phutil_console_confirm($prompt)) {
         throw new PhutilArgumentUsageException(pht('Aborted workflow.'));
     }
     $key = PhabricatorAuthSSHPublicKey::newFromRawKey($public_key);
     $key->forcePopulatePKCS8Cache($pkcs8_key);
     $console->writeOut("%s\n", pht('Cached PKCS8 key for public key.'));
     return 0;
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $tasks = $this->loadTasks($args);
     foreach ($tasks as $task) {
         $can_execute = !$task->isArchived();
         if (!$can_execute) {
             $console->writeOut("**<bg:yellow> %s </bg>** %s\n", pht('ARCHIVED'), pht('%s is already archived, and can not be executed.', $this->describeTask($task)));
             continue;
         }
         // NOTE: This ignores leases, maybe it should respect them without
         // a parameter like --force?
         $task->setLeaseOwner(null);
         $task->setLeaseExpires(PhabricatorTime::getNow());
         $task->save();
         $task_data = id(new PhabricatorWorkerTaskData())->loadOneWhere('id = %d', $task->getDataID());
         $task->setData($task_data->getData());
         $console->writeOut(pht('Executing task %d (%s)...', $task->getID(), $task->getTaskClass()));
         $task = $task->executeTask();
         $ex = $task->getExecutionException();
         if ($ex) {
             throw $ex;
         }
     }
     return 0;
 }
 protected function log($message)
 {
     if ($this->debug) {
         $console = PhutilConsole::getConsole();
         $console->writeErr("%s\n", $message);
     }
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $in = $args->getArg('in');
     if (!strlen($in)) {
         throw new PhutilArgumentUsageException(pht('Specify the dumpfile to read with --in.'));
     }
     $from = $args->getArg('from');
     if (!strlen($from)) {
         throw new PhutilArgumentUsageException(pht('Specify namespace to rename from with --from.'));
     }
     $to = $args->getArg('to');
     if (!strlen($to)) {
         throw new PhutilArgumentUsageException(pht('Specify namespace to rename to with --to.'));
     }
     $patterns = array('use' => '@^(USE `)([^_]+)(_.*)$@', 'create' => '@^(CREATE DATABASE /\\*.*?\\*/ `)([^_]+)(_.*)$@');
     $found = array_fill_keys(array_keys($patterns), 0);
     $matches = null;
     foreach (new LinesOfALargeFile($in) as $line) {
         foreach ($patterns as $key => $pattern) {
             if (preg_match($pattern, $line, $matches)) {
                 $namespace = $matches[2];
                 if ($namespace != $from) {
                     throw new Exception(pht('Expected namespace "%s", found "%s": %s.', $from, $namespace, $line));
                 }
                 $line = $matches[1] . $to . $matches[3];
                 $found[$key]++;
             }
         }
         echo $line . "\n";
     }
     // Give the user a chance to catch things if the results are crazy.
     $console->writeErr(pht('Adjusted **%s** create statements and **%s** use statements.', new PhutilNumber($found['create']), new PhutilNumber($found['use'])) . "\n");
     return 0;
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $daemon = new PhabricatorFactDaemon(array());
     $daemon->setVerbose(true);
     $daemon->setEngines(PhabricatorFactEngine::loadAllEngines());
     $iterators = PhabricatorFactDaemon::getAllApplicationIterators();
     $selected = $args->getArg('iterator');
     if ($selected) {
         $use = array();
         foreach ($selected as $iterator_name) {
             if (isset($iterators[$iterator_name])) {
                 $use[$iterator_name] = $iterators[$iterator_name];
             } else {
                 $console->writeErr("%s\n", pht("Iterator '%s' does not exist.", $iterator_name));
             }
         }
         $iterators = $use;
     }
     foreach ($iterators as $iterator_name => $iterator) {
         if ($args->getArg('all')) {
             $daemon->processIterator($iterator);
         } else {
             $daemon->processIteratorWithCursor($iterator_name, $iterator);
         }
     }
     if (!$args->getArg('skip-aggregates')) {
         $daemon->processAggregates();
     }
     return 0;
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $purge_all = $args->getArg('purge-all');
     $purge = array('remarkup' => $purge_all || $args->getArg('purge-remarkup'), 'changeset' => $purge_all || $args->getArg('purge-changeset'), 'general' => $purge_all || $args->getArg('purge-general'));
     if (!array_filter($purge)) {
         $list = array();
         foreach ($purge as $key => $ignored) {
             $list[] = "'--purge-" . $key . "'";
         }
         throw new PhutilArgumentUsageException("Specify which cache or caches to purge, or use '--purge-all'. " . "Available caches are: " . implode(', ', $list) . ". Use '--help' " . "for more information.");
     }
     if ($purge['remarkup']) {
         $console->writeOut('Purging remarkup cache...');
         $this->purgeRemarkupCache();
         $console->writeOut("done.\n");
     }
     if ($purge['changeset']) {
         $console->writeOut('Purging changeset cache...');
         $this->purgeChangesetCache();
         $console->writeOut("done.\n");
     }
     if ($purge['general']) {
         $console->writeOut('Purging general cache...');
         $this->purgeGeneralCache();
         $console->writeOut("done.\n");
     }
 }
 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));
 }
 public function execute(PhutilArgumentParser $args)
 {
     $saw_any_rows = false;
     $console = PhutilConsole::getConsole();
     $table = new DifferentialLegacyHunk();
     foreach (new LiskMigrationIterator($table) as $hunk) {
         $saw_any_rows = true;
         $id = $hunk->getID();
         $console->writeOut("%s\n", pht('Migrating hunk %d...', $id));
         $new_hunk = id(new DifferentialModernHunk())->setChangesetID($hunk->getChangesetID())->setOldOffset($hunk->getOldOffset())->setOldLen($hunk->getOldLen())->setNewOffset($hunk->getNewOffset())->setNewLen($hunk->getNewLen())->setChanges($hunk->getChanges())->setDateCreated($hunk->getDateCreated())->setDateModified($hunk->getDateModified());
         $hunk->openTransaction();
         $new_hunk->save();
         $hunk->delete();
         $hunk->saveTransaction();
         $old_len = strlen($hunk->getChanges());
         $new_len = strlen($new_hunk->getData());
         if ($old_len) {
             $diff_len = $old_len - $new_len;
             $console->writeOut("%s\n", pht('Saved %s bytes (%s).', new PhutilNumber($diff_len), sprintf('%.1f%%', 100 * ($diff_len / $old_len))));
         }
     }
     if ($saw_any_rows) {
         $console->writeOut("%s\n", pht('Done.'));
     } else {
         $console->writeOut("%s\n", pht('No rows to migrate.'));
     }
 }
 public function execute(PhutilArgumentParser $args)
 {
     $viewer = $this->getViewer();
     $names = $args->getArg('buildable');
     if (count($names) != 1) {
         throw new PhutilArgumentUsageException(pht('Specify exactly one buildable object, by object name.'));
     }
     $name = head($names);
     $buildable = id(new PhabricatorObjectQuery())->setViewer($viewer)->withNames($names)->executeOne();
     if (!$buildable) {
         throw new PhutilArgumentUsageException(pht('No such buildable "%s"!', $name));
     }
     if (!$buildable instanceof HarbormasterBuildableInterface) {
         throw new PhutilArgumentUsageException(pht('Object "%s" is not a buildable!', $name));
     }
     $plan_id = $args->getArg('plan');
     if (!$plan_id) {
         throw new PhutilArgumentUsageException(pht('Use --plan to specify a build plan to run.'));
     }
     $plan = id(new HarbormasterBuildPlanQuery())->setViewer($viewer)->withIDs(array($plan_id))->executeOne();
     if (!$plan) {
         throw new PhutilArgumentUsageException(pht('Build plan "%s" does not exist.', $plan_id));
     }
     $console = PhutilConsole::getConsole();
     $buildable = HarbormasterBuildable::initializeNewBuildable($viewer)->setIsManualBuildable(true)->setBuildablePHID($buildable->getHarbormasterBuildablePHID())->setContainerPHID($buildable->getHarbormasterContainerPHID())->save();
     $console->writeOut("%s\n", pht('Applying plan %s to new buildable %s...', $plan->getID(), 'B' . $buildable->getID()));
     $console->writeOut("\n    %s\n\n", PhabricatorEnv::getProductionURI('/B' . $buildable->getID()));
     PhabricatorWorker::setRunAllTasksInProcess(true);
     $buildable->applyPlan($plan);
     $console->writeOut("%s\n", pht('Done.'));
     return 0;
 }
 public function execute(PhutilArgumentParser $args)
 {
     $repos = $this->loadRepositories($args, 'repos');
     if (!$repos) {
         throw new PhutilArgumentUsageException('Specify one or more repositories to mark imported, by callsign.');
     }
     $new_importing_value = (bool) $args->getArg('mark-not-imported');
     $console = PhutilConsole::getConsole();
     foreach ($repos as $repo) {
         $callsign = $repo->getCallsign();
         if ($repo->isImporting() && $new_importing_value) {
             $console->writeOut("%s\n", pht("Repository '%s' is already importing.", $callsign));
         } else {
             if (!$repo->isImporting() && !$new_importing_value) {
                 $console->writeOut("%s\n", pht("Repository '%s' is already imported.", $callsign));
             } else {
                 if ($new_importing_value) {
                     $console->writeOut("%s\n", pht("Marking repository '%s' as importing.", $callsign));
                 } else {
                     $console->writeOut("%s\n", pht("Marking repository '%s' as imported.", $callsign));
                 }
                 $repo->setDetail('importing', $new_importing_value);
                 $repo->save();
             }
         }
     }
     $console->writeOut("Done.\n");
     return 0;
 }
 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 execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $reset = $args->getArg('reset');
     if ($reset) {
         foreach ($reset as $name) {
             $cursor = id(new PhabricatorFactCursor())->loadOneWhere('name = %s', $name);
             if ($cursor) {
                 $console->writeOut("%s\n", pht("Resetting cursor %s...", $name));
                 $cursor->delete();
             } else {
                 $console->writeErr("%s\n", pht("Cursor %s does not exist or is already reset.", $name));
             }
         }
         return 0;
     }
     $iterator_map = PhabricatorFactDaemon::getAllApplicationIterators();
     if (!$iterator_map) {
         $console->writeErr("%s\n", pht("No cursors."));
         return 0;
     }
     $cursors = id(new PhabricatorFactCursor())->loadAllWhere('name IN (%Ls)', array_keys($iterator_map));
     $cursors = mpull($cursors, 'getPosition', 'getName');
     foreach ($iterator_map as $iterator_name => $iterator) {
         $console->writeOut("%s (%s)\n", $iterator_name, idx($cursors, $iterator_name, 'start'));
     }
     return 0;
 }
 public function run()
 {
     $method = $this->getArgument('method', array());
     if (count($method) !== 1) {
         throw new ArcanistUsageException(pht('Provide exactly one Conduit method name.'));
     }
     $method = reset($method);
     $console = PhutilConsole::getConsole();
     if (!function_exists('posix_isatty') || posix_isatty(STDIN)) {
         $console->writeErr("%s\n", pht('Waiting for JSON parameters on stdin...'));
     }
     $params = @file_get_contents('php://stdin');
     try {
         $params = phutil_json_decode($params);
     } catch (PhutilJSONParserException $ex) {
         throw new ArcanistUsageException(pht('Provide method parameters on stdin as a JSON blob.'));
     }
     $error = null;
     $error_message = null;
     try {
         $result = $this->getConduit()->callMethodSynchronous($method, $params);
     } catch (ConduitClientException $ex) {
         $error = $ex->getErrorCode();
         $error_message = $ex->getMessage();
         $result = null;
     }
     echo json_encode(array('error' => $error, 'errorMessage' => $error_message, 'response' => $result)) . "\n";
     return 0;
 }
 public final function getConsole()
 {
     if ($this->console) {
         return $this->console;
     }
     return PhutilConsole::getConsole();
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $id = $args->getArg('id');
     if (!$id) {
         throw new PhutilArgumentUsageException(pht('Specify a public key to trust with --id.'));
     }
     $key = id(new PhabricatorAuthSSHKeyQuery())->setViewer($this->getViewer())->withIDs(array($id))->executeOne();
     if (!$key) {
         throw new PhutilArgumentUsageException(pht('No public key exists with ID "%s".', $id));
     }
     if ($key->getIsTrusted()) {
         throw new PhutilArgumentUsageException(pht('Public key with ID %s is already trusted.', $id));
     }
     if (!$key->getObject() instanceof AlmanacDevice) {
         throw new PhutilArgumentUsageException(pht('You can only trust keys associated with Almanac devices.'));
     }
     $handle = id(new PhabricatorHandleQuery())->setViewer($this->getViewer())->withPHIDs(array($key->getObject()->getPHID()))->executeOne();
     $console->writeOut("**<bg:red> %s </bg>**\n\n%s\n\n%s\n\n%s", pht('IMPORTANT!'), phutil_console_wrap(pht('Trusting a public key gives anyone holding the corresponding ' . 'private key complete, unrestricted access to all data in ' . 'Phabricator. The private key will be able to sign requests that ' . 'skip policy and security checks.')), phutil_console_wrap(pht('This is an advanced feature which should normally be used only ' . 'when building a Phabricator cluster. This feature is very ' . 'dangerous if misused.')), pht('This key is associated with device "%s".', $handle->getName()));
     $prompt = pht('Really trust this key?');
     if (!phutil_console_confirm($prompt)) {
         throw new PhutilArgumentUsageException(pht('User aborted workflow.'));
     }
     $key->setIsTrusted(1);
     $key->save();
     $console->writeOut("**<bg:green> %s </bg>** %s\n", pht('TRUSTED'), pht('Key %s has been marked as trusted.', $id));
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $paths = $args->getArg('paths');
     if (!$paths) {
         $paths = array(getcwd());
     }
     $targets = array();
     foreach ($paths as $path) {
         $root = Filesystem::resolvePath($path);
         if (!Filesystem::pathExists($root) || !is_dir($root)) {
             throw new PhutilArgumentUsageException(pht('Path "%s" does not exist, or is not a directory.', $path));
         }
         $libraries = id(new FileFinder($path))->withPath('*/__phutil_library_init__.php')->find();
         if (!$libraries) {
             throw new PhutilArgumentUsageException(pht('Path "%s" contains no libphutil libraries.', $path));
         }
         foreach ($libraries as $library) {
             $targets[] = Filesystem::resolvePath(dirname($library)) . '/';
         }
     }
     $targets = array_unique($targets);
     foreach ($targets as $library) {
         echo tsprintf("**<bg:blue> %s </bg>** %s\n", pht('EXTRACT'), pht('Extracting "%s"...', Filesystem::readablePath($library)));
         $this->extractLibrary($library);
     }
     return 0;
 }
 public function didExecute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $patches = $this->getPatches();
     if (!$this->isDryRun() && !$this->isForce()) {
         $console->writeOut(phutil_console_wrap(pht('Before running storage upgrades, you should take down the ' . 'Phabricator web interface and stop any running Phabricator ' . 'daemons (you can disable this warning with %s).', '--force')));
         if (!phutil_console_confirm(pht('Are you ready to continue?'))) {
             $console->writeOut("%s\n", pht('Cancelled.'));
             return 1;
         }
     }
     $apply_only = $args->getArg('apply');
     if ($apply_only) {
         if (empty($patches[$apply_only])) {
             throw new PhutilArgumentUsageException(pht("%s argument '%s' is not a valid patch. " . "Use '%s' to show patch status.", '--apply', $apply_only, './bin/storage status'));
         }
     }
     $no_quickstart = $args->getArg('no-quickstart');
     $init_only = $args->getArg('init-only');
     $no_adjust = $args->getArg('no-adjust');
     $this->upgradeSchemata($apply_only, $no_quickstart, $init_only);
     if ($no_adjust || $init_only || $apply_only) {
         $console->writeOut("%s\n", pht('Declining to apply storage adjustments.'));
         return 0;
     } else {
         return $this->adjustSchemata(false);
     }
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $viewer = $this->getViewer();
     $since = PhabricatorTime::getNow() - phutil_units('30 days in seconds');
     $until = PhabricatorTime::getNow();
     $mails = id(new PhabricatorMetaMTAMailQuery())->setViewer($viewer)->withDateCreatedBetween($since, $until)->execute();
     $unfiltered = array();
     foreach ($mails as $mail) {
         $unfiltered_actors = mpull($mail->loadAllActors(), 'getPHID');
         foreach ($unfiltered_actors as $phid) {
             if (empty($unfiltered[$phid])) {
                 $unfiltered[$phid] = 0;
             }
             $unfiltered[$phid]++;
         }
     }
     arsort($unfiltered);
     $table = id(new PhutilConsoleTable())->setBorders(true)->addColumn('user', array('title' => pht('User')))->addColumn('unfiltered', array('title' => pht('Unfiltered')));
     $handles = $viewer->loadHandles(array_keys($unfiltered));
     $names = mpull(iterator_to_array($handles), 'getName', 'getPHID');
     foreach ($unfiltered as $phid => $count) {
         $table->addRow(array('user' => idx($names, $phid), 'unfiltered' => $count));
     }
     $table->draw();
     echo "\n";
     echo pht('Mail sent in the last 30 days.') . "\n";
     echo pht('"Unfiltered" is raw volume before preferences were applied.') . "\n";
     echo "\n";
     return 0;
 }