3 final class PhabricatorConduitCallManagementWorkflow
4 extends PhabricatorConduitManagementWorkflow
{
6 protected function didConstruct() {
9 ->setSynopsis(pht('Call a Conduit method..'))
15 'help' => pht('Method to call.'),
21 'File to read parameters from, or "-" to read from '.
27 'Force the request to execute in this process, rather than '.
28 'proxying to another host in the cluster.'),
32 'param' => 'username',
34 'Execute the call as the given user. (If omitted, the call will '.
35 'be executed as an omnipotent user.)'),
40 public function execute(PhutilArgumentParser
$args) {
41 $viewer = $this->getViewer();
43 $method = $args->getArg('method');
44 if (!strlen($method)) {
45 throw new PhutilArgumentUsageException(
46 pht('Specify a method to call with "--method".'));
49 $input = $args->getArg('input');
50 if (!strlen($input)) {
51 throw new PhutilArgumentUsageException(
52 pht('Specify a file to read parameters from with "--input".'));
55 $as = $args->getArg('as');
57 $actor = id(new PhabricatorPeopleQuery())
59 ->withUsernames(array($as))
62 throw new PhutilArgumentUsageException(
64 'No such user "%s" exists.',
68 // Allow inline generation of user caches for the user we're acting
69 // as, since some calls may read user preferences.
70 $actor->setAllowInlineCacheGeneration(true);
76 fprintf(STDERR
, tsprintf("%s\n", pht('Reading input from stdin...')));
77 $input_json = file_get_contents('php://stdin');
79 $input_json = Filesystem
::readFile($input);
82 $params = phutil_json_decode($input_json);
84 $call = id(new ConduitCall($method, $params))
87 $api_request = $call->getAPIRequest();
89 $is_local = $args->getArg('local');
91 $api_request->setIsClusterRequest(true);
94 $result = $call->execute();
102 id(new PhutilJSON())->encodeFormatted($output));