getRouteParam('akteId'); $documentId = $request->getRouteParam('documentId'); $data = $request->getParsedBody(); if (!$akteId || !$documentId) { throw new BadRequest('Akte ID and Document ID are required'); } $pdo = $this->entityManager->getPDO(); // Build dynamic UPDATE with only provided fields $setClauses = []; $params = [ 'akteId' => $akteId, 'documentId' => $documentId ]; if (isset($data->hnr)) { if (!is_numeric($data->hnr)) { throw new BadRequest('hnr must be a number'); } $setClauses[] = "hnr = :hnr"; $params['hnr'] = (int)$data->hnr; } if (isset($data->syncstatus)) { $allowedStatuses = ['new', 'unclean', 'synced', 'failed', 'unsupported']; if (!in_array($data->syncstatus, $allowedStatuses)) { throw new BadRequest('Invalid syncstatus. Allowed: ' . implode(', ', $allowedStatuses)); } $setClauses[] = "syncstatus = :syncstatus"; $params['syncstatus'] = $data->syncstatus; } if (isset($data->lastSync)) { $setClauses[] = "last_sync = :lastSync"; $params['lastSync'] = $data->lastSync; } elseif (isset($data->updateLastSync) && $data->updateLastSync === true) { $setClauses[] = "last_sync = NOW()"; } if (empty($setClauses)) { throw new BadRequest('No fields to update. Provide: hnr, syncstatus, or lastSync'); } $sql = " UPDATE c_advoware_akten_dokumente SET " . implode(', ', $setClauses) . " WHERE c_advoware_akten_id = :akteId AND c_dokumente_id = :documentId AND deleted = 0 "; $sth = $pdo->prepare($sql); $sth->execute($params); if ($sth->rowCount() === 0) { throw new NotFound('Junction entry not found or no changes made'); } // Return updated data return ResponseComposer::json($this->getJunctionEntry($akteId, $documentId)); } private function getJunctionEntry(string $akteId, string $documentId): array { $pdo = $this->entityManager->getPDO(); $sql = " SELECT id as junctionId, c_advoware_akten_id as cAdvowareAktenId, c_dokumente_id as cDokumenteId, hnr, syncstatus, last_sync as lastSync FROM c_advoware_akten_dokumente WHERE c_advoware_akten_id = :akteId AND c_dokumente_id = :documentId AND deleted = 0 "; $sth = $pdo->prepare($sql); $sth->execute([ 'akteId' => $akteId, 'documentId' => $documentId ]); $result = $sth->fetch(\PDO::FETCH_ASSOC); if (!$result) { throw new NotFound('Junction entry not found'); } return $result; } }