| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- Lib::loadClass('Relations');
- class Api_Process_P5_CreateRelations { // TODO: extends Api_ProcessBase
- static function run($args, $responseForm) {
- $typeName = (!empty($args['typeName'][0])) ? $args['typeName'][0] : '';
- if (!$typeName) throw new Api_OwsException("Missing value for 'typeName'", 501, null, 'MissingParameterValue', 'request');
- $primaryKey = (!empty($args['primaryKey'][0])) ? $args['primaryKey'][0] : '';
- if (!$primaryKey) throw new Api_OwsException("Missing value for 'primaryKey'", 501, null, 'MissingParameterValue', 'request');
- $remoteTypeName = (!empty($args['remoteTypeName'][0])) ? $args['remoteTypeName'][0] : '';
- if (!$remoteTypeName) throw new Api_OwsException("Missing value for 'remoteTypeName'", 501, null, 'MissingParameterValue', 'request');
- $listRemotePrimaryKeys = (!empty($args['primaryKey'])) ? $args['remotePrimaryKey'] : [];
- if (empty($listRemotePrimaryKeys)) throw new Api_OwsException("Missing value for 'remotePrimaryKey'", 501, null, 'MissingParameterValue', 'request');
- try {
- Relations::isAllowedToCreateRelation($userLogin = User::getLogin(), $typeName, $primaryKey, $remoteTypeName);
- Relations::createRelations($typeName, $primaryKey, $remoteTypeName, $listRemotePrimaryKeys);
- // $listRelations = Relations::getRelations($typeName, $primaryKey, $remoteTypeName);
- // $totalRelations = count($listRelations);
- } catch (HttpException $e) {
- DBG::log($e);
- throw new Api_OwsException($e->getMessage(), $e->getCode(), null, Http::getStatusText($e->getCode()), 'request');
- } catch (Exception $e) {
- DBG::log($e);
- throw new Api_OwsException("User is not allowed to read relations from '{$typeName}.{$primaryKey}' to '{$remoteTypeName}'.\n" . $e->getMessage(), 501, null, 'AccessDenied', 'request');
- }
- header('Content-Type: application/json');
- echo json_encode([
- 'type' => "success",
- 'msg' => "done",
- // 'body' => [
- // 'relations' => $listRelations,
- // 'total' => $total,
- // ]
- ]);
- exit;
- }
- }
|