refactoring
This commit is contained in:
@@ -36,6 +36,7 @@ use Espo\Core\Exceptions\{
|
||||
use Espo\Core\{
|
||||
Record\Collection as RecordCollection,
|
||||
Api\Request,
|
||||
Select\SearchParams,
|
||||
};
|
||||
|
||||
use StdClass;
|
||||
@@ -93,19 +94,9 @@ class Record extends RecordBase
|
||||
}
|
||||
|
||||
if (!empty($data->massRelate)) {
|
||||
if (!is_array($data->where)) {
|
||||
throw new BadRequest();
|
||||
}
|
||||
$searchParams = $this->fetchMassLinkSearchParamsFromRequest($request);
|
||||
|
||||
$where = json_decode(json_encode($data->where), true);
|
||||
|
||||
$selectData = null;
|
||||
|
||||
if (isset($data->selectData) && is_array($data->selectData)) {
|
||||
$selectData = json_decode(json_encode($data->selectData), true);
|
||||
}
|
||||
|
||||
return $this->getRecordService()->massLink($id, $link, $where, $selectData);
|
||||
return $this->getRecordService()->massLink($id, $link, $searchParams);
|
||||
}
|
||||
|
||||
$foreignIdList = [];
|
||||
@@ -191,4 +182,34 @@ class Record extends RecordBase
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function fetchMassLinkSearchParamsFromRequest(Request $request): SearchParams
|
||||
{
|
||||
$data = $request->getParsedBody();
|
||||
|
||||
$where = $data->where ?? null;
|
||||
|
||||
if ($where !== null) {
|
||||
$where = json_decode(json_encode($where), true);
|
||||
}
|
||||
|
||||
$params = json_decode(json_encode(
|
||||
$data->searchParams ?? $data->selectData ?? (object) []
|
||||
), true);
|
||||
|
||||
if ($where !== null && !is_array($where)) {
|
||||
throw new BadRequest("Bad 'where.");
|
||||
}
|
||||
|
||||
if ($where !== null) {
|
||||
$params['where'] = array_merge(
|
||||
$params['where'] ?? [],
|
||||
$where
|
||||
);
|
||||
}
|
||||
|
||||
unset($params['select']);
|
||||
|
||||
return SearchParams::fromRaw($params);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user