<?php

/**
 * @group conduit
 */
final class ConduitAPI_maniphest_update_Method
  extends ConduitAPI_maniphest_Method {

  public function getMethodDescription() {
    return "Update an existing Maniphest task.";
  }

  public function defineErrorTypes() {
    return array(
      'ERR-BAD-TASK'          => 'No such maniphest task exists.',
      'ERR-INVALID-PARAMETER' => 'Missing or malformed parameter.'
    );
  }

  public function defineParamTypes() {
    return $this->getTaskFields($is_new = false);
  }

  public function defineReturnType() {
    return 'nonempty dict';
  }

  protected function execute(ConduitAPIRequest $request) {
    $id = $request->getValue('id');
    $phid = $request->getValue('phid');

    if (($id && $phid) || (!$id && !$phid)) {
      throw new Exception("Specify exactly one of 'id' and 'phid'.");
    }

    if ($id) {
      $task = id(new ManiphestTask())->load($id);
    } else {
      $task = id(new ManiphestTask())->loadOneWhere(
        'phid = %s',
        $phid);
    }

    if (!$task) {
      throw new ConduitException('ERR-BAD-TASK');
    }

    $this->applyRequest($task, $request, $is_new = false);

    return $this->buildTaskInfoDictionary($task);
  }

}

<?php

/**
 * @group conduit
 */
final class ConduitAPI_maniphest_update_Method
  extends ConduitAPI_maniphest_Method {

  public function getMethodDescription() {
    return "Update an existing Maniphest task.";
  }

  public function defineErrorTypes() {
    return array(
      'ERR-BAD-TASK'          => 'No such maniphest task exists.',
      'ERR-INVALID-PARAMETER' => 'Missing or malformed parameter.',
      'ERR-NO-EFFECT'         => 'Update has no effect.',
    );
  }

  public function defineParamTypes() {
    return $this->getTaskFields($is_new = false);
  }

  public function defineReturnType() {
    return 'nonempty dict';
  }

  protected function execute(ConduitAPIRequest $request) {
    $id = $request->getValue('id');
    $phid = $request->getValue('phid');

    if (($id && $phid) || (!$id && !$phid)) {
      throw new Exception("Specify exactly one of 'id' and 'phid'.");
    }

    if ($id) {
      $task = id(new ManiphestTask())->load($id);
    } else {
      $task = id(new ManiphestTask())->loadOneWhere(
        'phid = %s',
        $phid);
    }

    $params = $request->getAllParameters();
    unset($params['id']);
    unset($params['phid']);
    $params = call_user_func_array('coalesce', $params);

    if (!$params) {
      throw new ConduitException('ERR-NO-EFFECT');
    }

    if (!$task) {
      throw new ConduitException('ERR-BAD-TASK');
    }

    $this->applyRequest($task, $request, $is_new = false);

    return $this->buildTaskInfoDictionary($task);
  }

}

Implement option 1 from T3210
Implement option 1 from T3210

Summary: Fixes T3210

Test Plan: Run the conduit call via the UI and ensure it no longer breaks. Check I get an error returned if no params are set

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T3210

Differential Revision: https://secure.phabricator.com/D5950
