Path: blob/master/src/applications/differential/conduit/DifferentialSetDiffPropertyConduitAPIMethod.php
12256 views
<?php12final class DifferentialSetDiffPropertyConduitAPIMethod3extends DifferentialConduitAPIMethod {45public function getAPIMethodName() {6return 'differential.setdiffproperty';7}89public function getMethodDescription() {10return pht('Attach properties to Differential diffs.');11}1213protected function defineParamTypes() {14return array(15'diff_id' => 'required diff_id',16'name' => 'required string',17'data' => 'required string',18);19}2021protected function defineReturnType() {22return 'void';23}2425protected function defineErrorTypes() {26return array(27'ERR_NOT_FOUND' => pht('Diff was not found.'),28);29}3031protected function execute(ConduitAPIRequest $request) {32$data = $request->getValue('data');33if ($data === null || !strlen($data)) {34throw new Exception(pht('Field "data" must be non-empty.'));35}3637$diff_id = $request->getValue('diff_id');38if ($diff_id === null) {39throw new Exception(pht('Field "diff_id" must be non-null.'));40}4142$name = $request->getValue('name');43if ($name === null || !strlen($name)) {44throw new Exception(pht('Field "name" must be non-empty.'));45}4647$data = json_decode($data, true);4849self::updateDiffProperty($diff_id, $name, $data);50}5152private static function updateDiffProperty($diff_id, $name, $data) {53$property = id(new DifferentialDiffProperty())->loadOneWhere(54'diffID = %d AND name = %s',55$diff_id,56$name);57if (!$property) {58$property = new DifferentialDiffProperty();59$property->setDiffID($diff_id);60$property->setName($name);61}62$property->setData($data);63$property->save();64return $property;65}6667}686970