1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-15 19:32:40 +01:00
phorge-phorge/src/applications/differential/conduit/DifferentialSetDiffPropertyConduitAPIMethod.php

56 lines
1.3 KiB
PHP
Raw Normal View History

2011-01-24 21:07:34 +01:00
<?php
final class DifferentialSetDiffPropertyConduitAPIMethod
extends DifferentialConduitAPIMethod {
public function getAPIMethodName() {
return 'differential.setdiffproperty';
}
2011-01-24 21:07:34 +01:00
public function getMethodDescription() {
return pht('Attach properties to Differential diffs.');
2011-01-24 21:07:34 +01:00
}
protected function defineParamTypes() {
2011-01-24 21:07:34 +01:00
return array(
'diff_id' => 'required diff_id',
'name' => 'required string',
'data' => 'required string',
);
}
protected function defineReturnType() {
2011-01-24 21:07:34 +01:00
return 'void';
}
protected function defineErrorTypes() {
2011-01-24 21:07:34 +01:00
return array(
'ERR_NOT_FOUND' => pht('Diff was not found.'),
2011-01-24 21:07:34 +01:00
);
}
protected function execute(ConduitAPIRequest $request) {
$diff_id = $request->getValue('diff_id');
$name = $request->getValue('name');
$data = json_decode($request->getValue('data'), true);
self::updateDiffProperty($diff_id, $name, $data);
2011-01-24 21:07:34 +01:00
}
private static function updateDiffProperty($diff_id, $name, $data) {
$property = id(new DifferentialDiffProperty())->loadOneWhere(
'diffID = %d AND name = %s',
$diff_id,
$name);
if (!$property) {
$property = new DifferentialDiffProperty();
$property->setDiffID($diff_id);
$property->setName($name);
}
$property->setData($data);
$property->save();
return $property;
}
2011-01-24 21:07:34 +01:00
}