DeleteRelation.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. Lib::loadClass('Relations');
  3. class Api_Process_P5_DeleteRelation { // TODO: extends Api_ProcessBase
  4. static function run($args, $responseForm) {
  5. $typeName = (!empty($args['typeName'][0])) ? $args['typeName'][0] : '';
  6. if (!$typeName) throw new Api_OwsException("Missing value for 'typeName'", 501, null, 'MissingParameterValue', 'request');
  7. $primaryKey = (!empty($args['primaryKey'][0])) ? $args['primaryKey'][0] : '';
  8. if (!$primaryKey) throw new Api_OwsException("Missing value for 'primaryKey'", 501, null, 'MissingParameterValue', 'request');
  9. $remoteTypeName = (!empty($args['remoteTypeName'][0])) ? $args['remoteTypeName'][0] : '';
  10. if (!$remoteTypeName) throw new Api_OwsException("Missing value for 'remoteTypeName'", 501, null, 'MissingParameterValue', 'request');
  11. $listRemotePrimaryKeys = (!empty($args['primaryKey'])) ? $args['remotePrimaryKey'] : [];
  12. if (empty($listRemotePrimaryKeys)) throw new Api_OwsException("Missing value for 'remotePrimaryKey'", 501, null, 'MissingParameterValue', 'request');
  13. if (!Relations::isAllowedToDeleteRelation($userLogin, $typeName, $primaryKey, $remoteTypeName)) {
  14. throw new Api_OwsException("User is not allowed to create relation from '{$typeName}.{$primaryKey}' to '{$remoteTypeName}' ", 501, null, 'AccessDenied', 'request');
  15. }
  16. try {
  17. Relations::deleteRelations($typeName, $primaryKey, $remoteTypeName, $listRemotePrimaryKeys);
  18. } catch (Exception $e) {
  19. DBG::log($e);
  20. throw new Api_OwsException($e->getMessage(), 501, null, 'AccessDenied', 'request');
  21. }
  22. header('Content-Type: application/json');
  23. echo json_encode([
  24. 'type' => "success",
  25. 'msg' => "done",
  26. // 'body' => [
  27. // 'relations' => $listRelations,
  28. // 'total' => $total,
  29. // ]
  30. ]);
  31. exit;
  32. }
  33. }